nmatrix 0.1.0.rc1 → 0.1.0.rc2

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.
@@ -40,7 +40,7 @@ describe NMatrix::LAPACK do
40
40
  a = NMatrix.new(:dense, [3,4], [1,2,3,4,5,6,7,8,9,10,11,12], dtype)
41
41
  NMatrix::LAPACK::clapack_laswp(3, a, 4, 0, 3, [2,1,3,0], 1)
42
42
  b = NMatrix.new(:dense, [3,4], [3,2,4,1,7,6,8,5,11,10,12,9], dtype)
43
- a.should == b
43
+ expect(a).to eq(b)
44
44
  end
45
45
 
46
46
  it "exposes NMatrix#permute_columns and #permute_columns! (user-friendly laswp)" do
@@ -48,10 +48,10 @@ describe NMatrix::LAPACK do
48
48
  b = NMatrix.new(:dense, [3,4], [3,2,4,1,7,6,8,5,11,10,12,9], dtype)
49
49
  piv = [2,1,3,0]
50
50
  r = a.permute_columns(piv)
51
- r.should_not == a
52
- r.should == b
51
+ expect(r).not_to eq(a)
52
+ expect(r).to eq(b)
53
53
  a.permute_columns!(piv)
54
- a.should == b
54
+ expect(a).to eq(b)
55
55
  end
56
56
  end
57
57
  end
@@ -71,7 +71,7 @@ describe NMatrix::LAPACK do
71
71
  else
72
72
  1e-64
73
73
  end
74
- NMatrix::LAPACK::clapack_gesv(:row,a.shape[0],b.shape[1],a,a.shape[0],b,b.shape[0]).should be_within(err).of(NMatrix[[-1.quo(2)], [0], [1.quo(2)]].cast(dtype: dtype))
74
+ expect(NMatrix::LAPACK::clapack_gesv(:row,a.shape[0],b.shape[1],a,a.shape[0],b,b.shape[0])).to be_within(err).of(NMatrix[[-1.quo(2)], [0], [1.quo(2)]].cast(dtype: dtype))
75
75
  end
76
76
 
77
77
 
@@ -89,15 +89,15 @@ describe NMatrix::LAPACK do
89
89
  1e-64 # FIXME: should be 0, but be_within(0) does not work.
90
90
  end
91
91
 
92
- a[0,0].should == 9 # 8
93
- a[0,1].should be_within(err).of(2.quo(9)) # 1
94
- a[0,2].should be_within(err).of(4.quo(9)) # 6
95
- a[1,0].should == 5 # 1.quo(2)
96
- a[1,1].should be_within(err).of(53.quo(9)) # 17.quo(2)
97
- a[1,2].should be_within(err).of(7.quo(53)) # -1
98
- a[2,0].should == 1 # 3.quo(8)
99
- a[2,1].should be_within(err).of(52.quo(9))
100
- a[2,2].should be_within(err).of(360.quo(53))
92
+ expect(a[0,0]).to eq(9) # 8
93
+ expect(a[0,1]).to be_within(err).of(2.quo(9)) # 1
94
+ expect(a[0,2]).to be_within(err).of(4.quo(9)) # 6
95
+ expect(a[1,0]).to eq(5) # 1.quo(2)
96
+ expect(a[1,1]).to be_within(err).of(53.quo(9)) # 17.quo(2)
97
+ expect(a[1,2]).to be_within(err).of(7.quo(53)) # -1
98
+ expect(a[2,0]).to eq(1) # 3.quo(8)
99
+ expect(a[2,1]).to be_within(err).of(52.quo(9))
100
+ expect(a[2,2]).to be_within(err).of(360.quo(53))
101
101
  end
102
102
 
103
103
  it "exposes clapack_potrf" do
@@ -106,7 +106,7 @@ describe NMatrix::LAPACK do
106
106
  a = NMatrix.new(:dense, 3, [25,15,-5, 0,18,0, 0,0,11], dtype)
107
107
  NMatrix::LAPACK::clapack_potrf(:row, :upper, 3, a, 3)
