narray 0.5.9.4 → 0.5.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/src/ChangeLog +29 -0
- data/src/MANIFEST +7 -36
- data/src/README.en +1 -5
- data/src/README.ja +1 -2
- data/src/SPEC.en +15 -8
- data/src/SPEC.ja +5 -2
- data/src/bench/all.rb +88 -0
- data/src/bench/bench.m +61 -0
- data/src/bench/bench.py +89 -0
- data/src/bench/bench.rb +59 -0
- data/src/bench/dummy.m +0 -0
- data/src/bench/dummy.py +13 -0
- data/src/bench/dummy.rb +0 -0
- data/src/lib/narray_ext.rb +36 -2
- data/src/mkmath.rb +4 -4
- data/src/mkop.rb +16 -16
- data/src/na_array.c +32 -32
- data/src/na_func.c +50 -50
- data/src/na_index.c +26 -32
- data/src/na_linalg.c +23 -26
- data/src/na_random.c +15 -18
- data/src/narray.c +22 -32
- data/src/narray.h +3 -3
- data/src/narray_local.h +1 -1
- metadata +10 -39
- data/src/nimage/README.en +0 -38
- data/src/nimage/demo/fits.rb +0 -97
- data/src/nimage/demo/fits_convol.rb +0 -28
- data/src/nimage/demo/fits_fftdemo.rb +0 -27
- data/src/nimage/demo/fitsdemo1.rb +0 -13
- data/src/nimage/demo/fitsdemo2.rb +0 -30
- data/src/nimage/demo/fitsdemo3.rb +0 -26
- data/src/nimage/demo/fitsmorph.rb +0 -39
- data/src/nimage/demo/life_na.rb +0 -57
- data/src/nimage/demo/mandel.rb +0 -41
- data/src/nimage/extconf.rb +0 -12
- data/src/nimage/lib/nimage.rb +0 -51
- data/src/nimage/nimage.c +0 -328
- data/src/speed/add.py +0 -12
- data/src/speed/add.rb +0 -8
- data/src/speed/add_int.py +0 -12
- data/src/speed/add_int.rb +0 -9
- data/src/speed/lu.m +0 -14
- data/src/speed/lu.rb +0 -22
- data/src/speed/mat.m +0 -23
- data/src/speed/mat.rb +0 -28
- data/src/speed/mul.py +0 -12
- data/src/speed/mul.rb +0 -9
- data/src/speed/mul2.py +0 -15
- data/src/speed/mul2.rb +0 -13
- data/src/speed/mul_comp.py +0 -12
- data/src/speed/mul_comp.rb +0 -9
- data/src/speed/mul_int.py +0 -12
- data/src/speed/mul_int.rb +0 -9
- data/src/speed/mybench.py +0 -15
- data/src/speed/mybench.rb +0 -31
- data/src/speed/solve.m +0 -18
- data/src/speed/solve.py +0 -16
- data/src/speed/solve.rb +0 -21
data/src/na_linalg.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* na_linalg.c
|
3
3
|
* Numerical Array Extention for Ruby
|
4
|
-
* (C) Copyright 2000-
|
4
|
+
* (C) Copyright 2000-2008 by Masahiro TANAKA
|
5
5
|
*/
|
6
6
|
#include <ruby.h>
|
7
7
|
#include "narray.h"
|
@@ -70,7 +70,7 @@ na_loop_linalg( int nd, char *p1, char *p2, char *p3,
|
|
70
70
|
for(;;) {
|
71
71
|
/* set pointers */
|
72
72
|
while (i > 0) {
|
73
|
-
i
|
73
|
+
--i;
|
74
74
|
s3[i].p = s3[i].pbeg + s3[i+1].p;
|
75
75
|
s2[i].p = s2[i].pbeg + s2[i+1].p;
|
76
76
|
s1[i].p = s1[i].pbeg + s1[i+1].p;
|
@@ -94,7 +94,7 @@ na_shape_total( int n, int *shape )
|
|
94
94
|
{
|
95
95
|
int total=1;
|
96
96
|
|
97
|
-
for (; n>0; n
|
97
|
+
for (; n>0; --n)
|
98
98
|
total *= *(shape++);
|
99
99
|
|
100
100
|
return total;
|
@@ -173,12 +173,12 @@ na_lu_fact_func_body(int ni, char *a, char *idx, int *shape, int type, char *buf
|
|
173
173
|
vi = v;
|
174
174
|
|
175
175
|
/* v[j] = 1/max( abs( a[i,j] ) ) */
|
176
|
-
for (j=0;j<n
|
176
|
+
for (j=0;j<n;++j) {
|
177
177
|
f->abs(n, buf, relmsz, aa, felmsz);
|
178
178
|
|
179
179
|
r->set(1, amax,0, r->zero,0);
|
180
180
|
rtmp = buf;
|
181
|
-
for (i=0;i<n
|
181
|
+
for (i=0;i<n;++i) {
|
182
182
|
if (r->sort(rtmp, amax) == 1)
|
183
183
|
r->set(1, amax,0, rtmp,0);
|
184
184
|
rtmp += relmsz;
|
@@ -194,20 +194,20 @@ na_lu_fact_func_body(int ni, char *a, char *idx, int *shape, int type, char *buf
|
|
194
194
|
ai0 = a0i = aii = a;
|
195
195
|
vi = v;
|
196
196
|
|
197
|
-
for (i=0;i<n
|
197
|
+
for (i=0;i<n;++i) {
|
198
198
|
|
199
199
|
f->set(n, buf, felmsz, ai0, rowsz);
|
200
200
|
|
201
201
|
aij = buf;
|
202
202
|
a0j = a;
|
203
203
|
/* a[i,j(<i)] -= sum(k<j){ a[i,k]*a[k,j] } */
|
204
|
-
for (j=1;j<i
|
204
|
+
for (j=1;j<i;++j) {
|
205
205
|
aij += felmsz;
|
206
206
|
a0j += rowsz;
|
207
207
|
f->mulsbt(j, aij, 0, buf, felmsz, a0j, felmsz);
|
208
208
|
}
|
209
209
|
/* a[i,j(>=i)] -= sum(k<i){ a[i,k]*a[k,j] } */
|
210
|
-
for ( ;j<n
|
210
|
+
for ( ;j<n;++j) {
|
211
211
|
aij += felmsz;
|
212
212
|
a0j += rowsz;
|
213
213
|
f->mulsbt(i, aij, 0, buf, felmsz, a0j, felmsz);
|
@@ -222,7 +222,7 @@ na_lu_fact_func_body(int ni, char *a, char *idx, int *shape, int type, char *buf
|
|
222
222
|
r->set(1, amax,0, r->zero,0);
|
223
223
|
rtmp = buf;
|
224
224
|
imax = 0;
|
225
|
-
for (j=i;j<n
|
225
|
+
for (j=i;j<n;++j) {
|
226
226
|
if (r->sort(rtmp,amax) == 1) {
|
227
227
|
r->set(1, amax,0, rtmp,0);
|
228
228
|
imax = j;
|
@@ -272,7 +272,6 @@ static int
|
|
272
272
|
RARRAY(val)->len = size;
|
273
273
|
buf = (char*)((RARRAY(val))->ptr);
|
274
274
|
status = na_lu_fact_func_body( ni, a, idx, shape, type, buf );
|
275
|
-
//na_touch_object(val);
|
276
275
|
} else {
|
277
276
|
size = na_sizeof[type]*n + na_sizeof[na_cast_real[type]]*(n+1);
|
278
277
|
buf = ALLOC_N(char, size);
|
@@ -303,7 +302,7 @@ static VALUE
|
|
303
302
|
rb_raise(rb_eTypeError,"not square matrix");
|
304
303
|
|
305
304
|
total=1;
|
306
|
-
for (i=2; i<ary->rank; i
|
305
|
+
for (i=2; i<ary->rank; ++i)
|
307
306
|
total *= ary->shape[i];
|
308
307
|
|
309
308
|
piv = na_make_object(NA_LINT, ary->rank-1, ary->shape+1, cNVector);
|
@@ -312,7 +311,7 @@ static VALUE
|
|
312
311
|
func = IndGenFuncs[NA_LINT];
|
313
312
|
sz = na_sizeof[NA_LINT];
|
314
313
|
ptr = idx = ((struct NARRAY *)DATA_PTR(piv))->ptr;
|
315
|
-
for (i=0; i<total; i
|
314
|
+
for (i=0; i<total; ++i) {
|
316
315
|
func(n,ptr,sz,0,1);
|
317
316
|
ptr += n*sz;
|
318
317
|
}
|
@@ -345,9 +344,9 @@ na_lu_pivot_func( int ni,
|
|
345
344
|
n = shape[1];
|
346
345
|
sz = f->elmsz * shape[0];
|
347
346
|
|
348
|
-
for (; ni>0; ni
|
347
|
+
for (; ni>0; --ni) {
|
349
348
|
xi = x;
|
350
|
-
for (i=0; i<n; i
|
349
|
+
for (i=0; i<n; ++i) {
|
351
350
|
memcpy(xi, y+((int32_t*)idx)[i]*sz, sz);
|
352
351
|
xi += sz;
|
353
352
|
}
|
@@ -374,11 +373,11 @@ na_lu_solve_func_body( int ni,
|
|
374
373
|
int matsz = rowsz * n;
|
375
374
|
int diagsz = rowsz + sz;
|
376
375
|
|
377
|
-
for (; ni>0; ni
|
376
|
+
for (; ni>0; --ni) {
|
378
377
|
|
379
378
|
xx = x;
|
380
379
|
|
381
|
-
for (k=shape[0]; k>0; k
|
380
|
+
for (k=shape[0]; k>0; --k) { /* once if x is vector */
|
382
381
|
|
383
382
|
f->set(n, buf,sz, xx,xsz);
|
384
383
|
|
@@ -386,7 +385,7 @@ na_lu_solve_func_body( int ni,
|
|
386
385
|
a0i = a;
|
387
386
|
|
388
387
|
/* solve Lx' = y' */
|
389
|
-
for (i=1; i<n; i
|
388
|
+
for (i=1; i<n; ++i) {
|
390
389
|
/* x[i] -= a[j(<i),i] * x[j(<i)] */
|
391
390
|
xi += sz;
|
392
391
|
a0i += rowsz;
|
@@ -398,7 +397,7 @@ na_lu_solve_func_body( int ni,
|
|
398
397
|
|
399
398
|
/* solve Ux = x' */
|
400
399
|
f->div(1, xi,0, aii,0);
|
401
|
-
for (i=n-1; i>0; i
|
400
|
+
for (i=n-1; i>0; --i) {
|
402
401
|
xi -= sz;
|
403
402
|
aii -= diagsz;
|
404
403
|
/* x[i] -= a[j(>i),i] * x[j(>i)] */
|
@@ -434,7 +433,6 @@ na_lu_solve_func( int ni,
|
|
434
433
|
RARRAY(val)->len = size;
|
435
434
|
buf = (char*)((RARRAY(val))->ptr);
|
436
435
|
na_lu_solve_func_body( ni, x, ps1, a, ps2, shape, type, buf );
|
437
|
-
//na_touch_object(val);
|
438
436
|
} else {
|
439
437
|
size = shape[1] * na_sizeof[type];
|
440
438
|
buf = ALLOC_N(char, size);
|
@@ -454,13 +452,13 @@ na_shape_max2(int ndim, int *shape, int n1, int *shape1, int n2, int *shape2)
|
|
454
452
|
NA_SWAP(shape1,shape2,tmp);
|
455
453
|
}
|
456
454
|
|
457
|
-
for (i=0; i<n2; i
|
455
|
+
for (i=0; i<n2; ++i) {
|
458
456
|
shape[i] = NA_MAX(shape1[i],shape2[i]);
|
459
457
|
}
|
460
|
-
for ( ; i<n1; i
|
458
|
+
for ( ; i<n1; ++i) {
|
461
459
|
shape[i] = shape1[i];
|
462
460
|
}
|
463
|
-
for ( ; i<ndim; i
|
461
|
+
for ( ; i<ndim; ++i) {
|
464
462
|
shape[i] = 1;
|
465
463
|
}
|
466
464
|
}
|
@@ -515,9 +513,8 @@ na_lu_solve(VALUE self, volatile VALUE other)
|
|
515
513
|
memcpy(shape,a2->shape+1,sizeof(int)*(ndim-1));
|
516
514
|
xfree(a2->shape);
|
517
515
|
a2->shape = shape;
|
518
|
-
a2->rank
|
516
|
+
--(a2->rank);
|
519
517
|
}
|
520
|
-
//na_touch_object(other,lu);
|
521
518
|
return obj;
|
522
519
|
}
|
523
520
|
|
@@ -547,7 +544,7 @@ na_lu_init(VALUE self, VALUE lu, VALUE piv)
|
|
547
544
|
rb_raise(rb_eRuntimeError,"LU matrix (%i,%i) is not square",
|
548
545
|
l->shape[0], l->shape[1]);
|
549
546
|
|
550
|
-
for (i=1; i<l->rank; i
|
547
|
+
for (i=1; i<l->rank; ++i)
|
551
548
|
if (l->shape[i] != p->shape[i-1])
|
552
549
|
rb_raise(rb_eRuntimeError,"array size mismatch %i!=%i at %i",
|
553
550
|
l->shape[i], p->shape[i-1], i);
|
@@ -569,7 +566,7 @@ void Init_na_linalg()
|
|
569
566
|
static VALUE onev = INT2FIX(1);
|
570
567
|
char *a = malloc(NA_NTYPES*sizeof(dcomplex)*2);
|
571
568
|
|
572
|
-
for (i=1;i<NA_NTYPES
|
569
|
+
for (i=1;i<NA_NTYPES;++i) {
|
573
570
|
sz = na_funcset[i].elmsz = na_sizeof[i];
|
574
571
|
sz = (sz>sizeof(int)) ? sz : sizeof(int);
|
575
572
|
SetFuncs[i][NA_LINT](1, a,0, &one, 0);
|
data/src/na_random.c
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
/*
|
2
2
|
na_random.c
|
3
3
|
Numerical Array Extention for Ruby
|
4
|
-
(C) Copyright 2003 by Masahiro TANAKA
|
4
|
+
(C) Copyright 2003-2008 by Masahiro TANAKA
|
5
5
|
|
6
6
|
This program is free software.
|
7
7
|
You can distribute/modify this program
|
8
8
|
under the same terms as Ruby itself.
|
9
9
|
NO WARRANTY.
|
10
|
-
|
11
|
-
This is based on ruby/random.c
|
12
|
-
Copyright (C) 1993-2003 Yukihiro Matsumoto
|
13
10
|
*/
|
14
11
|
|
15
12
|
/*
|
@@ -85,7 +82,7 @@ static void
|
|
85
82
|
{
|
86
83
|
int j;
|
87
84
|
state[0]= s & 0xffffffffUL;
|
88
|
-
for (j=1; j<N; j
|
85
|
+
for (j=1; j<N; ++j) {
|
89
86
|
state[j] = (1812433253UL * (state[j-1] ^ (state[j-1] >> 30)) + j);
|
90
87
|
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
91
88
|
/* In the previous versions, MSBs of the seed affect */
|
@@ -109,10 +106,10 @@ static void
|
|
109
106
|
left = N;
|
110
107
|
next = state;
|
111
108
|
|
112
|
-
for (j=N-M+1; --j; p
|
109
|
+
for (j=N-M+1; --j; ++p)
|
113
110
|
*p = p[M] ^ TWIST(p[0], p[1]);
|
114
111
|
|
115
|
-
for (j=M; --j; p
|
112
|
+
for (j=M; --j; ++p)
|
116
113
|
*p = p[M-N] ^ TWIST(p[0], p[1]);
|
117
114
|
|
118
115
|
*p = p[M-N] ^ TWIST(p[0], state[0]);
|
@@ -204,7 +201,7 @@ static int n_bits(int32_t a)
|
|
204
201
|
xu = 1<<(n+1);
|
205
202
|
xl = 0;
|
206
203
|
|
207
|
-
for (i=n; i>=0; i
|
204
|
+
for (i=n; i>=0; --i) {
|
208
205
|
m = ~((1<<(x-1))-1);
|
209
206
|
|
210
207
|
if (m & a) {
|
@@ -252,12 +249,12 @@ static void RndB(int n, char *p1, int i1, double rmax)
|
|
252
249
|
shift = 32 - n_bits(max);
|
253
250
|
|
254
251
|
if (max<1) {
|
255
|
-
for (; n; n
|
252
|
+
for (; n; --n) {
|
256
253
|
*(u_int8_t*)p1 = 0;
|
257
254
|
p1+=i1;
|
258
255
|
}
|
259
256
|
} else {
|
260
|
-
for (; n; n
|
257
|
+
for (; n; --n) {
|
261
258
|
do {
|
262
259
|
genrand(y);
|
263
260
|
y >>= shift;
|
@@ -279,12 +276,12 @@ static void RndI(int n, char *p1, int i1, double rmax)
|
|
279
276
|
shift = 32 - n_bits(max);
|
280
277
|
|
281
278
|
if (max<1) {
|
282
|
-
for (; n; n
|
279
|
+
for (; n; --n) {
|
283
280
|
*(int16_t*)p1 = 0;
|
284
281
|
p1+=i1;
|
285
282
|
}
|
286
283
|
} else {
|
287
|
-
for (; n; n
|
284
|
+
for (; n; --n) {
|
288
285
|
do {
|
289
286
|
genrand(y);
|
290
287
|
y >>= shift;
|
@@ -306,12 +303,12 @@ static void RndL(int n, char *p1, int i1, double rmax)
|
|
306
303
|
shift = 32 - n_bits(max);
|
307
304
|
|
308
305
|
if (max<1) {
|
309
|
-
for (; n; n
|
306
|
+
for (; n; --n) {
|
310
307
|
*(int32_t*)p1 = 0;
|
311
308
|
p1+=i1;
|
312
309
|
}
|
313
310
|
} else {
|
314
|
-
for (; n; n
|
311
|
+
for (; n; --n) {
|
315
312
|
do {
|
316
313
|
genrand(y);
|
317
314
|
y >>= shift;
|
@@ -326,7 +323,7 @@ static void RndF(int n, char *p1, int i1, double rmax)
|
|
326
323
|
{
|
327
324
|
u_int32_t y;
|
328
325
|
|
329
|
-
for (; n; n
|
326
|
+
for (; n; --n) {
|
330
327
|
genrand(y);
|
331
328
|
*(float*)p1 = rand_single(y) * rmax;
|
332
329
|
p1+=i1;
|
@@ -337,7 +334,7 @@ static void RndD(int n, char *p1, int i1, double rmax)
|
|
337
334
|
{
|
338
335
|
u_int32_t x,y;
|
339
336
|
|
340
|
-
for (; n; n
|
337
|
+
for (; n; --n) {
|
341
338
|
genrand(x);
|
342
339
|
genrand(y);
|
343
340
|
*(double*)p1 = rand_double(x,y) * rmax;
|
@@ -349,7 +346,7 @@ static void RndX(int n, char *p1, int i1, double rmax)
|
|
349
346
|
{
|
350
347
|
u_int32_t y;
|
351
348
|
|
352
|
-
for (; n; n
|
349
|
+
for (; n; --n) {
|
353
350
|
genrand(y);
|
354
351
|
((scomplex*)p1)->r = rand_single(y) * rmax;
|
355
352
|
((scomplex*)p1)->i = 0;
|
@@ -361,7 +358,7 @@ static void RndC(int n, char *p1, int i1, double rmax)
|
|
361
358
|
{
|
362
359
|
u_int32_t x,y;
|
363
360
|
|
364
|
-
for (; n; n
|
361
|
+
for (; n; --n) {
|
365
362
|
genrand(x);
|
366
363
|
genrand(y);
|
367
364
|
((dcomplex*)p1)->r = rand_double(x,y) * rmax;
|
data/src/narray.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
narray.c
|
3
3
|
Numerical Array Extention for Ruby
|
4
|
-
(C) Copyright 1999-
|
4
|
+
(C) Copyright 1999-2008 by Masahiro TANAKA
|
5
5
|
|
6
6
|
This program is free software.
|
7
7
|
You can distribute/modify this program
|
@@ -79,7 +79,7 @@ static void
|
|
79
79
|
VALUE *ptr;
|
80
80
|
|
81
81
|
ptr = (VALUE*) ary->ptr;
|
82
|
-
for (i=ary->total; i>0; i
|
82
|
+
for (i=ary->total; i>0; --i)
|
83
83
|
rb_gc_mark(*ptr++);
|
84
84
|
}
|
85
85
|
|
@@ -120,7 +120,7 @@ struct NARRAY*
|
|
120
120
|
int i, memsz;
|
121
121
|
struct NARRAY *ary;
|
122
122
|
|
123
|
-
for (i=0; i<rank; i
|
123
|
+
for (i=0; i<rank; ++i)
|
124
124
|
total *= shape[i];
|
125
125
|
|
126
126
|
if (rank<=0 || total<=0) {
|
@@ -148,7 +148,7 @@ struct NARRAY*
|
|
148
148
|
ary->rank = rank;
|
149
149
|
ary->total = total;
|
150
150
|
ary->type = type;
|
151
|
-
for (i=0; i<rank; i
|
151
|
+
for (i=0; i<rank; ++i)
|
152
152
|
ary->shape[i] = shape[i];
|
153
153
|
}
|
154
154
|
ary->ref = Qtrue;
|
@@ -278,7 +278,7 @@ struct NARRAY*
|
|
278
278
|
ary->rank = orig->rank;
|
279
279
|
ary->total = orig->total;
|
280
280
|
ary->type = orig->type;
|
281
|
-
for (i=0; i<orig->rank; i
|
281
|
+
for (i=0; i<orig->rank; ++i)
|
282
282
|
ary->shape[i] = orig->shape[i];
|
283
283
|
ary->ref = obj;
|
284
284
|
|
@@ -310,14 +310,6 @@ static VALUE
|
|
310
310
|
}
|
311
311
|
|
312
312
|
|
313
|
-
/*
|
314
|
-
void
|
315
|
-
na_touch_object(VALUE val, ...)
|
316
|
-
{
|
317
|
-
return;
|
318
|
-
}
|
319
|
-
*/
|
320
|
-
|
321
313
|
void
|
322
314
|
na_clear_data(struct NARRAY *ary)
|
323
315
|
{
|
@@ -340,7 +332,7 @@ static VALUE
|
|
340
332
|
rb_raise(rb_eArgError, "Argument required");
|
341
333
|
|
342
334
|
shape = ALLOCA_N(int,argc);
|
343
|
-
for (i=0; i<argc; i
|
335
|
+
for (i=0; i<argc; ++i) shape[i]=NUM2INT(argv[i]);
|
344
336
|
|
345
337
|
v = na_make_object(type,argc,shape,klass);
|
346
338
|
GetNArray(v,ary);
|
@@ -375,7 +367,7 @@ int
|
|
375
367
|
return na->type;
|
376
368
|
}
|
377
369
|
if (TYPE(v)==T_STRING) {
|
378
|
-
for (i=1; i<NA_NTYPES; i
|
370
|
+
for (i=1; i<NA_NTYPES; ++i) {
|
379
371
|
if ( !strncmp( RSTRING_PTR(v), na_typestring[i], RSTRING_LEN(v)) )
|
380
372
|
return i;
|
381
373
|
}
|
@@ -530,7 +522,7 @@ static VALUE
|
|
530
522
|
|
531
523
|
GetNArray(self,ary);
|
532
524
|
shape = ALLOCA_N(VALUE,ary->rank);
|
533
|
-
for (i = 0; i < ary->rank; i
|
525
|
+
for (i = 0; i < ary->rank; ++i)
|
534
526
|
shape[i] = INT2FIX(ary->shape[i]);
|
535
527
|
return rb_ary_new4(ary->rank,shape);
|
536
528
|
}
|
@@ -611,7 +603,7 @@ static VALUE
|
|
611
603
|
}
|
612
604
|
else {
|
613
605
|
shape = ALLOCA_N(int,rank);
|
614
|
-
for (i=0; i<rank; i
|
606
|
+
for (i=0; i<rank; ++i)
|
615
607
|
len *= shape[i] = NUM2INT(argv[i+1]);
|
616
608
|
len *= na_sizeof[type];
|
617
609
|
if ( len != str_len )
|
@@ -651,7 +643,7 @@ static VALUE
|
|
651
643
|
rank = a1->rank+1;
|
652
644
|
shape = ALLOCA_N(int,rank);
|
653
645
|
shape[0] = na_sizeof[a1->type];
|
654
|
-
for (i=1; i<rank; i
|
646
|
+
for (i=1; i<rank; ++i)
|
655
647
|
shape[i] = a1->shape[i-1];
|
656
648
|
|
657
649
|
v = na_make_object( NA_BYTE, rank, shape, cNArray );
|
@@ -689,7 +681,7 @@ static VALUE
|
|
689
681
|
static void
|
690
682
|
na_to_string_binary(int n, char *p1, int i1, char *p2, int i2)
|
691
683
|
{
|
692
|
-
for (; n>0; n
|
684
|
+
for (; n>0; --n) {
|
693
685
|
*(VALUE*)p1 = rb_str_new(p2,i2);
|
694
686
|
p1+=i1; p2+=i2;
|
695
687
|
}
|
@@ -799,7 +791,7 @@ static VALUE
|
|
799
791
|
sprintf(buf, (ary->ref==Qnil) ? org:ref,
|
800
792
|
classname, na_typestring[ary->type], ary->shape[0]);
|
801
793
|
rb_str_cat(str,buf,strlen(buf));
|
802
|
-
for (i=1; i<ary->rank; i
|
794
|
+
for (i=1; i<ary->rank; ++i) {
|
803
795
|
sprintf(buf,",%i",ary->shape[i]);
|
804
796
|
rb_str_cat(str,buf,strlen(buf));
|
805
797
|
}
|
@@ -827,8 +819,8 @@ static void
|
|
827
819
|
|
828
820
|
if (argc == 0) { /* trim ranks of size=1 */
|
829
821
|
shape = ALLOCA_N(int,ary->rank+1);
|
830
|
-
for (i=0; i<class_dim; i
|
831
|
-
for ( ; i<ary->rank; i
|
822
|
+
for (i=0; i<class_dim; ++i) shape[i]=0;
|
823
|
+
for ( ; i<ary->rank; ++i) shape[i]=1;
|
832
824
|
na_shrink_rank( self, class_dim, shape );
|
833
825
|
if (ary->rank==0) ary->rank=1;
|
834
826
|
return;
|
@@ -836,7 +828,7 @@ static void
|
|
836
828
|
|
837
829
|
/* get shape from argument */
|
838
830
|
shape = ALLOC_N(int,argc);
|
839
|
-
for (i=0; i<argc; i
|
831
|
+
for (i=0; i<argc; ++i)
|
840
832
|
switch(TYPE(argv[i])) {
|
841
833
|
case T_FIXNUM:
|
842
834
|
total *= shape[i] = NUM2INT(argv[i]);
|
@@ -927,19 +919,19 @@ static void
|
|
927
919
|
|
928
920
|
/* count new rank */
|
929
921
|
count = ALLOCA_N(int,ary->rank+1);
|
930
|
-
for (i=0; i<=ary->rank; i
|
922
|
+
for (i=0; i<=ary->rank; ++i)
|
931
923
|
count[i]=0;
|
932
|
-
for (i=0; i<argc; i
|
924
|
+
for (i=0; i<argc; ++i) {
|
933
925
|
j = NUM2INT(argv[i]);
|
934
926
|
if (j<0) /* negative rank : -1=>append after last rank */
|
935
927
|
j += ary->rank+1;
|
936
928
|
if (j<0 || j>ary->rank) /* range check */
|
937
929
|
rb_raise(rb_eArgError, "rank out of range");
|
938
|
-
count[j]
|
930
|
+
++count[j];
|
939
931
|
}
|
940
932
|
/* extend shape shape */
|
941
933
|
shape = ALLOC_N(int,ary->rank+argc);
|
942
|
-
for (j=i=0; i<ary->rank; i
|
934
|
+
for (j=i=0; i<ary->rank; ++i) {
|
943
935
|
while (count[i]-->0) shape[j++] = 1;
|
944
936
|
shape[j++] = ary->shape[i];
|
945
937
|
}
|
@@ -992,7 +984,6 @@ VALUE na_fill(VALUE self, volatile VALUE val)
|
|
992
984
|
SetFuncs[a1->type][a2->type]( a1->total,
|
993
985
|
a1->ptr, na_sizeof[a1->type],
|
994
986
|
a2->ptr, 0 );
|
995
|
-
//na_touch_object(val);
|
996
987
|
return self;
|
997
988
|
}
|
998
989
|
|
@@ -1039,8 +1030,8 @@ static VALUE
|
|
1039
1030
|
/* Count true */
|
1040
1031
|
c = ary->ptr;
|
1041
1032
|
n1 = 0;
|
1042
|
-
for (i=0; i<n; i
|
1043
|
-
if (*(c++)) n1
|
1033
|
+
for (i=0; i<n; ++i)
|
1034
|
+
if (*(c++)) ++n1;
|
1044
1035
|
|
1045
1036
|
n0 = n-n1;
|
1046
1037
|
|
@@ -1054,14 +1045,13 @@ static VALUE
|
|
1054
1045
|
|
1055
1046
|
/* Get Indices */
|
1056
1047
|
c = ary->ptr;
|
1057
|
-
for ( i=0; i<n; i
|
1048
|
+
for ( i=0; i<n; ++i ) {
|
1058
1049
|
if (*(c++))
|
1059
1050
|
*(idx1++) = i;
|
1060
1051
|
else
|
1061
1052
|
*(idx0++) = i;
|
1062
1053
|
}
|
1063
1054
|
|
1064
|
-
//na_touch_object(obj);
|
1065
1055
|
return rb_assoc_new( v1, v0 );
|
1066
1056
|
}
|
1067
1057
|
|