rubysl-matrix 1.0.0

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.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +1 -0
  8. data/lib/matrix.rb +1 -0
  9. data/lib/rubysl/matrix.rb +2 -0
  10. data/lib/rubysl/matrix/matrix.rb +1537 -0
  11. data/lib/rubysl/matrix/version.rb +5 -0
  12. data/rubysl-matrix.gemspec +27 -0
  13. data/spec/I_spec.rb +5 -0
  14. data/spec/build_spec.rb +75 -0
  15. data/spec/clone_spec.rb +26 -0
  16. data/spec/coerce_spec.rb +11 -0
  17. data/spec/collect_spec.rb +5 -0
  18. data/spec/column_size_spec.rb +14 -0
  19. data/spec/column_spec.rb +36 -0
  20. data/spec/column_vector_spec.rb +36 -0
  21. data/spec/column_vectors_spec.rb +25 -0
  22. data/spec/columns_spec.rb +45 -0
  23. data/spec/conj_spec.rb +7 -0
  24. data/spec/conjugate_spec.rb +7 -0
  25. data/spec/constructor_spec.rb +68 -0
  26. data/spec/det_spec.rb +6 -0
  27. data/spec/determinant_spec.rb +6 -0
  28. data/spec/diagonal_spec.rb +73 -0
  29. data/spec/divide_spec.rb +60 -0
  30. data/spec/each_spec.rb +77 -0
  31. data/spec/each_with_index_spec.rb +84 -0
  32. data/spec/eigenvalue_decomposition/eigenvalue_matrix_spec.rb +10 -0
  33. data/spec/eigenvalue_decomposition/eigenvalues_spec.rb +23 -0
  34. data/spec/eigenvalue_decomposition/eigenvector_matrix_spec.rb +23 -0
  35. data/spec/eigenvalue_decomposition/eigenvectors_spec.rb +25 -0
  36. data/spec/eigenvalue_decomposition/initialize_spec.rb +27 -0
  37. data/spec/eigenvalue_decomposition/to_a_spec.rb +19 -0
  38. data/spec/element_reference_spec.rb +24 -0
  39. data/spec/empty_spec.rb +69 -0
  40. data/spec/eql_spec.rb +12 -0
  41. data/spec/equal_value_spec.rb +10 -0
  42. data/spec/exponent_spec.rb +66 -0
  43. data/spec/find_index_spec.rb +147 -0
  44. data/spec/fixtures/classes.rb +7 -0
  45. data/spec/hash_spec.rb +14 -0
  46. data/spec/hermitian_spec.rb +37 -0
  47. data/spec/identity_spec.rb +5 -0
  48. data/spec/imag_spec.rb +7 -0
  49. data/spec/imaginary_spec.rb +7 -0
  50. data/spec/inspect_spec.rb +30 -0
  51. data/spec/inv_spec.rb +6 -0
  52. data/spec/inverse_from_spec.rb +5 -0
  53. data/spec/inverse_spec.rb +6 -0
  54. data/spec/lower_triangular_spec.rb +25 -0
  55. data/spec/lup_decomposition/determinant_spec.rb +24 -0
  56. data/spec/lup_decomposition/initialize_spec.rb +14 -0
  57. data/spec/lup_decomposition/l_spec.rb +19 -0
  58. data/spec/lup_decomposition/p_spec.rb +19 -0
  59. data/spec/lup_decomposition/solve_spec.rb +54 -0
  60. data/spec/lup_decomposition/to_a_spec.rb +36 -0
  61. data/spec/lup_decomposition/u_spec.rb +19 -0
  62. data/spec/map_spec.rb +5 -0
  63. data/spec/minor_spec.rb +90 -0
  64. data/spec/minus_spec.rb +45 -0
  65. data/spec/multiply_spec.rb +73 -0
  66. data/spec/new_spec.rb +7 -0
  67. data/spec/normal_spec.rb +27 -0
  68. data/spec/orthogonal_spec.rb +27 -0
  69. data/spec/permutation_spec.rb +33 -0
  70. data/spec/plus_spec.rb +45 -0
  71. data/spec/rank_spec.rb +24 -0
  72. data/spec/real_spec.rb +45 -0
  73. data/spec/rect_spec.rb +7 -0
  74. data/spec/rectangular_spec.rb +7 -0
  75. data/spec/regular_spec.rb +34 -0
  76. data/spec/round_spec.rb +24 -0
  77. data/spec/row_size_spec.rb +12 -0
  78. data/spec/row_spec.rb +37 -0
  79. data/spec/row_vector_spec.rb +33 -0
  80. data/spec/row_vectors_spec.rb +25 -0
  81. data/spec/rows_spec.rb +40 -0
  82. data/spec/scalar/Fail_spec.rb +5 -0
  83. data/spec/scalar/Raise_spec.rb +5 -0
  84. data/spec/scalar/divide_spec.rb +5 -0
  85. data/spec/scalar/exponent_spec.rb +5 -0
  86. data/spec/scalar/included_spec.rb +5 -0
  87. data/spec/scalar/initialize_spec.rb +5 -0
  88. data/spec/scalar/minus_spec.rb +5 -0
  89. data/spec/scalar/multiply_spec.rb +5 -0
  90. data/spec/scalar/plus_spec.rb +5 -0
  91. data/spec/scalar_spec.rb +66 -0
  92. data/spec/shared/collect.rb +29 -0
  93. data/spec/shared/conjugate.rb +21 -0
  94. data/spec/shared/determinant.rb +53 -0
  95. data/spec/shared/equal_value.rb +35 -0
  96. data/spec/shared/identity.rb +21 -0
  97. data/spec/shared/imaginary.rb +22 -0
  98. data/spec/shared/inverse.rb +42 -0
  99. data/spec/shared/rectangular.rb +20 -0
  100. data/spec/shared/trace.rb +14 -0
  101. data/spec/shared/transpose.rb +23 -0
  102. data/spec/singular_spec.rb +34 -0
  103. data/spec/spec_helper.rb +35 -0
  104. data/spec/square_spec.rb +29 -0
  105. data/spec/symmetric_spec.rb +30 -0
  106. data/spec/t_spec.rb +5 -0
  107. data/spec/to_a_spec.rb +5 -0
  108. data/spec/to_s_spec.rb +5 -0
  109. data/spec/tr_spec.rb +6 -0
  110. data/spec/trace_spec.rb +6 -0
  111. data/spec/transpose_spec.rb +5 -0
  112. data/spec/unit_spec.rb +5 -0
  113. data/spec/unitary_spec.rb +29 -0
  114. data/spec/upper_triangular_spec.rb +26 -0
  115. data/spec/vector/cross_product_spec.rb +25 -0
  116. data/spec/vector/each2_spec.rb +52 -0
  117. data/spec/vector/eql_spec.rb +17 -0
  118. data/spec/vector/inner_product_spec.rb +25 -0
  119. data/spec/vector/normalize_spec.rb +19 -0
  120. data/spec/zero_spec.rb +55 -0
  121. metadata +341 -0
