octave-ruby 1.0.3 → 1.0.4
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 +5 -0
- data/Manifest.txt +2 -0
- data/ext/octave_api/Makefile +6 -6
- 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-variable.cpp +3 -0
- data/lib/octave/version.rb +1 -1
- data/test/driver/native/test_conversions.rb +4 -22
- metadata +6 -4
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -13,6 +13,8 @@ ext/octave_api/octave_api.c
|
|
13
13
|
ext/octave_api/octave_api.h
|
14
14
|
ext/octave_api/or-array.cpp
|
15
15
|
ext/octave_api/or-array.h
|
16
|
+
ext/octave_api/or-boolean_matrix.cpp
|
17
|
+
ext/octave_api/or-boolean_matrix.h
|
16
18
|
ext/octave_api/or-cell_matrix.cpp
|
17
19
|
ext/octave_api/or-cell_matrix.h
|
18
20
|
ext/octave_api/or-hash.cpp
|
data/ext/octave_api/Makefile
CHANGED
@@ -43,7 +43,7 @@ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)
|
|
43
43
|
RUBY_EXTCONF_H =
|
44
44
|
CFLAGS = -fno-common -arch i386 -Os -pipe -fno-common
|
45
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.
|
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.1/octave -I/Applications/Octave.app/Contents/Resources/lib/octave-3.0.1 -I/Applications/Octave.app/Contents/Resources/include/octave-3.0.1
|
47
47
|
CXXFLAGS = $(CFLAGS)
|
48
48
|
DLDFLAGS = -L. -arch i386
|
49
49
|
LDSHARED = g++ -pipe -bundle
|
@@ -68,8 +68,8 @@ COPY = cp
|
|
68
68
|
|
69
69
|
preload =
|
70
70
|
|
71
|
-
libpath = . $(libdir) /Applications/Octave.app/Contents/Resources/lib /Applications/Octave.app/Contents/Resources/lib/octave-3.0.
|
72
|
-
LIBPATH = -L"." -L"$(libdir)" -L"/Applications/Octave.app/Contents/Resources/lib" -L"/Applications/Octave.app/Contents/Resources/lib/octave-3.0.
|
71
|
+
libpath = . $(libdir) /Applications/Octave.app/Contents/Resources/lib /Applications/Octave.app/Contents/Resources/lib/octave-3.0.1
|
72
|
+
LIBPATH = -L"." -L"$(libdir)" -L"/Applications/Octave.app/Contents/Resources/lib" -L"/Applications/Octave.app/Contents/Resources/lib/octave-3.0.1"
|
73
73
|
DEFFILE =
|
74
74
|
|
75
75
|
CLEANFILES = mkmf.log
|
@@ -79,9 +79,9 @@ extout =
|
|
79
79
|
extout_prefix =
|
80
80
|
target_prefix =
|
81
81
|
LOCAL_LIBS =
|
82
|
-
LIBS = $(LIBRUBYARG_SHARED) -
|
83
|
-
SRCS = octave_api.c octave-ruby.cpp or-array.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-cell_matrix.o or-hash.o or-matrix.o or-string.o or-struct_matrix.o or-variable.o
|
82
|
+
LIBS = $(LIBRUBYARG_SHARED) -lcruft -loctave -loctinterp -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
85
|
TARGET = octave_api
|
86
86
|
DLLIB = $(TARGET).bundle
|
87
87
|
EXTSTATIC =
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#include "or-boolean_matrix.h"
|
2
|
+
|
3
|
+
OR_BooleanMatrix::~OR_BooleanMatrix() {}
|
4
|
+
|
5
|
+
VALUE OR_BooleanMatrix::to_ruby()
|
6
|
+
{
|
7
|
+
Matrix matrix;
|
8
|
+
MArray<double> values;
|
9
|
+
double cell;
|
10
|
+
int i, number_of_values;
|
11
|
+
VALUE argv[2];
|
12
|
+
|
13
|
+
matrix = octave_val.matrix_value();
|
14
|
+
int number_of_rows = matrix.rows();
|
15
|
+
int number_of_columns = matrix.columns();
|
16
|
+
|
17
|
+
if (number_of_rows == 1) {
|
18
|
+
values = matrix.row(0);
|
19
|
+
} else if (number_of_columns == 1) {
|
20
|
+
values = matrix.column(0);
|
21
|
+
} else {
|
22
|
+
argv[0] = INT2FIX(number_of_rows);
|
23
|
+
argv[1] = INT2FIX(number_of_columns);
|
24
|
+
ruby_val = rb_class_new_instance(2, argv, rb_path2class("Octave::Matrix"));
|
25
|
+
|
26
|
+
int row_index, column_index = 0;
|
27
|
+
VALUE cells, row;
|
28
|
+
cells = rb_ary_new2(number_of_rows);
|
29
|
+
for (row_index = 0; row_index < number_of_rows; row_index++) {
|
30
|
+
row = rb_ary_new2(number_of_columns);
|
31
|
+
values = matrix.row(row_index);
|
32
|
+
|
33
|
+
for (column_index = 0; column_index < number_of_columns; column_index++) {
|
34
|
+
cell = values(column_index);
|
35
|
+
if (xisnan(cell) || octave_is_NA(cell)) {
|
36
|
+
rb_ary_push(row, Qnil);
|
37
|
+
} else {
|
38
|
+
rb_ary_push(row, (int(cell) == 1 ? Qtrue : Qfalse));
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
rb_ary_push(cells, row);
|
43
|
+
}
|
44
|
+
|
45
|
+
rb_iv_set(ruby_val, "@cells", cells);
|
46
|
+
return ruby_val;
|
47
|
+
}
|
48
|
+
|
49
|
+
number_of_values = values.length();
|
50
|
+
ruby_val = rb_ary_new2(number_of_values);
|
51
|
+
for (i = 0; i < number_of_values; i++) {
|
52
|
+
cell = values(i);
|
53
|
+
if (xisnan(cell) || octave_is_NA(cell)) {
|
54
|
+
rb_ary_push(ruby_val, Qnil);
|
55
|
+
} else {
|
56
|
+
rb_ary_push(ruby_val, (int(cell) == 1 ? Qtrue : Qfalse));
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
return ruby_val;
|
61
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifndef OR_BOOLEAN_MATRIX_DEFINED_H_
|
2
|
+
#define OR_BOOLEAN_MATRIX_DEFINED_H_
|
3
|
+
|
4
|
+
#include "ruby.h"
|
5
|
+
#include "octave-includes.h"
|
6
|
+
|
7
|
+
class OR_BooleanMatrix
|
8
|
+
{
|
9
|
+
private:
|
10
|
+
VALUE ruby_val;
|
11
|
+
octave_value octave_val;
|
12
|
+
|
13
|
+
public:
|
14
|
+
OR_BooleanMatrix(octave_value o) : octave_val(o) { };
|
15
|
+
~OR_BooleanMatrix();
|
16
|
+
|
17
|
+
VALUE to_ruby();
|
18
|
+
};
|
19
|
+
|
20
|
+
#endif /* OR_BOOLEAN_MATRIX_DEFINED_H_ */
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#include "or-variable.h"
|
2
2
|
#include "or-string.h"
|
3
3
|
#include "or-matrix.h"
|
4
|
+
#include "or-boolean_matrix.h"
|
4
5
|
#include "or-struct_matrix.h"
|
5
6
|
#include "or-cell_matrix.h"
|
6
7
|
#include "or-array.h"
|
@@ -12,6 +13,8 @@ VALUE OR_Variable::to_ruby()
|
|
12
13
|
{
|
13
14
|
if (octave_val.is_string()) {
|
14
15
|
return OR_String(octave_val).to_ruby();
|
16
|
+
} else if (octave_val.is_bool_matrix()) {
|
17
|
+
return OR_BooleanMatrix(octave_val).to_ruby();
|
15
18
|
} else if (octave_val.is_bool_type()) {
|
16
19
|
return (octave_val.bool_value() ? Qtrue : Qfalse);
|
17
20
|
} else if (octave_val.is_cell()) {
|
data/lib/octave/version.rb
CHANGED
@@ -155,27 +155,9 @@ class ConversionsTest < Test::Unit::TestCase
|
|
155
155
|
assert_equal %w(foo bar baz), to_octave_to_ruby(cell_matrix)
|
156
156
|
end
|
157
157
|
|
158
|
-
def
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
struct_matrix[m, n]["name"] = "Bob #{m}.#{n}"
|
163
|
-
struct_matrix[m, n]["age"] = (rand * 100).to_i
|
164
|
-
struct_matrix[m, n]["married"] = (rand > 0.5)
|
165
|
-
struct_matrix[m, n]["cats"] = { "name" => "Kitty #{m}.#{n}" }
|
166
|
-
struct_matrix[m, n]["car"] = nil
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
data = {
|
171
|
-
"foo" => struct_matrix,
|
172
|
-
"bar" => [1,2,3,4],
|
173
|
-
"baz" => struct_matrix
|
174
|
-
}
|
175
|
-
|
176
|
-
@driver.put_variable "data", data
|
177
|
-
@driver.feval "save", "-V7", "/tmp/hmm.mat", "data"
|
178
|
-
# assert_octave_and_ruby_equal data
|
179
|
-
|
158
|
+
def test_should_convert_boolean_matrix
|
159
|
+
assert_octave_and_ruby_equal [true, false, true]
|
160
|
+
boolean_matrix = @driver.feval "eval", "x = [1,2]; (x > 2 | x < 2)"
|
161
|
+
assert_equal [true, false], boolean_matrix
|
180
162
|
end
|
181
163
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octave-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Younger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-05-14 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.5.
|
22
|
+
version: 1.5.1
|
23
23
|
version:
|
24
24
|
description: "== USAGE: require 'octave' engine = Octave::Engine.new engine.eval \"123.456 * 789.101112\" engine.rand(10) matrix = Octave::Matrix.new(20, 400) 20.times { |m| 400.times { |n| matrix[m, n] = rand } } engine.put_variable(\"m\", matrix) engine.save \"/tmp/20_x_400_matrix\" == REQUIREMENTS: * Octave * GCC or some other compiler to build the included extension * Mocha (For testing only)"
|
25
25
|
email:
|
@@ -49,6 +49,8 @@ files:
|
|
49
49
|
- ext/octave_api/octave_api.h
|
50
50
|
- ext/octave_api/or-array.cpp
|
51
51
|
- ext/octave_api/or-array.h
|
52
|
+
- ext/octave_api/or-boolean_matrix.cpp
|
53
|
+
- ext/octave_api/or-boolean_matrix.h
|
52
54
|
- ext/octave_api/or-cell_matrix.cpp
|
53
55
|
- ext/octave_api/or-cell_matrix.h
|
54
56
|
- ext/octave_api/or-hash.cpp
|
@@ -94,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
96
|
requirements: []
|
95
97
|
|
96
98
|
rubyforge_project: octave-ruby
|
97
|
-
rubygems_version: 1.
|
99
|
+
rubygems_version: 1.1.1
|
98
100
|
signing_key:
|
99
101
|
specification_version: 2
|
100
102
|
summary: A Ruby interface to the Octave interpreted language.
|