nmatrix 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +102 -10
  3. data/README.rdoc +24 -32
  4. data/Rakefile +1 -1
  5. data/ext/nmatrix/data/complex.h +9 -0
  6. data/ext/nmatrix/data/data.cpp +78 -4
  7. data/ext/nmatrix/data/data.h +86 -54
  8. data/ext/nmatrix/data/rational.h +2 -0
  9. data/ext/nmatrix/data/ruby_object.h +38 -8
  10. data/ext/nmatrix/extconf.rb +13 -7
  11. data/ext/nmatrix/nmatrix.cpp +262 -139
  12. data/ext/nmatrix/nmatrix.h +11 -4
  13. data/ext/nmatrix/storage/common.cpp +20 -13
  14. data/ext/nmatrix/storage/common.h +18 -12
  15. data/ext/nmatrix/storage/dense.cpp +122 -192
  16. data/ext/nmatrix/storage/dense.h +4 -2
  17. data/ext/nmatrix/storage/list.cpp +467 -636
  18. data/ext/nmatrix/storage/list.h +6 -3
  19. data/ext/nmatrix/storage/storage.cpp +83 -46
  20. data/ext/nmatrix/storage/storage.h +7 -7
  21. data/ext/nmatrix/storage/yale.cpp +621 -361
  22. data/ext/nmatrix/storage/yale.h +21 -9
  23. data/ext/nmatrix/ttable_helper.rb +27 -31
  24. data/ext/nmatrix/types.h +1 -1
  25. data/ext/nmatrix/util/math.cpp +9 -10
  26. data/ext/nmatrix/util/sl_list.cpp +1 -7
  27. data/ext/nmatrix/util/sl_list.h +0 -118
  28. data/lib/nmatrix/blas.rb +59 -18
  29. data/lib/nmatrix/monkeys.rb +0 -52
  30. data/lib/nmatrix/nmatrix.rb +136 -9
  31. data/lib/nmatrix/nvector.rb +33 -0
  32. data/lib/nmatrix/shortcuts.rb +95 -16
  33. data/lib/nmatrix/version.rb +1 -1
  34. data/lib/nmatrix/yale_functions.rb +25 -19
  35. data/spec/blas_spec.rb +1 -19
  36. data/spec/elementwise_spec.rb +132 -17
  37. data/spec/lapack_spec.rb +0 -3
  38. data/spec/nmatrix_list_spec.rb +18 -0
  39. data/spec/nmatrix_spec.rb +44 -18
  40. data/spec/nmatrix_yale_spec.rb +1 -3
  41. data/spec/shortcuts_spec.rb +26 -36
  42. data/spec/slice_spec.rb +2 -4
  43. metadata +2 -2
@@ -57,9 +57,7 @@ describe NMatrix do
57
57
  n[0,1] = 1
58
58
  m = NMatrix.new(:yale, [2,2], :float64)
59
59
  m[0,1] = -1
60
- r = NMatrix.new(:yale, [2,2], :float64)
61
- r[0,1] = 0
62
- (n+m).should == r
60
+ (n+m).should == NMatrix.new(:yale, [2,2], :float64)
63
61
  end
64
62
 
65
63
  it "sets diagonal values" do
@@ -51,6 +51,21 @@ describe NMatrix do
51
51
  m.should.eql? identity3
52
52
  end
53
53
 
54
+ it "diag() creates a matrix with pre-supplied diagonal" do
55
+ arr = [1,2,3,4]
56
+ m = NMatrix.diag(arr)
57
+ m.is_a?(NMatrix).should be_true
58
+ end
59
+
60
+ it "diagonals() contains the seeded values on the diagonal" do
61
+ arr = [1,2,3,4]
62
+ m = NMatrix.diagonals(arr)
63
+ m[0,0].should eq(arr[0])
64
+ m[1,1].should eq(arr[1])
65
+ m[2,2].should eq(arr[2])
66
+ m[3,3].should eq(arr[3])
67
+ end
68
+
54
69
  it "random() creates a matrix of random numbers" do
55
70
  m = NMatrix.random(2)
56
71
 
