numo-narray 0.9.0.3 → 0.9.0.4
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.
- checksums.yaml +4 -4
- data/README.md +12 -6
- data/Rakefile +2 -10
- data/ext/numo/narray/array.c +1 -6
- data/ext/numo/narray/data.c +3 -9
- data/ext/numo/narray/depend.erb +1 -1
- data/ext/numo/narray/extconf.rb +0 -1
- data/ext/numo/narray/gen/def/bit.rb +2 -0
- data/ext/numo/narray/gen/def/dcomplex.rb +2 -0
- data/ext/numo/narray/gen/def/dfloat.rb +2 -0
- data/ext/numo/narray/gen/def/int16.rb +2 -0
- data/ext/numo/narray/gen/def/int32.rb +2 -0
- data/ext/numo/narray/gen/def/int64.rb +2 -0
- data/ext/numo/narray/gen/def/int8.rb +2 -0
- data/ext/numo/narray/gen/def/robject.rb +2 -0
- data/ext/numo/narray/gen/def/scomplex.rb +2 -0
- data/ext/numo/narray/gen/def/sfloat.rb +2 -0
- data/ext/numo/narray/gen/def/uint16.rb +2 -0
- data/ext/numo/narray/gen/def/uint32.rb +2 -0
- data/ext/numo/narray/gen/def/uint64.rb +2 -0
- data/ext/numo/narray/gen/def/uint8.rb +2 -0
- data/ext/numo/narray/gen/dtype.erb.c +7 -7
- data/ext/numo/narray/gen/spec.rb +24 -2
- data/ext/numo/narray/gen/tmpl/accum_binary.c +6 -0
- data/ext/numo/narray/gen/tmpl/aref.c +6 -4
- data/ext/numo/narray/gen/tmpl/aset.c +6 -4
- data/ext/numo/narray/gen/tmpl/binary.c +4 -0
- data/ext/numo/narray/gen/tmpl/binary2.c +4 -0
- data/ext/numo/narray/gen/tmpl/bincount.c +180 -0
- data/ext/numo/narray/gen/tmpl/cast.c +4 -0
- data/ext/numo/narray/gen/tmpl/cast_array.c +3 -64
- data/ext/numo/narray/gen/tmpl/cond_binary.c +4 -0
- data/ext/numo/narray/gen/tmpl/inspect.c +4 -0
- data/ext/numo/narray/gen/tmpl/pow.c +4 -0
- data/ext/numo/narray/gen/tmpl/qsort.c +1 -7
- data/ext/numo/narray/gen/tmpl/rand.c +13 -2
- data/ext/numo/narray/gen/tmpl/rand_norm.c +89 -16
- data/ext/numo/narray/gen/tmpl/store.c +4 -0
- data/ext/numo/narray/gen/tmpl/store_array.c +99 -2
- data/ext/numo/narray/gen/tmpl_bit/allocate.c +1 -1
- data/ext/numo/narray/gen/tmpl_bit/aref.c +6 -4
- data/ext/numo/narray/gen/tmpl_bit/aset.c +6 -4
- data/ext/numo/narray/gen/tmpl_bit/cast_array.c +3 -65
- data/ext/numo/narray/gen/tmpl_bit/mask.c +16 -1
- data/ext/numo/narray/gen/tmpl_bit/store_array.c +101 -2
- data/ext/numo/narray/gen/tmpl_bit/where.c +7 -23
- data/ext/numo/narray/gen/tmpl_bit/where2.c +58 -4
- data/ext/numo/narray/index.c +168 -166
- data/ext/numo/narray/kwarg.c +1 -6
- data/ext/numo/narray/math.c +8 -12
- data/ext/numo/narray/narray.c +231 -71
- data/ext/numo/narray/ndloop.c +86 -26
- data/ext/numo/narray/numo/intern.h +6 -10
- data/ext/numo/narray/numo/narray.h +83 -54
- data/ext/numo/narray/numo/ndloop.h +0 -5
- data/ext/numo/narray/numo/template.h +0 -5
- data/ext/numo/narray/numo/types/complex.h +1 -6
- data/ext/numo/narray/numo/types/complex_macro.h +30 -3
- data/ext/numo/narray/numo/types/dcomplex.h +18 -0
- data/ext/numo/narray/numo/types/dfloat.h +18 -0
- data/ext/numo/narray/numo/types/float_macro.h +25 -2
- data/ext/numo/narray/numo/types/robj_macro.h +2 -4
- data/ext/numo/narray/numo/types/scomplex.h +18 -0
- data/ext/numo/narray/numo/types/sfloat.h +18 -0
- data/ext/numo/narray/rand.c +0 -15
- data/ext/numo/narray/step.c +0 -5
- data/ext/numo/narray/struct.c +7 -12
- data/lib/erbpp/line_number.rb +4 -4
- data/lib/erbpp/narray_def.rb +16 -7
- data/lib/numo/narray.rb +2 -0
- data/lib/numo/narray/extra.rb +465 -0
- data/numo-narray.gemspec +2 -2
- data/spec/narray_spec.rb +4 -3
- metadata +13 -7
- data/ext/numo/narray/gen/tmpl/head.c +0 -25
data/ext/numo/narray/ndloop.c
CHANGED
@@ -2,11 +2,6 @@
|
|
2
2
|
ndloop.c
|
3
3
|
Numerical Array Extension for Ruby
|
4
4
|
(C) Copyright 1999-2016 by Masahiro TANAKA
|
5
|
-
|
6
|
-
This program is free software.
|
7
|
-
You can distribute/modify this program
|
8
|
-
under the same terms as Ruby itself.
|
9
|
-
NO WARRANTY.
|
10
5
|
*/
|
11
6
|
|
12
7
|
#include <ruby.h>
|
@@ -514,7 +509,7 @@ ndloop_check_shape(na_md_loop_t *lp, int nf_dim, narray_t *na)
|
|
514
509
|
lp->n[i] = n;
|
515
510
|
} else if (lp->n[i] != n) {
|
516
511
|
// inconsistent array shape
|
517
|
-
rb_raise(
|
512
|
+
rb_raise(nary_eShapeError,"shape1[%d](=%"SZF"u) != shape2[%d](=%"SZF"u)",
|
518
513
|
i, lp->n[i], k, n);
|
519
514
|
}
|
520
515
|
}
|
@@ -1616,7 +1611,7 @@ loop_inspect(ndfunc_t *nf, na_md_loop_t *lp)
|
|
1616
1611
|
}
|
1617
1612
|
}
|
1618
1613
|
}
|
1619
|
-
|
1614
|
+
loop_end:
|
1620
1615
|
;
|
1621
1616
|
}
|
1622
1617
|
|
@@ -1657,7 +1652,63 @@ na_ndloop_inspect(VALUE nary, na_text_func_t func, VALUE opt)
|
|
1657
1652
|
//----------------------------------------------------------------------
|
1658
1653
|
|
1659
1654
|
static void
|
1660
|
-
|
1655
|
+
loop_store_subnarray(ndfunc_t *nf, na_md_loop_t *lp, int i0, size_t *c, VALUE a)
|
1656
|
+
{
|
1657
|
+
int nd = lp->ndim;
|
1658
|
+
int i, j;
|
1659
|
+
narray_t *na;
|
1660
|
+
int *dim_map;
|
1661
|
+
VALUE a_type;
|
1662
|
+
|
1663
|
+
a_type = CLASS_OF(LARG(lp,0).value);
|
1664
|
+
if (CLASS_OF(a) != a_type) {
|
1665
|
+
a = rb_funcall(a_type, rb_intern("cast"), 1, a);
|
1666
|
+
}
|
1667
|
+
GetNArray(a,na);
|
1668
|
+
if (na->ndim != nd-i0+1) {
|
1669
|
+
rb_raise(nary_eShapeError, "mismatched dimension of sub-narray: "
|
1670
|
+
"nd_src=%d, nd_dst=%d", na->ndim, nd-i0+1);
|
1671
|
+
}
|
1672
|
+
dim_map = ALLOCA_N(int, na->ndim);
|
1673
|
+
for (i=0; i<na->ndim; i++) {
|
1674
|
+
dim_map[i] = lp->trans_map[i+i0];
|
1675
|
+
//printf("dim_map[i=%d] = %d, i0=%d\n", i, dim_map[i], i0);
|
1676
|
+
}
|
1677
|
+
ndloop_set_stepidx(lp, 1, a, dim_map, NDL_READ);
|
1678
|
+
LARG(lp,1).shape = &(na->shape[na->ndim-1]);
|
1679
|
+
|
1680
|
+
// loop body
|
1681
|
+
for (i=i0;;) {
|
1682
|
+
LARG(lp,1).value = Qtrue;
|
1683
|
+
for (; i<nd; i++) {
|
1684
|
+
for (j=0; j<2; j++) {
|
1685
|
+
if (LITER(lp,i,j).idx) {
|
1686
|
+
LITER(lp,i+1,j).pos = LITER(lp,i,j).pos + LITER(lp,i,j).idx[c[i]];
|
1687
|
+
} else {
|
1688
|
+
LITER(lp,i+1,j).pos = LITER(lp,i,j).pos + LITER(lp,i,j).step*c[i];
|
1689
|
+
}
|
1690
|
+
}
|
1691
|
+
if (c[i] >= na->shape[i-i0]) {
|
1692
|
+
LARG(lp,1).value = Qfalse;
|
1693
|
+
}
|
1694
|
+
}
|
1695
|
+
|
1696
|
+
(*(nf->func))(&(lp->user));
|
1697
|
+
|
1698
|
+
for (;;) {
|
1699
|
+
if (i<=i0) goto loop_end;
|
1700
|
+
i--; c[i]++;
|
1701
|
+
if (c[i] < lp->n[i]) break;
|
1702
|
+
c[i] = 0;
|
1703
|
+
}
|
1704
|
+
}
|
1705
|
+
loop_end:
|
1706
|
+
LARG(lp,1).ptr = NULL;
|
1707
|
+
}
|
1708
|
+
|
1709
|
+
|
1710
|
+
static void
|
1711
|
+
loop_store_rarray(ndfunc_t *nf, na_md_loop_t *lp)
|
1661
1712
|
{
|
1662
1713
|
size_t *c;
|
1663
1714
|
int i;
|
@@ -1670,38 +1721,47 @@ loop_rarray_to_narray(ndfunc_t *nf, na_md_loop_t *lp)
|
|
1670
1721
|
|
1671
1722
|
// array at each dimension
|
1672
1723
|
a = ALLOCA_N(VALUE, nd+1);
|
1673
|
-
a[0] = LARG(lp,
|
1724
|
+
a[0] = LARG(lp,1).value;
|
1725
|
+
|
1726
|
+
//print_ndloop(lp);
|
1674
1727
|
|
1675
1728
|
// loop body
|
1676
1729
|
for (i=0;;) {
|
1677
1730
|
for (; i<nd; i++) {
|
1678
|
-
if (LITER(lp,i,
|
1679
|
-
LITER(lp,i+1,
|
1731
|
+
if (LITER(lp,i,0).idx) {
|
1732
|
+
LITER(lp,i+1,0).pos = LITER(lp,i,0).pos + LITER(lp,i,0).idx[c[i]];
|
1680
1733
|
} else {
|
1681
|
-
LITER(lp,i+1,
|
1734
|
+
LITER(lp,i+1,0).pos = LITER(lp,i,0).pos + LITER(lp,i,0).step*c[i];
|
1682
1735
|
}
|
1683
|
-
//LITER(lp,i+1,0).pos = LITER(lp,i,0).pos + c[i];
|
1684
1736
|
if (TYPE(a[i])==T_ARRAY) {
|
1685
1737
|
if (c[i] < (size_t)RARRAY_LEN(a[i])) {
|
1686
1738
|
a[i+1] = RARRAY_AREF(a[i],c[i]);
|
1687
1739
|
} else {
|
1688
1740
|
a[i+1] = Qnil;
|
1689
1741
|
}
|
1690
|
-
} else
|
1742
|
+
} else if (IsNArray(a[i])) {
|
1743
|
+
//printf("a[i=%d]=0x%lx\n",i,a[i]);
|
1744
|
+
loop_store_subnarray(nf,lp,i,c,a[i]);
|
1745
|
+
goto loop_next;
|
1746
|
+
} else {
|
1691
1747
|
if (c[i]==0) {
|
1692
1748
|
a[i+1] = a[i];
|
1693
1749
|
} else {
|
1694
1750
|
a[i+1] = Qnil;
|
1695
1751
|
}
|
1696
1752
|
}
|
1697
|
-
//printf("c[
|
1753
|
+
//printf("c[%d]=%lu\n",i,c[i]);
|
1698
1754
|
}
|
1699
1755
|
|
1700
|
-
//printf("a[i]=0x%
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1756
|
+
//printf("a[i=%d]=0x%lx\n",i,a[i]);
|
1757
|
+
if (IsNArray(a[i])) {
|
1758
|
+
loop_store_subnarray(nf,lp,i,c,a[i]);
|
1759
|
+
} else {
|
1760
|
+
LARG(lp,1).value = a[i];
|
1761
|
+
(*(nf->func))(&(lp->user));
|
1762
|
+
}
|
1704
1763
|
|
1764
|
+
loop_next:
|
1705
1765
|
for (;;) {
|
1706
1766
|
if (i<=0) goto loop_end;
|
1707
1767
|
i--; c[i]++;
|
@@ -1709,12 +1769,12 @@ loop_rarray_to_narray(ndfunc_t *nf, na_md_loop_t *lp)
|
|
1709
1769
|
c[i] = 0;
|
1710
1770
|
}
|
1711
1771
|
}
|
1712
|
-
|
1772
|
+
loop_end:
|
1713
1773
|
;
|
1714
1774
|
}
|
1715
1775
|
|
1716
1776
|
VALUE
|
1717
|
-
|
1777
|
+
na_ndloop_store_rarray(ndfunc_t *nf, VALUE nary, VALUE rary)
|
1718
1778
|
{
|
1719
1779
|
na_md_loop_t lp;
|
1720
1780
|
VALUE args;
|
@@ -1722,20 +1782,20 @@ na_ndloop_cast_rarray_to_narray(ndfunc_t *nf, VALUE rary, VALUE nary)
|
|
1722
1782
|
//rb_p(args);
|
1723
1783
|
if (na_debug_flag) print_ndfunc(nf);
|
1724
1784
|
|
1725
|
-
args = rb_assoc_new(rary
|
1785
|
+
args = rb_assoc_new(nary,rary);
|
1726
1786
|
|
1727
1787
|
// cast arguments to NArray
|
1728
1788
|
//ndloop_cast_args(nf, args);
|
1729
1789
|
|
1730
1790
|
// allocate ndloop struct
|
1731
|
-
ndloop_alloc(&lp, nf, args, NULL, 0,
|
1791
|
+
ndloop_alloc(&lp, nf, args, NULL, 0, loop_store_rarray);
|
1732
1792
|
|
1733
1793
|
return rb_ensure(ndloop_run, (VALUE)&lp, ndloop_release, (VALUE)&lp);
|
1734
1794
|
}
|
1735
1795
|
|
1736
1796
|
|
1737
1797
|
VALUE
|
1738
|
-
|
1798
|
+
na_ndloop_store_rarray2(ndfunc_t *nf, VALUE nary, VALUE rary, VALUE opt)
|
1739
1799
|
{
|
1740
1800
|
na_md_loop_t lp;
|
1741
1801
|
VALUE args;
|
@@ -1744,13 +1804,13 @@ na_ndloop_cast_rarray_to_narray2(ndfunc_t *nf, VALUE rary, VALUE nary, VALUE opt
|
|
1744
1804
|
if (na_debug_flag) print_ndfunc(nf);
|
1745
1805
|
|
1746
1806
|
//args = rb_assoc_new(rary,nary);
|
1747
|
-
args = rb_ary_new3(3,rary,
|
1807
|
+
args = rb_ary_new3(3,nary,rary,opt);
|
1748
1808
|
|
1749
1809
|
// cast arguments to NArray
|
1750
1810
|
//ndloop_cast_args(nf, args);
|
1751
1811
|
|
1752
1812
|
// allocate ndloop struct
|
1753
|
-
ndloop_alloc(&lp, nf, args, NULL, 0,
|
1813
|
+
ndloop_alloc(&lp, nf, args, NULL, 0, loop_store_rarray);
|
1754
1814
|
|
1755
1815
|
return rb_ensure(ndloop_run, (VALUE)&lp, ndloop_release, (VALUE)&lp);
|
1756
1816
|
}
|
@@ -2,11 +2,6 @@
|
|
2
2
|
intern.h
|
3
3
|
Numerical Array Extension for Ruby
|
4
4
|
(C) Copyright 1999-2016 by Masahiro TANAKA
|
5
|
-
|
6
|
-
This program is free software.
|
7
|
-
You can distribute/modify this program
|
8
|
-
under the same terms as Ruby itself.
|
9
|
-
NO WARRANTY.
|
10
5
|
*/
|
11
6
|
#ifndef INTERN_H
|
12
7
|
#define INTERN_H
|
@@ -24,6 +19,7 @@ VALUE na_expand_dims(VALUE self, VALUE vdim);
|
|
24
19
|
VALUE na_reduce_dimension(int argc, VALUE *argv, int naryc, VALUE *naryv);
|
25
20
|
|
26
21
|
VALUE na_check_ladder(VALUE self, int start_dim);
|
22
|
+
VALUE na_check_contiguous(VALUE self);
|
27
23
|
void na_setup_shape(narray_t *na, int ndim, size_t *shape);
|
28
24
|
|
29
25
|
VALUE na_transpose_map(VALUE self, int *map);
|
@@ -70,8 +66,8 @@ VALUE na_ndloop3(ndfunc_t *nf, void *ptr, int argc, ...);
|
|
70
66
|
VALUE na_ndloop4(ndfunc_t *nf, void *ptr, VALUE args);
|
71
67
|
|
72
68
|
VALUE na_ndloop_cast_narray_to_rarray(ndfunc_t *nf, VALUE nary, VALUE fmt);
|
73
|
-
VALUE
|
74
|
-
VALUE
|
69
|
+
VALUE na_ndloop_store_rarray(ndfunc_t *nf, VALUE nary, VALUE rary);
|
70
|
+
VALUE na_ndloop_store_rarray2(ndfunc_t *nf, VALUE nary, VALUE rary, VALUE opt);
|
75
71
|
|
76
72
|
VALUE na_ndloop_inspect(VALUE nary, na_text_func_t func, VALUE opt);
|
77
73
|
|
@@ -103,10 +99,10 @@ VALUE nary_init_accum_aref0(VALUE self, VALUE reduce);
|
|
103
99
|
VALUE nary_mathcast(int argc, VALUE *argv);
|
104
100
|
|
105
101
|
|
106
|
-
|
107
|
-
|
102
|
+
int
|
103
|
+
na_get_result_dimension(VALUE self, int argc, VALUE *argv, ssize_t stride, size_t *pos_idx);
|
108
104
|
VALUE
|
109
|
-
na_aref_main(int nidx, VALUE *idx, VALUE self, int keep_dim);
|
105
|
+
na_aref_main(int nidx, VALUE *idx, VALUE self, int keep_dim, int nd);
|
110
106
|
|
111
107
|
|
112
108
|
#endif /* ifndef INTERN_H */
|
@@ -2,17 +2,12 @@
|
|
2
2
|
narray.h
|
3
3
|
Numerical Array Extension for Ruby
|
4
4
|
(C) Copyright 1999-2016 by Masahiro TANAKA
|
5
|
-
|
6
|
-
This program is free software.
|
7
|
-
You can distribute/modify this program
|
8
|
-
under the same terms as Ruby itself.
|
9
|
-
NO WARRANTY.
|
10
5
|
*/
|
11
6
|
#ifndef NARRAY_H
|
12
7
|
#define NARRAY_H
|
13
8
|
|
14
|
-
#define NARRAY_VERSION "0.9.0.
|
15
|
-
#define NARRAY_VERSION_CODE
|
9
|
+
#define NARRAY_VERSION "0.9.0.4"
|
10
|
+
#define NARRAY_VERSION_CODE 904
|
16
11
|
|
17
12
|
#include <math.h>
|
18
13
|
#include "numo/compat.h"
|
@@ -94,7 +89,7 @@
|
|
94
89
|
# endif
|
95
90
|
#elif SIZEOF_INT==4
|
96
91
|
# define NUM2INT32(x) NUM2INT(x)
|
97
|
-
# define INT322NUM(x)
|
92
|
+
# define INT322NUM(x) INT2NUM(x)
|
98
93
|
# define NUM2UINT32(x) NUM2UINT(x)
|
99
94
|
# define UINT322NUM(x) UINT2NUM(x)
|
100
95
|
# ifndef PRId32
|
@@ -201,6 +196,7 @@ typedef struct RNArrayView {
|
|
201
196
|
} narray_view_t;
|
202
197
|
|
203
198
|
|
199
|
+
// filemap is unimplemented
|
204
200
|
typedef struct RNArrayFileMap {
|
205
201
|
narray_t base;
|
206
202
|
char *ptr;
|
@@ -239,7 +235,7 @@ _na_get_narray_t(VALUE obj, unsigned char na_type)
|
|
239
235
|
Check_Type(obj, T_DATA);
|
240
236
|
na = (narray_t*)DATA_PTR(obj);
|
241
237
|
if (na->type != na_type) {
|
242
|
-
|
238
|
+
rb_bug("unknown type 0x%x (0x%x given)", na_type, na->type);
|
243
239
|
}
|
244
240
|
return na;
|
245
241
|
}
|
@@ -260,38 +256,46 @@ _na_get_narray_t(VALUE obj, unsigned char na_type)
|
|
260
256
|
#define SDX_SET_STRIDE(x,s) ((x).stride=((s)<<1)|0x1)
|
261
257
|
#define SDX_SET_INDEX(x,idx) ((x).index=idx)
|
262
258
|
|
263
|
-
#define RNARRAY(val)
|
264
|
-
#define RNARRAY_DATA(val)
|
265
|
-
#define RNARRAY_VIEW(val)
|
266
|
-
#define RNARRAY_FILEMAP(val)
|
259
|
+
#define RNARRAY(val) ((narray_t*)DATA_PTR(val))
|
260
|
+
#define RNARRAY_DATA(val) ((narray_data_t*)DATA_PTR(val))
|
261
|
+
#define RNARRAY_VIEW(val) ((narray_view_t*)DATA_PTR(val))
|
262
|
+
#define RNARRAY_FILEMAP(val) ((narray_filemap_t*)DATA_PTR(val))
|
267
263
|
|
268
|
-
#define RNARRAY_NDIM(val)
|
269
|
-
#define RNARRAY_TYPE(val)
|
270
|
-
#define RNARRAY_FLAG(val)
|
271
|
-
#define RNARRAY_SIZE(val)
|
272
|
-
#define RNARRAY_SHAPE(val)
|
273
|
-
#define RNARRAY_REDUCE(val)
|
264
|
+
#define RNARRAY_NDIM(val) (RNARRAY(val)->ndim)
|
265
|
+
#define RNARRAY_TYPE(val) (RNARRAY(val)->type)
|
266
|
+
#define RNARRAY_FLAG(val) (RNARRAY(val)->flag)
|
267
|
+
#define RNARRAY_SIZE(val) (RNARRAY(val)->size)
|
268
|
+
#define RNARRAY_SHAPE(val) (RNARRAY(val)->shape)
|
269
|
+
#define RNARRAY_REDUCE(val) (RNARRAY(val)->reduce)
|
274
270
|
|
275
|
-
#define RNARRAY_DATA_PTR(val)
|
276
|
-
#define RNARRAY_VIEW_DATA(val)
|
271
|
+
#define RNARRAY_DATA_PTR(val) (RNARRAY_DATA(val)->ptr)
|
272
|
+
#define RNARRAY_VIEW_DATA(val) (RNARRAY_VIEW(val)->data)
|
277
273
|
#define RNARRAY_VIEW_OFFSET(val) (RNARRAY_VIEW(val)->offset)
|
278
274
|
#define RNARRAY_VIEW_STRIDX(val) (RNARRAY_VIEW(val)->stridx)
|
279
275
|
|
280
|
-
#define NA_NDIM(na)
|
281
|
-
#define NA_TYPE(na)
|
282
|
-
#define
|
283
|
-
#define
|
284
|
-
#define
|
285
|
-
|
286
|
-
#define
|
287
|
-
#define
|
276
|
+
#define NA_NDIM(na) (((narray_t*)na)->ndim)
|
277
|
+
#define NA_TYPE(na) (((narray_t*)na)->type)
|
278
|
+
#define NA_SIZE(na) (((narray_t*)na)->size)
|
279
|
+
#define NA_SHAPE(na) (((narray_t*)na)->shape)
|
280
|
+
#define NA_REDUCE(na) (((narray_t*)na)->reduce)
|
281
|
+
|
282
|
+
#define NA_FLAG(obj) (na_get_narray_t(obj)->flag)
|
283
|
+
#define NA_FLAG0(obj) (NA_FLAG(obj)[0])
|
284
|
+
#define NA_FLAG1(obj) (NA_FLAG(obj)[1])
|
285
|
+
|
286
|
+
#define NA_DATA(na) ((narray_data_t*)(na))
|
287
|
+
#define NA_VIEW(na) ((narray_view_t*)(na))
|
288
|
+
#define NA_DATA_PTR(na) (NA_DATA(na)->ptr)
|
289
|
+
#define NA_VIEW_DATA(na) (NA_VIEW(na)->data)
|
290
|
+
#define NA_VIEW_OFFSET(na) (NA_VIEW(na)->offset)
|
291
|
+
#define NA_VIEW_STRIDX(na) (NA_VIEW(na)->stridx)
|
288
292
|
|
289
|
-
#define
|
290
|
-
#define
|
291
|
-
#define
|
292
|
-
#define
|
293
|
+
#define NA_IS_INDEX_AT(na,i) (SDX_IS_INDEX(NA_VIEW_STRIDX(na)[i]))
|
294
|
+
#define NA_IS_STRIDE_AT(na,i) (SDX_IS_STRIDE(NA_VIEW_STRIDX(na)[i]))
|
295
|
+
#define NA_INDEX_AT(na,i) (SDX_GET_INDEX(NA_VIEW_STRIDX(na)[i]))
|
296
|
+
#define NA_STRIDE_AT(na,i) (SDX_GET_STRIDE(NA_VIEW_STRIDX(na)[i]))
|
293
297
|
|
294
|
-
#define NA_FILEMAP_PTR(na)
|
298
|
+
#define NA_FILEMAP_PTR(na) (((narray_filemap_t*)na)->ptr)
|
295
299
|
|
296
300
|
|
297
301
|
#define NA_FL0_TEST(x,f) (NA_FLAG0(x)&(f))
|
@@ -306,10 +310,6 @@ _na_get_narray_t(VALUE obj, unsigned char na_type)
|
|
306
310
|
#define NA_FL0_REVERSE(x,f) do {NA_FLAG0(x) ^= (f);} while(0)
|
307
311
|
#define NA_FL1_REVERSE(x,f) do {NA_FLAG1(x) ^= (f);} while(0)
|
308
312
|
|
309
|
-
#define NA_TEST_LOCK(x) NA_FL0_TEST(x,NA_FL_LOCK)
|
310
|
-
#define NA_SET_LOCK(x) NA_FL0_SET(x,NA_FL_LOCK)
|
311
|
-
#define NA_UNSET_LOCK(x) NA_FL0_UNSET(x,NA_FL_LOCK)
|
312
|
-
|
313
313
|
|
314
314
|
/* FLAGS
|
315
315
|
- row-major / column-major
|
@@ -319,31 +319,60 @@ _na_get_narray_t(VALUE obj, unsigned char na_type)
|
|
319
319
|
- matrix or not
|
320
320
|
*/
|
321
321
|
|
322
|
-
#define
|
323
|
-
#define
|
324
|
-
#define
|
325
|
-
#define
|
322
|
+
#define NA_FL0_BIG_ENDIAN (0x1<<0)
|
323
|
+
#define NA_FL0_COLUMN_MAJOR (0x1<<1)
|
324
|
+
#define NA_FL1_LOCK (0x1<<0)
|
325
|
+
#define NA_FL1_INPLACE (0x1<<1)
|
326
|
+
|
327
|
+
#define TEST_COLUMN_MAJOR(x) NA_FL0_TEST(x,NA_FL0_COLUMN_MAJOR)
|
328
|
+
#define SET_COLUMN_MAJOR(x) NA_FL0_SET(x,NA_FL0_COLUMN_MAJOR)
|
329
|
+
#define UNSET_COLUMN_MAJOR(x) NA_FL0_UNSET(x,NA_FL0_COLUMN_MAJOR)
|
326
330
|
|
327
|
-
#define
|
328
|
-
#define
|
329
|
-
#define
|
330
|
-
#define TEST_HOST_ORDER(x) (!TEST_BYTE_SWAPPED(x))
|
331
|
+
#define TEST_ROW_MAJOR(x) (!TEST_COLUMN_MAJOR(x))
|
332
|
+
#define SET_ROW_MAJOR(x) UNSET_COLUMN_MAJOR(x)
|
333
|
+
#define UNSET_ROW_MAJOR(x) SET_COLUMN_MAJOR(x)
|
331
334
|
|
332
|
-
#define
|
333
|
-
#define
|
334
|
-
#define
|
335
|
+
#define TEST_BIG_ENDIAN(x) NA_FL0_TEST(x,NA_FL0_BIG_ENDIAN)
|
336
|
+
#define SET_BIG_ENDIAN(x) NA_FL0_SET(x,NA_FL0_BIG_ENDIAN)
|
337
|
+
#define UNSET_BIG_ENDIAN(x) NA_FL0_UNSET(x,NA_FL0_BIG_ENDIAN)
|
335
338
|
|
336
|
-
#define
|
339
|
+
#define TEST_LITTLE_ENDIAN(x) (!TEST_BIG_ENDIAN(x))
|
340
|
+
#define SET_LITTLE_ENDIAN(x) UNSET_BIG_ENDIAN(x)
|
341
|
+
#define UNSET_LITTLE_ENDIAN(x) SET_BIG_ENDIAN(x)
|
342
|
+
|
343
|
+
#define REVERSE_ENDIAN(x) NA_FL0_REVERSE((x),NA_FL0_BIG_ENDIAN)
|
344
|
+
|
345
|
+
#define TEST_LOCK(x) NA_FL1_TEST(x,NA_FL1_LOCK)
|
346
|
+
#define SET_LOCK(x) NA_FL1_SET(x,NA_FL1_LOCK)
|
347
|
+
#define UNSET_LOCK(x) NA_FL1_UNSET(x,NA_FL1_LOCK)
|
348
|
+
|
349
|
+
#define TEST_INPLACE(x) NA_FL1_TEST(x,NA_FL1_INPLACE)
|
350
|
+
#define SET_INPLACE(x) NA_FL1_SET(x,NA_FL1_INPLACE)
|
351
|
+
#define UNSET_INPLACE(x) NA_FL1_UNSET(x,NA_FL1_INPLACE)
|
337
352
|
|
338
353
|
#ifdef DYNAMIC_ENDIAN
|
354
|
+
// not supported
|
339
355
|
#else
|
340
356
|
#ifdef WORDS_BIGENDIAN
|
341
|
-
#
|
342
|
-
|
343
|
-
#define
|
344
|
-
#define
|
357
|
+
#define TEST_HOST_ORDER(x) TEST_BIG_ENDIAN(x)
|
358
|
+
#define SET_HOST_ORDER(x) SET_BIG_ENDIAN(x)
|
359
|
+
#define UNSET_HOST_ORDER(x) UNSET_BIG_ENDIAN(x)
|
360
|
+
#define TEST_BYTE_SWAPPED(x) TEST_LITTLE_ENDIAN(x)
|
361
|
+
#define SET_BYTE_SWAPPED(x) SET_LITTLE_ENDIAN(x)
|
362
|
+
#define UNSET_BYTE_SWAPPED(x) UNSET_LITTLE_ENDIAN(x)
|
363
|
+
#define NA_FL0_INIT NA_FL0_BIG_ENDIAN
|
364
|
+
#else // LITTLE ENDIAN
|
365
|
+
#define TEST_HOST_ORDER(x) TEST_LITTLE_ENDIAN(x)
|
366
|
+
#define SET_HOST_ORDER(x) SET_LITTLE_ENDIAN(x)
|
367
|
+
#define UNSET_HOST_ORDER(x) UNSET_LITTLE_ENDIAN(x)
|
368
|
+
#define TEST_BYTE_SWAPPED(x) TEST_BIG_ENDIAN(x)
|
369
|
+
#define SET_BYTE_SWAPPED(x) SET_BIG_ENDIAN(x)
|
370
|
+
#define UNSET_BYTE_SWAPPED(x) UNSET_BIG_ENDIAN(x)
|
371
|
+
#define NA_FL0_INIT 0
|
345
372
|
#endif
|
346
373
|
#endif
|
374
|
+
#define NA_FL1_INIT 0
|
375
|
+
|
347
376
|
|
348
377
|
#define IsNArray(obj) (rb_obj_is_kind_of(obj,cNArray)==Qtrue)
|
349
378
|
|