numo-narray 0.9.0.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/README.md +47 -0
  4. data/Rakefile +41 -0
  5. data/ext/numo/narray/SFMT-params.h +97 -0
  6. data/ext/numo/narray/SFMT-params19937.h +46 -0
  7. data/ext/numo/narray/SFMT.c +620 -0
  8. data/ext/numo/narray/SFMT.h +157 -0
  9. data/ext/numo/narray/array.c +525 -0
  10. data/ext/numo/narray/data.c +901 -0
  11. data/ext/numo/narray/depend.erb +33 -0
  12. data/ext/numo/narray/extconf.rb +117 -0
  13. data/ext/numo/narray/gen/bit.erb.c +811 -0
  14. data/ext/numo/narray/gen/cogen.rb +18 -0
  15. data/ext/numo/narray/gen/def/dcomplex.rb +32 -0
  16. data/ext/numo/narray/gen/def/dfloat.rb +30 -0
  17. data/ext/numo/narray/gen/def/int16.rb +29 -0
  18. data/ext/numo/narray/gen/def/int32.rb +29 -0
  19. data/ext/numo/narray/gen/def/int64.rb +29 -0
  20. data/ext/numo/narray/gen/def/int8.rb +29 -0
  21. data/ext/numo/narray/gen/def/robject.rb +30 -0
  22. data/ext/numo/narray/gen/def/scomplex.rb +32 -0
  23. data/ext/numo/narray/gen/def/sfloat.rb +30 -0
  24. data/ext/numo/narray/gen/def/uint16.rb +29 -0
  25. data/ext/numo/narray/gen/def/uint32.rb +29 -0
  26. data/ext/numo/narray/gen/def/uint64.rb +29 -0
  27. data/ext/numo/narray/gen/def/uint8.rb +29 -0
  28. data/ext/numo/narray/gen/dtype.erb.c +328 -0
  29. data/ext/numo/narray/gen/tmpl/accum.c +36 -0
  30. data/ext/numo/narray/gen/tmpl/accum_binary.c +75 -0
  31. data/ext/numo/narray/gen/tmpl/accum_index.c +58 -0
  32. data/ext/numo/narray/gen/tmpl/allocate.c +35 -0
  33. data/ext/numo/narray/gen/tmpl/aref.c +51 -0
  34. data/ext/numo/narray/gen/tmpl/aset.c +61 -0
  35. data/ext/numo/narray/gen/tmpl/binary.c +53 -0
  36. data/ext/numo/narray/gen/tmpl/binary2.c +55 -0
  37. data/ext/numo/narray/gen/tmpl/binary_s.c +34 -0
  38. data/ext/numo/narray/gen/tmpl/bit_binary.c +94 -0
  39. data/ext/numo/narray/gen/tmpl/bit_count.c +82 -0
  40. data/ext/numo/narray/gen/tmpl/bit_unary.c +77 -0
  41. data/ext/numo/narray/gen/tmpl/cast.c +37 -0
  42. data/ext/numo/narray/gen/tmpl/cast_array.c +79 -0
  43. data/ext/numo/narray/gen/tmpl/cast_numeric.c +22 -0
  44. data/ext/numo/narray/gen/tmpl/coerce_cast.c +8 -0
  45. data/ext/numo/narray/gen/tmpl/cond_binary.c +51 -0
  46. data/ext/numo/narray/gen/tmpl/cond_unary.c +45 -0
  47. data/ext/numo/narray/gen/tmpl/cum.c +42 -0
  48. data/ext/numo/narray/gen/tmpl/each.c +43 -0
  49. data/ext/numo/narray/gen/tmpl/each_with_index.c +64 -0
  50. data/ext/numo/narray/gen/tmpl/extract.c +23 -0
  51. data/ext/numo/narray/gen/tmpl/eye.c +91 -0
  52. data/ext/numo/narray/gen/tmpl/fill.c +38 -0
  53. data/ext/numo/narray/gen/tmpl/format.c +60 -0
  54. data/ext/numo/narray/gen/tmpl/format_to_a.c +47 -0
  55. data/ext/numo/narray/gen/tmpl/head.c +25 -0
  56. data/ext/numo/narray/gen/tmpl/inspect.c +16 -0
  57. data/ext/numo/narray/gen/tmpl/map_with_index.c +94 -0
  58. data/ext/numo/narray/gen/tmpl/median.c +44 -0
  59. data/ext/numo/narray/gen/tmpl/minmax.c +47 -0
  60. data/ext/numo/narray/gen/tmpl/poly.c +49 -0
  61. data/ext/numo/narray/gen/tmpl/pow.c +74 -0
  62. data/ext/numo/narray/gen/tmpl/powint.c +17 -0
  63. data/ext/numo/narray/gen/tmpl/qsort.c +149 -0
  64. data/ext/numo/narray/gen/tmpl/rand.c +33 -0
  65. data/ext/numo/narray/gen/tmpl/rand_norm.c +46 -0
  66. data/ext/numo/narray/gen/tmpl/robj_allocate.c +32 -0
  67. data/ext/numo/narray/gen/tmpl/seq.c +61 -0
  68. data/ext/numo/narray/gen/tmpl/set2.c +56 -0
  69. data/ext/numo/narray/gen/tmpl/sort.c +36 -0
  70. data/ext/numo/narray/gen/tmpl/sort_index.c +86 -0
  71. data/ext/numo/narray/gen/tmpl/store.c +31 -0
  72. data/ext/numo/narray/gen/tmpl/store_array.c +5 -0
  73. data/ext/numo/narray/gen/tmpl/store_from.c +53 -0
  74. data/ext/numo/narray/gen/tmpl/store_numeric.c +22 -0
  75. data/ext/numo/narray/gen/tmpl/to_a.c +41 -0
  76. data/ext/numo/narray/gen/tmpl/unary.c +58 -0
  77. data/ext/numo/narray/gen/tmpl/unary2.c +58 -0
  78. data/ext/numo/narray/gen/tmpl/unary_s.c +57 -0
  79. data/ext/numo/narray/index.c +822 -0
  80. data/ext/numo/narray/kwarg.c +79 -0
  81. data/ext/numo/narray/math.c +140 -0
  82. data/ext/numo/narray/narray.c +1539 -0
  83. data/ext/numo/narray/ndloop.c +1928 -0
  84. data/ext/numo/narray/numo/compat.h +23 -0
  85. data/ext/numo/narray/numo/intern.h +112 -0
  86. data/ext/numo/narray/numo/narray.h +411 -0
  87. data/ext/numo/narray/numo/ndloop.h +99 -0
  88. data/ext/numo/narray/numo/template.h +140 -0
  89. data/ext/numo/narray/numo/types/bit.h +19 -0
  90. data/ext/numo/narray/numo/types/complex.h +410 -0
  91. data/ext/numo/narray/numo/types/complex_macro.h +205 -0
  92. data/ext/numo/narray/numo/types/dcomplex.h +11 -0
  93. data/ext/numo/narray/numo/types/dfloat.h +12 -0
  94. data/ext/numo/narray/numo/types/float_def.h +34 -0
  95. data/ext/numo/narray/numo/types/float_macro.h +277 -0
  96. data/ext/numo/narray/numo/types/int16.h +12 -0
  97. data/ext/numo/narray/numo/types/int32.h +12 -0
  98. data/ext/numo/narray/numo/types/int64.h +12 -0
  99. data/ext/numo/narray/numo/types/int8.h +12 -0
  100. data/ext/numo/narray/numo/types/int_macro.h +34 -0
  101. data/ext/numo/narray/numo/types/robj_macro.h +218 -0
  102. data/ext/numo/narray/numo/types/robject.h +21 -0
  103. data/ext/numo/narray/numo/types/scomplex.h +11 -0
  104. data/ext/numo/narray/numo/types/sfloat.h +13 -0
  105. data/ext/numo/narray/numo/types/uint16.h +12 -0
  106. data/ext/numo/narray/numo/types/uint32.h +12 -0
  107. data/ext/numo/narray/numo/types/uint64.h +12 -0
  108. data/ext/numo/narray/numo/types/uint8.h +12 -0
  109. data/ext/numo/narray/numo/types/uint_macro.h +31 -0
  110. data/ext/numo/narray/numo/types/xint_macro.h +133 -0
  111. data/ext/numo/narray/rand.c +87 -0
  112. data/ext/numo/narray/step.c +506 -0
  113. data/ext/numo/narray/struct.c +872 -0
  114. data/lib/2.1/numo/narray.so +0 -0
  115. data/lib/2.2/numo/narray.so +0 -0
  116. data/lib/2.3/numo/narray.so +0 -0
  117. data/lib/erbpp.rb +286 -0
  118. data/lib/erbpp/line_number.rb +126 -0
  119. data/lib/erbpp/narray_def.rb +338 -0
  120. data/lib/numo/narray.rb +6 -0
  121. data/numo-narray.gemspec +35 -0
  122. data/spec/bit_spec.rb +93 -0
  123. data/spec/narray_spec.rb +249 -0
  124. metadata +238 -0
