narray-nmatrix 0.6.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ EXPORTS
2
+ Init_narray
3
+ na_sizeof
4
+ na_make_object
5
+ na_make_scalar
6
+ na_make_empty
7
+ na_get_typecode
8
+ na_clear_data
9
+ na_clone
10
+ na_fill
11
+ na_copy_nary
12
+ na_to_array
13
+ na_ary_to_nary
14
+ na_object_type
15
+ na_cast_object
16
+ na_cast_unless_narray
17
+ na_cast_unless_array
18
+ na_upcast_object
19
+ na_dup_w_type
20
+ na_change_type
21
+ na_upcast_type
22
+ na_to_narray
23
+ na_aset
24
+ na_aref
25
+ na_slice
26
+ na_count_true
27
+ na_count_false
28
+ na_aref_mask
29
+ na_aset_mask
@@ -0,0 +1,186 @@
1
+ /*
2
+ narray.h
3
+ Numerical Array Extention 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 NARRAY_H
12
+ #define NARRAY_H
13
+
14
+ #include <math.h>
15
+
16
+ #include "narray_config.h"
17
+
18
+ #ifdef HAVE_STDINT_H
19
+ # include <stdint.h>
20
+ #endif
21
+
22
+ #ifdef HAVE_SYS_TYPES_H
23
+ # include <sys/types.h>
24
+ #endif
25
+
26
+ #define NARRAY_VERSION "0.6.1.0.pre"
27
+ #define NARRAY_VERSION_CODE 610
28
+
29
+ /*
30
+ Data types used in NArray :
31
+ Please modify these types if your system has any different type.
32
+ */
33
+
34
+
35
+ /* NA_BYTE : unsigned 8-bit integer */
36
+ #ifndef HAVE_U_INT8_T
37
+ # ifdef HAVE_UINT8_T
38
+ typedef uint8_t u_int8_t;
39
+ # else
40
+ typedef unsigned char u_int8_t;
41
+ # endif
42
+ #endif
43
+
44
+ #ifndef HAVE_INT16_T
45
+ # if SIZEOF_SHORT == 2
46
+ typedef short int16_t; /* NA_SINT */
47
+ # else
48
+ ---->> Please define int16_t manually because sizeof(short) != 2. <<----
49
+ # endif
50
+ #endif /* HAVE_INT16_T */
51
+
52
+ #ifndef HAVE_INT32_T
53
+ # if SIZEOF_LONG == 4
54
+ typedef long int32_t; /* NA_LINT */
55
+ # else
56
+ # if SIZEOF_INT == 4
57
+ typedef int int32_t; /* NA_LINT */
58
+ # else
59
+ ---->> Please define int32_t manually because sizeof(long) != 4. <<----
60
+ # endif
61
+ # endif
62
+ #endif /* HAVE_INT32_T */
63
+
64
+ /* unsigned 32-bit integer */
65
+ #ifndef HAVE_U_INT32_T
66
+ # ifdef HAVE_UINT32_T
67
+ typedef uint32_t u_int32_t;
68
+ # else
69
+ # if SIZEOF_LONG == 4
70
+ typedef unsigned long u_int32_t;
71
+ # else
72
+ # if SIZEOF_INT == 4
73
+ typedef unsigned int u_int32_t;
74
+ # else
75
+ ---->> Please define u_int32_t manually because sizeof(long) != 4. <<----
76
+ # endif
77
+ # endif
78
+ # endif
79
+ #endif /* HAVE_U_INT32_T */
80
+
81
+ typedef struct { float r,i; } scomplex;
82
+ typedef struct { double r,i; } dcomplex;
83
+
84
+ enum NArray_Types {
85
+ NA_NONE,
86
+ NA_BYTE, /* 1 */
87
+ NA_SINT, /* 2 */
88
+ NA_LINT, /* 3 */
89
+ NA_SFLOAT, /* 4 */
90
+ NA_DFLOAT, /* 5 */
91
+ NA_SCOMPLEX, /* 6 */
92
+ NA_DCOMPLEX, /* 7 */
93
+ NA_ROBJ, /* 8 */
94
+ NA_NTYPES /* 9 */
95
+ };
96
+
97
+ /* struct for Numerical Array */
98
+ struct NARRAY {
99
+ int rank; /* # of dimension */
100
+ int total; /* # of total element */
101
+ int type; /* data type */
102
+ int *shape;
103
+ char *ptr; /* pointer to data */
104
+ VALUE ref; /* NArray object wrapping this structure */
105
+ };
106
+
107
+ #ifndef NARRAY_C
108
+ extern VALUE cNArray;
109
+
110
+ extern const int na_sizeof[NA_NTYPES+1];
111
+ #endif
112
+
113
+ #define NA_MAX_RANK 15
114
+
115
+ #define GetNArray(obj,var) Data_Get_Struct(obj, struct NARRAY, var)
116
+ #define IsNArray(obj) (rb_obj_is_kind_of(obj,cNArray)==Qtrue)
117
+
118
+ #define NA_PTR(a,p) ((a)->ptr+(p)*na_sizeof[(a)->type])
119
+ #define NA_STRUCT(val) ((struct NARRAY*)DATA_PTR(val))
120
+ #define NA_PTR_TYPE(val,type) (type)(((struct NARRAY*)DATA_PTR(val))->ptr)
121
+ #define NA_RANK(val) (((struct NARRAY*)DATA_PTR(val))->rank)
122
+ #define NA_TYPE(val) (((struct NARRAY*)DATA_PTR(val))->type)
123
+ #define NA_TOTAL(val) (((struct NARRAY*)DATA_PTR(val))->total)
124
+ #define NA_SHAPE0(val) (((struct NARRAY*)DATA_PTR(val))->shape[0])
125
+ #define NA_SHAPE1(val) (((struct NARRAY*)DATA_PTR(val))->shape[1])
126
+
127
+ #define NA_IsNArray(obj) \
128
+ (rb_obj_is_kind_of(obj,cNArray)==Qtrue)
129
+ #define NA_IsArray(obj) \
130
+ (TYPE(obj)==T_ARRAY || rb_obj_is_kind_of(obj,cNArray)==Qtrue)
131
+ #define NA_IsROBJ(d) ((d)->type==NA_ROBJ)
132
+ #define NA_IsINTEGER(a) \
133
+ ((a)->type==NA_BYTE || (a)->type==NA_SINT || (a)->type==NA_LINT )
134
+ #define NA_IsCOMPLEX(a) \
135
+ ((a)->type==NA_SCOMPLEX || (a)->type==NA_DCOMPLEX)
136
+ #define NA_MAX(a,b) (((a)>(b))?(a):(b))
137
+ #define NA_SWAP(a,b,tmp) {(tmp)=(a);(a)=(b);(b)=(tmp);}
138
+
139
+ #define na_class_dim(klass) NUM2INT(rb_const_get(klass, na_id_class_dim))
140
+
141
+ #define NUM2REAL(v) NUM2DBL( rb_funcall((v),na_id_real,0) )
142
+ #define NUM2IMAG(v) NUM2DBL( rb_funcall((v),na_id_imag,0) )
143
+
144
+ #define NA_ALLOC_SLICE(slc,nc,shp,np) \
145
+ { slc = (struct slice*)xmalloc( sizeof(struct slice)*(nc) + \
146
+ sizeof(int)*(np) );\
147
+ shp = (int*)&( (slc)[nc] ); }
148
+
149
+
150
+ /* Function Prototypes */
151
+
152
+ /* narray.c */
153
+ VALUE na_make_object(int type, int rank, int *shape, VALUE klass);
154
+ VALUE na_make_scalar(VALUE obj, int type);
155
+ VALUE na_make_empty(int type, VALUE klass);
156
+ int na_get_typecode(VALUE v);
157
+ void na_clear_data(struct NARRAY *ary);
158
+ VALUE na_clone(VALUE self);
159
+ VALUE na_fill(VALUE self, volatile VALUE obj);
160
+ void na_copy_nary(struct NARRAY *dst, struct NARRAY *src);
161
+
162
+ /* na_array.c */
163
+ VALUE na_to_array(VALUE obj);
164
+ VALUE na_make_inspect(VALUE self);
165
+ VALUE na_ary_to_nary(VALUE ary, VALUE klass);
166
+ int na_object_type(VALUE v);
167
+
168
+ VALUE na_cast_object(VALUE obj, int type);
169
+ VALUE na_cast_unless_narray(VALUE obj, int type);
170
+ VALUE na_cast_unless_array(VALUE obj, int type);
171
+ VALUE na_upcast_object(VALUE obj, int type);
172
+ VALUE na_dup_w_type(VALUE obj, int type);
173
+ VALUE na_change_type(VALUE obj, int type);
174
+ VALUE na_upcast_type(VALUE obj, int type);
175
+ VALUE na_to_narray(VALUE obj);
176
+
177
+ /* na_index.c */
178
+ VALUE na_aset(int argc, VALUE *argv, VALUE self);
179
+ VALUE na_aref(int argc, VALUE *argv, VALUE self);
180
+ VALUE na_slice(int argc, VALUE *argv, VALUE self);
181
+ VALUE na_count_true(VALUE self);
182
+ VALUE na_count_false(VALUE self);
183
+ VALUE na_aref_mask(VALUE self, VALUE mask);
184
+ void na_aset_mask(VALUE self, VALUE mask, VALUE v);
185
+
186
+ #endif /* ifndef NARRAY_H */
@@ -0,0 +1,218 @@
1
+ /*
2
+ narray_local.h
3
+ Numerical Array Extention for Ruby
4
+ (C) Copyright 1999-2008 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
+
12
+ typedef int32_t na_index_t;
13
+
14
+ struct slice {
15
+ char *p; /* pointer to data --- used in loop */
16
+ int n; /* n of indices of this rank */
17
+ int pstep; /* = step * stride * elmsz --- set in na_init_slice */
18
+ int pbeg; /* = beg * stride * elmsz --- set in na_init_slice */
19
+ int stride; /* = shape[0]*shape[1]*...*shape[r-1]
20
+ --- set in na_init_slice */
21
+ int step;
22
+ int beg;
23
+ na_index_t *idx; /* NULL if normal step */
24
+ };
25
+
26
+ typedef void (*na_setfunc_t[NA_NTYPES][NA_NTYPES]) ();
27
+ typedef void (*na_func_t[NA_NTYPES]) ();
28
+ typedef void (*na_ufunc_t[NA_NTYPES]) ();
29
+ typedef void (*na_bifunc_t[NA_NTYPES]) ();
30
+ typedef void (*na_mathfunc_t[NA_NTYPES]) ();
31
+ typedef int (*na_sortfunc_t[NA_NTYPES]) (const void *, const void *);
32
+
33
+ /* function arrays */
34
+ extern na_setfunc_t SetFuncs;
35
+ extern na_ufunc_t SwpFuncs;
36
+ extern na_ufunc_t H2NFuncs;
37
+ extern na_ufunc_t H2VFuncs;
38
+ extern na_ufunc_t NegFuncs;
39
+ extern na_ufunc_t RcpFuncs;
40
+ extern na_ufunc_t AbsFuncs;
41
+ extern na_ufunc_t RealFuncs;
42
+ extern na_ufunc_t ImagFuncs;
43
+ extern na_ufunc_t AnglFuncs;
44
+ extern na_ufunc_t ImagMulFuncs;
45
+ extern na_ufunc_t ConjFuncs;
46
+ extern na_ufunc_t FloorFuncs;
47
+ extern na_ufunc_t CeilFuncs;
48
+ extern na_ufunc_t RoundFuncs;
49
+ extern na_ufunc_t ToStrFuncs;
50
+ extern na_ufunc_t InspFuncs;
51
+ extern na_ufunc_t IndGenFuncs;
52
+ extern na_ufunc_t AddUFuncs;
53
+ extern na_ufunc_t SbtUFuncs;
54
+ extern na_ufunc_t MulUFuncs;
55
+ extern na_ufunc_t DivUFuncs;
56
+ extern na_ufunc_t ModUFuncs;
57
+ extern na_bifunc_t AddBFuncs;
58
+ extern na_bifunc_t SbtBFuncs;
59
+ extern na_bifunc_t MulBFuncs;
60
+ extern na_bifunc_t DivBFuncs;
61
+ extern na_bifunc_t MulAddFuncs;
62
+ extern na_bifunc_t MulSbtFuncs;
63
+ extern na_bifunc_t ModBFuncs;
64
+ extern na_bifunc_t BAnFuncs;
65
+ extern na_bifunc_t BOrFuncs;
66
+ extern na_bifunc_t BXoFuncs;
67
+ extern na_ufunc_t BRvFuncs;
68
+ extern na_bifunc_t ImgSetFuncs;
69
+ extern na_setfunc_t PowFuncs;
70
+ extern na_bifunc_t atan2Funcs;
71
+ extern na_bifunc_t CmpFuncs;
72
+ extern na_bifunc_t EqlFuncs;
73
+ extern na_ufunc_t AndFuncs;
74
+ extern na_ufunc_t Or_Funcs;
75
+ extern na_ufunc_t XorFuncs;
76
+ extern na_ufunc_t NotFuncs;
77
+ extern na_ufunc_t MinFuncs;
78
+ extern na_ufunc_t MaxFuncs;
79
+ extern na_sortfunc_t SortFuncs;
80
+ extern na_sortfunc_t SortIdxFuncs;
81
+ extern na_bifunc_t RefMaskFuncs;
82
+ extern na_bifunc_t SetMaskFuncs;
83
+
84
+ /* variables */
85
+
86
+ extern VALUE rb_mNMath;
87
+ extern ID na_id_beg, na_id_end, na_id_exclude_end;
88
+ extern ID na_id_minus, na_id_abs, na_id_power;
89
+ extern ID na_id_compare, na_id_and, na_id_or;
90
+ extern ID na_id_equal;
91
+ extern ID na_id_class_dim;
92
+ extern ID na_id_add, na_id_sbt, na_id_mul, na_id_div, na_id_mod;
93
+ extern ID na_id_real, na_id_imag;
94
+ extern ID na_id_coerce_rev;
95
+ extern ID na_id_new;
96
+ extern ID na_id_Complex;
97
+
98
+ extern const int na_upcast[NA_NTYPES][NA_NTYPES];
99
+ extern const int na_no_cast[NA_NTYPES];
100
+ extern const int na_cast_real[NA_NTYPES];
101
+ extern const int na_cast_comp[NA_NTYPES];
102
+ extern const int na_cast_round[NA_NTYPES];
103
+ extern const int na_cast_byte[NA_NTYPES];
104
+
105
+ extern const char *na_typestring[];
106
+
107
+ extern VALUE cNArrayScalar, cComplex;
108
+
109
+ /* narray.c */
110
+ VALUE na_newdim_ref(int argc, VALUE *argv, VALUE self);
111
+
112
+ /* na_func.c */
113
+ int na_max3(int a, int b, int c);
114
+ void na_shape_max3(int ndim, int *max_shp, int *shp1, int *shp2, int *shp3);
115
+ void na_shape_copy( int ndim, int *shape, struct NARRAY *a );
116
+
117
+ void na_init_slice(struct slice *s, int rank, int *shape, int elmsz);
118
+ void na_set_slice_1obj(int ndim, struct slice *slc, int *shape);
119
+ int na_set_slice_3obj( int ndim,
120
+ struct slice *s1, struct slice *s2, struct slice *s3,
121
+ int *shp1, int *shp2, int *shp3, int *shape );
122
+ void na_loop_general(struct NARRAY *a1, struct NARRAY *a2,
123
+ struct slice *s1, struct slice *s2, void (*func)());
124
+ void na_loop_index_ref(struct NARRAY *a1, struct NARRAY *a2,
125
+ struct slice *s1, struct slice *s2, void (*func)());
126
+
127
+ /* na_index.c */
128
+ void na_aset_slice(struct NARRAY *dst, struct NARRAY *src, struct slice *s1);
129
+ int na_shrink_class(int class_dim, int *shrink);
130
+ VALUE na_shrink_rank(VALUE obj, int class_dim, int *shrink);
131
+
132
+ #define rb_complex_new(r,i) \
133
+ rb_funcall(rb_mKernel, na_id_Complex, 2, rb_float_new(r), rb_float_new(i))
134
+
135
+
136
+ typedef union {
137
+ u_int8_t b[2];
138
+ int16_t s;
139
+ } na_size16_t;
140
+
141
+ typedef union {
142
+ u_int8_t b[4];
143
+ int32_t i;
144
+ float f;
145
+ } na_size32_t;
146
+
147
+ typedef union {
148
+ u_int8_t b[8];
149
+ float f[2];
150
+ double d;
151
+ } na_size64_t;
152
+
153
+ typedef union {
154
+ u_int8_t b[16];
155
+ double d[2];
156
+ } na_size128_t;
157
+
158
+
159
+ #define swap16(d,s) \
160
+ (d).b[0]=(s).b[1];\
161
+ (d).b[1]=(s).b[0];
162
+
163
+ #define swap32(d,s) \
164
+ (d).b[0]=(s).b[3];\
165
+ (d).b[1]=(s).b[2];\
166
+ (d).b[2]=(s).b[1];\
167
+ (d).b[3]=(s).b[0];
168
+
169
+ #define swap64(d,s) \
170
+ (d).b[0]=(s).b[7];\
171
+ (d).b[1]=(s).b[6];\
172
+ (d).b[2]=(s).b[5];\
173
+ (d).b[3]=(s).b[4];\
174
+ (d).b[4]=(s).b[3];\
175
+ (d).b[5]=(s).b[2];\
176
+ (d).b[6]=(s).b[1];\
177
+ (d).b[7]=(s).b[0];
178
+
179
+ #define swap64c(d,s) \
180
+ (d).b[0]=(s).b[3];\
181
+ (d).b[1]=(s).b[2];\
182
+ (d).b[2]=(s).b[1];\
183
+ (d).b[3]=(s).b[0];\
184
+ (d).b[4]=(s).b[7];\
185
+ (d).b[5]=(s).b[6];\
186
+ (d).b[6]=(s).b[5];\
187
+ (d).b[7]=(s).b[4];
188
+
189
+ #define swap128c(d,s) \
190
+ (d).b[0]=(s).b[7];\
191
+ (d).b[1]=(s).b[6];\
192
+ (d).b[2]=(s).b[5];\
193
+ (d).b[3]=(s).b[4];\
194
+ (d).b[4]=(s).b[3];\
195
+ (d).b[5]=(s).b[2];\
196
+ (d).b[6]=(s).b[1];\
197
+ (d).b[7]=(s).b[0];\
198
+ (d).b[8]=(s).b[15];\
199
+ (d).b[9]=(s).b[14];\
200
+ (d).b[10]=(s).b[13];\
201
+ (d).b[11]=(s).b[12];\
202
+ (d).b[12]=(s).b[11];\
203
+ (d).b[13]=(s).b[10];\
204
+ (d).b[14]=(s).b[9];\
205
+ (d).b[15]=(s).b[8];
206
+
207
+ #if !defined RSTRING_LEN
208
+ #define RSTRING_LEN(a) RSTRING(a)->len
209
+ #endif
210
+ #if !defined RSTRING_PTR
211
+ #define RSTRING_PTR(a) RSTRING(a)->ptr
212
+ #endif
213
+ #if !defined RARRAY_LEN
214
+ #define RARRAY_LEN(a) RARRAY(a)->len
215
+ #endif
216
+ #if !defined RARRAY_PTR
217
+ #define RARRAY_PTR(a) RARRAY(a)->ptr
218
+ #endif
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: narray-nmatrix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.1.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Masahiro Tanaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Numerical N-dimensional Array class
14
+ email: masa16.tanaka@gmail.com
15
+ executables: []
16
+ extensions:
17
+ - extconf.rb
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ChangeLog
21
+ - MANIFEST
22
+ - README.en
23
+ - README.ja
24
+ - SPEC.en
25
+ - SPEC.ja
26
+ - depend
27
+ - extconf.rb
28
+ - mkmath.rb
29
+ - mknafunc.rb
30
+ - mkop.rb
31
+ - na_array.c
32
+ - na_func.c
33
+ - na_index.c
34
+ - na_linalg.c
35
+ - na_random.c
36
+ - narray.c
37
+ - narray.def
38
+ - narray.h
39
+ - narray_local.h
40
+ - lib/narray.rb
41
+ - lib/narray_ext.rb
42
+ - lib/narray/narray.rb
43
+ - lib/nmatrix.rb
44
+ homepage: http://narray.rubyforge.org/
45
+ licenses:
46
+ - Ruby
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --title
51
+ - NArray
52
+ - --main
53
+ - NArray
54
+ - --exclude
55
+ - mk.*
56
+ - --exclude
57
+ - extconf\.rb
58
+ - --exclude
59
+ - .*\.h
60
+ - --exclude
61
+ - lib/
62
+ - --exclude
63
+ - .*\.o
64
+ - --exclude
65
+ - narray\.so
66
+ - --exclude
67
+ - narray\.dll
68
+ - --exclude
69
+ - narray\.bundle
70
+ - --exclude
71
+ - narray\.dylib
72
+ - --exclude
73
+ - libnarray\.*
74
+ require_paths:
75
+ - .
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: 1.8.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project: narray
88
+ rubygems_version: 2.0.2
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: N-dimensional Numerical Array class for Ruby
92
+ test_files: []