narray 0.5.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/src/ChangeLog +614 -0
  2. data/src/MANIFEST +82 -0
  3. data/src/README.en +54 -0
  4. data/src/README.ja +63 -0
  5. data/src/SPEC.en +300 -0
  6. data/src/SPEC.ja +284 -0
  7. data/src/depend +14 -0
  8. data/src/extconf.rb +111 -0
  9. data/src/lib/narray_ext.rb +211 -0
  10. data/src/lib/nmatrix.rb +244 -0
  11. data/src/mkmath.rb +780 -0
  12. data/src/mknafunc.rb +190 -0
  13. data/src/mkop.rb +638 -0
  14. data/src/na_array.c +644 -0
  15. data/src/na_func.c +1624 -0
  16. data/src/na_index.c +988 -0
  17. data/src/na_linalg.c +616 -0
  18. data/src/na_random.c +409 -0
  19. data/src/narray.c +1308 -0
  20. data/src/narray.def +29 -0
  21. data/src/narray.h +170 -0
  22. data/src/narray_local.h +210 -0
  23. data/src/nimage/README.en +38 -0
  24. data/src/nimage/demo/fits.rb +97 -0
  25. data/src/nimage/demo/fits_convol.rb +28 -0
  26. data/src/nimage/demo/fits_fftdemo.rb +27 -0
  27. data/src/nimage/demo/fitsdemo1.rb +13 -0
  28. data/src/nimage/demo/fitsdemo2.rb +30 -0
  29. data/src/nimage/demo/fitsdemo3.rb +26 -0
  30. data/src/nimage/demo/fitsmorph.rb +39 -0
  31. data/src/nimage/demo/life_na.rb +57 -0
  32. data/src/nimage/demo/mandel.rb +41 -0
  33. data/src/nimage/extconf.rb +12 -0
  34. data/src/nimage/lib/nimage.rb +51 -0
  35. data/src/nimage/nimage.c +328 -0
  36. data/src/speed/add.py +12 -0
  37. data/src/speed/add.rb +8 -0
  38. data/src/speed/add_int.py +12 -0
  39. data/src/speed/add_int.rb +9 -0
  40. data/src/speed/lu.m +14 -0
  41. data/src/speed/lu.rb +22 -0
  42. data/src/speed/mat.m +23 -0
  43. data/src/speed/mat.rb +28 -0
  44. data/src/speed/mul.py +12 -0
  45. data/src/speed/mul.rb +9 -0
  46. data/src/speed/mul2.py +15 -0
  47. data/src/speed/mul2.rb +13 -0
  48. data/src/speed/mul_comp.py +12 -0
  49. data/src/speed/mul_comp.rb +9 -0
  50. data/src/speed/mul_int.py +12 -0
  51. data/src/speed/mul_int.rb +9 -0
  52. data/src/speed/mybench.py +15 -0
  53. data/src/speed/mybench.rb +31 -0
  54. data/src/speed/solve.m +18 -0
  55. data/src/speed/solve.py +16 -0
  56. data/src/speed/solve.rb +21 -0
  57. data/src/test/statistics.rb +22 -0
  58. data/src/test/testarray.rb +20 -0
  59. data/src/test/testbit.rb +27 -0
  60. data/src/test/testcast.rb +14 -0
  61. data/src/test/testcomplex.rb +35 -0
  62. data/src/test/testfftw.rb +16 -0
  63. data/src/test/testindex.rb +11 -0
  64. data/src/test/testindexary.rb +26 -0
  65. data/src/test/testindexset.rb +55 -0
  66. data/src/test/testmask.rb +40 -0
  67. data/src/test/testmath.rb +48 -0
  68. data/src/test/testmath2.rb +46 -0
  69. data/src/test/testmatrix.rb +13 -0
  70. data/src/test/testmatrix2.rb +33 -0
  71. data/src/test/testmatrix3.rb +19 -0
  72. data/src/test/testminmax.rb +46 -0
  73. data/src/test/testobject.rb +29 -0
  74. data/src/test/testpow.rb +19 -0
  75. data/src/test/testrandom.rb +23 -0
  76. data/src/test/testround.rb +11 -0
  77. data/src/test/testsort.rb +37 -0
  78. data/src/test/teststr.rb +13 -0
  79. data/src/test/testtrans.rb +18 -0
  80. data/src/test/testwhere.rb +27 -0
  81. metadata +127 -0
