daikini-octave-ruby 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,203 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + "/../../../lib"
|
2
|
+
require 'test/unit'
|
3
|
+
require 'octave'
|
4
|
+
require 'octave/driver/native/driver'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'mocha'
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
class ConversionsTest < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@driver = Octave::Driver::Native::Driver.new
|
12
|
+
@driver.feval "eval", "function r = to_octave(val); r = val; endfunction"
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_octave_to_ruby(value)
|
16
|
+
@driver.feval "to_octave", value
|
17
|
+
end
|
18
|
+
|
19
|
+
def assert_octave_and_ruby_equal(value)
|
20
|
+
result = to_octave_to_ruby(value)
|
21
|
+
assert_equal value, result
|
22
|
+
assert_equal value.class, result.class
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_convert_string
|
26
|
+
assert_octave_and_ruby_equal "foo"
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_convert_true
|
30
|
+
assert_octave_and_ruby_equal true
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_convert_false
|
34
|
+
assert_octave_and_ruby_equal false
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_convert_nil
|
38
|
+
assert_octave_and_ruby_equal nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_convert_float
|
42
|
+
assert_octave_and_ruby_equal 12.345
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_convert_fixnum
|
46
|
+
# Fixnums are sent to and returned from Octave as Float
|
47
|
+
result = to_octave_to_ruby(12345)
|
48
|
+
assert_equal 12345.0, result
|
49
|
+
assert_instance_of Float, result
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_convert_array_from_and_to
|
53
|
+
assert_octave_and_ruby_equal [1, nil, 3.0]
|
54
|
+
assert_octave_and_ruby_equal [1, "2", false, ["foo", "bar", "baz"]]
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_convert_hash_from_and_to
|
58
|
+
assert_octave_and_ruby_equal "foo" => "bar"
|
59
|
+
assert_octave_and_ruby_equal "foo" => [1,2,3]
|
60
|
+
assert_octave_and_ruby_equal "foo" => { "bar" => [1,2,3, [4,5,6]] }
|
61
|
+
assert_octave_and_ruby_equal "foo" => { "bar" => [1,2,3, [4,5,6]], "baz" => "buz", "bob" => [7,8,9] }
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_should_be_able_to_reference_structure_fields_from_hash
|
65
|
+
hash = { "foo" => { "bar" => [1,2,3, [4,5,6]] }, "baz" => { "buz" => [7,8,9] } }
|
66
|
+
@driver.put_variable "hash", hash
|
67
|
+
assert_equal hash["foo"]["bar"], @driver.feval("eval", "hash.foo.bar")
|
68
|
+
assert_equal hash["baz"]["buz"], @driver.feval("eval", "hash.baz.buz")
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_should_be_able_to_reference_structure_fields_from_octave_struct_matrix
|
72
|
+
bar_matrix = Octave::StructMatrix.new(1, 1, "bar")
|
73
|
+
bar_matrix[0,0]["bar"] = [1,2,3, [4,5,6]]
|
74
|
+
|
75
|
+
struct_matrix = Octave::StructMatrix.new(1, 1, "foo")
|
76
|
+
struct_matrix[0,0]["foo"] = bar_matrix
|
77
|
+
|
78
|
+
@driver.put_variable "struct_matrix", struct_matrix
|
79
|
+
assert_equal [1,2,3, [4,5,6]], @driver.feval("eval", "struct_matrix.foo.bar")
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_should_convert_octave_matrix
|
83
|
+
matrix = Octave::Matrix.new(3, 3)
|
84
|
+
3.times { |m| 3.times { |n| matrix[m, n] = rand } }
|
85
|
+
matrix[1, 1] = nil
|
86
|
+
|
87
|
+
assert_octave_and_ruby_equal matrix
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_should_convert_a_0x0_octave_matrix_to_an_empty_array
|
91
|
+
matrix = Octave::Matrix.new(0, 0)
|
92
|
+
|
93
|
+
expected_array = []
|
94
|
+
result = to_octave_to_ruby(matrix)
|
95
|
+
|
96
|
+
assert_equal expected_array, result
|
97
|
+
assert_instance_of Array, result
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_should_convert_an_empty_ruby_array
|
101
|
+
assert_octave_and_ruby_equal []
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_should_convert_a_1xn_octave_matrix_to_an_octave_matrix
|
105
|
+
matrix = Octave::Matrix.new(1, 3)
|
106
|
+
matrix[0, 0] = 1
|
107
|
+
matrix[0, 1] = 2
|
108
|
+
matrix[0, 2] = 3
|
109
|
+
|
110
|
+
result = @driver.put_variable "octave_matrix", matrix
|
111
|
+
|
112
|
+
assert_instance_of Octave::Matrix, result
|
113
|
+
assert_equal matrix, result
|
114
|
+
assert_equal 1, @driver.feval("rows", result)
|
115
|
+
assert_equal 3, @driver.feval("columns", result)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_should_convert_an_nx1_octave_matrix_to_an_array
|
119
|
+
matrix = Octave::Matrix.new(3, 1)
|
120
|
+
matrix[0, 0] = 1
|
121
|
+
matrix[1, 0] = 2
|
122
|
+
matrix[2, 0] = 3
|
123
|
+
|
124
|
+
expected_array = [1,2,3]
|
125
|
+
result = to_octave_to_ruby(matrix)
|
126
|
+
|
127
|
+
assert_equal expected_array, result
|
128
|
+
assert_instance_of Array, result
|
129
|
+
assert_equal 3, @driver.feval("rows", result)
|
130
|
+
assert_equal 1, @driver.feval("columns", result)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_should_convert_octave_struct_matrix
|
134
|
+
struct_matrix = Octave::StructMatrix.new(17, 2, "name", "age", "married", "cats", "car")
|
135
|
+
17.times do |m|
|
136
|
+
2.times do |n|
|
137
|
+
struct_matrix[m, n]["name"] = "Bob #{m}.#{n}"
|
138
|
+
struct_matrix[m, n]["age"] = (rand * 100).to_i
|
139
|
+
struct_matrix[m, n]["married"] = (rand > 0.5)
|
140
|
+
struct_matrix[m, n]["cats"] = { "name" => "Kitty #{m}.#{n}" }
|
141
|
+
struct_matrix[m, n]["car"] = nil
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
assert_octave_and_ruby_equal struct_matrix
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_should_convert_a_1x1_struct_matrix_to_a_hash
|
149
|
+
struct_matrix = Octave::StructMatrix.new(1, 1, "foo")
|
150
|
+
struct_matrix[0,0]["foo"] = { "bar" => [1,2,3] }
|
151
|
+
|
152
|
+
expected_hash = { "foo" => { "bar" => [1,2,3] } }
|
153
|
+
result = to_octave_to_ruby(struct_matrix)
|
154
|
+
|
155
|
+
assert_equal expected_hash, result
|
156
|
+
assert_instance_of Hash, result
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_should_convert_octave_cell_matrix
|
160
|
+
cell_matrix = Octave::CellMatrix.new(3, 3)
|
161
|
+
cell_matrix[0, 0] = 1
|
162
|
+
cell_matrix[1, 0] = "2"
|
163
|
+
cell_matrix[2, 0] = false
|
164
|
+
|
165
|
+
assert_octave_and_ruby_equal cell_matrix
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_should_convert_a_1x1_cell_matrix_to_value
|
169
|
+
cell_matrix = Octave::CellMatrix.new(1, 1)
|
170
|
+
cell_matrix[0,0] = [1, 2, 3]
|
171
|
+
|
172
|
+
assert_equal [1, 2, 3], to_octave_to_ruby(cell_matrix)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_should_convert_a_1xn_cell_matrix_to_an_octave_cell_matrix
|
176
|
+
cell_matrix = Octave::CellMatrix.new(1, 3)
|
177
|
+
cell_matrix[0,0] = "foo"
|
178
|
+
cell_matrix[0,1] = "bar"
|
179
|
+
cell_matrix[0,2] = "baz"
|
180
|
+
|
181
|
+
result = @driver.put_variable "octave_cell_matrix", cell_matrix
|
182
|
+
|
183
|
+
assert_instance_of Octave::CellMatrix, result
|
184
|
+
assert_equal cell_matrix, result
|
185
|
+
assert_equal 1, @driver.feval("rows", result)
|
186
|
+
assert_equal 3, @driver.feval("columns", result)
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_should_convert_a_nx1_cell_matrix_to_an_array
|
190
|
+
cell_matrix = Octave::CellMatrix.new(3, 1)
|
191
|
+
cell_matrix[0,0] = "foo"
|
192
|
+
cell_matrix[1,0] = "bar"
|
193
|
+
cell_matrix[2,0] = "baz"
|
194
|
+
|
195
|
+
assert_equal %w(foo bar baz), to_octave_to_ruby(cell_matrix)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_should_convert_boolean_matrix
|
199
|
+
assert_octave_and_ruby_equal [true, false, true]
|
200
|
+
boolean_matrix = @driver.feval "eval", "x = [1,2]; (x > 2 | x < 2)"
|
201
|
+
assert_equal [true, false], boolean_matrix
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
$:.unshift "../../../lib"
|
2
|
+
require 'test/unit'
|
3
|
+
require 'octave'
|
4
|
+
require 'octave/driver/native/driver'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
class DriverTest < Test::Unit::TestCase
|
9
|
+
include Octave::Driver::Native
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@driver = Driver.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_feval
|
16
|
+
API.expects(:feval).with("some_function_name", ["argument 1", "argument 2"])
|
17
|
+
@driver.feval("some_function_name", "argument 1", "argument 2")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_put_and_get_variable
|
21
|
+
assert_equal "some_value", @driver.put_variable("some_variable_name", "some_value")
|
22
|
+
assert_equal "some_value", @driver.get_variable("some_variable_name")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_putting_variable_with_same_name_multiple_times
|
26
|
+
assert_equal "foo", @driver.put_variable("some_variable_name", "foo")
|
27
|
+
assert_equal "bar", @driver.put_variable("some_variable_name", "bar")
|
28
|
+
assert_equal "baz", @driver.put_variable("some_variable_name", "baz")
|
29
|
+
|
30
|
+
assert_equal "baz", @driver.get_variable("some_variable_name")
|
31
|
+
end
|
32
|
+
end
|
data/test/test_engine.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'octave'
|
3
|
+
require 'octave/engine'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
class Driver
|
8
|
+
end
|
9
|
+
|
10
|
+
class EngineTest_Init < Test::Unit::TestCase
|
11
|
+
def test_new
|
12
|
+
driver = mock()
|
13
|
+
Driver.expects(:new).returns(driver)
|
14
|
+
|
15
|
+
engine = Octave::Engine.new(:driver => Driver)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_new_with_invalid_driver
|
19
|
+
exception = assert_raise(LoadError) do
|
20
|
+
engine = Octave::Engine.new(:driver => "foo")
|
21
|
+
end
|
22
|
+
assert_equal "no such file to load -- octave/driver/foo/driver", exception.message
|
23
|
+
|
24
|
+
exception = assert_raise(LoadError) do
|
25
|
+
engine = Octave::Engine.new(:driver => :bar)
|
26
|
+
end
|
27
|
+
assert_equal "no such file to load -- octave/driver/bar/driver", exception.message
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_new_with_native_driver
|
31
|
+
assert_nothing_raised do
|
32
|
+
engine = Octave::Engine.new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class EngineTest < Test::Unit::TestCase
|
38
|
+
def setup
|
39
|
+
@driver = mock()
|
40
|
+
@handle = mock()
|
41
|
+
Driver.expects(:new).returns(@driver)
|
42
|
+
|
43
|
+
@engine = Octave::Engine.new(:driver => Driver)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_method_missing
|
47
|
+
@driver.expects(:feval).with("some_method_name", "argument 1", "argument 2")
|
48
|
+
@engine.some_method_name("argument 1", "argument 2")
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: daikini-octave-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Younger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-30 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
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)"
|
17
|
+
email:
|
18
|
+
- jonathan@daikini.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions:
|
22
|
+
- ext/octave_api/extconf.rb
|
23
|
+
extra_rdoc_files:
|
24
|
+
- History.txt
|
25
|
+
- LICENSE.txt
|
26
|
+
- Manifest.txt
|
27
|
+
- README.txt
|
28
|
+
files:
|
29
|
+
- History.txt
|
30
|
+
- LICENSE.txt
|
31
|
+
- Manifest.txt
|
32
|
+
- README.txt
|
33
|
+
- Rakefile
|
34
|
+
- ext/octave_api/MANIFEST
|
35
|
+
- ext/octave_api/Makefile
|
36
|
+
- ext/octave_api/extconf.rb
|
37
|
+
- ext/octave_api/octave-includes.h
|
38
|
+
- ext/octave_api/octave-ruby.cpp
|
39
|
+
- ext/octave_api/octave-ruby.h
|
40
|
+
- ext/octave_api/octave_api.c
|
41
|
+
- ext/octave_api/octave_api.h
|
42
|
+
- ext/octave_api/or-array.cpp
|
43
|
+
- ext/octave_api/or-array.h
|
44
|
+
- ext/octave_api/or-boolean_matrix.cpp
|
45
|
+
- ext/octave_api/or-boolean_matrix.h
|
46
|
+
- ext/octave_api/or-cell_matrix.cpp
|
47
|
+
- ext/octave_api/or-cell_matrix.h
|
48
|
+
- ext/octave_api/or-hash.cpp
|
49
|
+
- ext/octave_api/or-hash.h
|
50
|
+
- ext/octave_api/or-matrix.cpp
|
51
|
+
- ext/octave_api/or-matrix.h
|
52
|
+
- ext/octave_api/or-string.cpp
|
53
|
+
- ext/octave_api/or-string.h
|
54
|
+
- ext/octave_api/or-struct_matrix.cpp
|
55
|
+
- ext/octave_api/or-struct_matrix.h
|
56
|
+
- ext/octave_api/or-variable.cpp
|
57
|
+
- ext/octave_api/or-variable.h
|
58
|
+
- lib/octave.rb
|
59
|
+
- lib/octave/driver/native/driver.rb
|
60
|
+
- lib/octave/engine.rb
|
61
|
+
- lib/octave/matrix.rb
|
62
|
+
- lib/octave/version.rb
|
63
|
+
- octave-ruby.gemspec
|
64
|
+
- setup.rb
|
65
|
+
- test/driver/native/test_conversions.rb
|
66
|
+
- test/driver/native/test_driver.rb
|
67
|
+
- test/test_engine.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://octave-ruby.rubyforge.org/
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- --main
|
73
|
+
- README.txt
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
- ext
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
version:
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project: octave-ruby
|
92
|
+
rubygems_version: 1.2.0
|
93
|
+
signing_key:
|
94
|
+
specification_version: 2
|
95
|
+
summary: A Ruby interface to the Octave interpreted language.
|
96
|
+
test_files:
|
97
|
+
- test/driver/native/test_conversions.rb
|
98
|
+
- test/driver/native/test_driver.rb
|
99
|
+
- test/test_engine.rb
|