@@ -201,12 +216,7 @@ describe "NVector" do
201
216
 
202
217
  it "seq() creates a vector of integers, sequentially" do
203
218
  v = NVector.seq(7)
204
- i = 0
205
-
206
- v.each do |elem|
207
- elem.should == i
208
- i += 1
209
- end
219
+ v.should == NVector.new(7, [0, 1, 2, 3, 4, 5, 6], :int64)
210
220
  end
211
221
 
212
222
  it "seq() only accepts integers as dimension" do
@@ -218,52 +228,32 @@ describe "NVector" do
218
228
 
219
229
  it "indgen() creates a vector of integers as well as seq()" do
220
230
  v = NVector.indgen(7)
221
- i = 0
222
-
223
- v.each do |elem|
224
- elem.should == i
225
- i += 1
226
- end
231
+ v.should == NVector.new(7, [0, 1, 2, 3, 4, 5, 6], :int64)
227
232
  end
228
233
 
229
234
  it "findgen creates a vector of floats, sequentially" do
230
235
  v = NVector.findgen(2)
231
-
232
- 2.times do |i|
233
- (v[i]/10).should be_within(Float::EPSILON).of(i.to_f/10)
234
- end
236
+ v.should == NVector.new(2, [0.0, 1.0], :float32)
235
237
  end
236
238
 
237
239
  it "bindgen() creates a vector of bytes, sequentially" do
238
- v = NVector.bindgen(7)
239
- i = 0
240
-
241
- v.each do |elem|
242
- elem.should == i
243
- i += 1
244
- end
240
+ v = NVector.bindgen(4)
241
+ v.should == NVector.new(4, [0, 1, 2, 3], :byte)
245
242
  end
246
243
 
247
244
  it "cindgen() creates a vector of complexes, sequentially" do
248
245
  v = NVector.cindgen(2)
249
- value = 0
250
-
251
- 2.times do |i|
252
- v[i].real.should be_within(Float::EPSILON).of(value)
253
- v[i].imag.should be_within(Float::EPSILON).of(0.0)
254
- value += 1
255
- end
246
+ v.should == NVector.new(2, [Complex(0.0, 0.0), Complex(1.0, 0.0)], :complex64)
256
247
  end
257
248
 
258
-
259
249
  it "linspace() creates a vector with n values equally spaced between a and b" do
260
250
  v = NVector.linspace(0, 2, 5)
261
- i = 0
251
+ v.should == NVector.new(5, [0, 0.5, 1.0, 1.5, 2.0], :float64)
252
+ end
262
253
 
263
- v.each do |elem|
264
- elem.should == i * 0.5
265
- i += 1
266
- end
254
+ it "logspace() creates a vector with n values logarithmically spaced between decades 10^a and 10^b" do
255
+ v = NVector.logspace(0, 3, 4)
256
+ v.should == NVector.new(4, [1, 10, 100, 1000], :float64)
267
257
  end
268
258
  end
269
259
 
data/spec/slice_spec.rb CHANGED
@@ -157,8 +157,6 @@ describe "Slice operation" do
157
157
  @m[0,1].should eql(-9)
158
158
  end
159
159
 
160
- it 'should set value from NMatrix'
161
-
162
160
  it 'should slice again' do
163
161
  n = @m[1..2, 1..2]
164
162
  nm_eql(n[1,0..1], NVector.new(2, [7,8], :int32).transpose).should be_true
@@ -224,11 +222,11 @@ describe "Slice operation" do
224
222
  (N[[0,0,0]] + @m[1,0..2]).should eq N[[3, 4, 5]]
225
223
  end
226
224
 
227
- it "scalar adds to slices" do
225
+ it "scalar adds to slices" do
228
226
  (@m[1,0..2]+1).should eq N[[4, 5, 6]]
229
227
  end
230
228
 
231
- it "compares slices to scalars" do
229
+ it "compares slices to scalars" do
232
230
  (@m[1, 0..2] > 2).each { |e| (e != 0).should be_true }
233
231
  end
234
232
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nmatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Woods
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-09 00:00:00.000000000 Z
13
+ date: 2013-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdoc