numru-narray 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +56 -0
- data/README +8 -5
- data/ext/numru/narray/extconf.rb +1 -1
- data/ext/numru/narray/mkmath.rb +2 -2
- data/ext/numru/narray/na_func.c +2 -1
- data/ext/numru/narray/na_linalg.c +1 -1
- data/ext/numru/narray/narray.c +36 -0
- data/ext/numru/narray/narray.h +2 -2
- data/lib/numru/narray_ext.rb +36 -36
- data/lib/numru/nmatrix.rb +78 -78
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 245218221c00f1e210e6743a9dab4c1baf277791
|
4
|
+
data.tar.gz: d18efa11c4da83b5b1de3e59146c9c245d8ecd32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6222fdcaa4d98cb07714873c7c0002d701e86b35f2184125d995b59cc6539c4bb615568bb67e16b970420c885defd615a75963861a2a9fd557c4fd2db36f9703
|
7
|
+
data.tar.gz: cb5f9c61d30a56279a301da5051a8a15af9c05917b36371b42263dbb2540d93391f66f5a8d26c9a517038ca02f8124d605a0053318f7f54734b182d8c3008938
|
data/ChangeLog
CHANGED
@@ -1,3 +1,59 @@
|
|
1
|
+
2016-02-15 Seiya Nishizawa <seiya@gfd-dennou.org>
|
2
|
+
|
3
|
+
* fixed wrong integer type in the lu solver
|
4
|
+
|
5
|
+
2016-02-15 Seiya Nishizawa <seiya@gfd-dennou.org>
|
6
|
+
|
7
|
+
* fixed wrong type
|
8
|
+
|
9
|
+
2016-02-15 Seiya Nishizawa <seiya@gfd-dennou.org>
|
10
|
+
|
11
|
+
* add "include NumRu" to the benchmark scripts
|
12
|
+
|
13
|
+
2016-02-15 Seiya Nishizawa <seiya@gfd-dennou.org>
|
14
|
+
|
15
|
+
* enable #to_s_refer for ruby >= 1.9
|
16
|
+
|
17
|
+
2016-02-14 Seiya Nishizawa <seiya@gfd-dennou.org>
|
18
|
+
|
19
|
+
* use #to_s for #to_s_refer for ruby < 2.2
|
20
|
+
|
21
|
+
2016-02-13 Seiya Nishizawa <seiya@gfd-dennou.org>
|
22
|
+
|
23
|
+
* update README
|
24
|
+
|
25
|
+
2016-02-13 Seiya Nishizawa <seiya@gfd-dennou.org>
|
26
|
+
|
27
|
+
* update mkmath.rb (na_math.c was overwrited)
|
28
|
+
|
29
|
+
2016-02-13 Seiya Nishizawa <seiya@gfd-dennou.org>
|
30
|
+
|
31
|
+
* update tests
|
32
|
+
|
33
|
+
2016-02-13 Seiya Nishizawa <seiya@gfd-dennou.org>
|
34
|
+
|
35
|
+
* add "include NumRu" to the test files
|
36
|
+
|
37
|
+
2016-02-13 Seiya Nishizawa <seiya@gfd-dennou.org>
|
38
|
+
|
39
|
+
* add Gemfile file
|
40
|
+
|
41
|
+
2016-02-13 Seiya Nishizawa <seiya@gfd-dennou.org>
|
42
|
+
|
43
|
+
* add travis setting
|
44
|
+
|
45
|
+
2016-02-13 Seiya Nishizawa <seiya@gfd-dennou.org>
|
46
|
+
|
47
|
+
* add NumRu::NArray#to_s_refer method (same as #to_s but not dup data)
|
48
|
+
|
49
|
+
2016-02-12 Seiya Nishizawa <seiya@gfd-dennou.org>
|
50
|
+
|
51
|
+
* remove narray.gemspec
|
52
|
+
|
53
|
+
2016-02-12 Seiya Nishizawa <seiya@gfd-dennou.org>
|
54
|
+
|
55
|
+
* update ChangeLog
|
56
|
+
|
1
57
|
2016-02-12 Seiya Nishizawa <seiya@gfd-dennou.org>
|
2
58
|
|
3
59
|
* update version
|
data/README
CHANGED
@@ -11,11 +11,14 @@
|
|
11
11
|
|
12
12
|
* Installation
|
13
13
|
|
14
|
-
+
|
14
|
+
+ Install NumRu NArray
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
% gem install numru-narray
|
17
|
+
|
18
|
+
+ Compile (if you do not want to via gem)
|
19
|
+
|
20
|
+
% bundle install
|
21
|
+
% bundle exec rake compile
|
19
22
|
|
20
23
|
+ For OpenMP support
|
21
24
|
|
@@ -30,7 +33,7 @@
|
|
30
33
|
* Run
|
31
34
|
|
32
35
|
+ load library
|
33
|
-
require 'narray'
|
36
|
+
require 'numru/narray'
|
34
37
|
|
35
38
|
+ enable OpenMP
|
36
39
|
|
data/ext/numru/narray/extconf.rb
CHANGED
data/ext/numru/narray/mkmath.rb
CHANGED
@@ -775,10 +775,10 @@ print <<EOM
|
|
775
775
|
|
776
776
|
|
777
777
|
/* Initialization of NMath module */
|
778
|
-
void Init_nmath(
|
778
|
+
void Init_nmath(VALUE mNumRu)
|
779
779
|
{
|
780
780
|
/* define ExtMath module */
|
781
|
-
rb_mNMath =
|
781
|
+
rb_mNMath = rb_define_module_under(mNumRu, "NMath");
|
782
782
|
|
783
783
|
/* methods */
|
784
784
|
EOM
|
data/ext/numru/narray/na_func.c
CHANGED
@@ -381,6 +381,7 @@ static int
|
|
381
381
|
else
|
382
382
|
rb_raise(rb_eRuntimeError, "Array size mismatch: %zd != %zd at %i-th dim",
|
383
383
|
ary_sz, itr_sz, i);
|
384
|
+
return -1;
|
384
385
|
}
|
385
386
|
|
386
387
|
|
@@ -1035,7 +1036,7 @@ static int
|
|
1035
1036
|
r = NUM2SHAPE(v);
|
1036
1037
|
if (r<0) r += rankc; /* negative for from end */
|
1037
1038
|
if (r<0 || r>=rankc)
|
1038
|
-
rb_raise(rb_eArgError, "rank %
|
1039
|
+
rb_raise(rb_eArgError, "rank %zd out of range", r);
|
1039
1040
|
if (flag)
|
1040
1041
|
rankv[c] = r;
|
1041
1042
|
else
|
@@ -375,7 +375,7 @@ na_lu_solve_func_body( int ni,
|
|
375
375
|
na_shape_t i,k;
|
376
376
|
na_funcset_t *f = &na_funcset[type];
|
377
377
|
na_shape_t n = shape[1];
|
378
|
-
|
378
|
+
na_shape_t sz = (na_shape_t) na_sizeof[type];
|
379
379
|
na_shape_t xsz = shape[0] * sz;
|
380
380
|
na_shape_t rowsz = sz * n;
|
381
381
|
na_shape_t matsz = rowsz * n;
|
data/ext/numru/narray/narray.c
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
*/
|
11
11
|
#define NARRAY_C
|
12
12
|
#include <ruby.h>
|
13
|
+
#include "ruby/version.h"
|
13
14
|
#include "narray.h"
|
14
15
|
#include "narray_local.h"
|
15
16
|
|
@@ -657,6 +658,40 @@ static VALUE
|
|
657
658
|
return rb_str_new(ary->ptr,ary->total*na_sizeof[ary->type]);
|
658
659
|
}
|
659
660
|
|
661
|
+
/* method: to_s_refer -- convert the data contents to a binary string (not dup data) */
|
662
|
+
static VALUE
|
663
|
+
na_to_s_refer(VALUE self)
|
664
|
+
{
|
665
|
+
struct NARRAY *ary;
|
666
|
+
VALUE str;
|
667
|
+
GetNArray(self,ary);
|
668
|
+
if (NA_IsROBJ(ary))
|
669
|
+
rb_raise(rb_eTypeError,"cannot convert object-type NArray");
|
670
|
+
#if RUBY_API_VERSION_CODE >= 20200
|
671
|
+
str = rb_str_new_static(ary->ptr,ary->total*na_sizeof[ary->type]);
|
672
|
+
RB_OBJ_WRITE(str, &RSTRING(str)->as.heap.aux.shared, self);
|
673
|
+
FL_SET(str, ELTS_SHARED);
|
674
|
+
#elif RUBY_API_VERSION_CODE >= 10900
|
675
|
+
{
|
676
|
+
NEWOBJ(rstr, struct RString);
|
677
|
+
str = (VALUE)rstr;
|
678
|
+
}
|
679
|
+
OBJSETUP(str, rb_cString, T_STRING);
|
680
|
+
FL_SET(str, FL_USER1);
|
681
|
+
RBASIC(str)->flags &= ~RSTRING_EMBED_LEN_MASK;
|
682
|
+
RBASIC(str)->flags |= (0L << RSTRING_EMBED_LEN_SHIFT);
|
683
|
+
RSTRING(str)->as.heap.len = ary->total*na_sizeof[ary->type];
|
684
|
+
RSTRING(str)->as.heap.ptr = ary->ptr;
|
685
|
+
RSTRING(str)->as.heap.aux.capa = RSTRING(str)->as.heap.len;
|
686
|
+
RSTRING(str)->as.heap.aux.shared = self;
|
687
|
+
FL_SET(str, ELTS_SHARED);
|
688
|
+
#else
|
689
|
+
str = rb_str_new(ary->ptr,ary->total*na_sizeof[ary->type]);
|
690
|
+
rb_warn("#to_s is used for #to_s_refer for ruby < 1.9 (%d.%d.%d)", RUBY_API_VERSION_MAJOR, RUBY_API_VERSION_MINOR, RUBY_API_VERSION_TEENY);
|
691
|
+
#endif
|
692
|
+
return rb_obj_freeze(str);
|
693
|
+
}
|
694
|
+
|
660
695
|
|
661
696
|
/* method: to_binary -- convert the data contents to a BYTE type NArray */
|
662
697
|
static VALUE
|
@@ -1264,6 +1299,7 @@ void
|
|
1264
1299
|
rb_define_alias(cNArray, "map", "collect");
|
1265
1300
|
rb_define_alias(cNArray, "map!", "collect!");
|
1266
1301
|
rb_define_method(cNArray, "to_s", na_to_s, 0);
|
1302
|
+
rb_define_method(cNArray, "to_s_refer", na_to_s_refer, 0);
|
1267
1303
|
rb_define_method(cNArray, "to_f", na_to_float, 0);
|
1268
1304
|
rb_define_method(cNArray, "to_i", na_to_integer, 0);
|
1269
1305
|
rb_define_method(cNArray, "to_type", na_to_type, 1);
|
data/ext/numru/narray/narray.h
CHANGED
@@ -27,8 +27,8 @@
|
|
27
27
|
#define NARRAY_VERSION "0.6.0.8"
|
28
28
|
#define NARRAY_VERSION_CODE 608
|
29
29
|
|
30
|
-
#define NUMRU_NARRAY_VERSION "1.0.
|
31
|
-
#define NUMRU_NARRAY_VERSION_CODE
|
30
|
+
#define NUMRU_NARRAY_VERSION "1.0.2"
|
31
|
+
#define NUMRU_NARRAY_VERSION_CODE 102
|
32
32
|
|
33
33
|
/* big memory support */
|
34
34
|
#define NARRAY_BIGMEM 1
|
data/lib/numru/narray_ext.rb
CHANGED
@@ -10,11 +10,11 @@ class NumRu::NArray
|
|
10
10
|
|
11
11
|
def self.cast(array,type=nil)
|
12
12
|
case array
|
13
|
-
when NArray
|
13
|
+
when NumRu::NArray
|
14
14
|
when Array
|
15
|
-
array = NArray.to_na(array)
|
15
|
+
array = NumRu::NArray.to_na(array)
|
16
16
|
else
|
17
|
-
raise ArgumentError, "1st argument must be NArray or Array"
|
17
|
+
raise ArgumentError, "1st argument must be NumRu::NArray or Array"
|
18
18
|
end
|
19
19
|
type = array.typecode if type.nil?
|
20
20
|
shape = array.shape
|
@@ -24,13 +24,13 @@ class NumRu::NArray
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def integer?
|
27
|
-
self.typecode==NArray::BYTE ||
|
28
|
-
self.typecode==NArray::SINT ||
|
29
|
-
self.typecode==NArray::LINT
|
27
|
+
self.typecode==NumRu::NArray::BYTE ||
|
28
|
+
self.typecode==NumRu::NArray::SINT ||
|
29
|
+
self.typecode==NumRu::NArray::LINT
|
30
30
|
end
|
31
31
|
def complex?
|
32
|
-
self.typecode==NArray::DCOMPLEX ||
|
33
|
-
self.typecode==NArray::SCOMPLEX
|
32
|
+
self.typecode==NumRu::NArray::DCOMPLEX ||
|
33
|
+
self.typecode==NumRu::NArray::SCOMPLEX
|
34
34
|
end
|
35
35
|
|
36
36
|
def all?
|
@@ -46,7 +46,7 @@ class NumRu::NArray
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def ==(other)
|
49
|
-
other.kind_of?(NArray) &&
|
49
|
+
other.kind_of?(NumRu::NArray) &&
|
50
50
|
shape == other.shape &&
|
51
51
|
eq(other).all?
|
52
52
|
end
|
@@ -56,7 +56,7 @@ class NumRu::NArray
|
|
56
56
|
typecode == other.typecode &&
|
57
57
|
shape == other.shape &&
|
58
58
|
case typecode
|
59
|
-
when NArray::OBJECT
|
59
|
+
when NumRu::NArray::OBJECT
|
60
60
|
to_a.eql? other.to_a
|
61
61
|
else
|
62
62
|
to_s.eql? other.to_s
|
@@ -65,7 +65,7 @@ class NumRu::NArray
|
|
65
65
|
|
66
66
|
def hash
|
67
67
|
case typecode
|
68
|
-
when NArray::OBJECT
|
68
|
+
when NumRu::NArray::OBJECT
|
69
69
|
[self.class, to_a].hash
|
70
70
|
else
|
71
71
|
[self.class, typecode, shape, to_s].hash
|
@@ -130,56 +130,56 @@ class NumRu::NArray
|
|
130
130
|
# Statistics
|
131
131
|
def mean(*ranks)
|
132
132
|
if integer?
|
133
|
-
a = self.to_type(NArray::DFLOAT)
|
133
|
+
a = self.to_type(NumRu::NArray::DFLOAT)
|
134
134
|
else
|
135
135
|
a = self
|
136
136
|
end
|
137
|
-
a = NArray.ref(a)
|
137
|
+
a = NumRu::NArray.ref(a)
|
138
138
|
a.sum(*ranks) / (rank_total(*ranks))
|
139
139
|
end
|
140
140
|
|
141
141
|
def stddev(*ranks)
|
142
142
|
if integer?
|
143
|
-
a = self.to_type(NArray::DFLOAT)
|
143
|
+
a = self.to_type(NumRu::NArray::DFLOAT)
|
144
144
|
else
|
145
145
|
a = self
|
146
146
|
end
|
147
|
-
a = NArray.ref(a)
|
147
|
+
a = NumRu::NArray.ref(a)
|
148
148
|
n = rank_total(*ranks)
|
149
149
|
if complex?
|
150
|
-
NMath::sqrt( (( a-a.accum(*ranks).div!(n) ).abs**2).sum(*ranks)/(n-1) )
|
150
|
+
NumRu::NMath::sqrt( (( a-a.accum(*ranks).div!(n) ).abs**2).sum(*ranks)/(n-1) )
|
151
151
|
else
|
152
|
-
NMath::sqrt( (( a-a.accum(*ranks).div!(n) )**2).sum(*ranks)/(n-1) )
|
152
|
+
NumRu::NMath::sqrt( (( a-a.accum(*ranks).div!(n) )**2).sum(*ranks)/(n-1) )
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
156
|
def rms(*ranks)
|
157
157
|
if integer?
|
158
|
-
a = self.to_type(NArray::DFLOAT)
|
158
|
+
a = self.to_type(NumRu::NArray::DFLOAT)
|
159
159
|
else
|
160
160
|
a = self
|
161
161
|
end
|
162
|
-
a = NArray.ref(a)
|
162
|
+
a = NumRu::NArray.ref(a)
|
163
163
|
n = rank_total(*ranks)
|
164
164
|
if complex?
|
165
|
-
NMath::sqrt( (a.abs**2).sum(*ranks)/n )
|
165
|
+
NumRu::NMath::sqrt( (a.abs**2).sum(*ranks)/n )
|
166
166
|
else
|
167
|
-
NMath::sqrt( (a**2).sum(*ranks)/n )
|
167
|
+
NumRu::NMath::sqrt( (a**2).sum(*ranks)/n )
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
171
|
def rmsdev(*ranks)
|
172
172
|
if integer?
|
173
|
-
a = self.to_type(NArray::DFLOAT)
|
173
|
+
a = self.to_type(NumRu::NArray::DFLOAT)
|
174
174
|
else
|
175
175
|
a = self
|
176
176
|
end
|
177
|
-
a = NArray.ref(a)
|
177
|
+
a = NumRu::NArray.ref(a)
|
178
178
|
n = rank_total(*ranks)
|
179
179
|
if complex?
|
180
|
-
NMath::sqrt( (( a-a.accum(*ranks).div!(n) ).abs**2).sum(*ranks)/n )
|
180
|
+
NumRu::NMath::sqrt( (( a-a.accum(*ranks).div!(n) ).abs**2).sum(*ranks)/n )
|
181
181
|
else
|
182
|
-
NMath::sqrt( (( a-a.accum(*ranks).div!(n) )**2).sum(*ranks)/n )
|
182
|
+
NumRu::NMath::sqrt( (( a-a.accum(*ranks).div!(n) )**2).sum(*ranks)/n )
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
@@ -205,16 +205,16 @@ class NumRu::NArray
|
|
205
205
|
when FLOAT
|
206
206
|
when SFLOAT
|
207
207
|
else
|
208
|
-
raise TypeError, "NArray type must be (S)FLOAT or (S)COMPLEX."
|
208
|
+
raise TypeError, "NumRu::NArray type must be (S)FLOAT or (S)COMPLEX."
|
209
209
|
end
|
210
|
-
rr = NArray.new(type,size)
|
211
|
-
xx = NArray.new(type,size)
|
210
|
+
rr = NumRu::NArray.new(type,size)
|
211
|
+
xx = NumRu::NArray.new(type,size)
|
212
212
|
i = 0
|
213
213
|
while i < size
|
214
214
|
n = size-i
|
215
215
|
m = ((n+Math::sqrt(n))*1.27).to_i
|
216
|
-
x = NArray.new(type,m).random!(1) * 2 - 1
|
217
|
-
y = NArray.new(type,m).random!(1) * 2 - 1
|
216
|
+
x = NumRu::NArray.new(type,m).random!(1) * 2 - 1
|
217
|
+
y = NumRu::NArray.new(type,m).random!(1) * 2 - 1
|
218
218
|
r = x**2 + y**2
|
219
219
|
idx = (r<1).where
|
220
220
|
idx = idx[0...n] if idx.size > n
|
@@ -225,7 +225,7 @@ class NumRu::NArray
|
|
225
225
|
end
|
226
226
|
end
|
227
227
|
# Box-Muller transform
|
228
|
-
rr = ( xx * NMath::sqrt( -2 * NMath::log(rr) / rr ) )
|
228
|
+
rr = ( xx * NumRu::NMath::sqrt( -2 * NumRu::NMath::log(rr) / rr ) )
|
229
229
|
# finish
|
230
230
|
rr.reshape!(*self.shape) if self.rank > 1
|
231
231
|
rr = rr.to_type(self.typecode) if type!=self.typecode
|
@@ -278,7 +278,7 @@ class NumRu::NArray
|
|
278
278
|
end
|
279
279
|
end
|
280
280
|
|
281
|
-
#SFloatOne = NArray.sfloat(1).fill!(1)
|
281
|
+
#SFloatOne = NumRu::NArray.sfloat(1).fill!(1)
|
282
282
|
end
|
283
283
|
|
284
284
|
|
@@ -332,10 +332,10 @@ module NumRu::NMath
|
|
332
332
|
|
333
333
|
# Statistics
|
334
334
|
def covariance(x,y,*ranks)
|
335
|
-
x = NArray.to_na(x) unless x.kind_of?(NArray)
|
336
|
-
x = x.to_type(NArray::DFLOAT) if x.integer?
|
337
|
-
y = NArray.to_na(y) unless y.kind_of?(NArray)
|
338
|
-
y = y.to_type(NArray::DFLOAT) if y.integer?
|
335
|
+
x = NumRu::NArray.to_na(x) unless x.kind_of?(NumRu::NArray)
|
336
|
+
x = x.to_type(NumRu::NArray::DFLOAT) if x.integer?
|
337
|
+
y = NumRu::NArray.to_na(y) unless y.kind_of?(NumRu::NArray)
|
338
|
+
y = y.to_type(NumRu::NArray::DFLOAT) if y.integer?
|
339
339
|
n = x.rank_total(*ranks)
|
340
340
|
xm = x.accum(*ranks).div!(n)
|
341
341
|
ym = y.accum(*ranks).div!(n)
|
data/lib/numru/nmatrix.rb
CHANGED
@@ -10,70 +10,70 @@ class NumRu::NMatrix < NumRu::NArray
|
|
10
10
|
|
11
11
|
def +(other)
|
12
12
|
case other
|
13
|
-
when NMatrix
|
14
|
-
return super(NArray.refer(other))
|
15
|
-
when NArray
|
16
|
-
unless other.instance_of?(NArray)
|
13
|
+
when NumRu::NMatrix
|
14
|
+
return super(NumRu::NArray.refer(other))
|
15
|
+
when NumRu::NArray
|
16
|
+
unless other.instance_of?(NumRu::NArray)
|
17
17
|
return other.coerce_rev( self, :+ )
|
18
18
|
end
|
19
19
|
end
|
20
|
-
raise TypeError,"Illegal operation: NMatrix + %s" % other.class
|
20
|
+
raise TypeError,"Illegal operation: NumRu::NMatrix + %s" % other.class
|
21
21
|
end
|
22
22
|
|
23
23
|
def -(other)
|
24
24
|
case other
|
25
|
-
when NMatrix
|
26
|
-
return super(NArray.refer(other))
|
27
|
-
when NArray
|
28
|
-
unless other.instance_of?(NArray)
|
25
|
+
when NumRu::NMatrix
|
26
|
+
return super(NumRu::NArray.refer(other))
|
27
|
+
when NumRu::NArray
|
28
|
+
unless other.instance_of?(NumRu::NArray)
|
29
29
|
return other.coerce_rev( self, :- )
|
30
30
|
end
|
31
31
|
end
|
32
|
-
raise TypeError,"Illegal operation: NMatrix - %s" % other.class
|
32
|
+
raise TypeError,"Illegal operation: NumRu::NMatrix - %s" % other.class
|
33
33
|
end
|
34
34
|
|
35
35
|
def *(other)
|
36
36
|
case other
|
37
|
-
when NMatrix
|
38
|
-
NMatrix.mul_add( NArray.refer(self).newdim!(0),other.newdim(2), 1 )
|
39
|
-
#NMatrix.mul_add( NArray.refer(self).newdim!(0),
|
37
|
+
when NumRu::NMatrix
|
38
|
+
NumRu::NMatrix.mul_add( NumRu::NArray.refer(self).newdim!(0),other.newdim(2), 1 )
|
39
|
+
#NumRu::NMatrix.mul_add( NumRu::NArray.refer(self).newdim!(0),
|
40
40
|
# other.transpose(1,0).newdim!(2), 0 )
|
41
|
-
when NVector
|
42
|
-
NVector.mul_add( NArray.refer(self), other.newdim(1), 0 )
|
43
|
-
when NArray
|
44
|
-
if other.instance_of?(NArray)
|
45
|
-
NMatrix.mul( NArray.refer(self), other.newdim(0,0) )
|
41
|
+
when NumRu::NVector
|
42
|
+
NumRu::NVector.mul_add( NumRu::NArray.refer(self), other.newdim(1), 0 )
|
43
|
+
when NumRu::NArray
|
44
|
+
if other.instance_of?(NumRu::NArray)
|
45
|
+
NumRu::NMatrix.mul( NumRu::NArray.refer(self), other.newdim(0,0) )
|
46
46
|
else
|
47
47
|
other.coerce_rev( self, :* )
|
48
48
|
end
|
49
49
|
when Numeric
|
50
50
|
super
|
51
|
-
#NMatrix.mul( NArray.refer(self), other )
|
51
|
+
#NumRu::NMatrix.mul( NumRu::NArray.refer(self), other )
|
52
52
|
when Array
|
53
|
-
NMatrix.mul( self, NArray[*other].newdim!(0,0) )
|
53
|
+
NumRu::NMatrix.mul( self, NumRu::NArray[*other].newdim!(0,0) )
|
54
54
|
else
|
55
|
-
raise TypeError,"Illegal operation: NMatrix * %s" % other.class
|
55
|
+
raise TypeError,"Illegal operation: NumRu::NMatrix * %s" % other.class
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
def /(other)
|
60
60
|
case other
|
61
|
-
when NMatrix
|
61
|
+
when NumRu::NMatrix
|
62
62
|
other.lu.solve(self)
|
63
|
-
when NVector
|
64
|
-
raise TypeError,"Illegal operation: NMatrix / %s" % other.class
|
65
|
-
when NArray
|
66
|
-
if other.instance_of?(NArray)
|
67
|
-
NMatrix.div( NArray.refer(self), other.newdim(0,0) )
|
63
|
+
when NumRu::NVector
|
64
|
+
raise TypeError,"Illegal operation: NumRu::NMatrix / %s" % other.class
|
65
|
+
when NumRu::NArray
|
66
|
+
if other.instance_of?(NumRu::NArray)
|
67
|
+
NumRu::NMatrix.div( NumRu::NArray.refer(self), other.newdim(0,0) )
|
68
68
|
else
|
69
69
|
other.coerce_rev( self, :/ )
|
70
70
|
end
|
71
71
|
when Numeric
|
72
|
-
NMatrix.div( NArray.refer(self), other )
|
72
|
+
NumRu::NMatrix.div( NumRu::NArray.refer(self), other )
|
73
73
|
when Array
|
74
|
-
NMatrix.div( self, NArray[*other].newdim!(0,0) )
|
74
|
+
NumRu::NMatrix.div( self, NumRu::NArray[*other].newdim!(0,0) )
|
75
75
|
else
|
76
|
-
raise TypeError,"Illegal operation: NMatrix / %s" % other.class
|
76
|
+
raise TypeError,"Illegal operation: NumRu::NMatrix / %s" % other.class
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -91,33 +91,33 @@ class NumRu::NMatrix < NumRu::NArray
|
|
91
91
|
(2..n).each{ m *= self }
|
92
92
|
m
|
93
93
|
else
|
94
|
-
raise TypeError,"Illegal operation: NMatrix ** %s" % other.class
|
94
|
+
raise TypeError,"Illegal operation: NumRu::NMatrix ** %s" % other.class
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
def coerce_rev(other,id)
|
99
99
|
case id
|
100
100
|
when :*
|
101
|
-
if other.instance_of?(NArray)
|
102
|
-
return NMatrix.mul( other.newdim(0,0), self )
|
101
|
+
if other.instance_of?(NumRu::NArray)
|
102
|
+
return NumRu::NMatrix.mul( other.newdim(0,0), self )
|
103
103
|
end
|
104
|
-
if other.instance_of?(NArrayScalar)
|
105
|
-
return NMatrix.mul( other.newdim(0), self )
|
104
|
+
if other.instance_of?(NumRu::NArrayScalar)
|
105
|
+
return NumRu::NMatrix.mul( other.newdim(0), self )
|
106
106
|
end
|
107
107
|
when :/
|
108
|
-
if other.instance_of?(NArray)
|
109
|
-
return NMatrix.mul( other.newdim(0,0), self.inverse )
|
108
|
+
if other.instance_of?(NumRu::NArray)
|
109
|
+
return NumRu::NMatrix.mul( other.newdim(0,0), self.inverse )
|
110
110
|
end
|
111
|
-
if other.instance_of?(NArrayScalar)
|
112
|
-
return NMatrix.mul( other.newdim(0), self.inverse )
|
111
|
+
if other.instance_of?(NumRu::NArrayScalar)
|
112
|
+
return NumRu::NMatrix.mul( other.newdim(0), self.inverse )
|
113
113
|
end
|
114
114
|
end
|
115
|
-
raise TypeError,"Illegal operation: %s %s NMatrix" %
|
115
|
+
raise TypeError,"Illegal operation: %s %s NumRu::NMatrix" %
|
116
116
|
[other.class, id.id2name]
|
117
117
|
end
|
118
118
|
|
119
119
|
def inverse
|
120
|
-
self.lu.solve( NMatrix.new(self.typecode, *self.shape).fill!(0).unit )
|
120
|
+
self.lu.solve( NumRu::NMatrix.new(self.typecode, *self.shape).fill!(0).unit )
|
121
121
|
end
|
122
122
|
|
123
123
|
def transpose(*arg)
|
@@ -130,12 +130,12 @@ class NumRu::NMatrix < NumRu::NArray
|
|
130
130
|
|
131
131
|
def diagonal!(val=1)
|
132
132
|
shp = self.shape
|
133
|
-
idx = NArray.int(shp[0..1].min).indgen! * (shp[0]+1)
|
133
|
+
idx = NumRu::NArray.int(shp[0..1].min).indgen! * (shp[0]+1)
|
134
134
|
ref = reshape(shp[0]*shp[1],true)
|
135
135
|
if val.kind_of?(Numeric)
|
136
136
|
ref[idx,true] = val
|
137
137
|
else
|
138
|
-
val = NArray.to_na(val)
|
138
|
+
val = NumRu::NArray.to_na(val)
|
139
139
|
raise ArgumentError, "must be 1-d array" if val.dim!=1
|
140
140
|
ref[idx,true] = val.newdim!(-1)
|
141
141
|
end
|
@@ -152,74 +152,74 @@ class NumRu::NMatrix < NumRu::NArray
|
|
152
152
|
alias identity unit
|
153
153
|
alias I unit
|
154
154
|
|
155
|
-
end # class NMatrix
|
155
|
+
end # class NumRu::NMatrix
|
156
156
|
|
157
157
|
|
158
158
|
#
|
159
|
-
# ------ NVector ------
|
159
|
+
# ------ NumRu::NVector ------
|
160
160
|
#
|
161
161
|
class NumRu::NVector < NumRu::NArray
|
162
162
|
CLASS_DIMENSION = 1
|
163
163
|
|
164
164
|
def +(other)
|
165
165
|
case other
|
166
|
-
when NVector
|
167
|
-
return super(NArray.refer(other))
|
168
|
-
when NArray
|
169
|
-
unless other.instance_of?(NArray)
|
166
|
+
when NumRu::NVector
|
167
|
+
return super(NumRu::NArray.refer(other))
|
168
|
+
when NumRu::NArray
|
169
|
+
unless other.instance_of?(NumRu::NArray)
|
170
170
|
return other.coerce_rev( self, :+ )
|
171
171
|
end
|
172
172
|
end
|
173
|
-
raise TypeError,"Illegal operation: NVector + %s" % other.class
|
173
|
+
raise TypeError,"Illegal operation: NumRu::NVector + %s" % other.class
|
174
174
|
end
|
175
175
|
|
176
176
|
def -(other)
|
177
177
|
case other
|
178
|
-
when NVector
|
179
|
-
return super(NArray.refer(other))
|
180
|
-
when NArray
|
181
|
-
unless other.instance_of?(NArray)
|
178
|
+
when NumRu::NVector
|
179
|
+
return super(NumRu::NArray.refer(other))
|
180
|
+
when NumRu::NArray
|
181
|
+
unless other.instance_of?(NumRu::NArray)
|
182
182
|
return other.coerce_rev( self, :- )
|
183
183
|
end
|
184
184
|
end
|
185
|
-
raise TypeError,"Illegal operation: NVector - %s" % other.class
|
185
|
+
raise TypeError,"Illegal operation: NumRu::NVector - %s" % other.class
|
186
186
|
end
|
187
187
|
|
188
188
|
def *(other)
|
189
189
|
case other
|
190
|
-
when NMatrix
|
191
|
-
NVector.mul_add( NArray.refer(self).newdim!(0), other, 1 )
|
192
|
-
when NVector
|
193
|
-
NArray.mul_add( NArray.refer(self), other, 0 ) # inner product
|
194
|
-
when NArray
|
195
|
-
if other.instance_of?(NArray)
|
196
|
-
NVector.mul( NArray.refer(self), other.newdim(0) )
|
190
|
+
when NumRu::NMatrix
|
191
|
+
NumRu::NVector.mul_add( NumRu::NArray.refer(self).newdim!(0), other, 1 )
|
192
|
+
when NumRu::NVector
|
193
|
+
NumRu::NArray.mul_add( NumRu::NArray.refer(self), other, 0 ) # inner product
|
194
|
+
when NumRu::NArray
|
195
|
+
if other.instance_of?(NumRu::NArray)
|
196
|
+
NumRu::NVector.mul( NumRu::NArray.refer(self), other.newdim(0) )
|
197
197
|
else
|
198
198
|
other.coerce_rev( self, :* )
|
199
199
|
end
|
200
200
|
when Numeric
|
201
|
-
NVector.mul( NArray.refer(self), other )
|
201
|
+
NumRu::NVector.mul( NumRu::NArray.refer(self), other )
|
202
202
|
else
|
203
|
-
raise TypeError,"Illegal operation: NVector * %s" % other.class
|
203
|
+
raise TypeError,"Illegal operation: NumRu::NVector * %s" % other.class
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
207
207
|
def /(other)
|
208
208
|
case other
|
209
|
-
when NMatrix
|
209
|
+
when NumRu::NMatrix
|
210
210
|
other.lu.solve(self)
|
211
|
-
when NVector
|
212
|
-
raise TypeError,"Illegal operation: NVector / %s" % other.class
|
213
|
-
when NArray
|
214
|
-
if other.instance_of?(NArray)
|
215
|
-
NVector.div( NArray.refer(self), other.newdim(0) )
|
211
|
+
when NumRu::NVector
|
212
|
+
raise TypeError,"Illegal operation: NumRu::NVector / %s" % other.class
|
213
|
+
when NumRu::NArray
|
214
|
+
if other.instance_of?(NumRu::NArray)
|
215
|
+
NumRu::NVector.div( NumRu::NArray.refer(self), other.newdim(0) )
|
216
216
|
else
|
217
217
|
other.coerce_rev( self, :/ )
|
218
218
|
end
|
219
219
|
when Numeric
|
220
|
-
NVector.div( NArray.refer(self), other )
|
220
|
+
NumRu::NVector.div( NumRu::NArray.refer(self), other )
|
221
221
|
else
|
222
|
-
raise TypeError,"Illegal operation: NVector / %s" % other.class
|
222
|
+
raise TypeError,"Illegal operation: NumRu::NVector / %s" % other.class
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
@@ -234,15 +234,15 @@ class NumRu::NVector < NumRu::NArray
|
|
234
234
|
def coerce_rev(other,id)
|
235
235
|
case id
|
236
236
|
when :*
|
237
|
-
if other.instance_of?(NArray)
|
238
|
-
return NVector.mul( other.newdim(0), self )
|
237
|
+
if other.instance_of?(NumRu::NArray)
|
238
|
+
return NumRu::NVector.mul( other.newdim(0), self )
|
239
239
|
end
|
240
|
-
if other.instance_of?(NArrayScalar)
|
241
|
-
return NVector.mul( other, self )
|
240
|
+
if other.instance_of?(NumRu::NArrayScalar)
|
241
|
+
return NumRu::NVector.mul( other, self )
|
242
242
|
end
|
243
243
|
end
|
244
|
-
raise TypeError,"Illegal operation: %s %s NVector" %
|
244
|
+
raise TypeError,"Illegal operation: %s %s NumRu::NVector" %
|
245
245
|
[other.class, id.id2name]
|
246
246
|
end
|
247
247
|
|
248
|
-
end # class NVector
|
248
|
+
end # class NumRu::NVector
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numru-narray
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seiya Nishizawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: NArray with big memory support
|
14
14
|
email: seiya@gfd-dennou.org
|