pnmatrix 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/ext/nmatrix/binary_format.txt +53 -0
  3. data/ext/nmatrix/data/complex.h +388 -0
  4. data/ext/nmatrix/data/data.cpp +274 -0
  5. data/ext/nmatrix/data/data.h +651 -0
  6. data/ext/nmatrix/data/meta.h +64 -0
  7. data/ext/nmatrix/data/ruby_object.h +386 -0
  8. data/ext/nmatrix/extconf.rb +70 -0
  9. data/ext/nmatrix/math/asum.h +99 -0
  10. data/ext/nmatrix/math/cblas_enums.h +36 -0
  11. data/ext/nmatrix/math/cblas_templates_core.h +507 -0
  12. data/ext/nmatrix/math/gemm.h +241 -0
  13. data/ext/nmatrix/math/gemv.h +178 -0
  14. data/ext/nmatrix/math/getrf.h +255 -0
  15. data/ext/nmatrix/math/getrs.h +121 -0
  16. data/ext/nmatrix/math/imax.h +82 -0
  17. data/ext/nmatrix/math/laswp.h +165 -0
  18. data/ext/nmatrix/math/long_dtype.h +62 -0
  19. data/ext/nmatrix/math/magnitude.h +54 -0
  20. data/ext/nmatrix/math/math.h +751 -0
  21. data/ext/nmatrix/math/nrm2.h +165 -0
  22. data/ext/nmatrix/math/rot.h +117 -0
  23. data/ext/nmatrix/math/rotg.h +106 -0
  24. data/ext/nmatrix/math/scal.h +71 -0
  25. data/ext/nmatrix/math/trsm.h +336 -0
  26. data/ext/nmatrix/math/util.h +162 -0
  27. data/ext/nmatrix/math.cpp +1368 -0
  28. data/ext/nmatrix/nm_memory.h +60 -0
  29. data/ext/nmatrix/nmatrix.cpp +285 -0
  30. data/ext/nmatrix/nmatrix.h +476 -0
  31. data/ext/nmatrix/ruby_constants.cpp +151 -0
  32. data/ext/nmatrix/ruby_constants.h +106 -0
  33. data/ext/nmatrix/ruby_nmatrix.c +3130 -0
  34. data/ext/nmatrix/storage/common.cpp +77 -0
  35. data/ext/nmatrix/storage/common.h +183 -0
  36. data/ext/nmatrix/storage/dense/dense.cpp +1096 -0
  37. data/ext/nmatrix/storage/dense/dense.h +129 -0
  38. data/ext/nmatrix/storage/list/list.cpp +1628 -0
  39. data/ext/nmatrix/storage/list/list.h +138 -0
  40. data/ext/nmatrix/storage/storage.cpp +730 -0
  41. data/ext/nmatrix/storage/storage.h +99 -0
  42. data/ext/nmatrix/storage/yale/class.h +1139 -0
  43. data/ext/nmatrix/storage/yale/iterators/base.h +143 -0
  44. data/ext/nmatrix/storage/yale/iterators/iterator.h +131 -0
  45. data/ext/nmatrix/storage/yale/iterators/row.h +450 -0
  46. data/ext/nmatrix/storage/yale/iterators/row_stored.h +140 -0
  47. data/ext/nmatrix/storage/yale/iterators/row_stored_nd.h +169 -0
  48. data/ext/nmatrix/storage/yale/iterators/stored_diagonal.h +124 -0
  49. data/ext/nmatrix/storage/yale/math/transpose.h +110 -0
  50. data/ext/nmatrix/storage/yale/yale.cpp +2074 -0
  51. data/ext/nmatrix/storage/yale/yale.h +203 -0
  52. data/ext/nmatrix/types.h +55 -0
  53. data/ext/nmatrix/util/io.cpp +279 -0
  54. data/ext/nmatrix/util/io.h +115 -0
  55. data/ext/nmatrix/util/sl_list.cpp +627 -0
  56. data/ext/nmatrix/util/sl_list.h +144 -0
  57. data/ext/nmatrix/util/util.h +78 -0
  58. data/lib/nmatrix/blas.rb +378 -0
  59. data/lib/nmatrix/cruby/math.rb +744 -0
  60. data/lib/nmatrix/enumerate.rb +253 -0
  61. data/lib/nmatrix/homogeneous.rb +241 -0
  62. data/lib/nmatrix/io/fortran_format.rb +138 -0
  63. data/lib/nmatrix/io/harwell_boeing.rb +221 -0
  64. data/lib/nmatrix/io/market.rb +263 -0
  65. data/lib/nmatrix/io/point_cloud.rb +189 -0
  66. data/lib/nmatrix/jruby/decomposition.rb +24 -0
  67. data/lib/nmatrix/jruby/enumerable.rb +13 -0
  68. data/lib/nmatrix/jruby/error.rb +4 -0
  69. data/lib/nmatrix/jruby/math.rb +501 -0
  70. data/lib/nmatrix/jruby/nmatrix_java.rb +840 -0
  71. data/lib/nmatrix/jruby/operators.rb +283 -0
  72. data/lib/nmatrix/jruby/slice.rb +264 -0
  73. data/lib/nmatrix/lapack_core.rb +181 -0
  74. data/lib/nmatrix/lapack_plugin.rb +44 -0
  75. data/lib/nmatrix/math.rb +953 -0
  76. data/lib/nmatrix/mkmf.rb +100 -0
  77. data/lib/nmatrix/monkeys.rb +137 -0
  78. data/lib/nmatrix/nmatrix.rb +1172 -0
  79. data/lib/nmatrix/rspec.rb +75 -0
  80. data/lib/nmatrix/shortcuts.rb +1163 -0
  81. data/lib/nmatrix/version.rb +39 -0
  82. data/lib/nmatrix/yale_functions.rb +118 -0
  83. data/lib/nmatrix.rb +28 -0
  84. data/spec/00_nmatrix_spec.rb +892 -0
  85. data/spec/01_enum_spec.rb +196 -0
  86. data/spec/02_slice_spec.rb +407 -0
  87. data/spec/03_nmatrix_monkeys_spec.rb +80 -0
  88. data/spec/2x2_dense_double.mat +0 -0
  89. data/spec/4x4_sparse.mat +0 -0
  90. data/spec/4x5_dense.mat +0 -0
  91. data/spec/blas_spec.rb +215 -0
  92. data/spec/elementwise_spec.rb +311 -0
  93. data/spec/homogeneous_spec.rb +100 -0
  94. data/spec/io/fortran_format_spec.rb +88 -0
  95. data/spec/io/harwell_boeing_spec.rb +98 -0
  96. data/spec/io/test.rua +9 -0
  97. data/spec/io_spec.rb +159 -0
  98. data/spec/lapack_core_spec.rb +482 -0
  99. data/spec/leakcheck.rb +16 -0
  100. data/spec/math_spec.rb +1363 -0
  101. data/spec/nmatrix_yale_resize_test_associations.yaml +2802 -0
  102. data/spec/nmatrix_yale_spec.rb +286 -0
  103. data/spec/rspec_monkeys.rb +56 -0
  104. data/spec/rspec_spec.rb +35 -0
  105. data/spec/shortcuts_spec.rb +474 -0
  106. data/spec/slice_set_spec.rb +162 -0
  107. data/spec/spec_helper.rb +172 -0
  108. data/spec/stat_spec.rb +214 -0
  109. data/spec/test.pcd +20 -0
  110. data/spec/utm5940.mtx +83844 -0
  111. metadata +295 -0