data/src/mknafunc.rb ADDED
@@ -0,0 +1,190 @@
1
+ $type_codes = %w(n B I L F D X C O)
2
+ $data_types =
3
+ %w(none u_int8_t int16_t int32_t float double scomplex dcomplex VALUE)
4
+ $real_types =
5
+ %w(none u_int8_t int16_t int32_t float double float double VALUE)
6
+ $int_types =
7
+ %w(none u_int8_t int16_t int32_t int32_t int32_t scomplex dcomplex VALUE)
8
+ $comp_types =
9
+ %w(none scomplex scomplex scomplex scomplex dcomplex scomplex dcomplex VALUE)
10
+ $swap_types =
11
+ %w(none u_int8_t na_size16_t na_size32_t na_size32_t na_size64_t na_size64_t na_size128_t VALUE)
12
+ $upcast = [
13
+ [ 0, 0, 0, 0, 0, 0, 0, 0, 0],
14
+ [ 0, 1, 2, 3, 4, 5, 6, 7, 8],
15
+ [ 0, 2, 2, 3, 4, 5, 6, 7, 8],
16
+ [ 0, 3, 3, 3, 4, 5, 6, 7, 8],
17
+ [ 0, 4, 4, 4, 4, 5, 6, 7, 8],
18
+ [ 0, 5, 5, 5, 5, 5, 7, 7, 8],
19
+ [ 0, 6, 6, 6, 6, 7, 6, 7, 8],
20
+ [ 0, 7, 7, 7, 7, 7, 7, 7, 8],
21
+ [ 0, 8, 8, 8, 8, 8, 8, 8, 8] ]
22
+ $data_obj = [
23
+ [/[O]/,/[O]/, "
24
+ *p1 = rb_funcall(*p1,#id,1,*p2);"],
25
+ [/[O]/,/[BIL]/,"
26
+ *p1 = rb_funcall(*p1,#id,1,INT2FIX(*p2));"],
27
+ [/[O]/,/[FD]/, "
28
+ *p1 = rb_funcall(*p1,#id,1,rb_float_new(*p2));"],
29
+ [/[O]/,/[XC]/, "
30
+ *p1 = rb_funcall(*p1,#id,1,rb_complex_new(p2->r,p2->i));"],
31
+ [/[BIL]/,/[O]/,"
32
+ *p1 = NUM2INT(rb_funcall(INT2FIX(*p1),#id,1,*p2));"],
33
+ [/[FD]/,/[O]/, "
34
+ *p1 = NUM2DBL(rb_funcall(rb_float_new(*p1),#id,1,*p2));"],
35
+ [/[XC]/,/[O]/, "VALUE v=rb_funcall(rb_complex_new(p1->r,p1->i),#id,1,*p2);
36
+ p1->r = NUM2REAL(v); p1->i = NUM2IMAG(v);"] ]
37
+
38
+
39
+ def mksetfuncs(name,op,id,funcs)
40
+
41
+ print "
42
+ /* ------------------------- #{name} --------------------------- */\n"
43
+ c = $type_codes
44
+ n = $type_codes.size
45
+ td = $data_types
46
+ tr = $real_types
47
+
48
+ # Function Definition
49
+
50
+ for i in 0...n
51
+ for j in 0...n
52
+ funcs.each do |k|
53
+ if c[i]=~k[0] && c[j]=~k[1]
54
+ #if i==j
55
+ # f = "memcpy(p1,p1,sizeof(typed));"
56
+ #else
57
+ f = k[2]
58
+ #end
59
+ f = f.
60
+ gsub(/p1->/,"((#{td[i]}*)p1)->").
61
+ gsub(/p2->/,"((#{td[j]}*)p2)->").
62
+ gsub(/\*p1/,"*(#{td[i]}*)p1").
63
+ gsub(/\*p2/,"*(#{td[j]}*)p2").
64
+ gsub(/#id/,id).
65
+ gsub(/#op/,op).
66
+ gsub(/typed/,td[i]).
67
+ gsub(/typef/,tr[i])
68
+ puts $func_body.
69
+ gsub(/#name/,name).
70
+ sub(/OPERATION/,f).
71
+ gsub(/#CC/,c[i]+c[j])
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ # function pointer array
78
+ print "\nna_setfunc_t "+name+"Funcs = {\n"
79
+ m = []
80
+ for i in 0...n
81
+ l = []
82
+ for j in 0...n
83
+ f = true
84
+ for k in funcs
85
+ if c[i]=~k[0] && c[j]=~k[1]
86
+ l += [name+c[i]+c[j]]
87
+ f = false
88
+ break
89
+ end
90
+ end
91
+ if f
92
+ l += ['TpErr']
93
+ end
94
+ end
95
+ m += [' { '+l.join(', ')+' }']
96
+ end
97
+ print m.join(",\n")+"\n};\n"
98
+
99
+ end
100
+
101
+
102
+
103
+ def mkfuncs(name,t1,t2,func)
104
+
105
+ print "
106
+ /* ------------------------- #{name} --------------------------- */\n"
107
+ c = $type_codes
108
+ td = $data_types
109
+ tr = $real_types
110
+
111
+ for i in 0...c.size
112
+ if func[i] != nil && func[i] != "copy"
113
+ f = func[i].
114
+ gsub(/p1->/,"((#{t1[i]}*)p1)->").
115
+ gsub(/p2->/,"((#{t2[i]}*)p2)->").
116
+ gsub(/p3->/,"((#{t2[i]}*)p3)->").
117
+ gsub(/\*p1/,"*(#{t1[i]}*)p1").
118
+ gsub(/\*p2/,"*(#{t2[i]}*)p2").
119
+ gsub(/\*p3/,"*(#{t2[i]}*)p3").
120
+ gsub(/type1/,td[i]).
121
+ gsub(/typef/,tr[i])
122
+ puts $func_body.
123
+ gsub(/#name/,name).
124
+ sub(/OPERATION/,f).
125
+ gsub(/#C/,c[i])
126
+ end
127
+ end
128
+
129
+ # Function Array
130
+
131
+ print "\nna_func_t #{name}Funcs =\n{ "
132
+ m = []
133
+ for i in 0...c.size
134
+ if func[i] == nil
135
+ m += ['TpErr']
136
+ elsif func[i]=='copy'
137
+ m += ['Set'+c[$data_types.index(t1[i])]+c[i]]
138
+ else
139
+ m += [name+c[i]]
140
+ end
141
+ end
142
+ print m.join(", ")+" };\n"
143
+
144
+ end
145
+
146
+
147
+
148
+ def mksortfuncs(bsname,t1,t2,func)
149
+
150
+ print "
151
+ /* ------------------------- #{bsname} --------------------------- */\n"
152
+ c = $type_codes
153
+ tf = $real_types
154
+ name = bsname
155
+
156
+ # Function Definition
157
+ head = "static int #{name}#code(const void *p1, const void *p2)"
158
+ for i in 0...c.size
159
+ if func[i] != nil && func[i]=~/^\{/
160
+ f = func[i].
161
+ gsub(/p1->/,"((#{t1[i]}*)p1)->").
162
+ gsub(/p2->/,"((#{t2[i]}*)p2)->").
163
+ gsub(/\*\*p1/,"**(#{t1[i]}**)p1").
164
+ gsub(/\*\*p2/,"**(#{t2[i]}**)p2").
165
+ gsub(/\*p1/,"*(#{t1[i]}*)p1").
166
+ gsub(/\*p2/,"*(#{t2[i]}*)p2").
167
+ gsub(/typef/,tf[i])
168
+ puts( (head+f).gsub(/#code/,c[i]) )
169
+ end
170
+ end
171
+
172
+ # Function Array
173
+
174
+ print "\nna_sortfunc_t #{name}Funcs =\n{ "
175
+ m = []
176
+ for i in 0...c.size
177
+ if func[i] == nil
178
+ m += ['(int (*)(const void *, const void *))TpErrI']
179
+ elsif func[i]=='copy'
180
+ m += ['Set'+c[i]*2]
181
+ elsif !( func[i] =~ /^\{/ )
182
+ m += [func[i]]
183
+ else
184
+ m += [name+c[i]]
185
+ end
186
+ end
187
+ print m.join(", ")+" };\n"
188
+
189
+ end
190
+