numo-narray 0.9.0.1-x86-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/line_number.rb +126 -0
  118. data/lib/erbpp/narray_def.rb +338 -0
  119. data/lib/erbpp.rb +286 -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,23 @@
1
+ #ifndef COMPAT_H
2
+ #define COMPAT_H
3
+
4
+ #if !defined RSTRING_LEN
5
+ #define RSTRING_LEN(a) RSTRING(a)->len
6
+ #endif
7
+ #if !defined RSTRING_PTR
8
+ #define RSTRING_PTR(a) RSTRING(a)->ptr
9
+ #endif
10
+ #if !defined RARRAY_LEN
11
+ #define RARRAY_LEN(a) RARRAY(a)->len
12
+ #endif
13
+ #if !defined RARRAY_PTR
14
+ #define RARRAY_PTR(a) RARRAY(a)->ptr
15
+ #endif
16
+ #if !defined RARRAY_AREF
17
+ #define RARRAY_AREF(a,i) RARRAY_PTR(a)[i]
18
+ #endif
19
+ #if !defined RARRAY_ASET
20
+ #define RARRAY_ASET(a,i,v) (RARRAY_PTR(a)[i] = v)
21
+ #endif
22
+
23
+ #endif /* ifndef COMPAT_H */
@@ -0,0 +1,112 @@
1
+ /*
2
+ intern.h
3
+ Numerical Array Extension for Ruby
4
+ (C) Copyright 1999-2011 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
+ */
11
+ #ifndef INTERN_H
12
+ #define INTERN_H
13
+
14
+ VALUE rb_narray_new(VALUE elem, int ndim, size_t *shape);
15
+ VALUE rb_narray_view_new(VALUE elem, int ndim, size_t *shape);
16
+ VALUE rb_narray_debug_info(VALUE);
17
+
18
+ VALUE na_original_data(VALUE self);
19
+ VALUE na_make_view(VALUE self);
20
+ VALUE na_make_view_struct(VALUE self, VALUE dtype, VALUE offset);
21
+ void na_array_to_internal_shape(VALUE self, VALUE ary, size_t *shape);
22
+
23
+ VALUE na_reduce_dimension(int argc, VALUE *argv, int naryc, VALUE *naryv);
24
+
25
+ VALUE na_check_ladder(VALUE self, int start_dim);
26
+ void na_setup_shape(narray_t *na, int ndim, size_t *shape);
27
+
28
+ VALUE na_transpose_map(VALUE self, int *map);
29
+ VALUE na_flatten_dim(VALUE self, int sd);
30
+ VALUE na_flatten_by_reduce(int argc, VALUE *argv, VALUE self);
31
+
32
+ VALUE na_sort_main(int argc, VALUE *argv, volatile VALUE self, na_iter_func_t iter_func);
33
+ VALUE na_median_main(int argc, VALUE *argv, volatile VALUE self, na_iter_func_t iter_func);
34
+
35
+ VALUE na_sort_index_main(int argc, VALUE *argv, VALUE self, void (*func_qsort)());
36
+
37
+ char *na_get_pointer(VALUE);
38
+ char *na_get_pointer_for_write(VALUE);
39
+ char *na_get_pointer_for_read(VALUE);
40
+ char *na_get_pointer_at_origin_for_read(VALUE);
41
+
42
+ size_t na_get_offset(VALUE self);
43
+
44
+ VALUE na_s_allocate(VALUE klass);
45
+ VALUE na_s_allocate_view(VALUE klass);
46
+
47
+ void na_alloc_shape(narray_t *na, int ndim);
48
+ void na_alloc_index(narray_t *na);
49
+
50
+ void na_copy_flags(VALUE src, VALUE dst);
51
+
52
+ VALUE na_flatten(VALUE);
53
+ VALUE na_dup(VALUE);
54
+ VALUE na_copy(VALUE);
55
+ VALUE na_upcast(VALUE type1, VALUE type2);
56
+
57
+ stridx_t *na_get_stride(VALUE v);
58
+
59
+ void na_release_lock(VALUE);
60
+
61
+ void na_index_arg_to_internal_order(int argc, VALUE *argv, VALUE self);
62
+
63
+ //ndfunc_t *ndfunc_alloc(na_iter_func_t func, int has_loop, int narg, int nres, ...);
64
+ //ndfunc_t *ndfunc_alloc2(na_iter_func_t func, unsigned int flag, int narg, int nres, VALUE *etypes);
65
+ //void ndfunc_free(ndfunc_t* nf);
66
+
67
+ VALUE na_ndloop(ndfunc_t *nf, int argc, ...);
68
+ VALUE na_ndloop2(ndfunc_t *nf, VALUE args);
69
+ VALUE na_ndloop3(ndfunc_t *nf, void *ptr, int argc, ...);
70
+ VALUE na_ndloop4(ndfunc_t *nf, void *ptr, VALUE args);
71
+
72
+ VALUE na_ndloop_cast_narray_to_rarray(ndfunc_t *nf, VALUE nary, VALUE fmt);
73
+ VALUE na_ndloop_cast_rarray_to_narray(ndfunc_t *nf, VALUE rary, VALUE nary);
74
+ VALUE na_ndloop_cast_rarray_to_narray2(ndfunc_t *nf, VALUE rary, VALUE nary, VALUE opt);
75
+
76
+ VALUE na_ndloop_inspect(VALUE nary, na_text_func_t func, VALUE opt);
77
+
78
+ VALUE na_ndloop_with_index(ndfunc_t *nf, int argc, ...);
79
+
80
+
81
+ VALUE na_info_str(VALUE);
82
+
83
+ size_t na_get_elmsz(VALUE nary);
84
+ size_t na_dtype_elmsz(VALUE klass);
85
+
86
+ bool na_test_reduce(VALUE reduce, int dim);
87
+
88
+ //size_t *na_mdarray_investigate(VALUE ary, int *ndim, VALUE *type);
89
+ VALUE na_ary_composition(VALUE ary);
90
+
91
+ //void na_copy_bytes(na_loop_t *const itr);
92
+
93
+ VALUE na_debug_set(VALUE mod, VALUE flag);
94
+
95
+ void nary_step_array_index(VALUE self, size_t ary_size, size_t *plen, ssize_t *pbeg, ssize_t *pstep);
96
+
97
+ VALUE na_store(VALUE self, VALUE src);
98
+
99
+ void nary_step_sequence(VALUE self, size_t *plen, double *pbeg, double *pstep);
100
+
101
+ VALUE nary_init_accum_aref0(VALUE self, VALUE reduce);
102
+
103
+ VALUE nary_mathcast(int argc, VALUE *argv);
104
+
105
+
106
+ ssize_t
107
+ na_get_scalar_position(VALUE self, int argc, VALUE *argv, ssize_t stride);
108
+ VALUE
109
+ na_aref_main(int nidx, VALUE *idx, VALUE self, int keep_dim);
110
+
111
+
112
+ #endif /* ifndef INTERN_H */
@@ -0,0 +1,411 @@
1
+ /*
2
+ narray.h
3
+ Numerical Array Extension for Ruby
4
+ (C) Copyright 1999-2003 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
+ */
11
+ #ifndef NARRAY_H
12
+ #define NARRAY_H
13
+
14
+ #define NARRAY_VERSION "0.9.0.1"
15
+ #define NARRAY_VERSION_CODE 901
16
+
17
+ #include <math.h>
18
+ #include "numo/compat.h"
19
+ #include "numo/template.h"
20
+
21
+ #include "extconf.h"
22
+
23
+ #ifdef HAVE_STDBOOL_H
24
+ # include <stdbool.h>
25
+ #endif
26
+
27
+ #ifdef HAVE_STDINT_H
28
+ # include <stdint.h>
29
+ #endif
30
+
31
+ #ifdef HAVE_SYS_TYPES_H
32
+ # include <sys/types.h>
33
+ #endif
34
+
35
+ #ifndef HAVE_U_INT8_T
36
+ # ifdef HAVE_UINT8_T
37
+ typedef uint8_t u_int8_t;
38
+ # endif
39
+ #endif
40
+
41
+ #ifndef HAVE_U_INT16_T
42
+ # ifdef HAVE_UINT16_T
43
+ typedef uint16_t u_int16_t;
44
+ # endif
45
+ #endif
46
+
47
+ #ifndef HAVE_U_INT32_T
48
+ # ifdef HAVE_UINT32_T
49
+ typedef uint32_t u_int32_t;
50
+ # endif
51
+ #endif
52
+
53
+ #ifndef HAVE_U_INT64_T
54
+ # ifdef HAVE_UINT64_T
55
+ typedef uint64_t u_int64_t;
56
+ # endif
57
+ #endif
58
+
59
+ #if SIZEOF_VOIDP==SIZEOF_LONG
60
+ # define NUM2SIZE(x) NUM2ULONG(x)
61
+ # define NUM2SSIZE(x) NUM2LONG(x)
62
+ # define SIZE2NUM(x) ULONG2NUM(x)
63
+ # define SSIZE2NUM(x) LONG2NUM(x)
64
+ # define SZF "l"
65
+ #elif SIZEOF_VOIDP==SIZEOF_LONG_LONG
66
+ # define NUM2SIZE(x) NUM2ULL(x)
67
+ # define NUM2SSIZE(x) NUM2LL(x)
68
+ # define SIZE2NUM(x) ULL2NUM(x)
69
+ # define SSIZE2NUM(x) LL2NUM(x)
70
+ # define SZF "ll"
71
+ #endif
72
+
73
+ #if SIZEOF_LONG==8
74
+ # define NUM2INT64(x) NUM2LONG(x)
75
+ # define INT642NUM(x) LONG2NUM(x)
76
+ # define NUM2UINT64(x) NUM2ULONG(x)
77
+ # define UINT642NUM(x) ULONG2NUM(x)
78
+ # ifndef PRId64
79
+ # define PRId64 "ld"
80
+ # endif
81
+ # ifndef PRIu64
82
+ # define PRIu64 "lu"
83
+ # endif
84
+ #elif SIZEOF_LONG_LONG==8
85
+ # define NUM2INT64(x) NUM2LL(x)
86
+ # define INT642NUM(x) LL2NUM(x)
87
+ # define NUM2UINT64(x) NUM2ULL(x)
88
+ # define UINT642NUM(x) ULL2NUM(x)
89
+ # ifndef PRId64
90
+ # define PRId64 "lld"
91
+ # endif
92
+ # ifndef PRIu64
93
+ # define PRIu64 "llu"
94
+ # endif
95
+ #endif
96
+
97
+ #if SIZEOF_LONG==4
98
+ # define NUM2INT32(x) NUM2LONG(x)
99
+ # define INT322NUM(x) LONG2NUM(x)
100
+ # define NUM2UINT32(x) NUM2ULONG(x)
101
+ # define UINT322NUM(x) ULONG2NUM(x)
102
+ # ifndef PRId32
103
+ # define PRId32 "ld"
104
+ # endif
105
+ # ifndef PRIu32
106
+ # define PRIu32 "lu"
107
+ # endif
108
+ #elif SIZEOF_INT==4
109
+ # define NUM2INT32(x) NUM2INT(x)
110
+ # define INT322NUM(x) UINT2NUM(x)
111
+ # define NUM2UINT32(x) NUM2UINT(x)
112
+ # define UINT322NUM(x) UINT2NUM(x)
113
+ # ifndef PRId32
114
+ # define PRId32 "d"
115
+ # endif
116
+ # ifndef PRIu32
117
+ # define PRIu32 "u"
118
+ # endif
119
+ #endif
120
+
121
+ #ifndef HAVE_TYPE_BOOL
122
+ typedef int bool;
123
+ #endif
124
+ #ifndef FALSE /* in case these macros already exist */
125
+ # define FALSE 0 /* values of bool */
126
+ #endif
127
+ #ifndef TRUE
128
+ # define TRUE 1
129
+ #endif
130
+
131
+ typedef struct { float dat[2]; } scomplex;
132
+ typedef struct { double dat[2]; } dcomplex;
133
+ typedef int fortran_integer;
134
+
135
+ #define REAL(x) ((x).dat[0])
136
+ #define IMAG(x) ((x).dat[1])
137
+
138
+ extern int na_debug_flag;
139
+
140
+ #ifndef NARRAY_C
141
+ extern VALUE numo_cNArray;
142
+ extern VALUE rb_mNumo;
143
+ extern VALUE nary_eCastError;
144
+ extern VALUE nary_eShapeError;
145
+ extern VALUE nary_eOperationError;
146
+ extern VALUE nary_eDimensionError;
147
+
148
+ //EXTERN const int na_sizeof[NA_NTYPES+1];
149
+ #endif
150
+
151
+ #define cNArray numo_cNArray
152
+ #define mNumo rb_mNumo
153
+ #define na_upcast(x,y) numo_na_upcast(x,y)
154
+
155
+ /* global variables within this module */
156
+ extern VALUE numo_cBit;
157
+ extern VALUE numo_cDFloat;
158
+ extern VALUE numo_cSFloat;
159
+ extern VALUE numo_cDComplex;
160
+ extern VALUE numo_cSComplex;
161
+ extern VALUE numo_cInt64;
162
+ extern VALUE numo_cInt32;
163
+ extern VALUE numo_cInt16;
164
+ extern VALUE numo_cInt8;
165
+ extern VALUE numo_cUInt64;
166
+ extern VALUE numo_cUInt32;
167
+ extern VALUE numo_cUInt16;
168
+ extern VALUE numo_cUInt8;
169
+ extern VALUE numo_cRObject;
170
+ extern VALUE na_cStep;
171
+ #ifndef HAVE_RB_CCOMPLEX
172
+ extern VALUE rb_cComplex;
173
+ #endif
174
+
175
+ extern VALUE sym_reduce;
176
+ extern VALUE sym_option;
177
+ extern VALUE sym_loop_opt;
178
+ extern VALUE sym_init;
179
+
180
+ #define NARRAY_DATA_T 0x1
181
+ #define NARRAY_VIEW_T 0x2
182
+ #define NARRAY_FILEMAP_T 0x3
183
+
184
+ typedef struct RNArray {
185
+ unsigned char ndim; // # of dimensions
186
+ unsigned char type;
187
+ unsigned char flag[2]; // flags
188
+ size_t size; // # of total elements
189
+ size_t *shape; // # of elements for each dimension
190
+ VALUE reduce;
191
+ } narray_t;
192
+
193
+
194
+ typedef struct RNArrayData {
195
+ narray_t base;
196
+ char *ptr;
197
+ } narray_data_t;
198
+
199
+
200
+ typedef union {
201
+ ssize_t stride;
202
+ size_t *index;
203
+ } stridx_t;
204
+
205
+ typedef struct RNArrayView {
206
+ narray_t base;
207
+ VALUE data; // data object
208
+ size_t offset; // offset of start point from data pointer
209
+ // :in units of elm.unit_bits
210
+ // address_unit pointer_unit access_unit data_unit
211
+ // elm.step_unit = elm.bit_size / elm.access_unit
212
+ // elm.step_unit = elm.size_bits / elm.unit_bits
213
+ stridx_t *stridx; // stride or indices of data pointer for each dimension
214
+ } narray_view_t;
215
+
216
+
217
+ typedef struct RNArrayFileMap {
218
+ narray_t base;
219
+ char *ptr;
220
+ #ifdef WIN32
221
+ HANDLE hFile;
222
+ HANDLE hMap;
223
+ #else // POSIX mmap
224
+ int prot;
225
+ int flag;
226
+ #endif
227
+ } narray_filemap_t;
228
+
229
+
230
+ typedef struct {
231
+ int ndim;
232
+ size_t *shape;
233
+ VALUE dtype;
234
+ } na_compose_t;
235
+
236
+
237
+ static inline narray_t *
238
+ na_get_narray_t(VALUE obj)
239
+ {
240
+ narray_t *na;
241
+
242
+ Check_Type(obj, T_DATA);
243
+ na = (narray_t*)DATA_PTR(obj);
244
+ return na;
245
+ }
246
+
247
+ static inline narray_t *
248
+ _na_get_narray_t(VALUE obj, unsigned char na_type)
249
+ {
250
+ narray_t *na;
251
+
252
+ Check_Type(obj, T_DATA);
253
+ na = (narray_t*)DATA_PTR(obj);
254
+ if (na->type != na_type) {
255
+ rb_bug("unknown type 0x%x (0x%x given)", na_type, na->type);
256
+ }
257
+ return na;
258
+ }
259
+
260
+ #define na_get_narray_data_t(obj) (narray_data_t*)_na_get_narray_t(obj,NARRAY_DATA_T)
261
+ #define na_get_narray_view_t(obj) (narray_view_t*)_na_get_narray_t(obj,NARRAY_VIEW_T)
262
+ #define na_get_narray_filemap_t(obj) (narray_filemap_t*)_na_get_narray_t(obj,NARRAY_FILEMAP_T)
263
+
264
+ #define GetNArray(obj,var) Data_Get_Struct(obj, narray_t, var)
265
+ #define GetNArrayView(obj,var) Data_Get_Struct(obj, narray_view_t, var)
266
+ #define GetNArrayData(obj,var) Data_Get_Struct(obj, narray_data_t, var)
267
+
268
+ #define SDX_IS_STRIDE(x) ((x).stride&0x1)
269
+ #define SDX_IS_INDEX(x) (!SDX_IS_STRIDE(x))
270
+ #define SDX_GET_STRIDE(x) ((x).stride>>1)
271
+ #define SDX_GET_INDEX(x) ((x).index)
272
+
273
+ #define SDX_SET_STRIDE(x,s) ((x).stride=((s)<<1)|0x1)
274
+ #define SDX_SET_INDEX(x,idx) ((x).index=idx)
275
+
276
+ #define RNARRAY(val) ((narray_t*)DATA_PTR(val))
277
+ #define RNARRAY_DATA(val) ((narray_data_t*)DATA_PTR(val))
278
+ #define RNARRAY_VIEW(val) ((narray_view_t*)DATA_PTR(val))
279
+ #define RNARRAY_FILEMAP(val) ((narray_filemap_t*)DATA_PTR(val))
280
+
281
+ #define RNARRAY_NDIM(val) (RNARRAY(val)->ndim)
282
+ #define RNARRAY_TYPE(val) (RNARRAY(val)->type)
283
+ #define RNARRAY_FLAG(val) (RNARRAY(val)->flag)
284
+ #define RNARRAY_SIZE(val) (RNARRAY(val)->size)
285
+ #define RNARRAY_SHAPE(val) (RNARRAY(val)->shape)
286
+ #define RNARRAY_REDUCE(val) (RNARRAY(val)->reduce)
287
+
288
+ #define RNARRAY_DATA_PTR(val) (RNARRAY_DATA(val)->ptr)
289
+ #define RNARRAY_VIEW_DATA(val) (RNARRAY_VIEW(val)->data)
290
+ #define RNARRAY_VIEW_OFFSET(val) (RNARRAY_VIEW(val)->offset)
291
+ #define RNARRAY_VIEW_STRIDX(val) (RNARRAY_VIEW(val)->stridx)
292
+
293
+ #define NA_NDIM(na) (((narray_t*)na)->ndim)
294
+ #define NA_TYPE(na) (((narray_t*)na)->type)
295
+ #define NA_FLAG(na) (((narray_t*)na)->flag)
296
+ #define NA_FLAG0(na) (((narray_t*)na)->flag[0])
297
+ #define NA_FLAG1(na) (((narray_t*)na)->flag[1])
298
+ #define NA_SIZE(na) (((narray_t*)na)->size)
299
+ #define NA_SHAPE(na) (((narray_t*)na)->shape)
300
+ #define NA_REDUCE(na) (((narray_t*)na)->reduce)
301
+
302
+ #define NA_DATA_PTR(na) (((narray_data_t*)na)->ptr)
303
+ #define NA_VIEW_DATA(na) (((narray_view_t*)na)->data)
304
+ #define NA_VIEW_OFFSET(na) (((narray_view_t*)na)->offset)
305
+ #define NA_VIEW_STRIDX(na) (((narray_view_t*)na)->stridx)
306
+
307
+ #define NA_FILEMAP_PTR(na) (((narray_filemap_t*)na)->ptr)
308
+
309
+
310
+ #define NA_FL0_TEST(x,f) (NA_FLAG0(x)&(f))
311
+ #define NA_FL1_TEST(x,f) (NA_FLAG1(x)&(f))
312
+
313
+ #define NA_FL0_SET(x,f) do {NA_FLAG0(x) |= (f);} while(0)
314
+ #define NA_FL1_SET(x,f) do {NA_FLAG1(x) |= (f);} while(0)
315
+
316
+ #define NA_FL0_UNSET(x,f) do {NA_FLAG0(x) &= ~(f);} while(0)
317
+ #define NA_FL1_UNSET(x,f) do {NA_FLAG1(x) &= ~(f);} while(0)
318
+
319
+ #define NA_FL0_REVERSE(x,f) do {NA_FLAG0(x) ^= (f);} while(0)
320
+ #define NA_FL1_REVERSE(x,f) do {NA_FLAG1(x) ^= (f);} while(0)
321
+
322
+ #define NA_TEST_LOCK(x) NA_FL0_TEST(x,NA_FL_LOCK)
323
+ #define NA_SET_LOCK(x) NA_FL0_SET(x,NA_FL_LOCK)
324
+ #define NA_UNSET_LOCK(x) NA_FL0_UNSET(x,NA_FL_LOCK)
325
+
326
+
327
+ /* FLAGS
328
+ - row-major / column-major
329
+ - Overwrite or not
330
+ - byteswapp
331
+ - Extensible?
332
+ - matrix or not
333
+ */
334
+
335
+ #define NA_FL_LOCK (0x1<<0)
336
+ #define NA_FL_COLUMN_MAJOR (0x1<<1)
337
+ #define NA_FL_BYTE_SWAPPED (0x1<<2)
338
+ #define NA_FL_INPLACE (0x1<<3)
339
+
340
+ #define TEST_COLUMN_MAJOR(x) NA_FL0_TEST(x,NA_FL_COLUMN_MAJOR)
341
+ #define TEST_ROW_MAJOR(x) (!NA_FL0_TEST(x,NA_FL_COLUMN_MAJOR))
342
+ #define TEST_BYTE_SWAPPED(x) NA_FL0_TEST(x,NA_FL_BYTE_SWAPPED)
343
+ #define TEST_HOST_ORDER(x) (!TEST_BYTE_SWAPPED(x))
344
+
345
+ #define TEST_INPLACE(x) NA_FL0_TEST(x,NA_FL_INPLACE)
346
+ #define SET_INPLACE(x) NA_FL0_SET(x,NA_FL_INPLACE)
347
+ #define UNSET_INPLACE(x) NA_FL0_UNSET(x,NA_FL_INPLACE)
348
+
349
+ #define REVERSE_BYTE_SWAPPED(x) NA_FL0_REVERSE((x),NA_FL_BYTE_SWAPPED)
350
+
351
+ #ifdef DYNAMIC_ENDIAN
352
+ #else
353
+ #ifdef WORDS_BIGENDIAN
354
+ #else // LITTLE_ENDIAN
355
+
356
+ #define TEST_NETWORK_ORDER(x) TEST_BYTE_SWAPPED(x)
357
+ #define TEST_VACS_ORDER(x) TEST_HOST_ORDER(x)
358
+ #endif
359
+ #endif
360
+
361
+
362
+ #define IsNArray(obj) (rb_obj_is_kind_of(obj,cNArray)==Qtrue)
363
+
364
+ #define DEBUG_PRINT(v) puts(StringValueCStr(rb_funcall(v,rb_intern("inspect"),0)))
365
+
366
+
367
+
368
+ #define NA_IsNArray(obj) \
369
+ (rb_obj_is_kind_of(obj,cNArray)==Qtrue)
370
+ #define NA_IsArray(obj) \
371
+ (TYPE(obj)==T_ARRAY || rb_obj_is_kind_of(obj,cNArray)==Qtrue)
372
+
373
+ #define NUM2REAL(v) NUM2DBL( rb_funcall((v),na_id_real,0) )
374
+ #define NUM2IMAG(v) NUM2DBL( rb_funcall((v),na_id_imag,0) )
375
+
376
+ #define NA_MAX_DIMENSION (int)(sizeof(VALUE)*8-2)
377
+
378
+ /* Function Prototypes */
379
+
380
+
381
+ typedef struct {
382
+ double beg;
383
+ double step;
384
+ double count;
385
+ } seq_opt_t;
386
+
387
+ typedef struct {
388
+ u_int64_t max;
389
+ int64_t sign;
390
+ int shift;
391
+ } rand_opt_t;
392
+
393
+
394
+ typedef unsigned int BIT_DIGIT;
395
+ //#define BYTE_BIT_DIGIT sizeof(BIT_DIGIT)
396
+ #define NB (sizeof(BIT_DIGIT)*8)
397
+ #define BALL (~(BIT_DIGIT)0)
398
+ #define SLB(n) (((n)==NB)?~(BIT_DIGIT)0:(~(~(BIT_DIGIT)0<<(n))))
399
+
400
+ //#include "template.h"
401
+
402
+ #define ELEMENT_BIT_SIZE "ELEMENT_BIT_SIZE"
403
+ #define ELEMENT_BYTE_SIZE "ELEMENT_BYTE_SIZE"
404
+ #define CONTIGUOUS_STRIDE "CONTIGUOUS_STRIDE"
405
+
406
+ #include "numo/ndloop.h"
407
+ //#include "ndfunc.h"
408
+
409
+ #include "numo/intern.h"
410
+
411
+ #endif /* ifndef NARRAY_H */
@@ -0,0 +1,99 @@
1
+ /*
2
+ ndloop.h
3
+ Numerical Array Extension for Ruby
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
+ */
11
+ #ifndef NDLOOP_H
12
+ #define NDLOOP_H
13
+
14
+ typedef struct NA_LOOP_ITER {
15
+ ssize_t pos; // - required for each dimension.
16
+ ssize_t step;
17
+ size_t *idx;
18
+ } na_loop_iter_t;
19
+
20
+ typedef struct NA_LOOP_ARGS {
21
+ VALUE value;
22
+ ssize_t elmsz;
23
+ char *ptr;
24
+ //char *buf_ptr; //
25
+ int ndim; // required for each argument.
26
+ // ssize_t pos; - not required here.
27
+ size_t *shape;
28
+ na_loop_iter_t *iter; // moved from na_loop_t
29
+ } na_loop_args_t;
30
+
31
+ // pass this structure to user iterator
32
+ typedef struct NA_LOOP {
33
+ int narg;
34
+ int ndim; // n of user dimention - required for each iterator.
35
+ size_t *n; // n of elements for each dim (=shape)
36
+ na_loop_args_t *args; // for each arg
37
+ VALUE option;
38
+ void *opt_ptr;
39
+ VALUE err_type;
40
+ } na_loop_t;
41
+
42
+
43
+ // ------------------ ndfunc -------------------------------------------
44
+
45
+ #define NDF_HAS_LOOP (1<<0) // x[i]
46
+ #define NDF_STRIDE_LOOP (1<<1) // *(x+stride*i)
47
+ #define NDF_INDEX_LOOP (1<<2) // *(x+idx[i])
48
+ #define NDF_KEEP_DIM (1<<3)
49
+ #define NDF_INPLACE (1<<4)
50
+ #define NDF_ACCEPT_BYTESWAP (1<<5)
51
+
52
+ #define NDF_FLAT_REDUCE (1<<6)
53
+ #define NDF_EXTRACT (1<<7)
54
+ #define NDF_CUM (1<<8)
55
+
56
+ #define FULL_LOOP (NDF_HAS_LOOP|NDF_STRIDE_LOOP|NDF_INDEX_LOOP|NDF_INPLACE)
57
+ #define FULL_LOOP_NIP (NDF_HAS_LOOP|NDF_STRIDE_LOOP|NDF_INDEX_LOOP)
58
+ #define STRIDE_LOOP (NDF_HAS_LOOP|NDF_STRIDE_LOOP|NDF_INPLACE)
59
+ #define STRIDE_LOOP_NIP (NDF_HAS_LOOP|NDF_STRIDE_LOOP)
60
+ #define NO_LOOP 0
61
+
62
+ #define OVERWRITE Qtrue // used for CASTABLE(t)
63
+
64
+ #define NDF_TEST(nf,fl) ((nf)->flag & (fl))
65
+ #define NDF_SET(nf,fl) {(nf)->flag |= (fl);}
66
+
67
+ #define NDF_ARG_READ_ONLY 1
68
+ #define NDF_ARG_WRITE_ONLY 2
69
+ #define NDF_ARG_READ_WRITE 3
70
+
71
+ // type of user function
72
+ typedef void (*na_iter_func_t) _((na_loop_t *const));
73
+ typedef VALUE (*na_text_func_t) _((char *ptr, size_t pos, VALUE opt));
74
+ //typedef void (*) void (*loop_func)(ndfunc_t*, na_md_loop_t*))
75
+
76
+
77
+ typedef struct NDF_ARG_IN {
78
+ VALUE type; // argument types
79
+ int dim; // # of dimension of argument handled by user function
80
+ // if dim==-1, reduce dimension
81
+ } ndfunc_arg_in_t;
82
+
83
+ typedef struct NDF_ARG_OUT {
84
+ VALUE type; // argument types
85
+ int dim; // # of dimension of argument handled by user function
86
+ size_t *shape;
87
+ } ndfunc_arg_out_t;
88
+
89
+ // spec of user function
90
+ typedef struct NDFUNCTION {
91
+ na_iter_func_t func; // user function
92
+ unsigned int flag; // what kind of loop user function supports
93
+ int nin; // # of arguments
94
+ int nout; // # of results
95
+ ndfunc_arg_in_t *ain; // spec of input arguments
96
+ ndfunc_arg_out_t *aout; // spec of output result
97
+ } ndfunc_t;
98
+
99
+ #endif /* NDLOOP_H */