octave-ruby 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/ext/octave_api/or-hash.cpp +2 -2
- data/ext/octave_api/or-struct_matrix.cpp +7 -2
- data/lib/octave/version.rb +1 -1
- data/test/driver/native/test_conversions.rb +27 -2
- metadata +2 -2
data/History.txt
CHANGED
data/ext/octave_api/or-hash.cpp
CHANGED
@@ -14,9 +14,9 @@ octave_value OR_Hash::to_octave()
|
|
14
14
|
keys.append(std::string(RSTRING(RARRAY(names)->ptr[i])->ptr));
|
15
15
|
}
|
16
16
|
|
17
|
-
Octave_map struct_matrix = Octave_map(dim_vector(
|
17
|
+
Octave_map struct_matrix = Octave_map(dim_vector(0, 1), Cell(keys));
|
18
18
|
for (i = 0; i < number_of_keys; i++) {
|
19
|
-
struct_matrix.contents(std::string(RSTRING(RARRAY(names)->ptr[i])->ptr))
|
19
|
+
struct_matrix.contents(std::string(RSTRING(RARRAY(names)->ptr[i])->ptr)) = OR_Variable(rb_hash_aref(ruby_val, rb_str_new2(RSTRING(RARRAY(names)->ptr[i])->ptr))).to_octave();
|
20
20
|
}
|
21
21
|
|
22
22
|
return struct_matrix;
|
@@ -13,10 +13,15 @@ VALUE OR_StructMatrix::to_ruby()
|
|
13
13
|
int i;
|
14
14
|
VALUE cells, row, cell;
|
15
15
|
|
16
|
-
if (number_of_columns == 1) {
|
16
|
+
if (number_of_rows == 0 && number_of_columns == 1) {
|
17
17
|
ruby_val = rb_hash_new();
|
18
18
|
for (i = 0; i < number_of_keys; i++) {
|
19
|
-
rb_hash_aset(ruby_val, rb_str_new2(keys[i].c_str()), OR_Variable(struct_matrix.contents(keys[i])
|
19
|
+
rb_hash_aset(ruby_val, rb_str_new2(keys[i].c_str()), OR_Variable(struct_matrix.contents(keys[i])).to_ruby());
|
20
|
+
}
|
21
|
+
} else if (number_of_rows == 1 && number_of_columns == 1) {
|
22
|
+
ruby_val = rb_hash_new();
|
23
|
+
for (i = 0; i < number_of_keys; i++) {
|
24
|
+
rb_hash_aset(ruby_val, rb_str_new2(keys[i].c_str()), OR_Variable(struct_matrix.contents(keys[i])(0)).to_ruby());
|
20
25
|
}
|
21
26
|
} else {
|
22
27
|
int number_of_arguments_to_struct_matrix = number_of_keys + 2;
|
data/lib/octave/version.rb
CHANGED
@@ -4,6 +4,7 @@ require 'octave'
|
|
4
4
|
require 'octave/driver/native/driver'
|
5
5
|
require 'rubygems'
|
6
6
|
require 'mocha'
|
7
|
+
require 'yaml'
|
7
8
|
|
8
9
|
class ConversionsTest < Test::Unit::TestCase
|
9
10
|
def setup
|
@@ -57,7 +58,7 @@ class ConversionsTest < Test::Unit::TestCase
|
|
57
58
|
assert_octave_and_ruby_equal "foo" => "bar"
|
58
59
|
assert_octave_and_ruby_equal "foo" => [1,2,3]
|
59
60
|
assert_octave_and_ruby_equal "foo" => { "bar" => [1,2,3, [4,5,6]] }
|
60
|
-
assert_octave_and_ruby_equal "foo" => { "bar" => [1,2,3, [4,5,6]], "baz" => "buz" }
|
61
|
+
assert_octave_and_ruby_equal "foo" => { "bar" => [1,2,3, [4,5,6]], "baz" => "buz", "bob" => [7,8,9] }
|
61
62
|
end
|
62
63
|
|
63
64
|
def test_should_convert_octave_matrix
|
@@ -153,4 +154,28 @@ class ConversionsTest < Test::Unit::TestCase
|
|
153
154
|
|
154
155
|
assert_equal %w(foo bar baz), to_octave_to_ruby(cell_matrix)
|
155
156
|
end
|
156
|
-
|
157
|
+
|
158
|
+
def test_hmm
|
159
|
+
struct_matrix = Octave::StructMatrix.new(17, 2, "name", "age", "married", "cats", "car")
|
160
|
+
17.times do |m|
|
161
|
+
2.times do |n|
|
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
|
+
|
180
|
+
end
|
181
|
+
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.3
|
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-02-
|
12
|
+
date: 2008-02-29 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|