@@ -0,0 +1,6 @@
1
+ begin
2
+ major, minor, _ = RUBY_VERSION.split(/\./)
3
+ require "#{major}.#{minor}/numo/narray.so"
4
+ rescue LoadError
5
+ require "numo/narray.so"
6
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ open("ext/numo/narray/numo/narray.h") do |f|
6
+ f.each_line do |l|
7
+ if /NARRAY_VERSION "([\d.]+)"/ =~ l
8
+ NARRAY_VERSION = $1
9
+ break
10
+ end
11
+ end
12
+ end
13
+
14
+ Gem::Specification.new do |spec|
15
+ spec.name = "numo-narray"
16
+ spec.version = NARRAY_VERSION
17
+ spec.authors = ["Masahiro TANAKA"]
18
+ spec.email = ["masa16.tanaka@gmail.com"]
19
+ spec.description = %q{NArray development version.}
20
+ spec.summary = %q{NArray development version}
21
+ spec.homepage = "https://github.com/ruby-numo/narray"
22
+ spec.license = "MIT"
23
+
24
+ spec.files = `git ls-files Gemfile README.md Rakefile lib ext numo-narray.gemspec spec`.split($/)
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
27
+ spec.require_paths = ["lib"]
28
+ spec.extensions = ["ext/numo/narray/extconf.rb"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.3"
31
+ spec.add_development_dependency "rake", "~> 0"
32
+ spec.add_development_dependency "rspec", "~> 3"
33
+ spec.add_development_dependency "rake-compiler", ">= 1.0.1"
34
+ spec.add_development_dependency "rake-compiler-dock"
35
+ end
data/spec/bit_spec.rb ADDED
@@ -0,0 +1,93 @@
1
+ require File.join(File.dirname(__FILE__), "../ext/numo/narray/narray")
2
+ #Numo::NArray.debug = true
3
+
4
+ RSpec.configure do |config|
5
+ config.filter_run :focus
6
+ config.run_all_when_everything_filtered = true
7
+ end
8
+ #context :focus=>true do ... end
9
+
10
+ dtype = Numo::Bit
11
+
12
+ describe dtype do
13
+ it{expect(dtype).to be < Numo::NArray}
14
+ end
15
+
16
+ procs = [
17
+ [proc{|tp,a| tp[*a] },""],
18
+ [proc{|tp,a| tp[*a][true] },"[true]"],
19
+ [proc{|tp,a| tp[*a][0..-1] },"[0..-1]"]
20
+ ]
21
+ procs.each do |init,ref|
22
+
23
+ describe dtype,"[0,1,1,0,1,0,0,1]"+ref do
24
+ before(:all) do
25
+ @src = [0,1,1,0,1,0,0,1]
26
+ @n = @src.size
27
+ @a = init.call(dtype,@src)
28
+ end
29
+
30
+ it{expect(@a).to eq @src}
31
+ it{expect(@a & 0).to eq [0]*@n}
32
+ it{expect(@a & 1).to eq @src}
33
+ it{expect(@a | 0).to eq @src}
34
+ it{expect(@a | 1).to eq [1]*@n}
35
+ it{expect(@a ^ 0).to eq @src.map{|x| x^0}}
36
+ it{expect(@a ^ 1).to eq @src.map{|x| x^1}}
37
+ it{expect(~@a).to eq @src.map{|x| 1-x}}
38
+
39
+ it{expect(@a.count_true).to eq 4}
40
+ it{expect(@a.count_false).to eq 4}
41
+ it{expect(@a.where).to eq [1,2,4,7]}
42
+ it{expect(@a.where2).to eq [[1,2,4,7],[0,3,5,6]]}
43
+ it{expect(@a.mask(Numo::DFloat[1,2,3,4,5,6,7,8])).to eq [2,3,5,8]}
44
+ it{expect(@a).not_to be_all}
45
+ it{expect(@a).to be_any}
46
+ it{expect(@a).not_to be_none}
47
+
48
+ after(:all) do
49
+ @a = nil
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ procs = [
56
+ [proc{|tp,a| tp[*a] },""],
57
+ [proc{|tp,a| tp[*a][true,0..-1] },"[true,true]"],
58
+ ]
59
+ procs.each do |init,ref|
60
+
61
+ describe dtype,"[[0,1,1,0],[1,0,0,1]]"+ref do
62
+ before(:all) do
63
+ @src = [[0,1,1,0],[1,0,0,1]]
64
+ @n = @src.size
65
+ @a = init.call(dtype,@src)
66
+ end
67
+
68
+ it{expect(@a[5]).to eq 0}
69
+ it{expect(@a[-1]).to eq 1}
70
+ it{expect(@a[1,0]).to eq @src[1][0]}
71
+ it{expect(@a[1,1]).to eq @src[1][1]}
72
+ it{expect(@a[1,2]).to eq @src[1][2]}
73
+ it{expect(@a[3..4]).to eq [0,1]}
74
+ it{expect(@a[0,1..2]).to eq [1,1]}
75
+ it{expect(@a[0,:*]).to eq @src[0]}
76
+ it{expect(@a[1,:*]).to eq @src[1]}
77
+ it{expect(@a[:*,1]).to eq [@src[0][1],@src[1][1]]}
78
+
79
+ it{expect(@a.count_true).to eq 4}
80
+ it{expect(@a.count_false).to eq 4}
81
+ it{expect(@a.where).to eq [1,2,4,7]}
82
+ it{expect(@a.where2).to eq [[1,2,4,7],[0,3,5,6]]}
83
+ it{expect(@a.mask(Numo::DFloat[[1,2,3,4],[5,6,7,8]])).to eq [2,3,5,8]}
84
+ it{expect(@a).not_to be_all}
85
+ it{expect(@a).to be_any}
86
+ it{expect(@a).not_to be_none}
87
+
88
+ after(:all) do
89
+ @a = nil
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,249 @@
1
+ require File.join(File.dirname(__FILE__), "../ext/numo/narray/narray")
2
+ #Numo::NArray.debug = true
3
+
4
+ RSpec.configure do |config|
5
+ config.filter_run :focus
6
+ config.run_all_when_everything_filtered = true
7
+ end
8
+ #context :focus=>true do ... end
9
+
10
+ types = [
11
+ Numo::DFloat,
12
+ Numo::SFloat,
13
+ Numo::DComplex,
14
+ Numo::SComplex,
15
+ Numo::Int64,
16
+ Numo::Int32,
17
+ Numo::Int16,
18
+ Numo::Int8,
19
+ Numo::UInt64,
20
+ Numo::UInt32,
21
+ Numo::UInt16,
22
+ Numo::UInt8,
23
+ ]
24
+ #types = [Numo::DFloat]
25
+ float_types = [
26
+ Numo::DFloat,
27
+ Numo::DComplex,
28
+ ]
29
+
30
+ types.each do |dtype|
31
+
32
+ describe dtype do
33
+ it{expect(dtype).to be < Numo::NArray}
34
+ end
35
+
36
+ procs = [
37
+ [proc{|tp,a| tp[*a] },""],
38
+ [proc{|tp,a| tp[*a][true] },"[true]"],
39
+ [proc{|tp,a| tp[*a][0..-1] },"[0..-1]"]
40
+ ]
41
+ procs.each do |init,ref|
42
+
43
+ describe dtype,"[1,2,3,5,7,11]"+ref do
44
+ before(:all) do
45
+ @src = [1,2,3,5,7,11]
46
+ @a = init.call(dtype,@src)
47
+ end
48
+ #context :focus=>true do
49
+
50
+ it{expect(@a).to be_kind_of dtype}
51
+ it{expect(@a.size).to eq 6}
52
+ it{expect(@a.ndim).to eq 1}
53
+ it{expect(@a.shape).to eq [6]}
54
+ it{expect(@a).not_to be_inplace}
55
+ it{expect(@a).to be_row_major}
56
+ it{expect(@a).not_to be_column_major}
57
+ it{expect(@a).to be_host_order}
58
+ it{expect(@a).not_to be_byte_swapped}
59
+ it{expect(@a).to eq [1,2,3,5,7,11]}
60
+ it{expect(@a.to_a).to eq [1,2,3,5,7,11]}
61
+ it{expect(@a.to_a).to be_kind_of Array}
62
+ it{expect(@a.dup).to eq @a}
63
+ it{expect(@a.clone).to eq @a}
64
+ it{expect(@a.dup.object_id).not_to eq @a.object_id}
65
+ it{expect(@a.clone.object_id).not_to eq @a.object_id}
66
+
67
+ it{expect(@a.eq([1,1,3,3,7,7])).to eq [1,0,1,0,1,0]}
68
+ it{expect(@a[3..4]).to eq [5,7]}
69
+ it{expect(@a[5]).to eq 11}
70
+ it{expect(@a[-1]).to eq 11}
71
+ it{expect(@a[[4,3,0,1,5,2]]).to eq [7,5,1,2,11,3]}
72
+ it{expect(@a.sum).to eq 29}
73
+ if float_types.include?(dtype)
74
+ it{expect(@a.mean).to eq 29.0/6}
75
+ it{expect(@a.var).to eq 13.766666666666669}
76
+ it{expect(@a.stddev).to eq 3.710345895825168}
77
+ it{expect(@a.rms).to eq 5.901977069875258}
78
+ end
79
+ it{expect(@a.copy.fill(12)).to eq [12]*6}
80
+ it{expect((@a + 1)).to eq [2,3,4,6,8,12]}
81
+ it{expect((@a - 1)).to eq [0,1,2,4,6,10]}
82
+ it{expect((@a * 3)).to eq [3,6,9,15,21,33]}
83
+ it{expect((@a / 0.5)).to eq [2,4,6,10,14,22]}
84
+ it{expect((-@a)).to eq [-1,-2,-3,-5,-7,-11]}
85
+ it{expect((@a ** 2)).to eq [1,4,9,25,49,121]}
86
+ it{expect(@a.swap_byte.swap_byte).to eq [1,2,3,5,7,11]}
87
+ if dtype == Numo::DComplex || dtype == Numo::SComplex
88
+ it{expect(@a.real).to eq @src}
89
+ it{expect(@a.imag).to eq [0]*6}
90
+ it{expect(@a.conj).to eq @src}
91
+ it{expect(@a.angle).to eq [0]*6}
92
+ else
93
+ it{expect(@a.min).to eq 1}
94
+ it{expect(@a.max).to eq 11}
95
+ it{expect((@a >= 3)).to eq [0,0,1,1,1,1]}
96
+ it{expect((@a > 3)).to eq [0,0,0,1,1,1]}
97
+ it{expect((@a <= 3)).to eq [1,1,1,0,0,0]}
98
+ it{expect((@a < 3)).to eq [1,1,0,0,0,0]}
99
+ it{expect((@a.eq 3)).to eq [0,0,1,0,0,0]}
100
+ it{expect(@a.sort).to eq @src}
101
+ it{expect(@a.sort_index).to eq (0..5).to_a}
102
+ it{expect(@a.median).to eq 4}
103
+ end
104
+ end
105
+ end
106
+
107
+ describe dtype, '[1..4]' do
108
+ it{expect(dtype[1..4]).to eq [1,2,3,4]}
109
+ end
110
+
111
+ #describe dtype, ".seq(5)" do
112
+ # it do
113
+ # dtype.seq(5).should == [0,1,2,3,4]
114
+ # end
115
+ #end
116
+
117
+ procs2 = [
118
+ [proc{|tp,src| tp[*src] },""],
119
+ [proc{|tp,src| tp[*src][true,true] },"[true,true]"],
120
+ [proc{|tp,src| tp[*src][0..-1,0..-1] },"[0..-1,0..-1]"]
121
+ ]
122
+ procs2.each do |init,ref|
123
+
124
+ describe dtype,'[[1,2,3],[5,7,11]]'+ref do
125
+ before(:all) do
126
+ @src = [[1,2,3],[5,7,11]]
127
+ @a = init.call(dtype,@src)
128
+ end
129
+ #context :focus=>true do
130
+
131
+ it{expect(@a).to be_kind_of dtype}
132
+ it{expect(@a.size).to eq 6}
133
+ it{expect(@a.ndim).to eq 2}
134
+ it{expect(@a.shape).to eq [2,3]}
135
+ it{expect(@a).not_to be_inplace}
136
+ it{expect(@a).to be_row_major}
137
+ it{expect(@a).not_to be_column_major}
138
+ it{expect(@a).to be_host_order}
139
+ it{expect(@a).not_to be_byte_swapped}
140
+ it{expect(@a).to eq @src}
141
+ it{expect(@a.to_a).to eq @src}
142
+ it{expect(@a.to_a).to be_kind_of Array}
143
+
144
+ it{expect(@a.eq([[1,1,3],[3,7,7]])).to eq [[1,0,1],[0,1,0]]}
145
+ it{expect(@a[5]).to eq 11}
146
+ it{expect(@a[-1]).to eq 11}
147
+ it{expect(@a[1,0]).to eq @src[1][0]}
148
+ it{expect(@a[1,1]).to eq @src[1][1]}
149
+ it{expect(@a[1,2]).to eq @src[1][2]}
150
+ it{expect(@a[3..4]).to eq [5,7]}
151
+ it{expect(@a[0,1..2]).to eq [2,3]}
152
+ it{expect(@a[0,:*]).to eq @src[0]}
153
+ it{expect(@a[1,:*]).to eq @src[1]}
154
+ it{expect(@a[:*,1]).to eq [@src[0][1],@src[1][1]]}
155
+ it{expect(@a[true,[2,0,1]]).to eq [[3,1,2],[11,5,7]]}
156
+ it{expect(@a.reshape(3,2)).to eq [[1,2],[3,5],[7,11]]}
157
+ it{expect(@a.reshape(3,nil)).to eq [[1,2],[3,5],[7,11]]}
158
+ it{expect(@a.reshape(nil,2)).to eq [[1,2],[3,5],[7,11]]}
159
+ it{expect(@a.transpose).to eq [[1,5],[2,7],[3,11]]}
160
+ it{expect(@a.transpose(1,0)).to eq [[1,5],[2,7],[3,11]]}
161
+
162
+ it{expect(@a.sum).to eq 29}
163
+ it{expect(@a.sum(0)).to eq [6, 9, 14]}
164
+ it{expect(@a.sum(1)).to eq [6, 23]}
165
+ if float_types.include?(dtype)
166
+ it{expect(@a.mean).to eq 29.0/6}
167
+ it{expect(@a.mean(0)).to eq [3, 4.5, 7]}
168
+ it{expect(@a.mean(1)).to eq [2, 23.0/3]}
169
+ end
170
+ if dtype == Numo::DComplex || dtype == Numo::SComplex
171
+ it{expect(@a.real).to eq @src}
172
+ it{expect(@a.imag).to eq [[0]*3]*2}
173
+ it{expect(@a.conj).to eq @src}
174
+ it{expect(@a.angle).to eq [[0]*3]*2}
175
+ else
176
+ it{expect(@a.min).to eq 1}
177
+ it{expect(@a.max).to eq 11}
178
+ it{expect((@a >= 3)).to eq [[0,0,1],[1,1,1]]}
179
+ it{expect((@a > 3)).to eq [[0,0,0],[1,1,1]]}
180
+ it{expect((@a <= 3)).to eq [[1,1,1],[0,0,0]]}
181
+ it{expect((@a < 3)).to eq [[1,1,0],[0,0,0]]}
182
+ it{expect((@a.eq 3)).to eq [[0,0,1],[0,0,0]]}
183
+ it{expect(@a.sort).to eq @src}
184
+ it{expect(@a.sort_index).to eq [[0,1,2],[3,4,5]]}
185
+ end
186
+ it{expect(@a.copy.fill(12)).to eq [[12]*3]*2}
187
+ it{expect((@a + 1)).to eq [[2,3,4],[6,8,12]]}
188
+ it{expect((@a + [1,2,3])).to eq [[2,4,6],[6,9,14]]}
189
+ it{expect((@a - 1)).to eq [[0,1,2],[4,6,10]]}
190
+ it{expect((@a - [1,2,3])).to eq [[0,0,0],[4,5,8]]}
191
+ it{expect((@a * 3)).to eq [[3,6,9],[15,21,33]]}
192
+ it{expect((@a * [1,2,3])).to eq [[1,4,9],[5,14,33]]}
193
+ it{expect((@a / 0.5)).to eq [[2,4,6],[10,14,22]]}
194
+ it{expect((-@a)).to eq [[-1,-2,-3],[-5,-7,-11]]}
195
+ it{expect((@a ** 2)).to eq [[1,4,9],[25,49,121]]}
196
+ it{expect((dtype[[1,0],[0,1]].dot dtype[[4,1],[2,2]])).to eq [[4,1],[2,2]]}
197
+ it{expect(@a.swap_byte.swap_byte).to eq @src}
198
+ end
199
+
200
+ end
201
+
202
+ describe dtype,"[[[1,2],[3,4]],[[5,6],[7,8]]]" do
203
+ before do
204
+ @a = dtype[[[1,2],[3,4]],[[5,6],[7,8]]]
205
+ end
206
+
207
+ it{expect(@a[0, 1, 1]).to eq 4}
208
+ #it{expect(@a[:rest]).to eq @a} # note: this spec probably shows the correct behaviour
209
+ it{expect(@a[0, :rest]).to eq [[1,2],[3,4]]}
210
+ it{expect(@a[0, false]).to eq [[1,2],[3,4]]}
211
+ it{expect(@a[0, 1, :rest]).to eq [3,4]}
212
+ it{expect(@a[0, 1, false]).to eq [3,4]}
213
+ it{expect(@a[:rest, 0]).to eq [[1,3],[5,7]]}
214
+ it{expect(@a[:rest, 0, 1]).to eq [2,6]}
215
+ it{expect(@a[1, :rest, 0]).to eq [5,7]}
216
+ it{expect{@a[1, 1, :rest, 0]}.to raise_error IndexError}
217
+ it{expect{@a[1, 1, 1, 1, :rest]}.to raise_error IndexError}
218
+ it{expect{@a[1, 1, 1, :rest, 1]}.to raise_error IndexError}
219
+ end
220
+
221
+ describe dtype, "#dot" do
222
+ it "vector.dot(vector)" do
223
+ a = dtype[1..3]
224
+ b = dtype[2..4]
225
+ expect(a.dot(b)).to eq (1*2 + 2*3 + 3*4)
226
+ end
227
+ it "matrix.dot(vector)" do
228
+ a = dtype[1..6].reshape(3,2)
229
+ b = dtype[1..2]
230
+ expect(a.dot(b)).to eq [5, 11, 17]
231
+ end
232
+ it "vector.dot(matrix)" do
233
+ a = dtype[1..2]
234
+ b = dtype[1..6].reshape(2,3)
235
+ expect(a.dot(b)).to eq [9, 12, 15]
236
+ end
237
+ it "matrix.dot(matrix)" do
238
+ a = dtype[1..6].reshape(3,2)
239
+ b = dtype[1..6].reshape(2,3)
240
+ expect(a.dot(b)).to eq [[9, 12, 15], [19, 26, 33], [29, 40, 51]]
241
+ expect(b.dot(a)).to eq [[22, 28], [49, 64]]
242
+ end
243
+ it "matrix.dot(matrix) with incorrect shape" do
244
+ a = dtype[1..6].reshape(3,2)
245
+ b = dtype[1..9].reshape(3,3)
246
+ expect{a.dot(b)}.to raise_error(TypeError)
247
+ end
248
+ end
249
+ end
metadata ADDED
@@ -0,0 +1,238 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: numo-narray
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0.1
5
+ platform: x64-mingw32
6
+ authors:
7
+ - Masahiro TANAKA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-compiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake-compiler-dock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: NArray development version.
84
+ email:
85
+ - masa16.tanaka@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - README.md
92
+ - Rakefile
93
+ - ext/numo/narray/SFMT-params.h
94
+ - ext/numo/narray/SFMT-params19937.h
95
+ - ext/numo/narray/SFMT.c
96
+ - ext/numo/narray/SFMT.h
97
+ - ext/numo/narray/array.c
98
+ - ext/numo/narray/data.c
99
+ - ext/numo/narray/depend.erb
100
+ - ext/numo/narray/extconf.rb
101
+ - ext/numo/narray/gen/bit.erb.c
102
+ - ext/numo/narray/gen/cogen.rb
103
+ - ext/numo/narray/gen/def/dcomplex.rb
104
+ - ext/numo/narray/gen/def/dfloat.rb
105
+ - ext/numo/narray/gen/def/int16.rb
106
+ - ext/numo/narray/gen/def/int32.rb
107
+ - ext/numo/narray/gen/def/int64.rb
108
+ - ext/numo/narray/gen/def/int8.rb
109
+ - ext/numo/narray/gen/def/robject.rb
110
+ - ext/numo/narray/gen/def/scomplex.rb
111
+ - ext/numo/narray/gen/def/sfloat.rb
112
+ - ext/numo/narray/gen/def/uint16.rb
113
+ - ext/numo/narray/gen/def/uint32.rb
114
+ - ext/numo/narray/gen/def/uint64.rb
115
+ - ext/numo/narray/gen/def/uint8.rb
116
+ - ext/numo/narray/gen/dtype.erb.c
117
+ - ext/numo/narray/gen/tmpl/accum.c
118
+ - ext/numo/narray/gen/tmpl/accum_binary.c
119
+ - ext/numo/narray/gen/tmpl/accum_index.c
120
+ - ext/numo/narray/gen/tmpl/allocate.c
121
+ - ext/numo/narray/gen/tmpl/aref.c
122
+ - ext/numo/narray/gen/tmpl/aset.c
123
+ - ext/numo/narray/gen/tmpl/binary.c
124
+ - ext/numo/narray/gen/tmpl/binary2.c
125
+ - ext/numo/narray/gen/tmpl/binary_s.c
126
+ - ext/numo/narray/gen/tmpl/bit_binary.c
127
+ - ext/numo/narray/gen/tmpl/bit_count.c
128
+ - ext/numo/narray/gen/tmpl/bit_unary.c
129
+ - ext/numo/narray/gen/tmpl/cast.c
130
+ - ext/numo/narray/gen/tmpl/cast_array.c
131
+ - ext/numo/narray/gen/tmpl/cast_numeric.c
132
+ - ext/numo/narray/gen/tmpl/coerce_cast.c
133
+ - ext/numo/narray/gen/tmpl/cond_binary.c
134
+ - ext/numo/narray/gen/tmpl/cond_unary.c
135
+ - ext/numo/narray/gen/tmpl/cum.c
136
+ - ext/numo/narray/gen/tmpl/each.c
137
+ - ext/numo/narray/gen/tmpl/each_with_index.c
138
+ - ext/numo/narray/gen/tmpl/extract.c
139
+ - ext/numo/narray/gen/tmpl/eye.c
140
+ - ext/numo/narray/gen/tmpl/fill.c
141
+ - ext/numo/narray/gen/tmpl/format.c
142
+ - ext/numo/narray/gen/tmpl/format_to_a.c
143
+ - ext/numo/narray/gen/tmpl/head.c
144
+ - ext/numo/narray/gen/tmpl/inspect.c
145
+ - ext/numo/narray/gen/tmpl/map_with_index.c
146
+ - ext/numo/narray/gen/tmpl/median.c
147
+ - ext/numo/narray/gen/tmpl/minmax.c
148
+ - ext/numo/narray/gen/tmpl/poly.c
149
+ - ext/numo/narray/gen/tmpl/pow.c
150
+ - ext/numo/narray/gen/tmpl/powint.c
151
+ - ext/numo/narray/gen/tmpl/qsort.c
152
+ - ext/numo/narray/gen/tmpl/rand.c
153
+ - ext/numo/narray/gen/tmpl/rand_norm.c
154
+ - ext/numo/narray/gen/tmpl/robj_allocate.c
155
+ - ext/numo/narray/gen/tmpl/seq.c
156
+ - ext/numo/narray/gen/tmpl/set2.c
157
+ - ext/numo/narray/gen/tmpl/sort.c
158
+ - ext/numo/narray/gen/tmpl/sort_index.c
159
+ - ext/numo/narray/gen/tmpl/store.c
160
+ - ext/numo/narray/gen/tmpl/store_array.c
161
+ - ext/numo/narray/gen/tmpl/store_from.c
162
+ - ext/numo/narray/gen/tmpl/store_numeric.c
163
+ - ext/numo/narray/gen/tmpl/to_a.c
164
+ - ext/numo/narray/gen/tmpl/unary.c
165
+ - ext/numo/narray/gen/tmpl/unary2.c
166
+ - ext/numo/narray/gen/tmpl/unary_s.c
167
+ - ext/numo/narray/index.c
168
+ - ext/numo/narray/kwarg.c
169
+ - ext/numo/narray/math.c
170
+ - ext/numo/narray/narray.c
171
+ - ext/numo/narray/ndloop.c
172
+ - ext/numo/narray/numo/compat.h
173
+ - ext/numo/narray/numo/intern.h
174
+ - ext/numo/narray/numo/narray.h
175
+ - ext/numo/narray/numo/ndloop.h
176
+ - ext/numo/narray/numo/template.h
177
+ - ext/numo/narray/numo/types/bit.h
178
+ - ext/numo/narray/numo/types/complex.h
179
+ - ext/numo/narray/numo/types/complex_macro.h
180
+ - ext/numo/narray/numo/types/dcomplex.h
181
+ - ext/numo/narray/numo/types/dfloat.h
182
+ - ext/numo/narray/numo/types/float_def.h
183
+ - ext/numo/narray/numo/types/float_macro.h
184
+ - ext/numo/narray/numo/types/int16.h
185
+ - ext/numo/narray/numo/types/int32.h
186
+ - ext/numo/narray/numo/types/int64.h
187
+ - ext/numo/narray/numo/types/int8.h
188
+ - ext/numo/narray/numo/types/int_macro.h
189
+ - ext/numo/narray/numo/types/robj_macro.h
190
+ - ext/numo/narray/numo/types/robject.h
191
+ - ext/numo/narray/numo/types/scomplex.h
192
+ - ext/numo/narray/numo/types/sfloat.h
193
+ - ext/numo/narray/numo/types/uint16.h
194
+ - ext/numo/narray/numo/types/uint32.h
195
+ - ext/numo/narray/numo/types/uint64.h
196
+ - ext/numo/narray/numo/types/uint8.h
197
+ - ext/numo/narray/numo/types/uint_macro.h
198
+ - ext/numo/narray/numo/types/xint_macro.h
199
+ - ext/numo/narray/rand.c
200
+ - ext/numo/narray/step.c
201
+ - ext/numo/narray/struct.c
202
+ - lib/2.1/numo/narray.so
203
+ - lib/2.2/numo/narray.so
204
+ - lib/2.3/numo/narray.so
205
+ - lib/erbpp.rb
206
+ - lib/erbpp/line_number.rb
207
+ - lib/erbpp/narray_def.rb
208
+ - lib/numo/narray.rb
209
+ - numo-narray.gemspec
210
+ - spec/bit_spec.rb
211
+ - spec/narray_spec.rb
212
+ homepage: https://github.com/ruby-numo/narray
213
+ licenses:
214
+ - MIT
215
+ metadata: {}
216
+ post_install_message:
217
+ rdoc_options: []
218
+ require_paths:
219
+ - lib
220
+ required_ruby_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ version: '0'
225
+ required_rubygems_version: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ requirements: []
231
+ rubyforge_project:
232
+ rubygems_version: 2.5.1
233
+ signing_key:
234
+ specification_version: 4
235
+ summary: NArray development version
236
+ test_files:
237
+ - spec/bit_spec.rb
238
+ - spec/narray_spec.rb