cumo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/3rd_party/LICENSE.txt +60 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +13 -1
- data/LICENSE.txt +1 -62
- data/README.md +33 -29
- data/bench/cumo_bench.rb +47 -25
- data/bench/numo_bench.rb +27 -25
- data/docs/src-tree.md +16 -0
- data/ext/cumo/cuda/cublas.c +69 -219
- data/ext/cumo/cuda/memory_pool_impl.hpp +1 -0
- data/ext/cumo/cuda/runtime.c +2 -14
- data/ext/cumo/cumo.c +16 -16
- data/ext/cumo/include/cumo.h +2 -2
- data/ext/cumo/include/cumo/cuda/cublas.h +6 -129
- data/ext/cumo/include/cumo/cuda/runtime.h +16 -0
- data/ext/cumo/include/cumo/indexer.h +46 -63
- data/ext/cumo/include/cumo/intern.h +58 -112
- data/ext/cumo/include/cumo/narray.h +214 -185
- data/ext/cumo/include/cumo/narray_kernel.h +66 -37
- data/ext/cumo/include/cumo/ndloop.h +42 -42
- data/ext/cumo/include/cumo/reduce_kernel.h +55 -71
- data/ext/cumo/include/cumo/template.h +56 -51
- data/ext/cumo/include/cumo/template_kernel.h +31 -31
- data/ext/cumo/include/cumo/types/bit.h +3 -3
- data/ext/cumo/include/cumo/types/bit_kernel.h +2 -2
- data/ext/cumo/include/cumo/types/complex.h +126 -126
- data/ext/cumo/include/cumo/types/complex_kernel.h +126 -126
- data/ext/cumo/include/cumo/types/complex_macro.h +28 -28
- data/ext/cumo/include/cumo/types/complex_macro_kernel.h +20 -20
- data/ext/cumo/include/cumo/types/dcomplex.h +5 -5
- data/ext/cumo/include/cumo/types/dcomplex_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/robj_macro.h +30 -30
- data/ext/cumo/include/cumo/types/scomplex.h +5 -5
- data/ext/cumo/include/cumo/types/scomplex_kernel.h +1 -1
- data/ext/cumo/narray/array.c +143 -143
- data/ext/cumo/narray/data.c +184 -184
- data/ext/cumo/narray/gen/cogen.rb +5 -2
- data/ext/cumo/narray/gen/cogen_kernel.rb +5 -2
- data/ext/cumo/narray/gen/def/dcomplex.rb +1 -1
- data/ext/cumo/narray/gen/def/scomplex.rb +1 -1
- data/ext/cumo/narray/gen/erbln.rb +132 -0
- data/ext/cumo/narray/gen/erbpp2.rb +18 -13
- data/ext/cumo/narray/gen/narray_def.rb +3 -3
- data/ext/cumo/narray/gen/spec.rb +2 -2
- data/ext/cumo/narray/gen/tmpl/accum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/accum_binary.c +22 -22
- data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/accum_index.c +30 -30
- data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +14 -14
- data/ext/cumo/narray/gen/tmpl/allocate.c +11 -11
- data/ext/cumo/narray/gen/tmpl/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl/aref_cpu.c +4 -4
- data/ext/cumo/narray/gen/tmpl/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl/binary.c +28 -28
- data/ext/cumo/narray/gen/tmpl/binary2.c +18 -18
- data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/binary_s.c +13 -13
- data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/bincount.c +23 -23
- data/ext/cumo/narray/gen/tmpl/cast.c +7 -7
- data/ext/cumo/narray/gen/tmpl/cast_array.c +3 -3
- data/ext/cumo/narray/gen/tmpl/clip.c +38 -38
- data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/cond_binary.c +19 -19
- data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +7 -7
- data/ext/cumo/narray/gen/tmpl/cond_unary.c +15 -15
- data/ext/cumo/narray/gen/tmpl/cum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/each.c +9 -9
- data/ext/cumo/narray/gen/tmpl/each_with_index.c +9 -9
- data/ext/cumo/narray/gen/tmpl/ewcomp.c +15 -15
- data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/extract_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl/extract_data.c +12 -12
- data/ext/cumo/narray/gen/tmpl/eye.c +9 -9
- data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/fill.c +9 -9
- data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +1 -1
- data/ext/cumo/narray/gen/tmpl/format.c +11 -11
- data/ext/cumo/narray/gen/tmpl/format_to_a.c +8 -8
- data/ext/cumo/narray/gen/tmpl/frexp.c +13 -13
- data/ext/cumo/narray/gen/tmpl/gemm.c +252 -108
- data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
- data/ext/cumo/narray/gen/tmpl/lib.c +2 -2
- data/ext/cumo/narray/gen/tmpl/logseq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/map_with_index.c +17 -17
- data/ext/cumo/narray/gen/tmpl/median.c +10 -10
- data/ext/cumo/narray/gen/tmpl/minmax.c +10 -10
- data/ext/cumo/narray/gen/tmpl/new_dim0.c +3 -3
- data/ext/cumo/narray/gen/tmpl/poly.c +6 -6
- data/ext/cumo/narray/gen/tmpl/pow.c +28 -28
- data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/rand.c +10 -10
- data/ext/cumo/narray/gen/tmpl/rand_norm.c +7 -7
- data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/seq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/set2.c +20 -20
- data/ext/cumo/narray/gen/tmpl/sort.c +11 -11
- data/ext/cumo/narray/gen/tmpl/sort_index.c +18 -18
- data/ext/cumo/narray/gen/tmpl/store.c +6 -6
- data/ext/cumo/narray/gen/tmpl/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/store_bit.c +23 -23
- data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl/store_from.c +16 -16
- data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/to_a.c +10 -10
- data/ext/cumo/narray/gen/tmpl/unary.c +25 -25
- data/ext/cumo/narray/gen/tmpl/unary2.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +15 -15
- data/ext/cumo/narray/gen/tmpl/unary_ret2.c +13 -13
- data/ext/cumo/narray/gen/tmpl/unary_s.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/allocate.c +9 -9
- data/ext/cumo/narray/gen/tmpl_bit/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl_bit/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/binary.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +21 -21
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/each.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/extract.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/fill.c +17 -17
- data/ext/cumo/narray/gen/tmpl_bit/format.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +11 -11
- data/ext/cumo/narray/gen/tmpl_bit/inspect.c +3 -3
- data/ext/cumo/narray/gen/tmpl_bit/mask.c +33 -33
- data/ext/cumo/narray/gen/tmpl_bit/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +22 -22
- data/ext/cumo/narray/gen/tmpl_bit/store_from.c +18 -18
- data/ext/cumo/narray/gen/tmpl_bit/to_a.c +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/unary.c +24 -24
- data/ext/cumo/narray/gen/tmpl_bit/where.c +16 -16
- data/ext/cumo/narray/gen/tmpl_bit/where2.c +20 -20
- data/ext/cumo/narray/index.c +213 -213
- data/ext/cumo/narray/math.c +27 -27
- data/ext/cumo/narray/narray.c +484 -484
- data/ext/cumo/narray/ndloop.c +259 -258
- data/ext/cumo/narray/rand.c +3 -3
- data/ext/cumo/narray/step.c +70 -70
- data/ext/cumo/narray/struct.c +139 -139
- metadata +6 -7
- data/ext/cumo/include/cumo/intern_fwd.h +0 -38
- data/lib/erbpp.rb +0 -294
- data/lib/erbpp/line_number.rb +0 -137
- data/lib/erbpp/narray_def.rb +0 -381
@@ -12,7 +12,6 @@ extern "C" {
|
|
12
12
|
#include "cumo/compat.h"
|
13
13
|
#include "cumo/template.h"
|
14
14
|
#include "cumo/extconf.h"
|
15
|
-
#include "cumo/intern_fwd.h"
|
16
15
|
|
17
16
|
#ifdef HAVE_STDBOOL_H
|
18
17
|
# include <stdbool.h>
|
@@ -50,13 +49,31 @@ extern "C" {
|
|
50
49
|
# endif
|
51
50
|
#endif
|
52
51
|
|
52
|
+
#ifndef IS_INTEGER_CLASS
|
53
|
+
#ifdef RUBY_INTEGER_UNIFICATION
|
54
|
+
#define IS_INTEGER_CLASS(c) ((c)==rb_cInteger)
|
55
|
+
#else
|
56
|
+
#define IS_INTEGER_CLASS(c) ((c)==rb_cFixnum||(c)==rb_cBignum)
|
57
|
+
#endif
|
58
|
+
#endif
|
59
|
+
|
60
|
+
#ifndef SZF
|
53
61
|
#define SZF PRI_SIZE_PREFIX // defined in ruby.h
|
62
|
+
#endif
|
54
63
|
|
55
64
|
#if SIZEOF_LONG==8
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
65
|
+
# ifndef NUM2INT64
|
66
|
+
# define NUM2INT64(x) NUM2LONG(x)
|
67
|
+
# endif
|
68
|
+
# ifndef INT642NUM
|
69
|
+
# define INT642NUM(x) LONG2NUM(x)
|
70
|
+
# endif
|
71
|
+
# ifndef NUM2UINT64
|
72
|
+
# define NUM2UINT64(x) NUM2ULONG(x)
|
73
|
+
# endif
|
74
|
+
# ifndef UINT642NUM
|
75
|
+
# define UINT642NUM(x) ULONG2NUM(x)
|
76
|
+
# endif
|
60
77
|
# ifndef PRId64
|
61
78
|
# define PRId64 "ld"
|
62
79
|
# endif
|
@@ -64,10 +81,18 @@ extern "C" {
|
|
64
81
|
# define PRIu64 "lu"
|
65
82
|
# endif
|
66
83
|
#elif SIZEOF_LONG_LONG==8
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
84
|
+
# ifndef NUM2INT64
|
85
|
+
# define NUM2INT64(x) NUM2LL(x)
|
86
|
+
# endif
|
87
|
+
# ifndef INT642NUM
|
88
|
+
# define INT642NUM(x) LL2NUM(x)
|
89
|
+
# endif
|
90
|
+
# ifndef NUM2UINT64
|
91
|
+
# define NUM2UINT64(x) NUM2ULL(x)
|
92
|
+
# endif
|
93
|
+
# ifndef UINT642NUM
|
94
|
+
# define UINT642NUM(x) ULL2NUM(x)
|
95
|
+
# endif
|
71
96
|
# ifndef PRId64
|
72
97
|
# define PRId64 "lld"
|
73
98
|
# endif
|
@@ -77,10 +102,18 @@ extern "C" {
|
|
77
102
|
#endif
|
78
103
|
|
79
104
|
#if SIZEOF_LONG==4
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
105
|
+
# ifndef NUM2INT32
|
106
|
+
# define NUM2INT32(x) NUM2LONG(x)
|
107
|
+
# endif
|
108
|
+
# ifndef INT322NUM
|
109
|
+
# define INT322NUM(x) LONG2NUM(x)
|
110
|
+
# endif
|
111
|
+
# ifndef NUM2UINT32
|
112
|
+
# define NUM2UINT32(x) NUM2ULONG(x)
|
113
|
+
# endif
|
114
|
+
# ifndef UINT322NUM
|
115
|
+
# define UINT322NUM(x) ULONG2NUM(x)
|
116
|
+
# endif
|
84
117
|
# ifndef PRId32
|
85
118
|
# define PRId32 "ld"
|
86
119
|
# endif
|
@@ -88,10 +121,18 @@ extern "C" {
|
|
88
121
|
# define PRIu32 "lu"
|
89
122
|
# endif
|
90
123
|
#elif SIZEOF_INT==4
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
124
|
+
# ifndef NUM2INT32
|
125
|
+
# define NUM2INT32(x) NUM2INT(x)
|
126
|
+
# endif
|
127
|
+
# ifndef INT322NUM
|
128
|
+
# define INT322NUM(x) INT2NUM(x)
|
129
|
+
# endif
|
130
|
+
# ifndef NUM2UINT32
|
131
|
+
# define NUM2UINT32(x) NUM2UINT(x)
|
132
|
+
# endif
|
133
|
+
# ifndef UINT322NUM
|
134
|
+
# define UINT322NUM(x) UINT2NUM(x)
|
135
|
+
# endif
|
95
136
|
# ifndef PRId32
|
96
137
|
# define PRId32 "d"
|
97
138
|
# endif
|
@@ -117,29 +158,28 @@ extern "C" {
|
|
117
158
|
# define TRUE 1
|
118
159
|
#endif
|
119
160
|
|
120
|
-
typedef struct { float dat[2]; }
|
121
|
-
typedef struct { double dat[2]; }
|
122
|
-
typedef int fortran_integer;
|
161
|
+
typedef struct { float dat[2]; } cumo_scomplex;
|
162
|
+
typedef struct { double dat[2]; } cumo_dcomplex;
|
123
163
|
|
124
|
-
#define
|
125
|
-
#define
|
164
|
+
#define CUMO_REAL(x) ((x).dat[0])
|
165
|
+
#define CUMO_IMAG(x) ((x).dat[1])
|
126
166
|
|
127
|
-
extern int
|
167
|
+
extern int cumo_na_debug_flag;
|
128
168
|
|
129
|
-
#
|
130
|
-
extern VALUE cumo_cNArray;
|
169
|
+
#define mCumo rb_mCumo
|
131
170
|
extern VALUE rb_mCumo;
|
132
|
-
|
133
|
-
extern VALUE
|
134
|
-
extern VALUE
|
135
|
-
extern VALUE
|
136
|
-
extern VALUE
|
137
|
-
extern
|
138
|
-
|
139
|
-
|
140
|
-
|
171
|
+
#define cNArray cumo_cNArray
|
172
|
+
extern VALUE cumo_cNArray;
|
173
|
+
extern VALUE cumo_na_eCastError;
|
174
|
+
extern VALUE cumo_na_eShapeError;
|
175
|
+
extern VALUE cumo_na_eOperationError;
|
176
|
+
extern VALUE cumo_na_eDimensionError;
|
177
|
+
extern VALUE cumo_na_eValueError;
|
178
|
+
extern const rb_data_type_t cumo_na_data_type;
|
179
|
+
|
180
|
+
//EXTERN const int cumo_na_sizeof[CUMO_NA_NTYPES+1];
|
141
181
|
|
142
|
-
//#define
|
182
|
+
//#define cumo_na_upcast(x,y) cumo_na_upcast(x,y)
|
143
183
|
|
144
184
|
/* global variables within this module */
|
145
185
|
extern VALUE cumo_cBit;
|
@@ -156,21 +196,21 @@ extern VALUE cumo_cUInt32;
|
|
156
196
|
extern VALUE cumo_cUInt16;
|
157
197
|
extern VALUE cumo_cUInt8;
|
158
198
|
extern VALUE cumo_cRObject;
|
159
|
-
extern VALUE
|
199
|
+
extern VALUE cumo_na_cStep;
|
160
200
|
#ifndef HAVE_RB_CCOMPLEX
|
161
201
|
extern VALUE rb_cComplex;
|
162
202
|
#endif
|
163
203
|
|
164
|
-
extern VALUE
|
165
|
-
extern VALUE
|
166
|
-
extern VALUE
|
167
|
-
extern VALUE
|
204
|
+
extern VALUE cumo_sym_reduce;
|
205
|
+
extern VALUE cumo_sym_option;
|
206
|
+
extern VALUE cumo_sym_loop_opt;
|
207
|
+
extern VALUE cumo_sym_init;
|
168
208
|
|
169
|
-
#define
|
170
|
-
#define
|
171
|
-
#define
|
209
|
+
#define CUMO_NARRAY_DATA_T 0x1
|
210
|
+
#define CUMO_NARRAY_VIEW_T 0x2
|
211
|
+
#define CUMO_NARRAY_FILEMAP_T 0x3
|
172
212
|
|
173
|
-
typedef struct
|
213
|
+
typedef struct {
|
174
214
|
unsigned char ndim; // # of dimensions
|
175
215
|
unsigned char type;
|
176
216
|
unsigned char flag[2]; // flags
|
@@ -178,35 +218,35 @@ typedef struct RNArray {
|
|
178
218
|
size_t size; // # of total elements
|
179
219
|
size_t *shape; // # of elements for each dimension
|
180
220
|
VALUE reduce;
|
181
|
-
}
|
221
|
+
} cumo_narray_t;
|
182
222
|
|
183
223
|
|
184
|
-
typedef struct
|
185
|
-
|
224
|
+
typedef struct {
|
225
|
+
cumo_narray_t base;
|
186
226
|
char *ptr;
|
187
|
-
}
|
227
|
+
} cumo_narray_data_t;
|
188
228
|
|
189
229
|
|
190
230
|
typedef union {
|
191
231
|
ssize_t stride;
|
192
232
|
size_t *index;
|
193
|
-
}
|
233
|
+
} cumo_stridx_t;
|
194
234
|
|
195
|
-
typedef struct
|
196
|
-
|
235
|
+
typedef struct {
|
236
|
+
cumo_narray_t base;
|
197
237
|
VALUE data; // data object
|
198
238
|
size_t offset; // offset of start point from data pointer
|
199
239
|
// :in units of elm.unit_bits
|
200
240
|
// address_unit pointer_unit access_unit data_unit
|
201
241
|
// elm.step_unit = elm.bit_size / elm.access_unit
|
202
242
|
// elm.step_unit = elm.size_bits / elm.unit_bits
|
203
|
-
|
204
|
-
}
|
243
|
+
cumo_stridx_t *stridx; // stride or indices of data pointer for each dimension
|
244
|
+
} cumo_narray_view_t;
|
205
245
|
|
206
246
|
|
207
247
|
// filemap is unimplemented
|
208
|
-
typedef struct
|
209
|
-
|
248
|
+
typedef struct {
|
249
|
+
cumo_narray_t base;
|
210
250
|
char *ptr;
|
211
251
|
#ifdef WIN32
|
212
252
|
HANDLE hFile;
|
@@ -215,7 +255,7 @@ typedef struct RNArrayFileMap {
|
|
215
255
|
int prot;
|
216
256
|
int flag;
|
217
257
|
#endif
|
218
|
-
}
|
258
|
+
} cumo_narray_filemap_t;
|
219
259
|
|
220
260
|
|
221
261
|
// this will be revised in future.
|
@@ -223,101 +263,101 @@ typedef struct {
|
|
223
263
|
unsigned int element_bits;
|
224
264
|
unsigned int element_bytes;
|
225
265
|
unsigned int element_stride;
|
226
|
-
}
|
266
|
+
} cumo_narray_type_info_t;
|
227
267
|
|
228
268
|
|
229
|
-
static inline
|
230
|
-
|
269
|
+
static inline cumo_narray_t *
|
270
|
+
cumo_na_get_narray_t(VALUE obj)
|
231
271
|
{
|
232
|
-
|
272
|
+
cumo_narray_t *na;
|
233
273
|
|
234
|
-
Check_TypedStruct(obj,&
|
235
|
-
na = (
|
274
|
+
Check_TypedStruct(obj,&cumo_na_data_type);
|
275
|
+
na = (cumo_narray_t*)DATA_PTR(obj);
|
236
276
|
return na;
|
237
277
|
}
|
238
278
|
|
239
|
-
static inline
|
240
|
-
|
279
|
+
static inline cumo_narray_t *
|
280
|
+
_cumo_na_get_narray_t(VALUE obj, unsigned char cumo_na_type)
|
241
281
|
{
|
242
|
-
|
282
|
+
cumo_narray_t *na;
|
243
283
|
|
244
|
-
Check_TypedStruct(obj,&
|
245
|
-
na = (
|
246
|
-
if (na->type !=
|
247
|
-
rb_bug("unknown type 0x%x (0x%x given)",
|
284
|
+
Check_TypedStruct(obj,&cumo_na_data_type);
|
285
|
+
na = (cumo_narray_t*)DATA_PTR(obj);
|
286
|
+
if (na->type != cumo_na_type) {
|
287
|
+
rb_bug("unknown type 0x%x (0x%x given)", cumo_na_type, na->type);
|
248
288
|
}
|
249
289
|
return na;
|
250
290
|
}
|
251
291
|
|
252
|
-
#define
|
253
|
-
#define
|
254
|
-
#define
|
292
|
+
#define cumo_na_get_narray_data_t(obj) (cumo_narray_data_t*)_cumo_na_get_narray_t(obj,CUMO_NARRAY_DATA_T)
|
293
|
+
#define cumo_na_get_narray_view_t(obj) (cumo_narray_view_t*)_cumo_na_get_narray_t(obj,CUMO_NARRAY_VIEW_T)
|
294
|
+
#define cumo_na_get_narray_filemap_t(obj) (cumo_narray_filemap_t*)_cumo_na_get_narray_t(obj,CUMO_NARRAY_FILEMAP_T)
|
255
295
|
|
256
|
-
#define
|
257
|
-
#define
|
258
|
-
#define
|
296
|
+
#define CumoGetNArray(obj,var) TypedData_Get_Struct(obj, cumo_narray_t, &cumo_na_data_type, var)
|
297
|
+
#define CumoGetNArrayView(obj,var) TypedData_Get_Struct(obj, cumo_narray_view_t, &cumo_na_data_type, var)
|
298
|
+
#define CumoGetNArrayData(obj,var) TypedData_Get_Struct(obj, cumo_narray_data_t, &cumo_na_data_type, var)
|
259
299
|
|
260
|
-
#define
|
261
|
-
#define
|
262
|
-
#define
|
263
|
-
#define
|
300
|
+
#define CUMO_SDX_IS_STRIDE(x) ((x).stride&0x1)
|
301
|
+
#define CUMO_SDX_IS_INDEX(x) (!CUMO_SDX_IS_STRIDE(x))
|
302
|
+
#define CUMO_SDX_GET_STRIDE(x) ((x).stride>>1)
|
303
|
+
#define CUMO_SDX_GET_INDEX(x) ((x).index)
|
264
304
|
|
265
|
-
#define
|
266
|
-
#define
|
305
|
+
#define CUMO_SDX_SET_STRIDE(x,s) ((x).stride=((s)<<1)|0x1)
|
306
|
+
#define CUMO_SDX_SET_INDEX(x,idx) ((x).index=idx)
|
267
307
|
|
268
|
-
#define
|
269
|
-
#define
|
270
|
-
#define
|
271
|
-
#define
|
308
|
+
#define CUMO_RNARRAY(val) ((cumo_narray_t*)DATA_PTR(val))
|
309
|
+
#define CUMO_RNARRAY_DATA(val) ((cumo_narray_data_t*)DATA_PTR(val))
|
310
|
+
#define CUMO_RNARRAY_VIEW(val) ((cumo_narray_view_t*)DATA_PTR(val))
|
311
|
+
#define CUMO_RNARRAY_FILEMAP(val) ((cumo_narray_filemap_t*)DATA_PTR(val))
|
272
312
|
|
273
|
-
#define
|
274
|
-
#define
|
275
|
-
#define
|
276
|
-
#define
|
277
|
-
#define
|
278
|
-
#define
|
313
|
+
#define CUMO_RNARRAY_NDIM(val) (CUMO_RNARRAY(val)->ndim)
|
314
|
+
#define CUMO_RNARRAY_TYPE(val) (CUMO_RNARRAY(val)->type)
|
315
|
+
#define CUMO_RNARRAY_FLAG(val) (CUMO_RNARRAY(val)->flag)
|
316
|
+
#define CUMO_RNARRAY_SIZE(val) (CUMO_RNARRAY(val)->size)
|
317
|
+
#define CUMO_RNARRAY_SHAPE(val) (CUMO_RNARRAY(val)->shape)
|
318
|
+
#define CUMO_RNARRAY_REDUCE(val) (CUMO_RNARRAY(val)->reduce)
|
279
319
|
|
280
|
-
#define
|
281
|
-
#define
|
282
|
-
#define
|
283
|
-
#define
|
320
|
+
#define CUMO_RNARRAY_DATA_PTR(val) (CUMO_RNARRAY_DATA(val)->ptr)
|
321
|
+
#define CUMO_RNARRAY_VIEW_DATA(val) (CUMO_RNARRAY_VIEW(val)->data)
|
322
|
+
#define CUMO_RNARRAY_VIEW_OFFSET(val) (CUMO_RNARRAY_VIEW(val)->offset)
|
323
|
+
#define CUMO_RNARRAY_VIEW_STRIDX(val) (CUMO_RNARRAY_VIEW(val)->stridx)
|
284
324
|
|
285
|
-
#define
|
286
|
-
#define
|
287
|
-
#define
|
288
|
-
#define
|
289
|
-
#define
|
325
|
+
#define CUMO_NA_NDIM(na) (((cumo_narray_t*)na)->ndim)
|
326
|
+
#define CUMO_NA_TYPE(na) (((cumo_narray_t*)na)->type)
|
327
|
+
#define CUMO_NA_SIZE(na) (((cumo_narray_t*)na)->size)
|
328
|
+
#define CUMO_NA_SHAPE(na) (((cumo_narray_t*)na)->shape)
|
329
|
+
#define CUMO_NA_REDUCE(na) (((cumo_narray_t*)na)->reduce)
|
290
330
|
|
291
|
-
#define
|
292
|
-
#define
|
293
|
-
#define
|
331
|
+
#define CUMO_NA_FLAG(obj) (cumo_na_get_narray_t(obj)->flag)
|
332
|
+
#define CUMO_NA_FLAG0(obj) (CUMO_NA_FLAG(obj)[0])
|
333
|
+
#define CUMO_NA_FLAG1(obj) (CUMO_NA_FLAG(obj)[1])
|
294
334
|
|
295
|
-
#define
|
296
|
-
#define
|
297
|
-
#define
|
298
|
-
#define
|
299
|
-
#define
|
300
|
-
#define
|
335
|
+
#define CUMO_NA_DATA(na) ((cumo_narray_data_t*)(na))
|
336
|
+
#define CUMO_NA_VIEW(na) ((cumo_narray_view_t*)(na))
|
337
|
+
#define CUMO_NA_DATA_PTR(na) (CUMO_NA_DATA(na)->ptr)
|
338
|
+
#define CUMO_NA_VIEW_DATA(na) (CUMO_NA_VIEW(na)->data)
|
339
|
+
#define CUMO_NA_VIEW_OFFSET(na) (CUMO_NA_VIEW(na)->offset)
|
340
|
+
#define CUMO_NA_VIEW_STRIDX(na) (CUMO_NA_VIEW(na)->stridx)
|
301
341
|
|
302
|
-
#define
|
303
|
-
#define
|
304
|
-
#define
|
305
|
-
#define
|
342
|
+
#define CUMO_NA_IS_INDEX_AT(na,i) (CUMO_SDX_IS_INDEX(CUMO_NA_VIEW_STRIDX(na)[i]))
|
343
|
+
#define CUMO_NA_IS_STRIDE_AT(na,i) (CUMO_SDX_IS_STRIDE(CUMO_NA_VIEW_STRIDX(na)[i]))
|
344
|
+
#define CUMO_NA_INDEX_AT(na,i) (CUMO_SDX_GET_INDEX(CUMO_NA_VIEW_STRIDX(na)[i]))
|
345
|
+
#define CUMO_NA_STRIDE_AT(na,i) (CUMO_SDX_GET_STRIDE(CUMO_NA_VIEW_STRIDX(na)[i]))
|
306
346
|
|
307
|
-
#define
|
347
|
+
#define CUMO_NA_FILEMAP_PTR(na) (((cumo_narray_filemap_t*)na)->ptr)
|
308
348
|
|
309
349
|
|
310
|
-
#define
|
311
|
-
#define
|
350
|
+
#define CUMO_NA_FL0_TEST(x,f) (CUMO_NA_FLAG0(x)&(f))
|
351
|
+
#define CUMO_NA_FL1_TEST(x,f) (CUMO_NA_FLAG1(x)&(f))
|
312
352
|
|
313
|
-
#define
|
314
|
-
#define
|
353
|
+
#define CUMO_NA_FL0_SET(x,f) do {CUMO_NA_FLAG0(x) |= (f);} while(0)
|
354
|
+
#define CUMO_NA_FL1_SET(x,f) do {CUMO_NA_FLAG1(x) |= (f);} while(0)
|
315
355
|
|
316
|
-
#define
|
317
|
-
#define
|
356
|
+
#define CUMO_NA_FL0_UNSET(x,f) do {CUMO_NA_FLAG0(x) &= ~(f);} while(0)
|
357
|
+
#define CUMO_NA_FL1_UNSET(x,f) do {CUMO_NA_FLAG1(x) &= ~(f);} while(0)
|
318
358
|
|
319
|
-
#define
|
320
|
-
#define
|
359
|
+
#define CUMO_NA_FL0_REVERSE(x,f) do {CUMO_NA_FLAG0(x) ^= (f);} while(0)
|
360
|
+
#define CUMO_NA_FL1_REVERSE(x,f) do {CUMO_NA_FLAG1(x) ^= (f);} while(0)
|
321
361
|
|
322
362
|
|
323
363
|
/* FLAGS
|
@@ -328,93 +368,82 @@ _na_get_narray_t(VALUE obj, unsigned char na_type)
|
|
328
368
|
- matrix or not
|
329
369
|
*/
|
330
370
|
|
331
|
-
#define
|
332
|
-
#define
|
333
|
-
#define
|
334
|
-
#define
|
371
|
+
#define CUMO_NA_FL0_BIG_ENDIAN (0x1<<0)
|
372
|
+
#define CUMO_NA_FL0_COLUMN_MAJOR (0x1<<1)
|
373
|
+
#define CUMO_NA_FL1_LOCK (0x1<<0)
|
374
|
+
#define CUMO_NA_FL1_INPLACE (0x1<<1)
|
335
375
|
|
336
|
-
#define
|
337
|
-
#define
|
338
|
-
#define
|
376
|
+
#define CUMO_TEST_COLUMN_MAJOR(x) CUMO_NA_FL0_TEST(x,CUMO_NA_FL0_COLUMN_MAJOR)
|
377
|
+
#define CUMO_SET_COLUMN_MAJOR(x) CUMO_NA_FL0_SET(x,CUMO_NA_FL0_COLUMN_MAJOR)
|
378
|
+
#define CUMO_UNSET_COLUMN_MAJOR(x) CUMO_NA_FL0_UNSET(x,CUMO_NA_FL0_COLUMN_MAJOR)
|
339
379
|
|
340
|
-
#define
|
341
|
-
#define
|
342
|
-
#define
|
380
|
+
#define CUMO_TEST_ROW_MAJOR(x) (!CUMO_TEST_COLUMN_MAJOR(x))
|
381
|
+
#define CUMO_SET_ROW_MAJOR(x) CUMO_UNSET_COLUMN_MAJOR(x)
|
382
|
+
#define CUMO_UNSET_ROW_MAJOR(x) CUMO_SET_COLUMN_MAJOR(x)
|
343
383
|
|
344
|
-
#define
|
345
|
-
#define
|
346
|
-
#define
|
384
|
+
#define CUMO_TEST_BIG_ENDIAN(x) CUMO_NA_FL0_TEST(x,CUMO_NA_FL0_BIG_ENDIAN)
|
385
|
+
#define CUMO_SET_BIG_ENDIAN(x) CUMO_NA_FL0_SET(x,CUMO_NA_FL0_BIG_ENDIAN)
|
386
|
+
#define CUMO_UNSET_BIG_ENDIAN(x) CUMO_NA_FL0_UNSET(x,CUMO_NA_FL0_BIG_ENDIAN)
|
347
387
|
|
348
|
-
#define
|
349
|
-
#define
|
350
|
-
#define
|
388
|
+
#define CUMO_TEST_LITTLE_ENDIAN(x) (!CUMO_TEST_BIG_ENDIAN(x))
|
389
|
+
#define CUMO_SET_LITTLE_ENDIAN(x) CUMO_UNSET_BIG_ENDIAN(x)
|
390
|
+
#define CUMO_UNSET_LITTLE_ENDIAN(x) CUMO_SET_BIG_ENDIAN(x)
|
351
391
|
|
352
|
-
#define
|
392
|
+
#define CUMO_REVERSE_ENDIAN(x) CUMO_NA_FL0_REVERSE((x),CUMO_NA_FL0_BIG_ENDIAN)
|
353
393
|
|
354
|
-
#define
|
355
|
-
#define
|
356
|
-
#define
|
394
|
+
#define CUMO_TEST_LOCK(x) CUMO_NA_FL1_TEST(x,CUMO_NA_FL1_LOCK)
|
395
|
+
#define CUMO_SET_LOCK(x) CUMO_NA_FL1_SET(x,CUMO_NA_FL1_LOCK)
|
396
|
+
#define CUMO_UNCUMO_SET_LOCK(x) CUMO_NA_FL1_UNSET(x,CUMO_NA_FL1_LOCK)
|
357
397
|
|
358
|
-
#define
|
359
|
-
#define
|
360
|
-
#define
|
398
|
+
#define CUMO_TEST_INPLACE(x) CUMO_NA_FL1_TEST(x,CUMO_NA_FL1_INPLACE)
|
399
|
+
#define CUMO_SET_INPLACE(x) CUMO_NA_FL1_SET(x,CUMO_NA_FL1_INPLACE)
|
400
|
+
#define CUMO_UNCUMO_SET_INPLACE(x) CUMO_NA_FL1_UNSET(x,CUMO_NA_FL1_INPLACE)
|
361
401
|
|
362
402
|
#ifdef DYNAMIC_ENDIAN
|
363
403
|
// not supported
|
364
404
|
#else
|
365
405
|
#ifdef WORDS_BIGENDIAN
|
366
|
-
#define
|
367
|
-
#define
|
368
|
-
#define
|
369
|
-
#define
|
370
|
-
#define
|
371
|
-
#define
|
372
|
-
#define
|
406
|
+
#define CUMO_TEST_HOST_ORDER(x) CUMO_TEST_BIG_ENDIAN(x)
|
407
|
+
#define CUMO_SET_HOST_ORDER(x) CUMO_SET_BIG_ENDIAN(x)
|
408
|
+
#define CUMO_UNSET_HOST_ORDER(x) CUMO_UNSET_BIG_ENDIAN(x)
|
409
|
+
#define CUMO_TEST_BYTE_SWAPPED(x) CUMO_TEST_LITTLE_ENDIAN(x)
|
410
|
+
#define CUMO_SET_BYTE_SWAPPED(x) CUMO_SET_LITTLE_ENDIAN(x)
|
411
|
+
#define CUMO_UNCUMO_SET_BYTE_SWAPPED(x) CUMO_UNSET_LITTLE_ENDIAN(x)
|
412
|
+
#define CUMO_NA_FL0_INIT CUMO_NA_FL0_BIG_ENDIAN
|
373
413
|
#else // LITTLE ENDIAN
|
374
|
-
#define
|
375
|
-
#define
|
376
|
-
#define
|
377
|
-
#define
|
378
|
-
#define
|
379
|
-
#define
|
380
|
-
#define
|
414
|
+
#define CUMO_TEST_HOST_ORDER(x) CUMO_TEST_LITTLE_ENDIAN(x)
|
415
|
+
#define CUMO_SET_HOST_ORDER(x) CUMO_SET_LITTLE_ENDIAN(x)
|
416
|
+
#define CUMO_UNSET_HOST_ORDER(x) CUMO_UNSET_LITTLE_ENDIAN(x)
|
417
|
+
#define CUMO_TEST_BYTE_SWAPPED(x) CUMO_TEST_BIG_ENDIAN(x)
|
418
|
+
#define CUMO_SET_BYTE_SWAPPED(x) CUMO_SET_BIG_ENDIAN(x)
|
419
|
+
#define CUMO_UNCUMO_SET_BYTE_SWAPPED(x) CUMO_UNSET_BIG_ENDIAN(x)
|
420
|
+
#define CUMO_NA_FL0_INIT 0
|
381
421
|
#endif
|
382
422
|
#endif
|
383
|
-
#define
|
423
|
+
#define CUMO_NA_FL1_INIT 0
|
384
424
|
|
385
425
|
|
386
|
-
#define
|
426
|
+
#define CumoIsNArray(obj) (rb_obj_is_kind_of(obj,cNArray)==Qtrue)
|
387
427
|
|
388
|
-
#define
|
428
|
+
#define CUMO_DEBUG_PRINT(v) puts(StringValueCStr(rb_funcall(v,rb_intern("inspect"),0)))
|
389
429
|
|
390
|
-
#define
|
430
|
+
#define CUMO_NA_CumoIsNArray(obj) \
|
391
431
|
(rb_obj_is_kind_of(obj,cNArray)==Qtrue)
|
392
|
-
#define
|
432
|
+
#define CUMO_NA_IsArray(obj) \
|
393
433
|
(TYPE(obj)==T_ARRAY || rb_obj_is_kind_of(obj,cNArray)==Qtrue)
|
394
434
|
|
395
|
-
#define
|
396
|
-
#define
|
397
|
-
|
398
|
-
//#define NA_MAX_DIMENSION (int)(sizeof(VALUE)*8-2)
|
399
|
-
#define NA_MAX_DIMENSION 12
|
400
|
-
#define NA_MAX_ELMSZ 65535
|
401
|
-
|
402
|
-
typedef unsigned int BIT_DIGIT;
|
403
|
-
#define BYTE_BIT_DIGIT sizeof(BIT_DIGIT)
|
404
|
-
#define NB (sizeof(BIT_DIGIT)*8)
|
405
|
-
#define BALL (~(BIT_DIGIT)0)
|
406
|
-
#define SLB(n) (((n)==NB)?~(BIT_DIGIT)0:(~(~(BIT_DIGIT)0<<(n))))
|
407
|
-
|
408
|
-
#define ELEMENT_BIT_SIZE "ELEMENT_BIT_SIZE"
|
409
|
-
#define ELEMENT_BYTE_SIZE "ELEMENT_BYTE_SIZE"
|
410
|
-
#define CONTIGUOUS_STRIDE "CONTIGUOUS_STRIDE"
|
435
|
+
#define CUMO_NUM2REAL(v) NUM2DBL( rb_funcall((v),cumo_na_id_real,0) )
|
436
|
+
#define CUMO_NUM2IMAG(v) NUM2DBL( rb_funcall((v),cumo_na_id_imag,0) )
|
411
437
|
|
438
|
+
//#define CUMO_NA_MAX_DIMENSION (int)(sizeof(VALUE)*8-2)
|
439
|
+
#define CUMO_NA_MAX_DIMENSION 12
|
440
|
+
#define CUMO_NA_MAX_ELMSZ 65535
|
412
441
|
|
413
|
-
|
414
|
-
#define
|
415
|
-
#
|
416
|
-
#define
|
417
|
-
#
|
442
|
+
typedef unsigned int CUMO_BIT_DIGIT;
|
443
|
+
#define CUMO_BYTE_BIT_DIGIT sizeof(CUMO_BIT_DIGIT)
|
444
|
+
#define CUMO_NB (sizeof(CUMO_BIT_DIGIT)*8)
|
445
|
+
#define CUMO_BALL (~(CUMO_BIT_DIGIT)0)
|
446
|
+
#define CUMO_SLB(n) (((n)==CUMO_NB)?~(CUMO_BIT_DIGIT)0:(~(~(CUMO_BIT_DIGIT)0<<(n))))
|
418
447
|
|
419
448
|
#include "cumo/ndloop.h"
|
420
449
|
#include "cumo/intern.h"
|