public
Description: A Ruby interface to the MATLAB interpreted language
Clone URL: git://github.com/daikini/matlab-ruby.git
Fix empty arrays and matrices

  * Empty matrices are converted to empty ruby arrays.
  * Empty ruby arrays are converted to an empty MATLAB matrix
daikini (author)
Mon May 19 10:58:19 -0700 2008
commit  d1cf1b0c700c8bcbc8d8570f681d8c8e5b816b61
tree    3c42b6043a447f0d0ee2332dcddaa06b14e37863
parent  16bc7937a81a382b9187e835b29331d8655c1665
...
 
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
9
0
@@ -1,3 +1,9 @@
0
+== 2.0.3 / 2008-05-19
0
+
0
+* 2 bug fixes
0
+ * Empty matrices are converted to empty ruby arrays.
0
+ * Empty ruby arrays are converted to an empty MATLAB matrix
0
+
0
 == 2.0.2 / 2008-05-19
0
 
0
 * 1 bug fix
...
50
51
52
53
 
 
 
 
54
55
56
...
231
232
233
234
 
 
 
235
236
237
...
50
51
52
 
53
54
55
56
57
58
59
...
234
235
236
 
237
238
239
240
241
242
0
@@ -50,7 +50,10 @@ end
0
 class Array
0
   # Converts the array into a 1 Dimensional MATLAB numeric or cell matrix
0
   def to_matlab
0
- if all? { |value| value.kind_of?(Numeric) || value.nil? }
0
+ if empty?
0
+ matrix = Matlab::Matrix.new(0, 0)
0
+ matrix.to_matlab
0
+ elsif all? { |value| value.kind_of?(Numeric) || value.nil? }
0
       matrix = Matlab::Matrix.new(size, 1)
0
     
0
       each_with_index do |value, index|
0
@@ -231,7 +234,9 @@ class SWIG::TYPE_p_mxArray_tag
0
       mxArrayToString(self)
0
     when mxIsLogical(self)
0
       mxIsLogicalScalarTrue(self)
0
- when (mxGetM(self) > 1 || mxGetN(self) > 1) || (mxGetM(self) == 0 && mxGetN(self) == 0)
0
+ when (mxGetM(self) == 0 && mxGetN(self) == 0)
0
+ []
0
+ when (mxGetM(self) > 1 || mxGetN(self) > 1)
0
       Matlab::Matrix.from_matlab(self)
0
     when mxIsDouble(self)
0
       mxGetScalar(self)
...
4
5
6
7
 
8
9
10
...
4
5
6
 
7
8
9
10
0
@@ -4,7 +4,7 @@ module Matlab
0
 
0
     MAJOR = 2
0
     MINOR = 0
0
- TINY = 2
0
+ TINY = 3
0
 
0
     STRING = [ MAJOR, MINOR, TINY ].join( "." )
0
     #:beta-tag:
...
66
67
68
69
 
 
 
 
 
 
 
70
71
72
...
66
67
68
 
69
70
71
72
73
74
75
76
77
78
0
@@ -66,7 +66,13 @@ class ConversionsTest < Test::Unit::TestCase
0
   
0
   def test_should_convert_a_0x0_matlab_matrix
0
     matrix = Matlab::Matrix.new(0, 0)
0
- assert_equal matrix, matrix.to_matlab.to_ruby
0
+ result = matrix.to_matlab.to_ruby
0
+ assert_equal [], result
0
+ end
0
+
0
+ def test_should_convert_an_empty_ruby_array
0
+ array = []
0
+ assert_equal array, array.to_matlab.to_ruby
0
   end
0
   
0
   def test_matlab_cell_matrix_to_matlab_to_ruby

Comments

    No one has commented yet.