nmatrix 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -8
  3. data/.rspec +1 -1
  4. data/.travis.yml +12 -0
  5. data/CONTRIBUTING.md +27 -12
  6. data/Gemfile +1 -0
  7. data/History.txt +38 -0
  8. data/Manifest.txt +15 -15
  9. data/README.rdoc +7 -6
  10. data/Rakefile +40 -5
  11. data/ext/nmatrix/data/data.cpp +2 -37
  12. data/ext/nmatrix/data/data.h +19 -121
  13. data/ext/nmatrix/data/meta.h +70 -0
  14. data/ext/nmatrix/extconf.rb +40 -12
  15. data/ext/nmatrix/math/math.h +13 -103
  16. data/ext/nmatrix/nmatrix.cpp +10 -2018
  17. data/ext/nmatrix/nmatrix.h +16 -13
  18. data/ext/nmatrix/ruby_constants.cpp +12 -1
  19. data/ext/nmatrix/ruby_constants.h +7 -1
  20. data/ext/nmatrix/ruby_nmatrix.c +2169 -0
  21. data/ext/nmatrix/storage/dense.cpp +123 -14
  22. data/ext/nmatrix/storage/dense.h +10 -4
  23. data/ext/nmatrix/storage/list.cpp +265 -48
  24. data/ext/nmatrix/storage/list.h +6 -9
  25. data/ext/nmatrix/storage/storage.cpp +44 -54
  26. data/ext/nmatrix/storage/storage.h +2 -2
  27. data/ext/nmatrix/storage/yale/class.h +1070 -0
  28. data/ext/nmatrix/storage/yale/iterators/base.h +142 -0
  29. data/ext/nmatrix/storage/yale/iterators/iterator.h +130 -0
  30. data/ext/nmatrix/storage/yale/iterators/row.h +449 -0
  31. data/ext/nmatrix/storage/yale/iterators/row_stored.h +139 -0
  32. data/ext/nmatrix/storage/yale/iterators/row_stored_nd.h +167 -0
  33. data/ext/nmatrix/storage/yale/iterators/stored_diagonal.h +123 -0
  34. data/ext/nmatrix/storage/yale/math/transpose.h +110 -0
  35. data/ext/nmatrix/storage/yale/yale.cpp +1785 -0
  36. data/ext/nmatrix/storage/{yale.h → yale/yale.h} +23 -55
  37. data/ext/nmatrix/types.h +2 -0
  38. data/ext/nmatrix/util/io.cpp +27 -45
  39. data/ext/nmatrix/util/io.h +0 -2
  40. data/ext/nmatrix/util/sl_list.cpp +169 -28
  41. data/ext/nmatrix/util/sl_list.h +9 -3
  42. data/lib/nmatrix/blas.rb +20 -20
  43. data/lib/nmatrix/enumerate.rb +1 -1
  44. data/lib/nmatrix/io/mat5_reader.rb +8 -14
  45. data/lib/nmatrix/lapack.rb +3 -3
  46. data/lib/nmatrix/math.rb +3 -3
  47. data/lib/nmatrix/nmatrix.rb +19 -5
  48. data/lib/nmatrix/nvector.rb +2 -0
  49. data/lib/nmatrix/shortcuts.rb +90 -125
  50. data/lib/nmatrix/version.rb +1 -1
  51. data/nmatrix.gemspec +7 -8
  52. data/spec/{nmatrix_spec.rb → 00_nmatrix_spec.rb} +45 -208
  53. data/spec/01_enum_spec.rb +184 -0
  54. data/spec/{slice_spec.rb → 02_slice_spec.rb} +55 -39
  55. data/spec/blas_spec.rb +22 -54
  56. data/spec/elementwise_spec.rb +9 -8
  57. data/spec/io_spec.rb +6 -4
  58. data/spec/lapack_spec.rb +26 -26
  59. data/spec/math_spec.rb +9 -5
  60. data/spec/nmatrix_yale_spec.rb +29 -61
  61. data/spec/shortcuts_spec.rb +34 -22
  62. data/spec/slice_set_spec.rb +157 -0
  63. data/spec/spec_helper.rb +42 -2
  64. data/spec/stat_spec.rb +192 -0
  65. metadata +52 -55
  66. data/ext/nmatrix/storage/yale.cpp +0 -2284
  67. data/spec/nmatrix_list_spec.rb +0 -113
  68. data/spec/nvector_spec.rb +0 -112