108
108
  b = NMatrix.new(:dense, 3, [5,3,-1, 0,3,1, 0,0,3], dtype)
109
- a.should == b
109
+ expect(a).to eq(b)
110
110
  rescue NotImplementedError => e
111
111
  pending e.to_s
112
112
  end
@@ -115,7 +115,7 @@ describe NMatrix::LAPACK do
115
115
  a = NMatrix.new(:dense, 3, [25,0,0, 15,18,0,-5,0,11], dtype)
116
116
  NMatrix::LAPACK::clapack_potrf(:row, :lower, 3, a, 3)
117
117
  b = NMatrix.new(:dense, 3, [5,0,0, 3,3,0, -1,1,3], dtype)
118
- a.should == b
118
+ expect(a).to eq(b)
119
119
  end
120
120
 
121
121
  # Together, these calls are basically xGESV from LAPACK: http://www.netlib.org/lapack/double/dgesv.f
@@ -126,9 +126,9 @@ describe NMatrix::LAPACK do
126
126
 
127
127
  NMatrix::LAPACK::clapack_getrs(:row, false, 3, 1, a, 3, ipiv, b, 3)
128
128
 
129
- b[0].should == 5
130
- b[1].should == -15.quo(2)
131
- b[2].should == -13
129
+ expect(b[0]).to eq(5)
130
+ expect(b[1]).to eq(-15.quo(2))
131
+ expect(b[2]).to eq(-13)
132
132
  end
133
133
 
134
134
  it "exposes clapack_getri" do
@@ -139,7 +139,7 @@ describe NMatrix::LAPACK do
139
139
  NMatrix::LAPACK::clapack_getri(:row, 3, a, 3, ipiv)
140
140
 
141
141
  b = NMatrix.new(:dense, 3, [-5,0,-2,-4,1,-1,1.5,0,0.5], dtype)
142
- a.should == b
142
+ expect(a).to eq(b)
143
143
  rescue NotImplementedError => e
144
144
  pending e.to_s
145
145
  end
@@ -200,10 +200,10 @@ describe NMatrix::LAPACK do
200
200
  pending e.to_s
201
201
  end
202
202
 
203
- u.should be_within(err).of(left_true)
203
+ expect(u).to be_within(err).of(left_true)
204
204
  #FIXME: Is the next line correct?
205
- vt[0...right_true.shape[0], 0...right_true.shape[1]-1].should be_within(err).of(right_true[0...right_true.shape[0],0...right_true.shape[1]-1])
206
- s.transpose.should be_within(err).of(s_true.row(0))
205
+ expect(vt[0...right_true.shape[0], 0...right_true.shape[1]-1]).to be_within(err).of(right_true[0...right_true.shape[0],0...right_true.shape[1]-1])
206
+ expect(s.transpose).to be_within(err).of(s_true.row(0))
207
207
  end
208
208
 
209
209
 
@@ -272,10 +272,10 @@ describe NMatrix::LAPACK do
272
272
  pending e.to_s
273
273
  end
274
274
 
275
- u.should be_within(err).of(left_true)
275
+ expect(u).to be_within(err).of(left_true)
276
276
  #FIXME: Is the next line correct?
277
- vt[0...right_true.shape[0], 0...right_true.shape[1]-1].should be_within(err).of(right_true[0...right_true.shape[0],0...right_true.shape[1]-1])
278
- s.transpose.should be_within(err).of(s_true.row(0))
277
+ expect(vt[0...right_true.shape[0], 0...right_true.shape[1]-1]).to be_within(err).of(right_true[0...right_true.shape[0],0...right_true.shape[1]-1])
278
+ expect(s.transpose).to be_within(err).of(s_true.row(0))
279
279
 
280
280
  end
281
281
 
@@ -341,10 +341,10 @@ describe NMatrix::LAPACK do
341
341
  rescue NotImplementedError => e
342
342
  pending e.to_s
343
343
  end