@@ -0,0 +1,172 @@
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 - 2014, Ruby Science Foundation
12
+ # NMatrix is Copyright (c) 2012 - 2014, John Woods and the 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
+ # == spec_helper.rb
24
+ #
25
+ # Common data and helper functions for testing.
26
+
27
+ require "rspec/longrun"
28
+ #require "narray/narray"
29
+
30
+ require "./lib/nmatrix"
31
+ require "./lib/nmatrix/rspec"
32
+
33
+ ALL_DTYPES = [:byte,:int8,:int16,:int32,:int64, :float32,:float64, :object,
34
+ :complex64, :complex128]
35
+
36
+ NON_INTEGER_DTYPES = [:float32, :float64, :complex64, :complex128,
37
+ :object]
38
+
39
+ FLOAT_DTYPES = [:float32, :float64]
40
+
41
+ MATRIX43A_ARRAY = [14.0, 9.0, 3.0, 2.0, 11.0, 15.0, 0.0, 12.0, 17.0, 5.0, 2.0, 3.0]
42
+ MATRIX32A_ARRAY = [12.0, 25.0, 9.0, 10.0, 8.0, 5.0]
43
+
44
+ COMPLEX_MATRIX43A_ARRAY = MATRIX43A_ARRAY.zip(MATRIX43A_ARRAY.reverse).collect { |ary| Complex(ary[0], ary[1]) }
45
+ COMPLEX_MATRIX32A_ARRAY = MATRIX32A_ARRAY.zip(MATRIX32A_ARRAY.reverse).collect { |ary| Complex(ary[0], -ary[1]) }
46
+
47
+ #3x4 matrix used for testing various getrf and LU decomposition functions
48
+ GETRF_EXAMPLE_ARRAY = [-1,0,10,4,9,2,3,5,7,8,1,6]
49
+ GETRF_SOLUTION_ARRAY = [9.0, 2.0, 3.0, 5.0, 7.0/9, 58.0/9, -4.0/3, 19.0/9, -1.0/9, 1.0/29, 301.0/29, 130.0/29]
50
+
51
+ TAU_SOLUTION_ARRAY = [1.8571428571428572,1.9938461538461538, 0.0]
52
+
53
+ GEQRF_SOLUTION_ARRAY =[ -14.0, -21.0, 14.000000000000002,
54
+ 0.23076923076923078, -175.00000000000003, 70.00000000000001,
55
+ -0.15384615384615385, 0.055555555555555546, -35.0]
56
+
57
+ R_SOLUTION_ARRAY = [-159.2388143638353, -41.00131005172065, -56.75123892439876, -90.75048729628048,
58
+ 0.0, 25.137473501580676, 2.073591725046292, 9.790607357775713,
59
+ 0.0, 0.0, -20.83259700334131, -17.592414929551445]
60
+
61
+ Q_SOLUTION_ARRAY_1 = [-0.632455532033676, -0.5209522876558295, -0.3984263084135902, -0.41214704991068,
62
+ -0.42783756578748666, -0.20837937347171134, 0.876505919951498, 0.07259770177184455,
63
+ -0.48364246567281094, 0.8265854747306287,-0.015758658987033422, -0.2873988222474053,
64
+ -0.42783756578748666, 0.044081783789183565, -0.26971376257215296, 0.8615487797670971]
65
+
66
+ Q_SOLUTION_ARRAY_2 = [-0.8571428571428572, 0.3942857142857143, 0.33142857142857146,
67
+ -0.4285714285714286, -0.9028571428571428, -0.03428571428571425,
68
+ 0.28571428571428575, -0.1714285714285714, 0.9428571428571428]
69
+
70
+ Q_SOLUTION_ARRAY_3 = [-0.7724247413634004, -0.026670393594597247, -0.6345460653374136,
71
+ -0.5777485870360393, -0.38541856437557026, 0.7194853024298236,
72
+ -0.26375478973384403, 0.9223563413020934, 0.28229805268947933]
73
+
74
+ def create_matrix(stype) #:nodoc:
75
+ m = NMatrix.new([3,3], 0, dtype: :int32, stype: stype, default: 0)
76
+
77
+ m[0,0] = 0
78
+ m[0,1] = 1
79
+ m[0,2] = 2
80
+ m[1,0] = 3
81
+ m[1,1] = 4
82
+ m[1,2] = 5
83
+ m[2,0] = 6
84
+ m[2,1] = 7
85
+ m[2,2] = 8
86
+
87
+ m
88
+ end
89
+
90
+ def create_rectangular_matrix(stype) #:nodoc:
91
+ m = NMatrix.new([5,6], 0, dtype: :int32, stype: stype, default: 0)
92
+
93
+ m[0,0] = 1
94
+ m[0,1] = 2
95
+ m[0,2] = 3
96
+ m[0,3] = 4
97
+ m[0,4] = 5
98
+ m[0,5] = 0
99
+
100
+ m[1,0] = 6
101
+ m[1,1] = 7
102
+ m[1,2] = 8
103
+ m[1,3] = 9
104
+ m[1,4] = 0
105
+ m[1,5] = 10
106
+
107
+ m[2,0] = 11
108
+ m[2,1] = 12
109
+ m[2,2] = 13
110
+ m[2,3] = 0
111
+ m[2,4] = 14
112
+ m[2,5] = 15
113
+
114
+ # skip row 3 -- all 0
115
+ m[3,0] = m[3,1] = m[3,2] = m[3,3] = m[3,4] = m[3,5] = 0
116
+
117
+ m[4,0] = 16
118
+ m[4,1] = 0
119
+ m[4,2] = 17
120
+ m[4,3] = 18
121
+ m[4,4] = 19
122
+ m[4,5] = 20
123
+
124
+ m
125
+ end
126
+
127
+ def create_vector(stype) #:nodoc:
128
+ m = stype == :yale ? NVector.new(stype, 10, :int32) : NVector.new(stype, 10, 0, :int32)
129
+
130
+ m[0] = 1
131
+ m[1] = 2
132
+ m[2] = 3
133
+ m[3] = 4
134
+ m[4] = 5
135
+ m[5] = 6
136
+ m[6] = 7
137
+ m[7] = 8
138
+ m[8] = 9
139
+ m[9] = 10
140
+
141
+ m
142
+ end
143
+
144
+ # Stupid but independent comparison for slice_spec
145
+ def nm_eql(n, m) #:nodoc:
146
+ if n.shape != m.shape
147
+ false
148
+ else # NMatrix
149
+ n.shape[0].times do |i|
150
+ n.shape[1].times do |j|
151
+ if n[i,j] != m[i,j]
152
+ puts "n[#{i},#{j}] != m[#{i},#{j}] (#{n[i,j]} != #{m[i,j]})"
153
+ return false
154
+ end
155
+ end
156
+ end
157
+ end
158
+ true
159
+ end
160
+
161
+ def integer_dtype? dtype
162
+ [:byte,:int8,:int16,:int32,:int64].include?(dtype)
163
+ end
164
+
165
+ # If a focus: true option is supplied to any test, running `rake spec focus=true`
166
+ # will run only the focused tests and nothing else.
167
+ if ENV["focus"] == "true"
168
+ RSpec.configure do |c|
169
+ c.filter_run :focus => true
170
+ end
171
+ end
172
+
data/spec/stat_spec.rb ADDED
@@ -0,0 +1,214 @@
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 - 2014, Ruby Science Foundation
12
+ # NMatrix is Copyright (c) 2012 - 2014, John Woods and the 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
+ # == stat_spec.rb
24
+ #
25
+ # Tests for statistical functions in NMatrix.
26
+ #
27
+
28
+ require 'spec_helper'
29
+ require 'pry'
30
+
31
+ describe "Statistical functions" do
32
+ context "mapping and reduction related functions" do
33
+ [:dense, :yale, :list].each do |stype|
34
+ context "on #{stype} matrices" do
35
+ let(:nm_1d) { NMatrix.new([5], [5.0,0.0,1.0,2.0,3.0], stype: stype) unless stype == :yale }
36
+ let(:nm_2d) { NMatrix.new([2,2], [0.0, 1.0, 2.0, 3.0], stype: stype) }
37
+
38
+ it "behaves like Enumerable#reduce with no argument to reduce" do
39
+ expect(nm_1d.reduce_along_dim(0) { |acc, el| acc + el }.to_f).to eq 11 unless stype == :yale
40
+ expect(nm_2d.reduce_along_dim(1) { |acc, el| acc + el }).to eq NMatrix.new([2,1], [1.0, 5.0], stype: stype)
41
+ end
42
+
43
+ it "should calculate the mean along the specified dimension" do
44
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
45
+ unless stype == :yale then
46
+ puts nm_1d.mean
47
+ expect(nm_1d.mean).to eq NMatrix.new([1], [2.2], stype: stype, dtype: :float64)
48
+ end
49
+ expect(nm_2d.mean).to eq NMatrix[[1.0,2.0], stype: stype]
50
+ expect(nm_2d.mean(1)).to eq NMatrix[[0.5], [2.5], stype: stype]
51
+ end
52
+
53
+ it "should calculate the minimum along the specified dimension" do
54
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
55
+ expect(nm_1d.min).to eq 0.0 unless stype == :yale
56
+ expect(nm_2d.min).to eq NMatrix[[0.0, 1.0], stype: stype]
57
+ expect(nm_2d.min(1)).to eq NMatrix[[0.0], [2.0], stype: stype]
58
+ end
59
+
60
+ it "should calculate the maximum along the specified dimension" do
61
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
62
+ expect(nm_1d.max).to eq 5.0 unless stype == :yale
63
+ expect(nm_2d.max).to eq NMatrix[[2.0, 3.0], stype: stype]
64
+ end
65
+
66
+ it "should calculate the variance along the specified dimension" do
67
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
68
+ expect(nm_1d.variance).to eq NMatrix[3.7, stype: stype] unless stype == :yale
69
+ expect(nm_2d.variance(1)).to eq NMatrix[[0.5], [0.5], stype: stype]
70
+ end
71
+
72
+ it "should calculate the sum along the specified dimension" do
73
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
74
+ expect(nm_1d.sum).to eq NMatrix[11.0, stype: stype] unless stype == :yale
75
+ expect(nm_2d.sum).to eq NMatrix[[2.0, 4.0], stype: stype]
76
+ end
77
+
78
+ it "should calculate the standard deviation along the specified dimension" do
79
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
80
+ expect(nm_1d.std).to eq NMatrix[Math.sqrt(3.7), stype: stype] unless stype == :yale
81
+ expect(nm_2d.std(1)).to eq NMatrix[[Math.sqrt(0.5)], [Math.sqrt(0.5)], stype: stype]
82
+ end
83
+
84
+ it "should raise an ArgumentError when any invalid dimension is provided" do
85
+ expect { nm_1d.mean(3) }.to raise_exception(RangeError) unless stype == :yale
86
+ expect { nm_2d.mean(3) }.to raise_exception(RangeError)
87
+ end
88
+
89
+ it "should convert to float if it contains only a single element" do
90
+ expect(NMatrix[4.0, stype: stype].to_f).to eq 4.0 unless stype == :yale
91
+ expect(NMatrix[[[[4.0]]], stype: stype].to_f).to eq 4.0 unless stype == :yale
92
+ expect(NMatrix[[4.0], stype: stype].to_f).to eq 4.0
93
+ end
94
+
95
+ it "should raise an index error if it contains more than a single element" do
96
+ expect { nm_1d.to_f }.to raise_error(IndexError) unless stype == :yale
97
+ expect { nm_2d.to_f }.to raise_error(IndexError)
98
+ end
99
+
100
+ it "should map a block to all elements" do
101
+ expect(nm_1d.map { |e| e ** 2 }).to eq NMatrix[25.0,0.0,1.0,4.0,9.0, stype: stype] unless stype == :yale
102
+ expect(nm_2d.map { |e| e ** 2 }).to eq NMatrix[[0.0,1.0],[4.0,9.0], stype: stype]
103
+ end
104
+
105
+ it "should map! a block to all elements in place" do
106
+ fct = Proc.new { |e| e ** 2 }
107
+ unless stype == :yale then
108
+ expected1 = nm_1d.map(&fct)
109
+ nm_1d.map!(&fct)
110
+ expect(nm_1d).to eq expected1
111
+ end
112
+ expected2 = nm_2d.map(&fct)
113
+ nm_2d.map!(&fct)
114
+ expect(nm_2d).to eq expected2
115
+ end
116
+
117
+ it "should return an enumerator for map without a block" do
118
+ expect(nm_2d.map).to be_a Enumerator
119
+ end
120
+
121
+ it "should return an enumerator for reduce without a block" do
122
+ expect(nm_2d.reduce_along_dim(0)).to be_a Enumerator
123
+ end
124
+
125
+ it "should return an enumerator for each_along_dim without a block" do
126
+ expect(nm_2d.each_along_dim(0)).to be_a Enumerator
127
+ end
128
+
129
+ it "should iterate correctly for map without a block" do
130
+ en = nm_1d.map unless stype == :yale
131
+ expect(en.each { |e| e**2 }).to eq nm_1d.map { |e| e**2 } unless stype == :yale
132
+ en = nm_2d.map
133
+ expect(en.each { |e| e**2 }).to eq nm_2d.map { |e| e**2 }
134
+ end
135
+
136
+ it "should iterate correctly for reduce without a block" do
137
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
138
+ unless stype == :yale then
139
+ en = nm_1d.reduce_along_dim(0, 1.0)
140
+ expect(en.each { |a, e| a+e }.to_f).to eq 12
141
+ end
142
+ en = nm_2d.reduce_along_dim(1, 1.0)
143
+ expect(en.each { |a, e| a+e }).to eq NMatrix[[2.0],[6.0], stype: stype]
144
+ end
145
+
146
+ it "should iterate correctly for each_along_dim without a block" do
147
+ unless stype == :yale then
148
+ res = NMatrix.zeros_like(nm_1d[0...1])
149
+ en = nm_1d.each_along_dim(0)
150
+ en.each { |e| res += e }
151
+ expect(res.to_f).to eq 11
152
+ end
153
+ res = NMatrix.zeros_like (nm_2d[0...2, 0])
154
+ en = nm_2d.each_along_dim(1)
155
+ en.each { |e| res += e }
156
+ expect(res).to eq NMatrix[[1.0], [5.0], stype: stype]
157
+ end
158
+
159
+ it "should yield matrices of matching dtype for each_along_dim" do
160
+ m = NMatrix.new([2,3], [1,2,3,3,4,5], dtype: :complex128, stype: stype)
161
+ m.each_along_dim(1) do |sub_m|
162
+ expect(sub_m.dtype).to eq :complex128
163
+ end
164
+ end
165
+
166
+ it "should reduce to a matrix of matching dtype for reduce_along_dim" do
167
+ m = NMatrix.new([2,3], [1,2,3,3,4,5], dtype: :complex128, stype: stype)
168
+ m.reduce_along_dim(1) do |acc, sub_m|
169
+ expect(sub_m.dtype).to eq :complex128
170
+ acc
171
+ end
172
+
173
+ m.reduce_along_dim(1, 0.0) do |acc, sub_m|
174
+ expect(sub_m.dtype).to eq :complex128
175
+ acc
176
+ end
177
+ end
178
+
179
+ it "should allow overriding the dtype for reduce_along_dim" do
180
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
181
+ m = NMatrix[[1,2,3], [3,4,5], dtype: :complex128]
182
+ m.reduce_along_dim(1, 0.0, :float64) do |acc, sub_m|
183
+ expect(acc.dtype).to eq :float64
184
+ acc
185
+ end
186
+
187
+ m = NMatrix[[1,2,3], [3,4,5], dtype: :complex128, stype: stype]
188
+ m.reduce_along_dim(1, nil, :float64) do |acc, sub_m|
189
+ expect(acc.dtype).to eq :float64
190
+ acc
191
+ end
192
+ end
193
+
194
+ it "should convert integer dtypes to float when calculating mean" do
195
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
196
+ m = NMatrix[[1,2,3], [3,4,5], dtype: :int32, stype: stype]
197
+ expect(m.mean(0).dtype).to eq :float64
198
+ end
199
+
200
+ it "should convert integer dtypes to float when calculating variance" do
201
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
202
+ m = NMatrix[[1,2,3], [3,4,5], dtype: :int32, stype: stype]
203
+ expect(m.variance(0).dtype).to eq :float64
204
+ end
205
+
206
+ it "should convert integer dtypes to float when calculating standard deviation" do
207
+ pending("not yet implemented for NMatrix-JRuby") if jruby?
208
+ m = NMatrix[[1,2,3], [3,4,5], dtype: :int32, stype: stype]
209
+ expect(m.std(0).dtype).to eq :float64
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
data/spec/test.pcd ADDED
@@ -0,0 +1,20 @@
1
+ VERSION .7
2
+ FIELDS x y z intensity
3
+ SIZE 4 8 8 4
4
+ TYPE F U F I
5
+ COUNT 1 1 1 1
6
+ WIDTH 256 # comment here to challenge this thing
7
+ HEIGHT 256
8
+ VIEWPOINT 0 0 0 1 0 0 0
9
+ POINTS 10
10
+ DATA ASCII
11
+ 207.008 207.058 1174 0
12
+ 207.008 205.441 1174 0
13
+ 207.008 203.823 1174 0
14
+ 207.008 202.206 1174 0
15
+ 207.008 200.589 1174 0
16
+ 207.008 198.972 1174 0
17
+ 207.008 197.354 1174 0
18
+ 207.008 195.737 1174 0
19
+ 207.008 194.12 1174 0
20
+ 207.008 153.689 1174 0