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.
@@ -46,15 +46,15 @@ describe NMatrix::BLAS do
46
46
  # These test results all come from actually running a matrix through BLAS. We use them to ensure that NMatrix's
47
47
  # version of these functions (for rationals) give similar results.
48
48
 
49
- b[0].should == -1.quo(4)
50
- b[1].should == 33.quo(4)
51
- b[2].should == -13
49
+ expect(b[0]).to eq(-1.quo(4))
50
+ expect(b[1]).to eq(33.quo(4))
51
+ expect(b[2]).to eq(-13)
52
52
 
53
53
  NMatrix::BLAS::cblas_trsm(:row, :right, :upper, :transpose, :unit, 1, 3, 1.0, a, 3, b, 3)
54
54
 
55
- b[0].should == -15.quo(2)
56
- b[1].should == 5
57
- b[2].should == -13
55
+ expect(b[0]).to eq(-15.quo(2))
56
+ expect(b[1]).to eq(5)
57
+ expect(b[2]).to eq(-13)
58
58
  end
59
59
  end
60
60
  end
@@ -77,11 +77,11 @@ describe NMatrix::BLAS do
77
77
  y = NMatrix.new([5,1], [-5,-4,-3,-2,-1], dtype: dtype)
78
78
  x, y = NMatrix::BLAS::rot(x, y, 1.quo(2), Math.sqrt(3).quo(2), -1)
79
79
 