344
- u.should be_within(err).of(left_true)
344
+ expect(u).to be_within(err).of(left_true)
345
345
  #FIXME: Is the next line correct?
346
- vt[0...right_true.shape[0], 0...right_true.shape[1]-1].should be_within(err).of(right_true[0...right_true.shape[0],0...right_true.shape[1]-1])
347
- s.transpose.should be_within(err).of(s_true.row(0))
346
+ expect(vt[0...right_true.shape[0], 0...right_true.shape[1]-1]).to be_within(err).of(right_true[0...right_true.shape[0],0...right_true.shape[1]-1])
347
+ expect(s.transpose).to be_within(err).of(s_true.row(0))
348
348
 
349
349
  end
350
350
  it "exposes the convenience gesdd method" do
@@ -400,10 +400,10 @@ describe NMatrix::LAPACK do
400
400
  rescue NotImplementedError => e
401
401
  pending e.to_s
402
402
  end
403
- u.should be_within(err).of(left_true)
403
+ expect(u).to be_within(err).of(left_true)
404
404
  #FIXME: Is the next line correct?
405
- vt[0...right_true.shape[0], 0...right_true.shape[1]-1].should be_within(err).of(right_true[0...right_true.shape[0],0...right_true.shape[1]-1])
406
- s.transpose.should be_within(err).of(s_true.row(0))
405
+ expect(vt[0...right_true.shape[0], 0...right_true.shape[1]-1]).to be_within(err).of(right_true[0...right_true.shape[0],0...right_true.shape[1]-1])
406
+ expect(s.transpose).to be_within(err).of(s_true.row(0))
407
407
  end
408
408
 
409
409
 
@@ -428,7 +428,7 @@ describe NMatrix::LAPACK do
428
428
  ldvl = n
429
429
 
430
430
  info = NMatrix::LAPACK::lapack_geev(:left, :right, n, a.clone, lda, wr.clone, wi.nil? ? nil : wi.clone, vl.clone, ldvl, vr.clone, ldvr, -1)
431
- info.should == 0
431
+ expect(info).to eq(0)
432
432
 
433
433
  info = NMatrix::LAPACK::lapack_geev(:left, :right, n, a, lda, wr, wi, vl, ldvl, vr, ldvr, 2*n)
434
434
 
@@ -443,7 +443,7 @@ describe NMatrix::LAPACK do
443
443
  0.28, 0.01, 0.02, 0.19, 0.80,
444
444
  -0.04, 0.34, 0.40, -0.22, -0.18 ], :float64)
445
445
 
446
- vl.abs.should be_within(1e-2).of(vl_true.abs)
446
+ expect(vl.abs).to be_within(1e-2).of(vl_true.abs)
447
447
  # Not checking vr_true.
448
448
  # Example from:
449
449
  # http://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/lapacke_dgeev_row.c.htm
@@ -53,9 +53,16 @@ describe "math" do
53
53
  meth.to_s[1...meth.to_s.length].to_sym)
54
54
  next if meth == :atanh
55
55
 
56
+ if meth == :-@
57
+ it "should correctly apply elementwise negation" do
58
+ expect(@m.send(meth)).to eq N.new(@size, @a.map { |e| -e }, dtype: dtype, stype: stype)
59
+ end
60
+ next
61
+ end
62
+
56
63
  it "should correctly apply elementwise #{meth}" do
57
64
 
