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.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +47 -0
- data/Rakefile +41 -0
- data/ext/numo/narray/SFMT-params.h +97 -0
- data/ext/numo/narray/SFMT-params19937.h +46 -0
- data/ext/numo/narray/SFMT.c +620 -0
- data/ext/numo/narray/SFMT.h +157 -0
- data/ext/numo/narray/array.c +525 -0
- data/ext/numo/narray/data.c +901 -0
- data/ext/numo/narray/depend.erb +33 -0
- data/ext/numo/narray/extconf.rb +117 -0
- data/ext/numo/narray/gen/bit.erb.c +811 -0
- data/ext/numo/narray/gen/cogen.rb +18 -0
- data/ext/numo/narray/gen/def/dcomplex.rb +32 -0
- data/ext/numo/narray/gen/def/dfloat.rb +30 -0
- data/ext/numo/narray/gen/def/int16.rb +29 -0
- data/ext/numo/narray/gen/def/int32.rb +29 -0
- data/ext/numo/narray/gen/def/int64.rb +29 -0
- data/ext/numo/narray/gen/def/int8.rb +29 -0
- data/ext/numo/narray/gen/def/robject.rb +30 -0
- data/ext/numo/narray/gen/def/scomplex.rb +32 -0
- data/ext/numo/narray/gen/def/sfloat.rb +30 -0
- data/ext/numo/narray/gen/def/uint16.rb +29 -0
- data/ext/numo/narray/gen/def/uint32.rb +29 -0
- data/ext/numo/narray/gen/def/uint64.rb +29 -0
- data/ext/numo/narray/gen/def/uint8.rb +29 -0
- data/ext/numo/narray/gen/dtype.erb.c +328 -0
- data/ext/numo/narray/gen/tmpl/accum.c +36 -0
- data/ext/numo/narray/gen/tmpl/accum_binary.c +75 -0
- data/ext/numo/narray/gen/tmpl/accum_index.c +58 -0
- data/ext/numo/narray/gen/tmpl/allocate.c +35 -0
- data/ext/numo/narray/gen/tmpl/aref.c +51 -0
- data/ext/numo/narray/gen/tmpl/aset.c +61 -0
- data/ext/numo/narray/gen/tmpl/binary.c +53 -0
- data/ext/numo/narray/gen/tmpl/binary2.c +55 -0
- data/ext/numo/narray/gen/tmpl/binary_s.c +34 -0
- data/ext/numo/narray/gen/tmpl/bit_binary.c +94 -0
- data/ext/numo/narray/gen/tmpl/bit_count.c +82 -0
- data/ext/numo/narray/gen/tmpl/bit_unary.c +77 -0
- data/ext/numo/narray/gen/tmpl/cast.c +37 -0
- data/ext/numo/narray/gen/tmpl/cast_array.c +79 -0
- data/ext/numo/narray/gen/tmpl/cast_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl/coerce_cast.c +8 -0
- data/ext/numo/narray/gen/tmpl/cond_binary.c +51 -0
- data/ext/numo/narray/gen/tmpl/cond_unary.c +45 -0
- data/ext/numo/narray/gen/tmpl/cum.c +42 -0
- data/ext/numo/narray/gen/tmpl/each.c +43 -0
- data/ext/numo/narray/gen/tmpl/each_with_index.c +64 -0
- data/ext/numo/narray/gen/tmpl/extract.c +23 -0
- data/ext/numo/narray/gen/tmpl/eye.c +91 -0
- data/ext/numo/narray/gen/tmpl/fill.c +38 -0
- data/ext/numo/narray/gen/tmpl/format.c +60 -0
- data/ext/numo/narray/gen/tmpl/format_to_a.c +47 -0
- data/ext/numo/narray/gen/tmpl/head.c +25 -0
- data/ext/numo/narray/gen/tmpl/inspect.c +16 -0
- data/ext/numo/narray/gen/tmpl/map_with_index.c +94 -0
- data/ext/numo/narray/gen/tmpl/median.c +44 -0
- data/ext/numo/narray/gen/tmpl/minmax.c +47 -0
- data/ext/numo/narray/gen/tmpl/poly.c +49 -0
- data/ext/numo/narray/gen/tmpl/pow.c +74 -0
- data/ext/numo/narray/gen/tmpl/powint.c +17 -0
- data/ext/numo/narray/gen/tmpl/qsort.c +149 -0
- data/ext/numo/narray/gen/tmpl/rand.c +33 -0
- data/ext/numo/narray/gen/tmpl/rand_norm.c +46 -0
- data/ext/numo/narray/gen/tmpl/robj_allocate.c +32 -0
- data/ext/numo/narray/gen/tmpl/seq.c +61 -0
- data/ext/numo/narray/gen/tmpl/set2.c +56 -0
- data/ext/numo/narray/gen/tmpl/sort.c +36 -0
- data/ext/numo/narray/gen/tmpl/sort_index.c +86 -0
- data/ext/numo/narray/gen/tmpl/store.c +31 -0
- data/ext/numo/narray/gen/tmpl/store_array.c +5 -0
- data/ext/numo/narray/gen/tmpl/store_from.c +53 -0
- data/ext/numo/narray/gen/tmpl/store_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl/to_a.c +41 -0
- data/ext/numo/narray/gen/tmpl/unary.c +58 -0
- data/ext/numo/narray/gen/tmpl/unary2.c +58 -0
- data/ext/numo/narray/gen/tmpl/unary_s.c +57 -0
- data/ext/numo/narray/index.c +822 -0
- data/ext/numo/narray/kwarg.c +79 -0
- data/ext/numo/narray/math.c +140 -0
- data/ext/numo/narray/narray.c +1539 -0
- data/ext/numo/narray/ndloop.c +1928 -0
- data/ext/numo/narray/numo/compat.h +23 -0
- data/ext/numo/narray/numo/intern.h +112 -0
- data/ext/numo/narray/numo/narray.h +411 -0
- data/ext/numo/narray/numo/ndloop.h +99 -0
- data/ext/numo/narray/numo/template.h +140 -0
- data/ext/numo/narray/numo/types/bit.h +19 -0
- data/ext/numo/narray/numo/types/complex.h +410 -0
- data/ext/numo/narray/numo/types/complex_macro.h +205 -0
- data/ext/numo/narray/numo/types/dcomplex.h +11 -0
- data/ext/numo/narray/numo/types/dfloat.h +12 -0
- data/ext/numo/narray/numo/types/float_def.h +34 -0
- data/ext/numo/narray/numo/types/float_macro.h +277 -0
- data/ext/numo/narray/numo/types/int16.h +12 -0
- data/ext/numo/narray/numo/types/int32.h +12 -0
- data/ext/numo/narray/numo/types/int64.h +12 -0
- data/ext/numo/narray/numo/types/int8.h +12 -0
- data/ext/numo/narray/numo/types/int_macro.h +34 -0
- data/ext/numo/narray/numo/types/robj_macro.h +218 -0
- data/ext/numo/narray/numo/types/robject.h +21 -0
- data/ext/numo/narray/numo/types/scomplex.h +11 -0
- data/ext/numo/narray/numo/types/sfloat.h +13 -0
- data/ext/numo/narray/numo/types/uint16.h +12 -0
- data/ext/numo/narray/numo/types/uint32.h +12 -0
- data/ext/numo/narray/numo/types/uint64.h +12 -0
- data/ext/numo/narray/numo/types/uint8.h +12 -0
- data/ext/numo/narray/numo/types/uint_macro.h +31 -0
- data/ext/numo/narray/numo/types/xint_macro.h +133 -0
- data/ext/numo/narray/rand.c +87 -0
- data/ext/numo/narray/step.c +506 -0
- data/ext/numo/narray/struct.c +872 -0
- data/lib/2.1/numo/narray.so +0 -0
- data/lib/2.2/numo/narray.so +0 -0
- data/lib/2.3/numo/narray.so +0 -0
- data/lib/erbpp/line_number.rb +126 -0
- data/lib/erbpp/narray_def.rb +338 -0
- data/lib/erbpp.rb +286 -0
- data/lib/numo/narray.rb +6 -0
- data/numo-narray.gemspec +35 -0
- data/spec/bit_spec.rb +93 -0
- data/spec/narray_spec.rb +249 -0
- metadata +238 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
/*
|
2
|
+
kwarg.c : Process keyword arguments for Ruby
|
3
|
+
|
4
|
+
Copyright (c) 2001 Masahiro TANAKA <masa@ir.isas.ac.jp>
|
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
|
+
#include <ruby.h>
|
12
|
+
#include "numo/compat.h"
|
13
|
+
|
14
|
+
/* void rb_scan_kw_args __((VALUE, ...)); */
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
kw_hash_i(i, tmp)
|
18
|
+
VALUE i, tmp;
|
19
|
+
{
|
20
|
+
VALUE key;
|
21
|
+
|
22
|
+
key = RARRAY_AREF(i,0);
|
23
|
+
if (TYPE(key)==T_SYMBOL) {
|
24
|
+
key = rb_funcall(key, rb_intern("id2name"), 0);
|
25
|
+
} else
|
26
|
+
if (TYPE(key)!=T_STRING) {
|
27
|
+
rb_raise(rb_eArgError, "keywords must be String or Symbol");
|
28
|
+
}
|
29
|
+
|
30
|
+
rb_hash_aset(tmp, key, RARRAY_AREF(i,1));
|
31
|
+
return Qnil;
|
32
|
+
}
|
33
|
+
|
34
|
+
#ifdef HAVE_STDARG_PROTOTYPES
|
35
|
+
#include <stdarg.h>
|
36
|
+
#define va_init_list(a,b) va_start(a,b)
|
37
|
+
#else
|
38
|
+
#include <varargs.h>
|
39
|
+
#define va_init_list(a,b) va_start(a)
|
40
|
+
#endif
|
41
|
+
|
42
|
+
void
|
43
|
+
#ifdef HAVE_STDARG_PROTOTYPES
|
44
|
+
rb_scan_kw_args(VALUE hash, ...)
|
45
|
+
#else
|
46
|
+
rb_scan_kw_args(hash, va_alist)
|
47
|
+
VALUE hash;
|
48
|
+
va_dcl
|
49
|
+
#endif
|
50
|
+
{
|
51
|
+
va_list vargs;
|
52
|
+
va_init_list(vargs, hash);
|
53
|
+
|
54
|
+
char *key;
|
55
|
+
VALUE *var, val, str, tmp;
|
56
|
+
|
57
|
+
tmp = rb_hash_new();
|
58
|
+
if (TYPE(hash) == T_HASH)
|
59
|
+
rb_iterate(rb_each, hash, kw_hash_i, tmp);
|
60
|
+
else if (hash != Qnil)
|
61
|
+
rb_fatal("rb_san_kw_args: non-hash arg passed");
|
62
|
+
|
63
|
+
for (;;) {
|
64
|
+
key = va_arg(vargs, char*);
|
65
|
+
if (!key) break;
|
66
|
+
var = va_arg(vargs, VALUE*);
|
67
|
+
//printf("i=%d key=%x, val=%x\n",i,key,val);
|
68
|
+
str = rb_str_new2(key);
|
69
|
+
val = rb_funcall(tmp, rb_intern("delete"), 1, str);
|
70
|
+
if (var) *var = val;
|
71
|
+
}
|
72
|
+
va_end(vargs);
|
73
|
+
|
74
|
+
if (rb_funcall(tmp, rb_intern("empty?"), 0)==Qfalse) {
|
75
|
+
val = rb_funcall(tmp, rb_intern("keys"), 0);
|
76
|
+
val = rb_funcall(val, rb_intern("join"), 1, rb_str_new2(","));
|
77
|
+
rb_raise(rb_eArgError, "unknown keywords: %s",StringValueCStr(val));
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1,140 @@
|
|
1
|
+
/*
|
2
|
+
math.c
|
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
|
+
#include <ruby.h>
|
12
|
+
#include "numo/narray.h"
|
13
|
+
|
14
|
+
VALUE numo_mNMath;
|
15
|
+
EXTERN VALUE numo_mDFloatMath, numo_mDComplexMath;
|
16
|
+
static ID id_send;
|
17
|
+
|
18
|
+
VALUE
|
19
|
+
nary_type_s_upcast(VALUE type1, VALUE type2)
|
20
|
+
{
|
21
|
+
VALUE upcast_hash;
|
22
|
+
VALUE result_type;
|
23
|
+
|
24
|
+
if (type1==type2) return type1;
|
25
|
+
upcast_hash = rb_const_get(type1, rb_intern("UPCAST"));
|
26
|
+
result_type = rb_hash_aref(upcast_hash, type2);
|
27
|
+
if (NIL_P(result_type)) {
|
28
|
+
if (TYPE(type2)==T_CLASS) {
|
29
|
+
if ( RTEST(rb_class_inherited_p(type2,cNArray)) ) {
|
30
|
+
upcast_hash = rb_const_get(type2, rb_intern("UPCAST"));
|
31
|
+
result_type = rb_hash_aref(upcast_hash, type1);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return result_type;
|
36
|
+
}
|
37
|
+
|
38
|
+
|
39
|
+
VALUE nary_math_cast2(VALUE type1, VALUE type2)
|
40
|
+
{
|
41
|
+
if ( RTEST(rb_class_inherited_p( type1, cNArray )) ){
|
42
|
+
return nary_type_s_upcast( type1, type2 );
|
43
|
+
}
|
44
|
+
if ( RTEST(rb_class_inherited_p( type2, cNArray )) ){
|
45
|
+
return nary_type_s_upcast( type2, type1 );
|
46
|
+
}
|
47
|
+
if ( RTEST(rb_class_inherited_p( type1, rb_cNumeric )) &&
|
48
|
+
RTEST(rb_class_inherited_p( type2, rb_cNumeric )) ){
|
49
|
+
if ( RTEST(rb_class_inherited_p( type1, rb_cComplex)) ||
|
50
|
+
RTEST(rb_class_inherited_p( type2, rb_cComplex )) ){
|
51
|
+
return rb_cComplex;
|
52
|
+
}
|
53
|
+
return rb_cFloat;
|
54
|
+
}
|
55
|
+
return type2;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
VALUE na_ary_composition_dtype(VALUE);
|
60
|
+
|
61
|
+
VALUE nary_mathcast(int argc, VALUE *argv)
|
62
|
+
{
|
63
|
+
VALUE type, type2;
|
64
|
+
int i;
|
65
|
+
type = na_ary_composition_dtype(argv[0]);
|
66
|
+
for (i=1; i<argc; i++) {
|
67
|
+
type2 = na_ary_composition_dtype(argv[i]);
|
68
|
+
type = nary_math_cast2(type, type2);
|
69
|
+
if (NIL_P(type)) {
|
70
|
+
rb_raise(rb_eTypeError,"%s is unknown for Numo::NMath",
|
71
|
+
rb_class2name(argv[i]));
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return type;
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
/*
|
79
|
+
Dispatches method to Math module of upcasted type,
|
80
|
+
eg, Numo::DFloat::Math.
|
81
|
+
@overload method_missing(name,x,...)
|
82
|
+
@param [Symbol] name method name.
|
83
|
+
@param [NArray,Numeric] x input array.
|
84
|
+
@return [NArray] result.
|
85
|
+
*/
|
86
|
+
VALUE nary_math_method_missing(int argc, VALUE *argv, VALUE mod)
|
87
|
+
{
|
88
|
+
VALUE type, ans, typemod, hash;
|
89
|
+
if (argc>1) {
|
90
|
+
type = nary_mathcast(argc-1,argv+1);
|
91
|
+
|
92
|
+
hash = rb_const_get(mod, rb_intern("DISPATCH"));
|
93
|
+
typemod = rb_hash_aref( hash, type );
|
94
|
+
if (NIL_P(typemod)) {
|
95
|
+
rb_raise(rb_eTypeError,"%s is unknown for Numo::NMath",
|
96
|
+
rb_class2name(type));
|
97
|
+
}
|
98
|
+
|
99
|
+
ans = rb_funcall2(typemod,id_send,argc,argv);
|
100
|
+
|
101
|
+
if (!RTEST(rb_class_inherited_p(type,cNArray)) &&
|
102
|
+
IsNArray(ans) ) {
|
103
|
+
ans = rb_funcall(ans,rb_intern("extract"),0);
|
104
|
+
}
|
105
|
+
return ans;
|
106
|
+
}
|
107
|
+
rb_raise(rb_eArgError,"argument or method missing");
|
108
|
+
return Qnil;
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
void
|
113
|
+
Init_nary_math()
|
114
|
+
{
|
115
|
+
VALUE hCast;
|
116
|
+
|
117
|
+
numo_mNMath = rb_define_module_under(mNumo, "NMath");
|
118
|
+
rb_define_singleton_method(numo_mNMath, "method_missing", nary_math_method_missing, -1);
|
119
|
+
|
120
|
+
hCast = rb_hash_new();
|
121
|
+
rb_define_const(numo_mNMath, "DISPATCH", hCast);
|
122
|
+
rb_hash_aset(hCast, numo_cInt64, numo_mDFloatMath);
|
123
|
+
rb_hash_aset(hCast, numo_cInt32, numo_mDFloatMath);
|
124
|
+
rb_hash_aset(hCast, numo_cInt16, numo_mDFloatMath);
|
125
|
+
rb_hash_aset(hCast, numo_cInt8, numo_mDFloatMath);
|
126
|
+
rb_hash_aset(hCast, numo_cUInt64, numo_mDFloatMath);
|
127
|
+
rb_hash_aset(hCast, numo_cUInt32, numo_mDFloatMath);
|
128
|
+
rb_hash_aset(hCast, numo_cUInt16, numo_mDFloatMath);
|
129
|
+
rb_hash_aset(hCast, numo_cUInt8, numo_mDFloatMath);
|
130
|
+
rb_hash_aset(hCast, numo_cDFloat, numo_mDFloatMath);
|
131
|
+
rb_hash_aset(hCast, numo_cDFloat, numo_mDFloatMath);
|
132
|
+
rb_hash_aset(hCast, numo_cDComplex, numo_mDComplexMath);
|
133
|
+
rb_hash_aset(hCast, rb_cFixnum, rb_mMath);
|
134
|
+
rb_hash_aset(hCast, rb_cBignum, rb_mMath);
|
135
|
+
rb_hash_aset(hCast, rb_cInteger, rb_mMath);
|
136
|
+
rb_hash_aset(hCast, rb_cFloat, rb_mMath);
|
137
|
+
rb_hash_aset(hCast, rb_cComplex, numo_mDComplexMath);
|
138
|
+
|
139
|
+
id_send = rb_intern("send");
|
140
|
+
}
|