@@ -1,113 +0,0 @@
1
- # = NMatrix
2
- #
3
- # A linear algebra library for scientific computation in Ruby.
4
- # NMatrix is part of SciRuby.
5
- #
6
- # NMatrix was originally inspired by and derived from NArray, by
7
- # Masahiro Tanaka: http://narray.rubyforge.org
8
- #
9
- # == Copyright Information
10
- #
11
- # SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
12
- # NMatrix is Copyright (c) 2012, Ruby Science Foundation
13
- #
14
- # Please see LICENSE.txt for additional copyright notices.
15
- #
16
- # == Contributing
17
- #
18
- # By contributing source code to SciRuby, you agree to be bound by
19
- # our Contributor Agreement:
20
- #
21
- # * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
22
- #
23
- # == nmatrix_list_spec.rb
24
- #
25
- # Basic tests for NMatrix's list-of-lists storage type.
26
- #
27
- require "./lib/nmatrix"
28
-
29
- describe NMatrix do
30
- context :list do
31
- it "should compare with ==" do
32
- n = NMatrix.new(:list, [3,3,3], :int64)
33
- m = NMatrix.new(:list, [3,3,3], :int64)
34
- n.should == m
35
- n[0,0,0] = 5
36
- n.should_not == m
37
- n[0,0,1] = 52
38
- n[1,2,1] = -4
39
-
40
- m[0,0,0] = 5
41
- m[0,0,1] = 52
42
- m[1,2,1] = -4
43
- n.should == m
44
- end
45
-
46
- it "should compare 0-1 matrices with different default values with ==" do
47
- n = NMatrix.new(:list, 2, 0, :object)
48
- n[0,1] = 1
49
- n[1,0] = 1
50
-
51
- m = NMatrix.new(:list, 2, 1, :object)
52
- m[0,0] = 0
53
- m[1,1] = 0
54
-
55
- n.should == m
56
- end
57
-
58
- it "should allow creation of both true- and false-based matrix" do
59
- r1 = NMatrix.new(:list, 2, false, :object)
60
- r2 = NMatrix.new(:list, 2, true, :object)
61
- r1.should_not == r2
62
- end
63
-
64
- it "should handle missing default value" do
65
- NMatrix.new(:list, 3, :int8)[0,0].should == 0
66
- NMatrix.new(:list, 4, :float64)[0,0].should == 0.0
67
- end
68
-
69
- it "should allow conversion to a Ruby Hash" do
70
- n = NMatrix.new(:list, 3, 1, :int64)
71
- n[0,1] = 50
72
- h = n.to_h
73
- h.size.should == 1
74
- h[0].size.should == 1
75
- h[0][1].should == 50
76
- h[0][2].should == 1
77
- h[1][0].should == 1
78
- end
79
-
80
-
81
- ##TODO: Make this test better. It's not nearly exhaustive enough as is.
82
- it "should handle recursive removal" do
83
- n = NMatrix.new(:list, [3,3,3], 0)
84
- n[0,0,0] = 2
85
- n[1,1,1] = 1
86
- n[1,0,0] = 3
87
- n[0,0,1] = 4
88
-
89
- n[0,0,0].should == 2
90
- n[1,1,1].should == 1
91
- n[1,0,0].should == 3
92
- n[0,0,1].should == 4
93
-
94
- n[1,1,1] = 0
95
- n[0,0,0].should == 2
96
- n[1,1,1].should == 0
97
- n[1,0,0].should == 3
98
- n[0,0,1].should == 4
99
- end
100
-
101
- it "should correctly insert a value between the middle and last entries of a three-element list" do
102
- n = NMatrix.new(:list, 5940, 0, :float64)
103
- n[0,0] = -7.0710685196786e-01
104
- n[330,0] = 7.0710685196786e-01
105
- n[1,0] = -7.0710685196786e-01
106
- n[2,0] = -7.0710685196786e-01
107
- n[0,0].should_not == 0
108
- n[330,0].should_not == 0
109
- n[2,0].should_not == 0
110
- n[1,0].should_not == 0
111
- end
112
- end
113
- end
@@ -1,112 +0,0 @@
1
- # = NMatrix
2
- #
3
- # A linear algebra library for scientific computation in Ruby.
4
- # NMatrix is part of SciRuby.
5
- #
6
- # NMatrix was originally inspired by and derived from NArray, by
7
- # Masahiro Tanaka: http://narray.rubyforge.org
8
- #
9
- # == Copyright Information
10
- #
11
- # SciRuby is Copyright (c) 2010 - 2012, Ruby Science Foundation
12
- # NMatrix is Copyright (c) 2012, Ruby Science Foundation
13
- #
14
- # Please see LICENSE.txt for additional copyright notices.
15
- #
16
- # == Contributing
17
- #
18
- # By contributing source code to SciRuby, you agree to be bound by
19
- # our Contributor Agreement:
20
- #
21
- # * https://github.com/SciRuby/sciruby/wiki/Contributor-Agreement
22
- #
23
- # == nvector_spec.rb
24
- #
25
- # Basic tests for NVector.
26
- #
27
-
28
- require File.dirname(__FILE__) + "/spec_helper.rb"
29
-
30
- describe NVector do
31
- it "initializes" do
32
- v = NVector.new(5, 0, :float64)
33
- v.shape[0].should == 1
34
- v.shape[1].should == 5
35
- end
36
-
37
- it "permits setting and getting contents" do
38
- v = NVector.new(5, 0, :float64)
39
- v[0] = 1.555
40
- v[0].should == 1.555
41
- end
42
-
43
- it "transpose() changes raw and column stored structure" do
44
- v = NVector.new 5, :float64
45
- v = v.transpose
46
- v.shape[0].should == 5
47
- v.shape[1].should == 1
48
- v[0] = 1.555
49
- v[0].should == 1.555
50
- end
51
-
52
- it "dot() multiples itself by another NVector" do
53
- v1 = NVector.new(2, :float64)
54
- v2 = NVector.new(2, :float64).transpose
55
- v1[0] = 1.5
56
- v1[1] = 2.3
57
- v2[0] = 1.3
58
- v2[1] = 2.5
59
- v1.dot(v2).should be_within(0.000000001).of(7.7)
60
- end
61
-
62
- it "dot!() multiples itself destructively by another NVector" do
63
- pending "dot! not yet implemented"
64
- v1 = NVector.new 2, :float64
65
- v2 = NVector.new(2, :float64).transpose
66
- v1[0] = 1.5
67
- v1[1] = 2.3
68
- v2[0] = 1.3
69
- v2[1] = 2.5
70
- v1.dot!(v2)
71
- v1.should be_within(0.000000001).of(7.7)
72
- end
73
-
74
- it "pretty_print() prints values to standard output with a pretty format" do
75
- pending "pretty_print formatting is finalized"
76
- v = NVector.new(5, 0)
77
- $stdout = StringIO.new
78
- v.pretty_print
79
- out = $stdout.string
80
- $stdout = STDOUT
81
- out.should == "0 0 0 0 0\n"
82
- end
83
-
84
- it "inspect() formats the output with inspected, namely human readable format" do
85
- pending "inspect output is finalized"
86
- v = NVector.new(5, 0)
87
- $stdout = StringIO.new
88
- p v
89
- out = $stdout.string
90
- $stdout = STDOUT
91
- out.should == "0 0 0 0 0\n"
92
- end
93
-
94
- [:dense, :list, :yale].each do |storage_type|
95
- context "for #{storage_type}" do
96
- before :each do
97
- @m = create_vector(storage_type)
98
- end
99
-
100
- it "converts to an Array" do
101
- a = @m.to_a
102
- a.each.with_index { |v,idx| @m[idx].should equal(v) }
103
- end
104
-
105
- it "shuffles" do
106
- n = @m.shuffle
107
- n.to_a.hash.should_not == @m.to_a.hash
108
- n.to_a.sort.hash.should equal(@m.to_a.sort.hash)
109
- end
110
- end
111
- end
112
- end