daikini-octave-ruby 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +54 -0
- data/LICENSE.txt +674 -0
- data/Manifest.txt +39 -0
- data/README.txt +58 -0
- data/Rakefile +18 -0
- data/ext/octave_api/MANIFEST +4 -0
- data/ext/octave_api/Makefile +149 -0
- data/ext/octave_api/extconf.rb +30 -0
- data/ext/octave_api/octave-includes.h +11 -0
- data/ext/octave_api/octave-ruby.cpp +62 -0
- data/ext/octave_api/octave-ruby.h +18 -0
- data/ext/octave_api/octave_api.c +22 -0
- data/ext/octave_api/octave_api.h +13 -0
- data/ext/octave_api/or-array.cpp +56 -0
- data/ext/octave_api/or-array.h +20 -0
- data/ext/octave_api/or-boolean_matrix.cpp +61 -0
- data/ext/octave_api/or-boolean_matrix.h +20 -0
- data/ext/octave_api/or-cell_matrix.cpp +66 -0
- data/ext/octave_api/or-cell_matrix.h +22 -0
- data/ext/octave_api/or-hash.cpp +23 -0
- data/ext/octave_api/or-hash.h +19 -0
- data/ext/octave_api/or-matrix.cpp +89 -0
- data/ext/octave_api/or-matrix.h +22 -0
- data/ext/octave_api/or-string.cpp +13 -0
- data/ext/octave_api/or-string.h +22 -0
- data/ext/octave_api/or-struct_matrix.cpp +88 -0
- data/ext/octave_api/or-struct_matrix.h +22 -0
- data/ext/octave_api/or-variable.cpp +58 -0
- data/ext/octave_api/or-variable.h +22 -0
- data/lib/octave.rb +5 -0
- data/lib/octave/driver/native/driver.rb +26 -0
- data/lib/octave/engine.rb +75 -0
- data/lib/octave/matrix.rb +84 -0
- data/lib/octave/version.rb +14 -0
- data/octave-ruby.gemspec +21 -0
- data/setup.rb +1333 -0
- data/test/driver/native/test_conversions.rb +203 -0
- data/test/driver/native/test_driver.rb +32 -0
- data/test/test_engine.rb +50 -0
- metadata +99 -0
data/Manifest.txt
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
History.txt
|
2
|
+
LICENSE.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
ext/octave_api/MANIFEST
|
7
|
+
ext/octave_api/Makefile
|
8
|
+
ext/octave_api/extconf.rb
|
9
|
+
ext/octave_api/octave-includes.h
|
10
|
+
ext/octave_api/octave-ruby.cpp
|
11
|
+
ext/octave_api/octave-ruby.h
|
12
|
+
ext/octave_api/octave_api.c
|
13
|
+
ext/octave_api/octave_api.h
|
14
|
+
ext/octave_api/or-array.cpp
|
15
|
+
ext/octave_api/or-array.h
|
16
|
+
ext/octave_api/or-boolean_matrix.cpp
|
17
|
+
ext/octave_api/or-boolean_matrix.h
|
18
|
+
ext/octave_api/or-cell_matrix.cpp
|
19
|
+
ext/octave_api/or-cell_matrix.h
|
20
|
+
ext/octave_api/or-hash.cpp
|
21
|
+
ext/octave_api/or-hash.h
|
22
|
+
ext/octave_api/or-matrix.cpp
|
23
|
+
ext/octave_api/or-matrix.h
|
24
|
+
ext/octave_api/or-string.cpp
|
25
|
+
ext/octave_api/or-string.h
|
26
|
+
ext/octave_api/or-struct_matrix.cpp
|
27
|
+
ext/octave_api/or-struct_matrix.h
|
28
|
+
ext/octave_api/or-variable.cpp
|
29
|
+
ext/octave_api/or-variable.h
|
30
|
+
lib/octave.rb
|
31
|
+
lib/octave/driver/native/driver.rb
|
32
|
+
lib/octave/engine.rb
|
33
|
+
lib/octave/matrix.rb
|
34
|
+
lib/octave/version.rb
|
35
|
+
octave-ruby.gemspec
|
36
|
+
setup.rb
|
37
|
+
test/driver/native/test_conversions.rb
|
38
|
+
test/driver/native/test_driver.rb
|
39
|
+
test/test_engine.rb
|
data/README.txt
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
octave-ruby
|
2
|
+
http://octave-ruby.rubyforge.org/
|
3
|
+
jonathan@daikini.com
|
4
|
+
A big thank you to Lipomics Technologies, Inc. http://www.lipomics.com for sponsoring this project.
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
A Ruby interface to the Octave interpreted language.
|
9
|
+
|
10
|
+
== FEATURES:
|
11
|
+
|
12
|
+
* Data type conversion between Octave and Ruby String, Boolean, Nil and Numeric values
|
13
|
+
* Matrix, CellMatrix and StructMatrix helper classes for working with Octave matrices
|
14
|
+
|
15
|
+
== USAGE:
|
16
|
+
|
17
|
+
require 'octave'
|
18
|
+
|
19
|
+
engine = Octave::Engine.new
|
20
|
+
engine.eval "123.456 * 789.101112"
|
21
|
+
engine.rand(10)
|
22
|
+
|
23
|
+
matrix = Octave::Matrix.new(20, 400)
|
24
|
+
20.times { |m| 400.times { |n| matrix[m, n] = rand } }
|
25
|
+
engine.put_variable("m", matrix)
|
26
|
+
|
27
|
+
engine.save "/tmp/20_x_400_matrix"
|
28
|
+
|
29
|
+
== REQUIREMENTS:
|
30
|
+
|
31
|
+
* Octave
|
32
|
+
* GCC or some other compiler to build the included extension
|
33
|
+
* Mocha (For testing only)
|
34
|
+
|
35
|
+
== INSTALL:
|
36
|
+
|
37
|
+
Simply do the following, after installing Octave:
|
38
|
+
|
39
|
+
* ruby setup.rb config
|
40
|
+
* ruby setup.rb setup
|
41
|
+
* ruby setup.rb install
|
42
|
+
|
43
|
+
Alternatively, you can download and install the RubyGem package for
|
44
|
+
octave-ruby (you must have RubyGems and Octave installed, first):
|
45
|
+
|
46
|
+
* gem install octave-ruby
|
47
|
+
|
48
|
+
If you have Octave installed in a non-standard location, you can specify the location of the include and lib files by doing:
|
49
|
+
|
50
|
+
* gem install octave-ruby -- --with-octave-include=/usr/local/include/octave-3.0.0/octave \
|
51
|
+
--with-octave-lib=/usr/local/lib/octave-3.0.0 \
|
52
|
+
--with-dep-include=/usr/local/include/octave-3.0.0
|
53
|
+
|
54
|
+
== LICENSE
|
55
|
+
|
56
|
+
octave-ruby is licensed under the GPL License.
|
57
|
+
|
58
|
+
Copyright (c) 2007 Jonathan Younger <jonathan.younger@lipomics.com>
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/octave/version.rb'
|
6
|
+
|
7
|
+
Hoe.new('octave-ruby', Octave::Version::STRING) do |p|
|
8
|
+
p.rubyforge_name = 'octave-ruby'
|
9
|
+
p.author = ["Jonathan Younger"]
|
10
|
+
p.email = ["jonathan@daikini.com"]
|
11
|
+
p.summary = "A Ruby interface to the Octave interpreted language."
|
12
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
13
|
+
p.url = "http://octave-ruby.rubyforge.org/"
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
+
p.spec_extras["extensions"] = "ext/octave_api/extconf.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,149 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
prefix = $(DESTDIR)/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr
|
11
|
+
exec_prefix = $(prefix)
|
12
|
+
sitedir = $(DESTDIR)/Library/Ruby/Site
|
13
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
14
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
15
|
+
dvidir = $(docdir)
|
16
|
+
datarootdir = $(prefix)/share
|
17
|
+
archdir = $(rubylibdir)/$(arch)
|
18
|
+
sbindir = $(exec_prefix)/sbin
|
19
|
+
psdir = $(docdir)
|
20
|
+
localedir = $(datarootdir)/locale
|
21
|
+
htmldir = $(docdir)
|
22
|
+
datadir = $(datarootdir)
|
23
|
+
includedir = $(prefix)/include
|
24
|
+
infodir = $(DESTDIR)/usr/share/info
|
25
|
+
sysconfdir = $(prefix)/etc
|
26
|
+
mandir = $(DESTDIR)/usr/share/man
|
27
|
+
libdir = $(exec_prefix)/lib
|
28
|
+
sharedstatedir = $(prefix)/com
|
29
|
+
oldincludedir = $(DESTDIR)/usr/include
|
30
|
+
pdfdir = $(docdir)
|
31
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
32
|
+
bindir = $(exec_prefix)/bin
|
33
|
+
localstatedir = $(prefix)/var
|
34
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
35
|
+
libexecdir = $(exec_prefix)/libexec
|
36
|
+
|
37
|
+
CC = gcc
|
38
|
+
LIBRUBY = $(LIBRUBY_SO)
|
39
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
40
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
41
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)
|
42
|
+
|
43
|
+
RUBY_EXTCONF_H =
|
44
|
+
CFLAGS = -fno-common -arch i386 -Os -pipe -fno-common
|
45
|
+
INCFLAGS = -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I.
|
46
|
+
CPPFLAGS = -DHAVE_OCTAVE_H -I/Applications/Octave.app/Contents/Resources/include -I/Applications/Octave.app/Contents/Resources/lib -I/Applications/Octave.app/Contents/Resources/include/octave-3.0.2/octave -I/Applications/Octave.app/Contents/Resources/lib/octave-3.0.2 -I/Applications/Octave.app/Contents/Resources/include/octave-3.0.2
|
47
|
+
CXXFLAGS = $(CFLAGS)
|
48
|
+
DLDFLAGS = -L. -arch i386
|
49
|
+
LDSHARED = g++ -pipe -bundle
|
50
|
+
AR = ar
|
51
|
+
EXEEXT =
|
52
|
+
|
53
|
+
RUBY_INSTALL_NAME = ruby
|
54
|
+
RUBY_SO_NAME = ruby
|
55
|
+
arch = universal-darwin9.0
|
56
|
+
sitearch = universal-darwin9.0
|
57
|
+
ruby_version = 1.8
|
58
|
+
ruby = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
|
59
|
+
RUBY = $(ruby)
|
60
|
+
RM = rm -f
|
61
|
+
MAKEDIRS = mkdir -p
|
62
|
+
INSTALL = /usr/bin/install -c
|
63
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
64
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
65
|
+
COPY = cp
|
66
|
+
|
67
|
+
#### End of system configuration section. ####
|
68
|
+
|
69
|
+
preload =
|
70
|
+
|
71
|
+
libpath = . $(libdir) /Applications/Octave.app/Contents/Resources/lib /Applications/Octave.app/Contents/Resources/lib/octave-3.0.2
|
72
|
+
LIBPATH = -L"." -L"$(libdir)" -L"/Applications/Octave.app/Contents/Resources/lib" -L"/Applications/Octave.app/Contents/Resources/lib/octave-3.0.2"
|
73
|
+
DEFFILE =
|
74
|
+
|
75
|
+
CLEANFILES = mkmf.log
|
76
|
+
DISTCLEANFILES =
|
77
|
+
|
78
|
+
extout =
|
79
|
+
extout_prefix =
|
80
|
+
target_prefix =
|
81
|
+
LOCAL_LIBS =
|
82
|
+
LIBS = $(LIBRUBYARG_SHARED) -loctinterp -lcruft -loctave -lpthread -ldl -lm
|
83
|
+
SRCS = octave_api.c octave-ruby.cpp or-array.cpp or-boolean_matrix.cpp or-cell_matrix.cpp or-hash.cpp or-matrix.cpp or-string.cpp or-struct_matrix.cpp or-variable.cpp
|
84
|
+
OBJS = octave_api.o octave-ruby.o or-array.o or-boolean_matrix.o or-cell_matrix.o or-hash.o or-matrix.o or-string.o or-struct_matrix.o or-variable.o
|
85
|
+
TARGET = octave_api
|
86
|
+
DLLIB = $(TARGET).bundle
|
87
|
+
EXTSTATIC =
|
88
|
+
STATIC_LIB =
|
89
|
+
|
90
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
91
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
92
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
93
|
+
|
94
|
+
TARGET_SO = $(DLLIB)
|
95
|
+
CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
|
96
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
97
|
+
|
98
|
+
all: $(DLLIB)
|
99
|
+
static: $(STATIC_LIB)
|
100
|
+
|
101
|
+
clean:
|
102
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
103
|
+
|
104
|
+
distclean: clean
|
105
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
106
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
107
|
+
|
108
|
+
realclean: distclean
|
109
|
+
install: install-so install-rb
|
110
|
+
|
111
|
+
install-so: $(RUBYARCHDIR)
|
112
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
113
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
114
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
115
|
+
install-rb: pre-install-rb install-rb-default
|
116
|
+
install-rb-default: pre-install-rb-default
|
117
|
+
pre-install-rb: Makefile
|
118
|
+
pre-install-rb-default: Makefile
|
119
|
+
$(RUBYARCHDIR):
|
120
|
+
$(MAKEDIRS) $@
|
121
|
+
|
122
|
+
site-install: site-install-so site-install-rb
|
123
|
+
site-install-so: install-so
|
124
|
+
site-install-rb: install-rb
|
125
|
+
|
126
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
127
|
+
|
128
|
+
.cc.o:
|
129
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
130
|
+
|
131
|
+
.cxx.o:
|
132
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
133
|
+
|
134
|
+
.cpp.o:
|
135
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
136
|
+
|
137
|
+
.C.o:
|
138
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
139
|
+
|
140
|
+
.c.o:
|
141
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
142
|
+
|
143
|
+
$(DLLIB): $(OBJS)
|
144
|
+
@-$(RM) $@
|
145
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
$(OBJS): ruby.h defines.h
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Loads mkmf which is used to make makefiles for Ruby extensions
|
2
|
+
require 'mkmf'
|
3
|
+
|
4
|
+
octave_dirs = dir_config( "octave", "/usr/local/octave/include", "/usr/local/octave/lib" )
|
5
|
+
dep_dirs = dir_config( "dep", octave_dirs.first.split(File::SEPARATOR)[0..-3].join(File::SEPARATOR), octave_dirs.last.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR) )
|
6
|
+
|
7
|
+
if have_header("octave.h" ) &&
|
8
|
+
have_library("octave") &&
|
9
|
+
have_library("cruft") &&
|
10
|
+
have_library("octinterp", "octave_main" )
|
11
|
+
|
12
|
+
if Config::CONFIG["arch"] =~ /-darwin\d/
|
13
|
+
CONFIG['LDSHARED'] = "g++ -pipe -bundle"
|
14
|
+
if octave_dirs.any?
|
15
|
+
octave_dirs << File.dirname(octave_dirs.first)
|
16
|
+
octave_includes = (dep_dirs + octave_dirs).collect { |dir| "-I#{dir}" }.join(" ")
|
17
|
+
with_cppflags(octave_includes) { true }
|
18
|
+
end
|
19
|
+
else
|
20
|
+
CONFIG['LDSHARED'] = "g++ -shared"
|
21
|
+
if octave_dirs.any?
|
22
|
+
octave_dirs << File.dirname(octave_dirs.first)
|
23
|
+
octave_dirs << "/usr/local/include"
|
24
|
+
octave_includes = (dep_dirs + octave_dirs).collect { |dir| "-I#{dir}" }.join(" ")
|
25
|
+
with_cppflags(octave_includes) { true }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
create_makefile( "octave_api" )
|
30
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#include "octave/config.h"
|
2
|
+
#include "octave.h"
|
3
|
+
#include "symtab.h"
|
4
|
+
#include "parse.h"
|
5
|
+
#include "unwind-prot.h"
|
6
|
+
#include "toplev.h"
|
7
|
+
#include "error.h"
|
8
|
+
#include "variables.h"
|
9
|
+
#include "sighandlers.h"
|
10
|
+
#include "sysdep.h"
|
11
|
+
#include "ov-struct.h"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#include "octave-ruby.h"
|
2
|
+
#include "octave-includes.h"
|
3
|
+
#include "or-variable.h"
|
4
|
+
|
5
|
+
void initialize_octave()
|
6
|
+
{
|
7
|
+
char *argv[2];
|
8
|
+
argv[0] = "octave-ruby";
|
9
|
+
argv[1] = "-q";
|
10
|
+
octave_main(2,argv,1);
|
11
|
+
bind_internal_variable("crash_dumps_octave_core", false);
|
12
|
+
}
|
13
|
+
|
14
|
+
extern void recover_from_exception(void)
|
15
|
+
{
|
16
|
+
unwind_protect::run_all();
|
17
|
+
can_interrupt = true;
|
18
|
+
octave_interrupt_immediately = 0;
|
19
|
+
octave_interrupt_state = 0;
|
20
|
+
octave_allocation_error = 0;
|
21
|
+
}
|
22
|
+
|
23
|
+
VALUE or_feval(VALUE function_name, VALUE arguments)
|
24
|
+
{
|
25
|
+
VALUE ruby_val = Qnil;
|
26
|
+
int i, n;
|
27
|
+
octave_value_list argList;
|
28
|
+
|
29
|
+
n = RARRAY(arguments)->len;
|
30
|
+
|
31
|
+
for (i = 0; i < n; i++) {
|
32
|
+
argList(i) = OR_Variable(RARRAY(arguments)->ptr[i]).to_octave();
|
33
|
+
}
|
34
|
+
|
35
|
+
if (octave_set_current_context) {
|
36
|
+
unwind_protect::run_all();
|
37
|
+
raw_mode(0);
|
38
|
+
}
|
39
|
+
|
40
|
+
can_interrupt = true;
|
41
|
+
octave_initialized = true;
|
42
|
+
|
43
|
+
try {
|
44
|
+
curr_sym_tab = top_level_sym_tab;
|
45
|
+
reset_error_handler();
|
46
|
+
|
47
|
+
octave_value_list val = feval(std::string(RSTRING(function_name)->ptr), argList, 1);
|
48
|
+
if(val.length() > 0 && val(0).is_defined()) {
|
49
|
+
ruby_val = OR_Variable(val(0)).to_ruby();
|
50
|
+
}
|
51
|
+
} catch (octave_interrupt_exception) {
|
52
|
+
recover_from_exception();
|
53
|
+
error_state = -2;
|
54
|
+
} catch (std::bad_alloc) {
|
55
|
+
recover_from_exception();
|
56
|
+
error_state = -3;
|
57
|
+
}
|
58
|
+
|
59
|
+
octave_initialized = false;
|
60
|
+
|
61
|
+
return(ruby_val);
|
62
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#ifndef EXECUTECALL_H_INCLUDED_
|
2
|
+
#define EXECUTECALL_H_INCLUDED_
|
3
|
+
|
4
|
+
#include "ruby.h"
|
5
|
+
|
6
|
+
#ifdef __cplusplus
|
7
|
+
extern "C"
|
8
|
+
{
|
9
|
+
#endif
|
10
|
+
|
11
|
+
extern VALUE or_feval(VALUE function_name, VALUE arguments);
|
12
|
+
extern void initialize_octave();
|
13
|
+
|
14
|
+
#ifdef __cplusplus /* extern "C" */
|
15
|
+
}
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#endif /*EXECUTECALL_H_INCLUDED_ */
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#include "octave_api.h"
|
2
|
+
#include "ruby.h"
|
3
|
+
#include "octave-ruby.h"
|
4
|
+
|
5
|
+
// Defining a space for information and references about the module to be stored internally
|
6
|
+
VALUE OCTAVE_API = Qnil;
|
7
|
+
|
8
|
+
// The initialization method for this module
|
9
|
+
void Init_octave_api() {
|
10
|
+
OCTAVE_API = rb_define_module("Octave");
|
11
|
+
OCTAVE_API = rb_define_module_under(OCTAVE_API, "Driver");
|
12
|
+
OCTAVE_API = rb_define_module_under(OCTAVE_API, "Native");
|
13
|
+
OCTAVE_API = rb_define_module_under(OCTAVE_API, "API");
|
14
|
+
rb_define_module_function(OCTAVE_API, "feval", feval, 2);
|
15
|
+
|
16
|
+
initialize_octave();
|
17
|
+
}
|
18
|
+
|
19
|
+
VALUE feval(VALUE self, VALUE function_name, VALUE arguments)
|
20
|
+
{
|
21
|
+
return or_feval(function_name, arguments);
|
22
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
|
3
|
+
#ifdef __cplusplus
|
4
|
+
extern "C" {
|
5
|
+
#endif
|
6
|
+
|
7
|
+
// Prototype for the initialization method - Ruby calls this, not you
|
8
|
+
void Init_octave_api();
|
9
|
+
static VALUE feval(VALUE self, VALUE function_name, VALUE arguments);
|
10
|
+
|
11
|
+
#ifdef __cplusplus
|
12
|
+
}
|
13
|
+
#endif
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#include "or-array.h"
|
2
|
+
#include "or-variable.h"
|
3
|
+
|
4
|
+
OR_Array::~OR_Array() {}
|
5
|
+
|
6
|
+
octave_value OR_Array::to_octave()
|
7
|
+
{
|
8
|
+
int row_index;
|
9
|
+
int number_of_rows = RARRAY(ruby_val)->len;
|
10
|
+
VALUE cell;
|
11
|
+
|
12
|
+
if (should_convert_to_cell_matrix()) {
|
13
|
+
Cell matrix = Cell(number_of_rows, 1);
|
14
|
+
|
15
|
+
for (row_index = 0; row_index < number_of_rows; row_index++) {
|
16
|
+
cell = RARRAY(ruby_val)->ptr[row_index];
|
17
|
+
matrix(row_index, 0) = OR_Variable(cell).to_octave();
|
18
|
+
}
|
19
|
+
|
20
|
+
return matrix;
|
21
|
+
} else {
|
22
|
+
Matrix matrix = Matrix(number_of_rows, 1);
|
23
|
+
|
24
|
+
for (row_index = 0; row_index < number_of_rows; row_index++) {
|
25
|
+
cell = RARRAY(ruby_val)->ptr[row_index];
|
26
|
+
|
27
|
+
if (rb_type(cell) == T_FLOAT) {
|
28
|
+
matrix(row_index, 0) = RFLOAT(cell)->value;
|
29
|
+
} else if (rb_type(cell) == T_FIXNUM) {
|
30
|
+
matrix(row_index, 0) = FIX2LONG(cell);
|
31
|
+
} else {
|
32
|
+
matrix(row_index, 0) = octave_NaN;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
return matrix;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
bool OR_Array::should_convert_to_cell_matrix()
|
41
|
+
{
|
42
|
+
int row_index;
|
43
|
+
VALUE value;
|
44
|
+
VALUE type;
|
45
|
+
int number_of_rows = RARRAY(ruby_val)->len;
|
46
|
+
|
47
|
+
for (row_index = 0; row_index < number_of_rows; row_index++) {
|
48
|
+
value = RARRAY(ruby_val)->ptr[row_index];
|
49
|
+
type = rb_type(value);
|
50
|
+
if (type != T_FLOAT && type != T_FIXNUM && value != Qnil) {
|
51
|
+
return true;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
return false;
|
56
|
+
}
|