matlab-ruby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/LICENSE.txt +19 -0
- data/Manifest.txt +19 -0
- data/README.txt +88 -0
- data/Rakefile +18 -0
- data/ext/matlab_api/MANIFEST +4 -0
- data/ext/matlab_api/extconf.rb +15 -0
- data/ext/matlab_api/matlab_api.i +15 -0
- data/ext/matlab_api/matlab_api_wrap.c +5802 -0
- data/lib/matlab.rb +22 -0
- data/lib/matlab/driver/native/conversions.rb +200 -0
- data/lib/matlab/driver/native/driver.rb +26 -0
- data/lib/matlab/engine.rb +81 -0
- data/lib/matlab/matrix.rb +84 -0
- data/lib/matlab/version.rb +14 -0
- data/setup.rb +1333 -0
- data/test/driver/native/test_conversions.rb +79 -0
- data/test/driver/native/test_driver.rb +41 -0
- data/test/test_engine.rb +77 -0
- metadata +76 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
$:.unshift "../../../lib"
|
2
|
+
require 'test/unit'
|
3
|
+
require 'matlab'
|
4
|
+
require 'matlab/driver/native/conversions'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
class ConversionsTest < Test::Unit::TestCase
|
9
|
+
def test_string_to_matlab_to_ruby
|
10
|
+
assert_equal "foo", "foo".to_matlab.to_ruby
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_true_to_matlab_to_ruby
|
14
|
+
assert_equal true, true.to_matlab.to_ruby
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_false_to_matlab_to_ruby
|
18
|
+
assert_equal false, false.to_matlab.to_ruby
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_nil_to_matlab_to_ruby
|
22
|
+
assert_equal nil, nil.to_matlab.to_ruby
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_float_to_ruby
|
26
|
+
assert_nil nil.to_matlab.to_ruby
|
27
|
+
assert_equal 12.345, 12.345.to_ruby
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_numeric_to_matlab_to_ruby
|
31
|
+
assert_equal 12345.0, 12345.to_matlab.to_ruby
|
32
|
+
assert_equal 12.345, 12.345.to_matlab.to_ruby
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_array_to_cell_matrix
|
36
|
+
cell_matrix = Matlab::CellMatrix.new(9, 1)
|
37
|
+
9.times { |i| cell_matrix[i, 0] = (i > 4 ? i : i.to_s) }
|
38
|
+
cell_matrix[0, 0] = true
|
39
|
+
cell_matrix[4, 0] = nil
|
40
|
+
cell_matrix[8, 0] = false
|
41
|
+
|
42
|
+
assert_equal cell_matrix, [true, "1", "2", ["3", nil, 5], 6, 7, false].to_cell_matrix
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_matlab_matrix_to_matlab_to_ruby
|
46
|
+
matrix = Matlab::Matrix.new(3, 3)
|
47
|
+
3.times { |m| 3.times { |n| matrix[m, n] = rand } }
|
48
|
+
matrix[1, 1] = nil
|
49
|
+
|
50
|
+
assert_equal matrix, matrix.to_matlab.to_ruby
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_matlab_cell_matrix_to_matlab_to_ruby
|
54
|
+
cell_matrix = Matlab::CellMatrix.new(3, 3)
|
55
|
+
3.times { |m| 3.times { |n| cell_matrix[m, n] = (n == 1 ? rand.to_s : rand) } }
|
56
|
+
cell_matrix[0, 0] = true
|
57
|
+
cell_matrix[1, 1] = nil
|
58
|
+
cell_matrix[2, 2] = false
|
59
|
+
|
60
|
+
assert_equal cell_matrix, cell_matrix.to_matlab.to_ruby
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_matlab_struct_matrix_to_matlab_to_ruby
|
64
|
+
cats = Matlab::StructMatrix.new(17, 1, "name")
|
65
|
+
17.times { |m| 1.times { |n| cats[m, n]["name"] = "Kitty #{m}.#{n}" } }
|
66
|
+
|
67
|
+
struct_matrix = Matlab::StructMatrix.new(17, 1, "name", "age", "married", "cats", "car")
|
68
|
+
17.times do |m|
|
69
|
+
1.times do |n|
|
70
|
+
struct_matrix[m, n]["name"] = "Bob #{m}.#{n}"
|
71
|
+
struct_matrix[m, n]["age"] = (rand * 100).to_i
|
72
|
+
struct_matrix[m, n]["married"] = (rand > 0.5)
|
73
|
+
struct_matrix[m, n]["cats"] = cats
|
74
|
+
struct_matrix[m, n]["car"] = nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
assert_equal struct_matrix, struct_matrix.to_matlab.to_ruby
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
$:.unshift "../../../lib"
|
2
|
+
require 'test/unit'
|
3
|
+
require 'matlab'
|
4
|
+
require 'matlab/driver/native/driver'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
class DriverTest < Test::Unit::TestCase
|
9
|
+
include Matlab::Driver::Native
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@driver = Driver.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_open
|
16
|
+
API.expects(:engOpen).with("matfoo")
|
17
|
+
@driver.open("matfoo")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_close
|
21
|
+
API.expects(:engClose).with("engine")
|
22
|
+
@driver.close("engine")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_eval_string
|
26
|
+
API.expects(:engEvalString).with("engine", "string")
|
27
|
+
@driver.eval_string("engine", "string")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_get_variable
|
31
|
+
variable = mock(:to_ruby => "bar")
|
32
|
+
API.expects(:engGetVariable).with("engine", "foo").returns(variable)
|
33
|
+
assert_equal "bar", @driver.get_variable("engine", "foo")
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_put_variable
|
37
|
+
variable = mock(:to_matlab => "bar")
|
38
|
+
API.expects(:engPutVariable).with("engine", "foo", "bar")
|
39
|
+
@driver.put_variable("engine", "foo", variable)
|
40
|
+
end
|
41
|
+
end
|
data/test/test_engine.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'matlab'
|
3
|
+
require 'matlab/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(:open).with("matfoo")
|
14
|
+
Driver.expects(:new).returns(driver)
|
15
|
+
|
16
|
+
engine = Matlab::Engine.new("matfoo", :driver => Driver)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_new_with_invalid_driver
|
20
|
+
exception = assert_raise(LoadError) do
|
21
|
+
engine = Matlab::Engine.new("matfoo", :driver => "foo")
|
22
|
+
end
|
23
|
+
assert_equal "no such file to load -- matlab/driver/foo/driver", exception.message
|
24
|
+
|
25
|
+
exception = assert_raise(LoadError) do
|
26
|
+
engine = Matlab::Engine.new("matfoo", :driver => :bar)
|
27
|
+
end
|
28
|
+
assert_equal "no such file to load -- matlab/driver/bar/driver", exception.message
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_new_with_native_driver
|
32
|
+
begin
|
33
|
+
require 'matlab_api'
|
34
|
+
|
35
|
+
Matlab::Driver::Native::API.expects(:engOpen).with("matfoo")
|
36
|
+
assert_nothing_raised do
|
37
|
+
engine = Matlab::Engine.new("matfoo")
|
38
|
+
end
|
39
|
+
rescue LoadError => e
|
40
|
+
exception = assert_raise(RuntimeError) do
|
41
|
+
engine = Matlab::Engine.new("matfoo")
|
42
|
+
end
|
43
|
+
assert_equal "no driver for matlab found", exception.message
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class EngineTest < Test::Unit::TestCase
|
49
|
+
def setup
|
50
|
+
@driver = mock()
|
51
|
+
@handle = mock()
|
52
|
+
@driver.expects(:open).with("matfoo").returns(@handle)
|
53
|
+
Driver.expects(:new).returns(@driver)
|
54
|
+
|
55
|
+
@engine = Matlab::Engine.new("matfoo", :driver => Driver)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_eval_string
|
59
|
+
@driver.expects(:eval_string).with(@handle, "z = x * y")
|
60
|
+
@engine.eval_string "z = x * y"
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_close
|
64
|
+
@driver.expects(:close).with(@handle)
|
65
|
+
@engine.close
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_method_missing_get
|
69
|
+
@driver.expects(:get_variable).with(@handle, "x")
|
70
|
+
@engine.x
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_method_missing_put
|
74
|
+
@driver.expects(:put_variable).with(@handle, "y", 123.456)
|
75
|
+
@engine.y = 123.456
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: matlab-ruby
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2007-04-08 00:00:00 -06:00
|
8
|
+
summary: A Ruby interface to the Matlab interpreted language.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- ext
|
12
|
+
email:
|
13
|
+
- jonathan.younger@lipomics.com
|
14
|
+
homepage: http://matlab-ruby.rubyforge.org/
|
15
|
+
rubyforge_project: matlab-ruby
|
16
|
+
description: "== USAGE: require 'matlab' engine = Matlab::Engine.new engine.x = 123.456 engine.y = 789.101112 engine.eval_string \"z = x * y\" engine.z matrix = Matlab::Matrix.new(20, 400) 20.times { |m| 400.times { |n| matrix[m, n] = rand } } engine.m = matrix engine.eval_string \"save '/tmp/20_x_400_matrix\" engine.close == REQUIREMENTS: * MATLAB * GCC or some other compiler to build the included extension * SWIG (If you want to recompile the SWIG wrapper) * Mocha (For testing only)"
|
17
|
+
autorequire:
|
18
|
+
default_executable:
|
19
|
+
bindir: bin
|
20
|
+
has_rdoc: true
|
21
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.0.0
|
26
|
+
version:
|
27
|
+
platform: ruby
|
28
|
+
signing_key:
|
29
|
+
cert_chain:
|
30
|
+
post_install_message:
|
31
|
+
authors:
|
32
|
+
- Jonathan Younger
|
33
|
+
files:
|
34
|
+
- History.txt
|
35
|
+
- LICENSE.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.txt
|
38
|
+
- Rakefile
|
39
|
+
- ext/matlab_api/MANIFEST
|
40
|
+
- ext/matlab_api/extconf.rb
|
41
|
+
- ext/matlab_api/matlab_api.i
|
42
|
+
- ext/matlab_api/matlab_api_wrap.c
|
43
|
+
- lib/matlab.rb
|
44
|
+
- lib/matlab/driver/native/conversions.rb
|
45
|
+
- lib/matlab/driver/native/driver.rb
|
46
|
+
- lib/matlab/engine.rb
|
47
|
+
- lib/matlab/matrix.rb
|
48
|
+
- lib/matlab/version.rb
|
49
|
+
- setup.rb
|
50
|
+
- test/driver/native/test_conversions.rb
|
51
|
+
- test/driver/native/test_driver.rb
|
52
|
+
- test/test_engine.rb
|
53
|
+
test_files:
|
54
|
+
- test/driver/native/test_conversions.rb
|
55
|
+
- test/driver/native/test_driver.rb
|
56
|
+
- test/test_engine.rb
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
executables: []
|
62
|
+
|
63
|
+
extensions:
|
64
|
+
- ext/matlab_api/extconf.rb
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
dependencies:
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: hoe
|
70
|
+
version_requirement:
|
71
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.2.0
|
76
|
+
version:
|