80
- x.should be_within(1e-4).of(
80
+ expect(x).to be_within(1e-4).of(
81
81
  NMatrix.new([5,1], [-0.3660254037844386, -0.7320508075688772, -1.098076211353316, -1.4641016151377544, -1.8301270189221928], dtype: dtype)
82
82
  )
83
83
 
84
- y.should be_within(1e-4).of(
84
+ expect(y).to be_within(1e-4).of(
85
85
  NMatrix.new([5,1], [-6.830127018922193, -5.464101615137754, -4.098076211353316, -2.732050807568877, -1.3660254037844386], dtype: dtype)
86
86
  )
87
87
  end
@@ -99,16 +99,16 @@ describe NMatrix::BLAS do
99
99
  c,s = NMatrix::BLAS::rotg(ab)
100
100
 
101
101
  if [:float32, :float64].include?(dtype)
102
- ab[0].should be_within(1e-6).of(-10)
103
- ab[1].should be_within(1e-6).of(-5.quo(3))
104
- c.should be_within(1e-6).of(-3.quo(5))
102
+ expect(ab[0]).to be_within(1e-6).of(-10)
103
+ expect(ab[1]).to be_within(1e-6).of(-5.quo(3))
104
+ expect(c).to be_within(1e-6).of(-3.quo(5))
105
105
  else
106
106
  pending "need correct test cases"
107
- ab[0].should be_within(1e-6).of(10)
108
- ab[1].should be_within(1e-6).of(5.quo(3))
109
- c.should be_within(1e-6).of(3.quo(5))
107
+ expect(ab[0]).to be_within(1e-6).of(10)
108
+ expect(ab[1]).to be_within(1e-6).of(5.quo(3))
109
+ expect(c).to be_within(1e-6).of(3.quo(5))
110
110
  end
111
- s.should be_within(1e-6).of(4.quo(5))
111
+ expect(s).to be_within(1e-6).of(4.quo(5))
112
112
  end
113
113
 
114
114
  # Note: this exposes gemm, not cblas_gemm (which is the unfriendly CBLAS no-error-checking version)
@@ -120,7 +120,7 @@ describe NMatrix::BLAS do
120
120
  r = NMatrix::BLAS.gemm(n, m) #, c)
121
121
  #c.should equal(r) # check that both are same memory address
122
122
 
123
- r.should == NMatrix.new([4,2], [273,455,243,235,244,205,102,160], dtype: dtype)
123
+ expect(r).to eq(NMatrix.new([4,2], [273,455,243,235,244,205,102,160], dtype: dtype))
124
124
  end
125
125
 
126
126
 
@@ -133,13 +133,13 @@ describe NMatrix::BLAS do
133
133
 
134
134
  it "exposes asum" do
135
135
  x = NMatrix.new([4,1], [1,2,3,4], dtype: :float64)
136
- NMatrix::BLAS.asum(x).should == 10.0
136
+ expect(NMatrix::BLAS.asum(x)).to eq(10.0)
137
137
  end
138
138
 
139
139
 
140
140
  it "exposes nrm2" do
141
141
  x = NMatrix.new([4,1], [2,-4,3,5], dtype: :float64)
142
- NMatrix::BLAS.nrm2(x, 1, 3).should be_within(1e-10).of(5.385164807134504)
142
+ expect(NMatrix::BLAS.nrm2(x, 1, 3)).to be_within(1e-10).of(5.385164807134504)
143
143
  end
144
144
 
145
145
  end
@@ -50,15 +50,15 @@ describe NMatrix do
50
50
 
51
51
  it "should perform scalar math" do
52
52
  x = @n * 3
53
- x[0,0].should == 52 * 3
54
- x[0,1].should == 30 * 3
55
- x[0,2].should == 5 * 3
56
- x[1,1].should == 40 * 3
57
- x[2,0].should == 6 * 3
53
+ expect(x[0,0]).to eq(52 * 3)
54
+ expect(x[0,1]).to eq(30 * 3)
55
+ expect(x[0,2]).to eq(5 * 3)
56
+ expect(x[1,1]).to eq(40 * 3)
57
+ expect(x[2,0]).to eq(6 * 3)
58
58
 
59
59
  r = NMatrix.new(3, stype: :yale, dtype: :int64)
60
60
  y = r + 3
61
- y[0,0].should == 3
61
+ expect(y[0,0]).to eq(3)
62
62
  end
63
63
 
64
64
  it "should refuse to perform a dot operation on a yale with non-zero default" do
@@ -69,52 +69,52 @@ describe NMatrix do
69
69
  end
70
70
 
71
71
  it "should perform element-wise addition" do
72
- (@n+@m).should == NMatrix.new(:dense, 3, [52,30,0,0,-8,0,6,0,0], :int64).cast(:yale, :int64)
72
+ expect(@n+@m).to eq(NMatrix.new(:dense, 3, [52,30,0,0,-8,0,6,0,0], :int64).cast(:yale, :int64))
73
73
  end
74
74
 
75
75
  it "should perform element-wise subtraction" do
76
- (@n-@m).should == NMatrix.new(:dense, 3, [52,30,10,0,88,0,6,0,0], :int64).cast(:yale, :int64)
76
+ expect(@n-@m).to eq(NMatrix.new(:dense, 3, [52,30,10,0,88,0,6,0,0], :int64).cast(:yale, :int64))
77
77
  end
78
78
 
79
79
  it "should perform element-wise multiplication" do
80
80
  r = NMatrix.new(:dense, 3, [0,0,-25,0,-1920,0,0,0,0], :int64).cast(:yale, :int64)
81
81
  m = NMatrix.new(2, stype: :yale, dtype: :int64)
82
- (@n*@m).should == r
82
+ expect(@n*@m).to eq(r)
83
83
  end
84
84
 
85
85
  it "should perform element-wise division" do
86
86
  r = NMatrix.new(:dense, 3, [52, 30, -2, 0, -1, 0, 6, 0, 0], :int64).cast(:yale, :int64)
87
- (@n/(@m+1)).should == r
87
+ expect(@n/(@m+1)).to eq(r)
88
88
  end
89
89
 
90
90
  it "should perform element-wise modulo" do
91
91
  m = NMatrix.new(3, stype: :yale, dtype: :int64, default: 0) + 5
92
- (@n % m).should == NMatrix.new(:dense, 3, [2,0,0,0,0,0,1,0,0], :int64).cast(:yale, :int64)
92
+ expect(@n % m).to eq(NMatrix.new(:dense, 3, [2,0,0,0,0,0,1,0,0], :int64).cast(:yale, :int64))
93
93
  end
94
94
 
95
95
  it "should handle element-wise equality (=~)" do
96
- (@n =~ @m).should == NMatrix.new(:dense, 3, [false,false,false,true,false,true,false,true,true], :object).cast(:yale, :object, false)
96
+ expect(@n =~ @m).to eq(NMatrix.new(:dense, 3, [false,false,false,true,false,true,false,true,true], :object).cast(:yale, :object, false))
97
97
  end
98
98
 
99
99
  it "should handle element-wise inequality (!~)" do
100
- (@n !~ @m).should == NMatrix.new(:dense, 3, [true,true,true,false,true,false,true,false,false], :object).cast(:yale, :object, true)
100
+ expect(@n !~ @m).to eq(NMatrix.new(:dense, 3, [true,true,true,false,true,false,true,false,false], :object).cast(:yale, :object, true))
101
101
  end
102
102
 
103
103
  it "should handle element-wise less-than (<)" do
104
- (@m < @n).should == NMatrix.new(:dense, 3, [true,true,true,false,true,false,true,false,false], :object).cast(:yale, :object, true)
104
+ expect(@m < @n).to eq(NMatrix.new(:dense, 3, [true,true,true,false,true,false,true,false,false], :object).cast(:yale, :object, true))
105
105
  end
106
106
 
107
107
  it "should handle element-wise greater-than (>)" do
108
- (@n > @m).should == NMatrix.new(:dense, 3, [true,true,true,false,true,false,true,false,false], :object).cast(:yale, :object, false)
108
+ expect(@n > @m).to eq(NMatrix.new(:dense, 3, [true,true,true,false,true,false,true,false,false], :object).cast(:yale, :object, false))
109
109
  end
110
110
 
111
111
  it "should handle element-wise greater-than-or-equals (>=)" do
112
- (@n >= @m).should == NMatrix.new(:dense, 3, true, :object).cast(:yale,:object, true)
112
+ expect(@n >= @m).to eq(NMatrix.new(:dense, 3, true, :object).cast(:yale,:object, true))
113
113
  end
114
114
 
115
115
  it "should handle element-wise less-than-or-equals (<=)" do
116
116
  r = NMatrix.new(:dense, 3, [false,false,false,true,false,true,false,true,true], :object).cast(:yale, :object, false)
117
- (@n <= @m).should == r
117
+ expect(@n <= @m).to eq(r)
118
118
  end
119
119
  end
120
120
 
@@ -130,13 +130,13 @@ describe NMatrix do
130
130
 
131
131
  it "should perform scalar math" do
132
132
  x = @n * 3
133
- x[0,0].should == 52 * 3
134
- x[1,1].should == 40 * 3
135
- x[0,1].should == 0
133
+ expect(x[0,0]).to eq(52 * 3)
134
+ expect(x[1,1]).to eq(40 * 3)
135
+ expect(x[0,1]).to eq(0)
136
136
 
137
137
  r = NMatrix.new(3, stype: :list, default: 1)
138
138
  y = r + 3
139
- y[0,0].should == 4
139
+ expect(y[0,0]).to eq(4)
140
140
  end
141
141
 
142
142
  it "should perform element-wise addition" do
@@ -144,26 +144,26 @@ describe NMatrix do
144
144
  r[0,0] = 52
145
145
  r[1,1] = -8
146
146
  q = @n + @m
147
- q.should == r
147
+ expect(q).to eq(r)
148
148
  end
149
149
 
150
150
  it "should perform element-wise subtraction" do
151
151
  r = NMatrix.new(:dense, 2, [52, 0, 0, 88], :int64).cast(:list, :int64)
152
- (@n-@m).should == r
152
+ expect(@n-@m).to eq(r)
153
153
  end
154
154
 
155
155
  it "should perform element-wise multiplication" do
156
156
  r = NMatrix.new(:dense, 2, [52, 0, 0, -1920], :int64).cast(:list, :int64)
157
157
  m = NMatrix.new(:list, 2, 1, :int64)
158
158
  m[1,1] = -48
159
- (@n*m).should == r
159
+ expect(@n*m).to eq(r)
160
160
  end
161
161
 
162
162
  it "should perform element-wise division" do
163
163
  m = NMatrix.new(:list, 2, 1, :int64)
164
164
  m[1,1] = 2
165
165
  r = NMatrix.new(:dense, 2, [52, 0, 0, 20], :int64).cast(:list, :int64)
166
- (@n/m).should == r
166
+ expect(@n/m).to eq(r)
167
167
  end
168
168
 
169
169
  it "should perform element-wise modulo" do
@@ -178,7 +178,7 @@ describe NMatrix do
178
178
  r[0,1] = true
179
179
  r[1,0] = true
180
180
 
181
- (@n =~ @m).should == r
181
+ expect(@n =~ @m).to eq(r)
182
182
  end
183
183
 
184
184
  it "should handle element-wise inequality (!~)" do
@@ -186,29 +186,29 @@ describe NMatrix do
186
186
  r[0,0] = true
187
187
  r[1,1] = true
188
188
 
189
- (@n !~ @m).should == r
189
+ expect(@n !~ @m).to eq(r)
190
190
  end
191
191
 
192
192
  it "should handle element-wise less-than (<)" do
193
- (@n < @m).should == NMatrix.new(:list, 2, false, :object)
193
+ expect(@n < @m).to eq(NMatrix.new(:list, 2, false, :object))
194
194
  end
195
195
 
196
196
  it "should handle element-wise greater-than (>)" do
197
197
  r = NMatrix.new(:list, 2, false, :object)
198
198
  r[0,0] = true
199
199
  r[1,1] = true
200
- (@n > @m).should == r
200
+ expect(@n > @m).to eq(r)
201
201
  end
202
202
 
203
203
  it "should handle element-wise greater-than-or-equals (>=)" do
204
- (@n >= @m).should == NMatrix.new(:list, 2, true, :object)
204
+ expect(@n >= @m).to eq(NMatrix.new(:list, 2, true, :object))
205
205
  end
206
206
 
207
207
  it "should handle element-wise less-than-or-equals (<=)" do
208
208
  r = NMatrix.new(:list, 2, false, :object)
209
209
  r[0,1] = true
210
210
  r[1,0] = true
211
- (@n <= @m).should == r
211
+ expect(@n <= @m).to eq(r)
212
212
  end
213
213
  end
214
214
 
@@ -219,7 +219,7 @@ describe NMatrix do
219
219
  end
220
220
 
221
221
  it "works for integers" do
222
- (@n+1).should == NMatrix.new(:dense, 2, [2,3,4,5], :int64)
222
+ expect(@n+1).to eq(NMatrix.new(:dense, 2, [2,3,4,5], :int64))
223
223
  end
224
224
 
225
225
  #it "works for complex64" do
@@ -236,34 +236,34 @@ describe NMatrix do
236
236
 
237
237
  it "adds" do
238
238
  r = @n+@m
239
- r.should == NMatrix.new(:dense, [2,2], [-3, 1, 3, 70], :int64)
239
+ expect(r).to eq(NMatrix.new(:dense, [2,2], [-3, 1, 3, 70], :int64))
240
240
  end
241
241
 
242
242
  it "subtracts" do
243
243
  r = @n-@m
244
- r.should == NMatrix.new(:dense, [2,2], [5, 3, 3, -62], :int64)
244
+ expect(r).to eq(NMatrix.new(:dense, [2,2], [5, 3, 3, -62], :int64))
245
245
  end
246
246
 
247
247
  it "multiplies" do
248
248
  r = @n*@m
249
- r.should == NMatrix.new(:dense, [2,2], [-4, -2, 0, 264], :int64)
249
+ expect(r).to eq(NMatrix.new(:dense, [2,2], [-4, -2, 0, 264], :int64))
250
250
  end
251
251
 
252
252
  it "divides in the Ruby way" do
253
253
  m = @m.clone
254
254
  m[1,0] = 3
255
255
  r = @n/m
256
- r.should == NMatrix.new(:dense, [2,2], [-1, -2, 1, 0], :int64)
256
+ expect(r).to eq(NMatrix.new(:dense, [2,2], [-1, -2, 1, 0], :int64))
257
257
  end
258
258
 
259
259
  it "exponentiates" do
260
260
  r = @n ** 2
261
261
  # TODO: We might have problems with the dtype.
262
- r.should == NMatrix.new(:dense, [2,2], [1, 4, 9, 16], :int64)
262
+ expect(r).to eq(NMatrix.new(:dense, [2,2], [1, 4, 9, 16], :int64))
263
263
  end
264
264
 
265
265
  it "modulo" do
266
- (@n % (@m + 2)).should == NMatrix.new(:dense, [2,2], [-1, 0, 1, 4], :int64)
266
+ expect(@n % (@m + 2)).to eq(NMatrix.new(:dense, [2,2], [-1, 0, 1, 4], :int64))
267
267
  end
268
268
  end
269
269
 
@@ -275,33 +275,33 @@ describe NMatrix do
275
275
 
276
276
  it "equals" do
277
277
  r = @n =~ @m
278
- r.should == NMatrix.new(:dense, [2,2], [false, false, true, false], :object)
278
+ expect(r).to eq(NMatrix.new(:dense, [2,2], [false, false, true, false], :object))
279
279
  end
280
280
 
281
281
  it "is not equal" do
282
282
  r = @n !~ @m
283
- r.should == NMatrix.new(:dense, [2,2], [true, true, false, true], :object)
283
+ expect(r).to eq(NMatrix.new(:dense, [2,2], [true, true, false, true], :object))
284
284
  end
285
285
 
286
286
  it "is less than" do
287
287
  r = @n < @m
288
- r.should == NMatrix.new(:dense, [2,2], false, :object)
288
+ expect(r).to eq(NMatrix.new(:dense, [2,2], false, :object))
289
289
  end
290
290
 
291
291
  it "is greater than" do
292
292
  r = @n > @m
293
- r.should == NMatrix.new(:dense, [2,2], [true, true, false, true], :object)
293
+ expect(r).to eq(NMatrix.new(:dense, [2,2], [true, true, false, true], :object))
294
294
  end
295
295
 
296
296
  it "is less than or equal to" do
297
297
  r = @n <= @m
298
- r.should == NMatrix.new(:dense, [2,2], [false, false, true, false], :object)
298
+ expect(r).to eq(NMatrix.new(:dense, [2,2], [false, false, true, false], :object))
299
299
  end
300
300
 
301
301
  it "is greater than or equal to" do
302
302
  n = NMatrix.new(:dense, [2,2], [1, 2, 2, 4], :int64)
303
303
  r = n >= @m
304
- r.should == NMatrix.new(:dense, [2,2], [true, true, false, true], :object)
304
+ expect(r).to eq(NMatrix.new(:dense, [2,2], [true, true, false, true], :object))
305
305
  end
306
306
  end
307
307
  end
@@ -40,49 +40,56 @@ describe NMatrix::IO do
40
40
  end
41
41
 
42
42
  it "repacks a string" do
43
- NMatrix::IO::Matlab.repack("hello", :miUINT8, :byte).should == "hello"
43
+ expect(NMatrix::IO::Matlab.repack("hello", :miUINT8, :byte)).to eq("hello")
44
44
  end
45
45
 
46
46
  it "creates yale from internal byte-string function" do
47
47
  ia = NMatrix::IO::Matlab.repack("\0\1\3\3\4", :miUINT8, :itype)
48
48
  ja = NMatrix::IO::Matlab.repack("\0\1\3\0\0\0\0\0\0\0\0", :miUINT8, :itype)
49
49
  n = NMatrix.new(:yale, [4,4], :byte, ia, ja, "\2\3\5\4", :byte)
50
- n[0,0].should == 2
51
- n[1,1].should == 3
52
- n[1,3].should == 5
53
- n[3,0].should == 4
54
- n[2,2].should == 0
55
- n[3,3].should == 0
50
+ expect(n[0,0]).to eq(2)
51
+ expect(n[1,1]).to eq(3)
52
+ expect(n[1,3]).to eq(5)
53
+ expect(n[3,0]).to eq(4)
54
+ expect(n[2,2]).to eq(0)
55
+ expect(n[3,3]).to eq(0)
56
56
  end
57
57
 
58
58
  it "reads MATLAB .mat file containing a single square sparse matrix" do
59
59
  # Note: same matrix as above
60
60
  n = NMatrix::IO::Matlab.load_mat("spec/4x4_sparse.mat")
61
- n[0,0].should == 2
62
- n[1,1].should == 3
63
- n[1,3].should == 5
64
- n[3,0].should == 4
65
- n[2,2].should == 0
66
- n[3,3].should == 0
61
+ expect(n[0,0]).to eq(2)
62
+ expect(n[1,1]).to eq(3)
63
+ expect(n[1,3]).to eq(5)
64
+ expect(n[3,0]).to eq(4)
65
+ expect(n[2,2]).to eq(0)
66
+ expect(n[3,3]).to eq(0)
67
67
  end
68
68
 
69
69
  it "reads MATLAB .mat file containing a single dense integer matrix" do
70
70
  n = NMatrix::IO::Matlab.load_mat("spec/4x5_dense.mat")
71
71
  m = NMatrix.new([4,5], [16,17,18,19,20,15,14,13,12,11,6,7,8,9,10,5,4,3,2,1])
72
- n.should == m
72
+ expect(n).to eq(m)
73
73
  end
74
74
 
75
75
  it "reads MATLAB .mat file containing a single dense double matrix" do
76
76
  n = NMatrix::IO::Matlab.load_mat("spec/2x2_dense_double.mat")
77
77
  m = NMatrix.new(2, [1.1, 2.0, 3.0, 4.0], dtype: :float64)
78
- n.should == m
78
+ expect(n).to eq(m)
79
79
  end
80
80
 
81
81
  it "loads and saves MatrixMarket .mtx file containing a single large sparse double matrix" do
82
82
  pending "spec disabled because it's so slow"
83
83
  n = NMatrix::IO::Market.load("spec/utm5940.mtx")
84
84
  NMatrix::IO::Market.save(n, "spec/utm5940.saved.mtx")
85
- `wc -l spec/utm5940.mtx`.split[0].should == `wc -l spec/utm5940.saved.mtx`.split[0]
85
+ expect(`wc -l spec/utm5940.mtx`.split[0]).to eq(`wc -l spec/utm5940.saved.mtx`.split[0])
86
+ end
87
+
88
+ it "loads a Point Cloud Library PCD file" do
89
+ n = NMatrix::IO::PointCloud.load("spec/test.pcd")
90
+ expect(n.column(0).sort.uniq.size).to eq(1)
91
+ expect(n.column(0).sort.uniq.first).to eq(207.008)
92
+ expect(n[0,3]).to eq(0)
86
93
  end
87
94
 
88
95
  it "raises an error when reading a non-existent file" do
@@ -98,7 +105,7 @@ describe NMatrix::IO do
98
105
  n.write(@test_out)
99
106
 
100
107
  m = NMatrix.read(@test_out)
101
- n.should == m
108
+ expect(n).to eq(m)
102
109
  end
103
110
 
104
111
  it "reads and writes NMatrix dense as symmetric" do
@@ -106,7 +113,7 @@ describe NMatrix::IO do
106
113
  n.write(@test_out, :symmetric)
107
114
 
108
115
  m = NMatrix.read(@test_out)
109
- n.should == m
116
+ expect(n).to eq(m)
110
117
  end
111
118
 
112
119
  it "reads and writes NMatrix dense as skew" do
@@ -114,7 +121,7 @@ describe NMatrix::IO do
114
121
  n.write(@test_out, :skew)
115
122
 
116
123
  m = NMatrix.read(@test_out)
117
- n.should == m
124
+ expect(n).to eq(m)
118
125
  end
119
126
 
120
127
  it "reads and writes NMatrix dense as hermitian" do
@@ -122,7 +129,7 @@ describe NMatrix::IO do
122
129
  n.write(@test_out, :hermitian)
123
130
 
124
131
  m = NMatrix.read(@test_out)
125
- n.should == m
132
+ expect(n).to eq(m)
126
133
  end
127
134
 
128
135
  it "reads and writes NMatrix dense as upper" do
@@ -132,8 +139,8 @@ describe NMatrix::IO do
132
139
  m = NMatrix.new(:dense, 3, [-1,1,2,0,4,5,0,0,8], :int32) # lower version of the same
133
140
 
134
141
  o = NMatrix.read(@test_out)
135
- o.should == m
136
- o.should_not == n
142
+ expect(o).to eq(m)
143
+ expect(o).not_to eq(n)
137
144
  end
138
145
 
139
146
  it "reads and writes NMatrix dense as lower" do
@@ -143,7 +150,7 @@ describe NMatrix::IO do
143
150
  m = NMatrix.new(:dense, 3, [-1,0,0,3,4,0,6,7,8], :int32) # lower version of the same
144
151
 
145
152
  o = NMatrix.read(@test_out)
146
- o.should == m
147
- o.should_not == n
153
+ expect(o).to eq(m)
154
+ expect(o).not_to eq(n)
148
155
  end
149
156
  end