@@ -0,0 +1,19 @@
1
+ require 'matrix'
2
+
3
+ ruby_version_is "1.9.3" do
4
+ describe "Matrix::LUPDecomposition#l" do
5
+ before :each do
6
+ @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]]
7
+ @lu = Matrix::LUPDecomposition.new(@a)
8
+ @l = @lu.l
9
+ end
10
+
11
+ it "returns the first element of to_a" do
12
+ @l.should == @lu.to_a[0]
13
+ end
14
+
15
+ it "returns a lower triangular matrix" do
16
+ @l.lower_triangular?.should be_true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'matrix'
2
+
3
+ ruby_version_is "1.9.3" do
4
+ describe "Matrix::LUPDecomposition#p" do
5
+ before :each do
6
+ @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]]
7
+ @lu = Matrix::LUPDecomposition.new(@a)
8
+ @p = @lu.p
9
+ end
10
+
11
+ it "returns the third element of to_a" do
12
+ @p.should == @lu.to_a[2]
13
+ end
14
+
15
+ it "returns a permutation matrix" do
16
+ @p.permutation?.should be_true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,54 @@
1
+ require 'matrix'
2
+
3
+ ruby_version_is "1.9.3" do
4
+ describe "Matrix::LUPDecomposition#solve" do
5
+ describe "for rectangular matrices" do
6
+ it "raises an error for singular matrices" do
7
+ a = Matrix[[1, 2, 3], [1, 3, 5], [2, 5, 8]]
8
+ lu = Matrix::LUPDecomposition.new(a)
9
+ lambda {
10
+ lu.solve(a)
11
+ }.should raise_error(Matrix::ErrNotRegular)
12
+ end
13
+
14
+ describe "for non singular matrices" do
15
+ before :each do
16
+ @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]]
17
+ @lu = Matrix::LUPDecomposition.new(@a)
18
+ end
19
+
20
+ it "returns the appropriate empty matrix when given an empty matrix" do
21
+ @lu.solve(Matrix.empty(3,0)).should == Matrix.empty(3,0)
22
+ empty = Matrix::LUPDecomposition.new(Matrix.empty(0, 0))
23
+ empty.solve(Matrix.empty(0,3)).should == Matrix.empty(0,3)
24
+ end
25
+
26
+ it "returns the right matrix when given a matrix of the appropriate size" do
27
+ solution = Matrix[[1, 2, 3, 4], [0, 1, 2, 3], [-1, -2, -3, -4]]
28
+ values = Matrix[[-2, 4, 10, 16], [-37, -28, -19, -10], [-135, -188, -241, -294]] # == @a * solution
29
+ @lu.solve(values).should == solution
30
+ end
31
+
32
+ it "raises an error when given a matrix of the wrong size" do
33
+ values = Matrix[[1, 2, 3, 4], [0, 1, 2, 3]]
34
+ lambda {
35
+ @lu.solve(values)
36
+ }.should raise_error(Matrix::ErrDimensionMismatch)
37
+ end
38
+
39
+ it "returns the right vector when given a vector of the appropriate size" do
40
+ solution = Vector[1, 2, -1]
41
+ values = Vector[14, 55, 29] # == @a * solution
42
+ @lu.solve(values).should == solution
43
+ end
44
+
45
+ it "raises an error when given a vector of the wrong size" do
46
+ values = Vector[14, 55]
47
+ lambda {
48
+ @lu.solve(values)
49
+ }.should raise_error(Matrix::ErrDimensionMismatch)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ require 'matrix'
2
+
3
+ ruby_version_is "1.9.3" do
4
+ describe "Matrix::LUPDecomposition#to_a" do
5
+ before :each do
6
+ @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]]
7
+ @lu = Matrix::LUPDecomposition.new(@a)
8
+ @to_a = @lu.to_a
9
+ @l, @u, @p = @to_a
10
+ end
11
+
12
+ it "returns an array of three matrices" do
13
+ @to_a.should be_kind_of(Array)
14
+ @to_a.length.should == 3
15
+ @to_a.each{|m| m.should be_kind_of(Matrix)}
16
+ end
17
+
18
+ it "returns [l, u, p] such that l*u == a*p" do
19
+ (@l * @u).should == (@p * @a)
20
+ end
21
+
22
+ ruby_bug "#", "1.9.3" do
23
+ it "returns the right values for rectangular matrices" do
24
+ [
25
+ Matrix[[7, 8, 9], [14, 46, 51]],
26
+ Matrix[[4, 11], [5, 8], [3, 4]],
27
+ ].each do |a|
28
+ l, u, p = Matrix::LUPDecomposition.new(a).to_a
29
+ (l * u).should == (p * a)
30
+ end
31
+ end
32
+ end
33
+
34
+ it "has other properties implied by the specs of #l, #u and #p"
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ require 'matrix'
2
+
3
+ ruby_version_is "1.9.3" do
4
+ describe "Matrix::LUPDecomposition#u" do
5
+ before :each do
6
+ @a = Matrix[[7, 8, 9], [14, 46, 51], [28, 82, 163]]
7
+ @lu = Matrix::LUPDecomposition.new(@a)
8
+ @u = @lu.u
9
+ end
10
+
11
+ it "returns the second element of to_a" do
12
+ @u.should == @lu.to_a[1]
13
+ end
14
+
15
+ it "returns an upper triangular matrix" do
16
+ @u.upper_triangular?.should be_true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../shared/collect', __FILE__)
2
+
3
+ describe "Matrix#map" do
4
+ it_behaves_like(:collect, :map)
5
+ end
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../fixtures/classes', __FILE__)
2
+ require 'matrix'
3
+
4
+ describe "Matrix#minor" do
5
+ before(:each) do
6
+ @matrix = Matrix[ [1,2], [3,4], [5,6] ]
7
+ end
8
+
9
+ describe "with start_row, nrows, start_col, ncols" do
10
+ it "returns the given portion of the Matrix" do
11
+ @matrix.minor(0,1,0,2).should == Matrix[ [1, 2] ]
12
+ @matrix.minor(1,2,1,1).should == Matrix[ [4], [6] ]
13
+ end
14
+
15
+ ruby_bug "redmine:1532", "1.8.7" do
16
+ it "returns an empty Matrix if nrows or ncols is 0" do
17
+ @matrix.minor(0,0,0,0).should == Matrix[]
18
+ @matrix.minor(1,0,1,0).should == Matrix[]
19
+ @matrix.minor(1,0,1,1).should == Matrix.columns([[]])
20
+ @matrix.minor(1,1,1,0).should == Matrix[[]]
21
+ end
22
+
23
+ it "returns nil for out-of-bounds start_row/col" do
24
+ r = @matrix.row_size + 1
25
+ c = @matrix.column_size + 1
26
+ @matrix.minor(r,0,0,10).should == nil
27
+ @matrix.minor(0,10,c,9).should == nil
28
+ @matrix.minor(-r,0,0,10).should == nil
29
+ @matrix.minor(0,10,-c,9).should == nil
30
+ end
31
+
32
+ it "returns nil for negative nrows or ncols" do
33
+ @matrix.minor(0,1,0,-1).should == nil
34
+ @matrix.minor(0,-1,0,1).should == nil
35
+ end
36
+
37
+ it "start counting backwards for start_row or start_col below zero" do
38
+ @matrix.minor(0, 1, -1, 1).should == @matrix.minor(0, 1, 1, 1)
39
+ @matrix.minor(-1, 1, 0, 1).should == @matrix.minor(2, 1, 0, 1)
40
+ end
41
+ end
42
+
43
+ it "returns empty matrices for extreme start_row/col" do
44
+ @matrix.minor(3,10,1,10).should == Matrix.columns([[]])
45
+ @matrix.minor(1,10,2,10).should == Matrix[[], []]
46
+ @matrix.minor(3,0,0,10).should == Matrix.columns([[], []])
47
+ end
48
+
49
+ it "ignores big nrows or ncols" do
50
+ @matrix.minor(0,1,0,20).should == Matrix[ [1, 2] ]
51
+ @matrix.minor(1,20,1,1).should == Matrix[ [4], [6] ]
52
+ end
53
+ end
54
+
55
+ describe "with col_range, row_range" do
56
+ it "returns the given portion of the Matrix" do
57
+ @matrix.minor(0..0, 0..1).should == Matrix[ [1, 2] ]
58
+ @matrix.minor(1..2, 1..2).should == Matrix[ [4], [6] ]
59
+ @matrix.minor(1...3, 1...3).should == Matrix[ [4], [6] ]
60
+ end
61
+
62
+ ruby_bug "redmine:1532", "1.8.7" do
63
+ it "returns nil if col_range or row_range is out of range" do
64
+ r = @matrix.row_size + 1
65
+ c = @matrix.column_size + 1
66
+ @matrix.minor(r..6, c..6).should == nil
67
+ @matrix.minor(0..1, c..6).should == nil
68
+ @matrix.minor(r..6, 0..1).should == nil
69
+ @matrix.minor(-r..6, -c..6).should == nil
70
+ @matrix.minor(0..1, -c..6).should == nil
71
+ @matrix.minor(-r..6, 0..1).should == nil
72
+ end
73
+
74
+ it "start counting backwards for col_range or row_range below zero" do
75
+ @matrix.minor(0..1, -2..-1).should == @matrix.minor(0..1, 0..1)
76
+ @matrix.minor(0..1, -2..1).should == @matrix.minor(0..1, 0..1)
77
+ @matrix.minor(-2..-1, 0..1).should == @matrix.minor(1..2, 0..1)
78
+ @matrix.minor(-2..2, 0..1).should == @matrix.minor(1..2, 0..1)
79
+ end
80
+ end
81
+ end
82
+
83
+ ruby_bug "redmine #5307", "1.9.3" do
84
+ describe "for a subclass of Matrix" do
85
+ it "returns an instance of that subclass" do
86
+ MatrixSub.ins.minor(0, 1, 0, 1).should be_an_instance_of(MatrixSub)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../fixtures/classes', __FILE__)
2
+ require 'matrix'
3
+
4
+ describe "Matrix#-" do
5
+ before :each do
6
+ @a = Matrix[ [1, 2], [3, 4] ]
7
+ @b = Matrix[ [4, 5], [6, 7] ]
8
+ end
9
+
10
+ it "returns the result of subtracting the corresponding elements of other from self" do
11
+ (@a - @b).should == Matrix[ [-3,-3], [-3,-3] ]
12
+ end
13
+
14
+ it "returns an instance of Matrix" do
15
+ (@a - @b).should be_kind_of(Matrix)
16
+ end
17
+
18
+ it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do
19
+ lambda { @a - Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
20
+ end
21
+
22
+ it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do
23
+ lambda { @a - 2 }.should raise_error(Matrix::ErrOperationNotDefined)
24
+ lambda { @a - 1.2 }.should raise_error(Matrix::ErrOperationNotDefined)
25
+ lambda { @a - bignum_value }.should raise_error(Matrix::ErrOperationNotDefined)
26
+ end
27
+
28
+ ruby_bug "redmine:2365", "1.8.7" do
29
+ it "raises a TypeError if other is of wrong type" do
30
+ lambda { @a - nil }.should raise_error(TypeError)
31
+ lambda { @a - "a" }.should raise_error(TypeError)
32
+ lambda { @a - [ [1, 2] ] }.should raise_error(TypeError)
33
+ lambda { @a - Object.new }.should raise_error(TypeError)
34
+ end
35
+ end
36
+
37
+ ruby_bug "redmine #5307", "1.9.3" do
38
+ describe "for a subclass of Matrix" do
39
+ it "returns an instance of that subclass" do
40
+ m = MatrixSub.ins
41
+ (m-m).should be_an_instance_of(MatrixSub)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path('../fixtures/classes', __FILE__)
2
+ require 'matrix'
3
+
4
+ describe "Matrix#*" do
5
+ before :each do
6
+ @a = Matrix[ [1, 2], [3, 4] ]
7
+ @b = Matrix[ [4, 5], [6, 7] ]
8
+ end
9
+
10
+ it "returns the result of multiplying the corresponding elements of self and a Matrix" do
11
+ (@a * @b).should == Matrix[ [16,19], [36,43] ]
12
+ end
13
+
14
+ it "returns the result of multiplying the corresponding elements of self and a Vector" do
15
+ (@a * Vector[1,2]).should == Vector[5, 11]
16
+ end
17
+
18
+ it "returns the result of multiplying the elements of self and a Fixnum" do
19
+ (@a * 2).should == Matrix[ [2, 4], [6, 8] ]
20
+ end
21
+
22
+ it "returns the result of multiplying the elements of self and a Bignum" do
23
+ (@a * bignum_value).should == Matrix[
24
+ [9223372036854775808, 18446744073709551616],
25
+ [27670116110564327424, 36893488147419103232]
26
+ ]
27
+ end
28
+
29
+ it "returns the result of multiplying the elements of self and a Float" do
30
+ (@a * 2.0).should == Matrix[ [2.0, 4.0], [6.0, 8.0] ]
31
+ end
32
+
33
+ it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do
34
+ lambda { @a * Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
35
+ end
36
+
37
+ ruby_bug "redmine:1532", "1.8.7" do
38
+ it "returns a zero matrix if (nx0) * (0xn)" do
39
+ (Matrix[[],[],[]] * Matrix.columns([[],[],[]])).should == Matrix.zero(3)
40
+ end
41
+
42
+ it "returns an empty matrix if (0xn) * (nx0)" do
43
+ (Matrix.columns([[],[],[]]) * Matrix[[],[],[]]).should == Matrix[]
44
+ end
45
+
46
+ it "returns a mx0 matrix if (mxn) * (nx0)" do
47
+ (Matrix[[1,2],[3,4],[5,6]] * Matrix[[],[]]).should == Matrix[[],[],[]]
48
+ end
49
+
50
+ it "returns a 0xm matrix if (0xm) * (mxn)" do
51
+ (Matrix.columns([[], [], []]) * Matrix[[1,2],[3,4],[5,6]]).should == Matrix.columns([[],[]])
52
+ end
53
+ end
54
+
55
+ ruby_bug "redmine:2365", "1.8.7" do
56
+ it "raises a TypeError if other is of wrong type" do
57
+ lambda { @a * nil }.should raise_error(TypeError)
58
+ lambda { @a * "a" }.should raise_error(TypeError)
59
+ lambda { @a * [ [1, 2] ] }.should raise_error(TypeError)
60
+ lambda { @a * Object.new }.should raise_error(TypeError)
61
+ end
62
+ end
63
+
64
+ ruby_bug "redmine #5307", "1.9.3" do
65
+ describe "for a subclass of Matrix" do
66
+ it "returns an instance of that subclass" do
67
+ m = MatrixSub.ins
68
+ (m*m).should be_an_instance_of(MatrixSub)
69
+ (m*1).should be_an_instance_of(MatrixSub)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,7 @@
1
+ require 'matrix'
2
+
3
+ describe "Matrix.new" do
4
+ it "is private" do
5
+ Matrix.should have_private_method(:new)
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ require 'matrix'
2
+
3
+ ruby_version_is "1.9.3" do
4
+ describe "Matrix.normal?" do
5
+ # it "returns false for non normal matrices" do
6
+ # Matrix[[0, 1], [1, 2]].normal?.should == false
7
+ # end
8
+
9
+ it "returns true for normal matrices" do
10
+ Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].normal?.should == true
11
+ Matrix[[0, Complex(0, 2)], [Complex(0, -2), 0]].normal?.should == true
12
+ end
13
+
14
+ it "raises an error for rectangular matrices" do
15
+ [
16
+ Matrix[[0], [0]],
17
+ Matrix[[0, 0]],
18
+ Matrix.empty(0, 2),
19
+ Matrix.empty(2, 0),
20
+ ].each do |rectangual_matrix|
21
+ lambda {
22
+ rectangual_matrix.normal?
23
+ }.should raise_error(Matrix::ErrDimensionMismatch)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'matrix'
2
+
3
+ ruby_version_is "1.9.3" do
4
+ describe "Matrix.orthogonal?" do
5
+ it "returns false for non orthogonal matrices" do
6
+ Matrix[[0, 1], [1, 2]].orthogonal?.should == false
7
+ Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].orthogonal?.should == false
8
+ end
9
+
10
+ it "returns true for orthogonal matrices" do
11
+ Matrix[[0, 1], [1, 0]].orthogonal?.should == true
12
+ end
13
+
14
+ it "raises an error for rectangular matrices" do
15
+ [
16
+ Matrix[[0], [0]],
17
+ Matrix[[0, 0]],
18
+ Matrix.empty(0, 2),
19
+ Matrix.empty(2, 0),
20
+ ].each do |rectangual_matrix|
21
+ lambda {
22
+ rectangual_matrix.orthogonal?
23
+ }.should raise_error(Matrix::ErrDimensionMismatch)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ require 'matrix'
2
+
3
+ ruby_version_is "1.9.3" do
4
+ describe "Matrix#permutation?" do
5
+ it "returns true for a permutation Matrix" do
6
+ Matrix[[0, 1, 0], [0, 0, 1], [1, 0, 0]].permutation?.should be_true
7
+ end
8
+
9
+ it "returns false for a non permutation square Matrix" do
10
+ Matrix[[0, 1], [0, 0]].permutation?.should be_false
11
+ Matrix[[-1, 0], [0, -1]].permutation?.should be_false
12
+ Matrix[[1, 0], [1, 0]].permutation?.should be_false
13
+ Matrix[[1, 0], [1, 1]].permutation?.should be_false
14
+ end
15
+
16
+ it "returns true for an empty 0x0 matrix" do
17
+ Matrix.empty(0,0).permutation?.should be_true
18
+ end
19
+
20
+ it "raises an error for rectangular matrices" do
21
+ [
22
+ Matrix[[0], [0]],
23
+ Matrix[[0, 0]],
24
+ Matrix.empty(0, 2),
25
+ Matrix.empty(2, 0),
26
+ ].each do |rectangual_matrix|
27
+ lambda {
28
+ rectangual_matrix.permutation?
29
+ }.should raise_error(Matrix::ErrDimensionMismatch)
30
+ end
31
+ end
32
+ end
33
+ end