58
- @m.send(meth).should eq N.new(@size, @a.map{ |e| Math.send(meth, e) },
65
+ expect(@m.send(meth)).to eq N.new(@size, @a.map{ |e| Math.send(meth, e) },
59
66
  dtype: :float64, stype: stype)
60
67
  end
61
68
  end
@@ -63,28 +70,28 @@ describe "math" do
63
70
  NMatrix::NMMath::METHODS_ARITY_2.each do |meth|
64
71
  next if meth == :atan2
65
72
  it "should correctly apply elementwise #{meth}" do
66
- @m.send(meth, @m).should eq N.new(@size, @a.map{ |e|
73
+ expect(@m.send(meth, @m)).to eq N.new(@size, @a.map{ |e|
67
74
  Math.send(meth, e, e) },
68
- dtype: :float64,
75
+ dtype: :float64,
69
76
  stype: stype)
70
77
  end
71
78
 
72
79
  it "should correctly apply elementwise #{meth} with a scalar first arg" do
73
- Math.send(meth, 1, @m).should eq N.new(@size, @a.map { |e| Math.send(meth, 1, e) }, dtype: :float64, stype: stype)
80
+ expect(Math.send(meth, 1, @m)).to eq N.new(@size, @a.map { |e| Math.send(meth, 1, e) }, dtype: :float64, stype: stype)
74
81
  end
75
82
 
76
83
  it "should correctly apply elementwise #{meth} with a scalar second arg" do
77
- @m.send(meth, 1).should eq N.new(@size, @a.map { |e| Math.send(meth, e, 1) }, dtype: :float64, stype: stype)
84
+ expect(@m.send(meth, 1)).to eq N.new(@size, @a.map { |e| Math.send(meth, e, 1) }, dtype: :float64, stype: stype)
78
85
  end
79
86
  end
80
87
 
81
88
  it "should correctly apply elementwise natural log" do
82
- @m.log.should eq N.new(@size, [0, Math.log(2), Math.log(3), Math.log(4)],
89
+ expect(@m.log).to eq N.new(@size, [0, Math.log(2), Math.log(3), Math.log(4)],
83
90
  dtype: :float64, stype: stype)
84
91
  end
85
92
 
86
93
  it "should correctly apply elementwise log with arbitrary base" do
87
- @m.log(3).should eq N.new(@size, [0, Math.log(2,3), 1, Math.log(4,3)],
94
+ expect(@m.log(3)).to eq N.new(@size, [0, Math.log(2,3), 1, Math.log(4,3)],
88
95
  dtype: :float64, stype: stype)
89
96
  end
90
97
 
@@ -96,23 +103,23 @@ describe "math" do
96
103
  [:asin, :acos, :atan, :atanh].each do |atf|
97
104
 
98
105
  it "should correctly apply elementwise #{atf}" do
99
- @m.send(atf).should eq N.new(@size,
106
+ expect(@m.send(atf)).to eq N.new(@size,
100
107
  @a.map{ |e| Math.send(atf, e) },
101
108
  dtype: :float64, stype: stype)
102
109
  end
103
110
  end
104
111
 
105
112
  it "should correctly apply elementtwise atan2" do
106
- @m.atan2(@m*0+1).should eq N.new(@size,
113
+ expect(@m.atan2(@m*0+1)).to eq N.new(@size,
107
114
  @a.map { |e| Math.send(:atan2, e, 1) }, dtype: :float64, stype: stype)
108
115
  end
109
116
 
110
117
  it "should correctly apply elementwise atan2 with a scalar first arg" do
111
- Math.atan2(1, @m).should eq N.new(@size, @a.map { |e| Math.send(:atan2, 1, e) }, dtype: :float64, stype: stype)
118
+ expect(Math.atan2(1, @m)).to eq N.new(@size, @a.map { |e| Math.send(:atan2, 1, e) }, dtype: :float64, stype: stype)
112
119
  end
113
120
 
114
121
  it "should correctly apply elementwise atan2 with a scalar second arg" do
115
- @m.atan2(1).should eq N.new(@size, @a.map { |e| Math.send(:atan2, e, 1) }, dtype: :float64, stype: stype)
122
+ expect(@m.atan2(1)).to eq N.new(@size, @a.map { |e| Math.send(:atan2, e, 1) }, dtype: :float64, stype: stype)
116
123
  end
117
124
  end
118
125
  end
@@ -127,20 +134,20 @@ describe "math" do
127
134
  it "should correctly factorize a matrix" do
128
135
  m = NMatrix.new(:dense, 3, [4,9,2,3,5,7,8,1,6], dtype)
129
136
  a = m.factorize_lu
130
- a[0,0].should == 8
131
- a[0,1].should == 1
132
- a[0,2].should == 6
133
- a[1,0].should == 0.5
134
- a[1,1].should == 8.5
135
- a[1,2].should == -1
136
- a[2,0].should == 0.375
137
+ expect(a[0,0]).to eq(8)
138
+ expect(a[0,1]).to eq(1)
139
+ expect(a[0,2]).to eq(6)
140
+ expect(a[1,0]).to eq(0.5)
141
+ expect(a[1,1]).to eq(8.5)
142
+ expect(a[1,2]).to eq(-1)
143
+ expect(a[2,0]).to eq(0.375)
137
144
  end
138
145
  end
139
146
 
140
147
  context dtype do
141
- it "should correctly invert a matrix" do
148
+ it "should correctly invert a matrix in place" do
142
149
  a = NMatrix.new(:dense, 3, [1,0,4,1,1,6,-3,0,-10], dtype)
143
- b = NMatrix.new(:dense, 3, [-5,0,-2,-4,1,-1,1.5,0,0.5], dtype)
150
+ b = NMatrix.new(:dense, 3, [-5,0,-2,-4,1,-1,3.quo(2),0,1.quo(2)], dtype)
144
151
  begin
145
152
  a.invert!
146
153
  rescue NotImplementedError => e
@@ -150,7 +157,15 @@ describe "math" do
150
157
  pending e.to_s
151
158
  end
152
159
  end
153
- a.should == b
160
+ expect(a).to eq(b)
161
+ end
162
+
163
+ unless NMatrix.has_clapack?
164
+ it "should correctly exact-invert a matrix" do
165
+ a = NMatrix.new(:dense, 3, [1,0,4,1,1,6,-3,0,-10], dtype)
166
+ b = NMatrix.new(:dense, 3, [-5,0,-2,-4,1,-1,3.quo(2),0,1.quo(2)], dtype)
167
+ a.invert.should == b
168
+ end
154
169
  end
155
170
  end
156
171
  end
@@ -187,26 +202,26 @@ describe "math" do
187
202
  n = NMatrix.new([4,3], nary, dtype: left_dtype, stype: :dense)
188
203
  m = NMatrix.new([3,2], mary, dtype: right_dtype, stype: :dense)
189
204
 
190
- m.shape[0].should == 3
191
- m.shape[1].should == 2
192
- m.dim.should == 2
205
+ expect(m.shape[0]).to eq(3)
206
+ expect(m.shape[1]).to eq(2)
207
+ expect(m.dim).to eq(2)
193
208
 
194
- n.shape[0].should == 4
195
- n.shape[1].should == 3
196
- n.dim.should == 2
209
+ expect(n.shape[0]).to eq(4)
210
+ expect(n.shape[1]).to eq(3)
211
+ expect(n.dim).to eq(2)
197
212
 
198
- n.shape[1].should == m.shape[0]
213
+ expect(n.shape[1]).to eq(m.shape[0])
199
214
 
200
215
  r = n.dot m
201
216
 
202
- r[0,0].should == 273.0
203
- r[0,1].should == 455.0
204
- r[1,0].should == 243.0
205
- r[1,1].should == 235.0
206
- r[2,0].should == 244.0
207
- r[2,1].should == 205.0
208
- r[3,0].should == 102.0
209
- r[3,1].should == 160.0
217
+ expect(r[0,0]).to eq(273.0)
218
+ expect(r[0,1]).to eq(455.0)
219
+ expect(r[1,0]).to eq(243.0)
220
+ expect(r[1,1]).to eq(235.0)
221
+ expect(r[2,0]).to eq(244.0)
222
+ expect(r[2,1]).to eq(205.0)
223
+ expect(r[3,0]).to eq(102.0)
224
+ expect(r[3,1]).to eq(160.0)
210
225
 
211
226
  #r.dtype.should == :float64 unless left_dtype == :float32 && right_dtype == :float32
212
227
  end
@@ -226,22 +241,22 @@ describe "math" do
226
241
 
227
242
  m = NMatrix.new([3,1], [2.0, 1.0, 0.0], dtype: right_dtype)
228
243
 
229
- m.shape[0].should == 3
230
- m.shape[1].should == 1
244
+ expect(m.shape[0]).to eq(3)
245
+ expect(m.shape[1]).to eq(1)
231
246
 
232
- n.shape[0].should == 4
233
- n.shape[1].should == 3
234
- n.dim.should == 2
247
+ expect(n.shape[0]).to eq(4)
248
+ expect(n.shape[1]).to eq(3)
249
+ expect(n.dim).to eq(2)
235
250
 
236
- n.shape[1].should == m.shape[0]
251
+ expect(n.shape[1]).to eq(m.shape[0])
237
252
 
238
253
  r = n.dot m
239
254
  # r.class.should == NVector
240
255
 
241
- r[0,0].should == 4
242
- r[1,0].should == 13
243
- r[2,0].should == 22
244
- r[3,0].should == 31
256
+ expect(r[0,0]).to eq(4)
257
+ expect(r[1,0]).to eq(13)
258
+ expect(r[2,0]).to eq(22)
259
+ expect(r[3,0]).to eq(31)
245
260
 
246
261
  #r.dtype.should == :float64 unless left_dtype == :float32 && right_dtype == :float32
247
262
  end
@@ -36,7 +36,7 @@ describe NMatrix do
36
36
  it "compares two empty matrices" do
37
37
  n = NMatrix.new(4, stype: :yale, dtype: :float64)
38
38
  m = NMatrix.new(4, stype: :yale, dtype: :float64)
39
- n.should == m
39
+ expect(n).to eq(m)
40
40
  end
41
41
 
42
42
  it "compares two matrices following basic assignments" do
@@ -45,11 +45,11 @@ describe NMatrix do
45
45
 
46
46
  m[0,0] = 1
47
47
  m[0,1] = 1
48
- n.should_not == m
48
+ expect(n).not_to eq(m)
49
49
  n[0,0] = 1
50
- n.should_not == m
50
+ expect(n).not_to eq(m)
51
51
  n[0,1] = 1
52
- n.should == m
52
+ expect(n).to eq(m)
53
53
  end
54
54
 
55
55
  it "compares two matrices following elementwise operations" do
@@ -58,7 +58,7 @@ describe NMatrix do
58
58
  n[0,1] = 1
59
59
  m[0,1] = -1
60
60
  x = n+m
61
- (n+m).should == NMatrix.new(2, 0.0, stype: :yale)
61
+ expect(n+m).to eq(NMatrix.new(2, 0.0, stype: :yale))
62
62
  end
63
63
 
64
64
  it "sets diagonal values" do
@@ -66,7 +66,7 @@ describe NMatrix do
66
66
  n.extend(NMatrix::YaleFunctions)
67
67
  n[1,1] = 0.1
68
68
  n[0,0] = 0.2
69
- n.yale_d.should == [0.2, 0.1]
69
+ expect(n.yale_d).to eq([0.2, 0.1])
70
70
  end
71
71
 
72
72
  it "gets non-diagonal rows as hashes" do
@@ -77,7 +77,7 @@ describe NMatrix do
77
77
  n[0,3] = 0.3
78
78
  n[1,5] = 0.4
79
79
  h = n.yale_nd_row(0, :hash)
80
- h.should == {2 => 0.2, 3 => 0.3}
80
+ expect(h).to eq({2 => 0.2, 3 => 0.3})
81
81
  end
82
82
 
83
83
  it "gets non-diagonal occupied column indices for a given row" do
@@ -88,19 +88,19 @@ describe NMatrix do
88
88
  n[0,3] = 0.3
89
89
  n[1,5] = 0.4
90
90
  a = n.yale_nd_row(0, :array)
91
- a.should == [2,3]
91
+ expect(a).to eq([2,3])
92
92
  end
93
93
 
94
94
  it "does not resize until necessary" do
95
95
  n = NMatrix.new([2,3], stype: :yale, dtype: :float64)
96
96
  n.extend(NMatrix::YaleFunctions)
97
- n.yale_size.should == 3
98
- n.capacity.should == 5
97
+ expect(n.yale_size).to eq(3)
98
+ expect(n.capacity).to eq(5)
99
99
  n[0,0] = 0.1
100
100
  n[0,1] = 0.2
101
101
  n[1,0] = 0.3
102
- n.yale_size.should == 5
103
- n.capacity.should == 5
102
+ expect(n.yale_size).to eq(5)
103
+ expect(n.capacity).to eq(5)
104
104
  end
105
105
 
106
106
 
@@ -110,8 +110,8 @@ describe NMatrix do
110
110
  n[0,0] = 0.1
111
111
  n[0,1] = 0.2
112
112
  n[1,0] = 0.3
113
- n.yale_a.should == [0.1, 0.0, 0.0, 0.2, 0.3]
114
- n.yale_ija.should == [3,4,5,1,0]
113
+ expect(n.yale_a).to eq([0.1, 0.0, 0.0, 0.2, 0.3])
114
+ expect(n.yale_ija).to eq([3,4,5,1,0])
115
115
  end
116
116
 
117
117
  it "sets when resizing" do
@@ -122,10 +122,10 @@ describe NMatrix do
122
122
  n[0,1] = 0.2
123
123
  n[1,0] = 0.3
124
124
  n[1,2] = 0.4
125
- n.yale_d.should == [0.01, 0.1]
126
- n.yale_ia.should == [3,4,6]
127
- n.yale_ja.should == [1,0,2,nil]
128
- n.yale_lu.should == [0.2, 0.3, 0.4, nil]
125
+ expect(n.yale_d).to eq([0.01, 0.1])
126
+ expect(n.yale_ia).to eq([3,4,6])
127
+ expect(n.yale_ja).to eq([1,0,2,nil])
128
+ expect(n.yale_lu).to eq([0.2, 0.3, 0.4, nil])
129
129
  end
130
130
 
131
131
  it "resizes without erasing values" do
@@ -138,11 +138,11 @@ describe NMatrix do
138
138
 
139
139
  associations.each_pair do |j,i|
140
140
  n[i,j] = 1
141
- n[i,j].should be(1), "Value at #{i},#{j} not inserted correctly!"
141
+ expect(n[i,j]).to be(1), "Value at #{i},#{j} not inserted correctly!"
142
142
  end
143
143
 
144
144
  associations.each_pair do |j,i|
145
- n[i,j].should be(1), "Value at #{i},#{j} erased during resize!"
145
+ expect(n[i,j]).to be(1), "Value at #{i},#{j} erased during resize!"
146
146
  end
147
147
  end
148
148
 
@@ -152,8 +152,8 @@ describe NMatrix do
152
152
  n[2,1] = 1.0
153
153
  n[2,0] = 1.5
154
154
  n[2,15] = 2.0
155
- n.yale_lu.should == [1.5, 1.0, 2.0]
156
- n.yale_ja.should == [0, 1, 15]
155
+ expect(n.yale_lu).to eq([1.5, 1.0, 2.0])
156
+ expect(n.yale_ja).to eq([0, 1, 15])
157
157
  end
158
158
 
159
159
  it "gets values within rows" do
@@ -161,9 +161,9 @@ describe NMatrix do
161
161
  n[2,1] = 1.0
162
162
  n[2,0] = 1.5
163
163
  n[2,15] = 2.0
164
- n[2,1].should == 1.0
165
- n[2,0].should == 1.5
166
- n[2,15].should == 2.0
164
+ expect(n[2,1]).to eq(1.0)
165
+ expect(n[2,0]).to eq(1.5)
166
+ expect(n[2,15]).to eq(2.0)
167
167
  end
168
168
 
169
169
  it "sets values within large rows" do
@@ -179,8 +179,8 @@ describe NMatrix do
179
179
  n[5,293] = 2.0
180
180
  n[5,299] = 7.0
181
181
  n[5,100] = 8.0
182
- n.yale_lu.should == [1.5, 1.0, 2.0, 8.0, 5.0, 6.0, 3.0, 4.0, 2.0, 7.0]
183
- n.yale_ja.should == [0, 1, 15, 100, 289, 290, 291, 292, 293, 299]
182
+ expect(n.yale_lu).to eq([1.5, 1.0, 2.0, 8.0, 5.0, 6.0, 3.0, 4.0, 2.0, 7.0])
183
+ expect(n.yale_ja).to eq([0, 1, 15, 100, 289, 290, 291, 292, 293, 299])
184
184
  end
185
185
 
186
186
  it "gets values within large rows" do
@@ -199,7 +199,7 @@ describe NMatrix do
199
199
 
200
200
  n.yale_ja.each_index do |idx|
201
201
  j = n.yale_ja[idx]
202
- n[5,j].should == n.yale_lu[idx]
202
+ expect(n[5,j]).to eq(n.yale_lu[idx])
203
203
  end
204
204
  end
205
205
 
@@ -215,7 +215,7 @@ describe NMatrix do
215
215
 
216
216
  d = NMatrix.new(4, [0,0,4,4, 0,2,0,0, 0,0,0,0, 0,0,2,2], dtype: :float64, stype: :yale)
217
217
 
218
- c.should == d
218
+ expect(c).to eq(d)
219
219
  end
220
220
 
221
221
  it "dots two identical matrices where a positive and negative partial sum cancel on the diagonal" do
@@ -233,8 +233,8 @@ describe NMatrix do
233
233
 
234
234
  c.extend(NMatrix::YaleFunctions)
235
235
 
236
- c.yale_ija.reject { |i| i.nil? }.should == [5,8,9,9,11,1,2,3,3,1,2]
237
- c.yale_a.reject { |i| i.nil? }.should == [1.0, -16.0, 0.0, 0.0, 0.0, 4.0, 8.0, -16.0, -16.0, 16.0, 8.0]
236
+ expect(c.yale_ija.reject { |i| i.nil? }).to eq([5,8,9,9,11,1,2,3,3,1,2])
237
+ expect(c.yale_a.reject { |i| i.nil? }).to eq([1.0, -16.0, 0.0, 0.0, 0.0, 4.0, 8.0, -16.0, -16.0, 16.0, 8.0])
238
238
 
239
239
  end
240
240
 
@@ -264,11 +264,11 @@ describe NMatrix do
264
264
  # We want to do a structure comparison to ensure multiplication is occurring properly, but more importantly, to
265
265
  # ensure that insertion sort is occurring as it should. If the row has more than four entries, it'll run quicksort
266
266
  # instead. Quicksort calls insertion sort for small rows, so we test both with this particular multiplication.
267
- nm.yale_ija[0...107].should == nmr.yale_ija[0...107]
268
- nm.yale_a[0...107].should == nmr.yale_a[0...107]
267
+ expect(nm.yale_ija[0...107]).to eq(nmr.yale_ija[0...107])
268
+ expect(nm.yale_a[0...107]).to eq(nmr.yale_a[0...107])
269
269
 
270
270
  mn = m.dot(n)
271
- mn[0,0].should == 541
271
+ expect(mn[0,0]).to eq(541)
272
272
  end
273
273
 
274
274
  it "calculates the row key intersections of two matrices" do
@@ -280,7 +280,7 @@ describe NMatrix do
280
280
  (0...3).each do |ai|
281
281
  (0...3).each do |bi|
282
282
  STDERR.puts (a.yale_ja_d_keys_at(ai) & b.yale_ja_d_keys_at(bi)).inspect
283
- (a.yale_ja_d_keys_at(ai) & b.yale_ja_d_keys_at(bi)).should == a.yale_row_keys_intersection(ai, b, bi)
283
+ expect(a.yale_ja_d_keys_at(ai) & b.yale_ja_d_keys_at(bi)).to eq(a.yale_row_keys_intersection(ai, b, bi))
284
284
  end
285
285
  end
286
286