carray 1.3.7 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (295) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +32 -0
  3. data/LICENSE +22 -0
  4. data/NEWS.md +78 -0
  5. data/README.md +43 -30
  6. data/Rakefile +31 -0
  7. data/TODO.md +17 -0
  8. data/carray.gemspec +21 -31
  9. data/{ca_iter_block.c → ext/ca_iter_block.c} +16 -18
  10. data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +20 -21
  11. data/{ca_iter_window.c → ext/ca_iter_window.c} +12 -14
  12. data/{ca_obj_array.c → ext/ca_obj_array.c} +451 -176
  13. data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +18 -23
  14. data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +12 -16
  15. data/{ca_obj_block.c → ext/ca_obj_block.c} +47 -54
  16. data/{ca_obj_fake.c → ext/ca_obj_fake.c} +10 -12
  17. data/{ca_obj_farray.c → ext/ca_obj_farray.c} +21 -23
  18. data/{ca_obj_field.c → ext/ca_obj_field.c} +30 -32
  19. data/{ca_obj_grid.c → ext/ca_obj_grid.c} +32 -33
  20. data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +11 -13
  21. data/{ca_obj_object.c → ext/ca_obj_object.c} +40 -42
  22. data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +3 -5
  23. data/{ca_obj_refer.c → ext/ca_obj_refer.c} +44 -48
  24. data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +45 -47
  25. data/{ca_obj_select.c → ext/ca_obj_select.c} +4 -6
  26. data/{ca_obj_shift.c → ext/ca_obj_shift.c} +26 -28
  27. data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +26 -28
  28. data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +106 -160
  29. data/{ca_obj_window.c → ext/ca_obj_window.c} +33 -35
  30. data/{carray.h → ext/carray.h} +90 -59
  31. data/{carray_access.c → ext/carray_access.c} +244 -109
  32. data/{carray_attribute.c → ext/carray_attribute.c} +161 -207
  33. data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +1 -3
  34. data/{carray_cast.c → ext/carray_cast.c} +350 -149
  35. data/{carray_cast_func.rb → ext/carray_cast_func.rb} +1 -2
  36. data/{carray_class.c → ext/carray_class.c} +28 -36
  37. data/{carray_conversion.c → ext/carray_conversion.c} +65 -70
  38. data/{carray_copy.c → ext/carray_copy.c} +34 -50
  39. data/{carray_core.c → ext/carray_core.c} +75 -62
  40. data/ext/carray_data_type.c +66 -0
  41. data/{carray_element.c → ext/carray_element.c} +34 -53
  42. data/{carray_generate.c → ext/carray_generate.c} +137 -50
  43. data/{carray_iterator.c → ext/carray_iterator.c} +53 -53
  44. data/{carray_loop.c → ext/carray_loop.c} +77 -106
  45. data/{carray_mask.c → ext/carray_mask.c} +105 -114
  46. data/{carray_math.rb → ext/carray_math.rb} +47 -31
  47. data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +1 -3
  48. data/{carray_numeric.c → ext/carray_numeric.c} +43 -46
  49. data/{carray_operator.c → ext/carray_operator.c} +72 -36
  50. data/{carray_order.c → ext/carray_order.c} +232 -217
  51. data/{carray_sort_addr.c → ext/carray_sort_addr.c} +14 -21
  52. data/{carray_stat.c → ext/carray_stat.c} +6 -8
  53. data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +25 -27
  54. data/{carray_test.c → ext/carray_test.c} +59 -51
  55. data/{carray_undef.c → ext/carray_undef.c} +1 -11
  56. data/{carray_utils.c → ext/carray_utils.c} +12 -4
  57. data/{extconf.rb → ext/extconf.rb} +6 -7
  58. data/{mkmath.rb → ext/mkmath.rb} +14 -4
  59. data/{ruby_carray.c → ext/ruby_carray.c} +20 -8
  60. data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +2 -4
  61. data/{ruby_float_func.c → ext/ruby_float_func.c} +1 -3
  62. data/ext/version.h +16 -0
  63. data/{version.rb → ext/version.rb} +0 -0
  64. data/lib/carray.rb +52 -10
  65. data/lib/carray/{base/autoload.rb → autoload.rb} +48 -8
  66. data/lib/carray/autoload/autoload_base.rb +1 -5
  67. data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
  68. data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
  69. data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
  70. data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
  71. data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
  72. data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
  73. data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
  74. data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
  75. data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
  76. data/lib/carray/autoload/autoload_gem_random.rb +8 -0
  77. data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
  78. data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
  79. data/lib/carray/basic.rb +191 -0
  80. data/lib/carray/broadcast.rb +101 -0
  81. data/lib/carray/compose.rb +315 -0
  82. data/lib/carray/construct.rb +484 -0
  83. data/lib/carray/convert.rb +115 -0
  84. data/lib/carray/info.rb +1 -3
  85. data/lib/carray/{base/inspect.rb → inspect.rb} +9 -11
  86. data/lib/carray/io/imagemagick.rb +2 -4
  87. data/lib/carray/{base/iterator.rb → iterator.rb} +6 -6
  88. data/lib/carray/mask.rb +102 -0
  89. data/lib/carray/{base/math.rb → math.rb} +21 -53
  90. data/lib/carray/math/histogram.rb +8 -10
  91. data/lib/carray/math/recurrence.rb +1 -3
  92. data/lib/carray/mkmf.rb +9 -3
  93. data/lib/carray/object/ca_obj_iterator.rb +1 -3
  94. data/lib/carray/object/ca_obj_link.rb +1 -3
  95. data/lib/carray/object/ca_obj_pack.rb +9 -11
  96. data/lib/carray/obsolete.rb +256 -0
  97. data/lib/carray/ordering.rb +181 -0
  98. data/lib/carray/{base/serialize.rb → serialize.rb} +50 -66
  99. data/lib/carray/string.rb +188 -0
  100. data/lib/carray/{base/struct.rb → struct.rb} +19 -21
  101. data/lib/carray/{io/table.rb → table.rb} +1 -10
  102. data/lib/carray/testing.rb +51 -0
  103. data/lib/carray/time.rb +76 -0
  104. data/lib/carray/transform.rb +109 -0
  105. data/misc/Methods.ja.md +182 -0
  106. data/{NOTE → misc/NOTE} +16 -38
  107. data/spec/Classes/CABitfield_spec.rb +58 -0
  108. data/spec/Classes/CABlockIterator_spec.rb +114 -0
  109. data/spec/Classes/CABlock_spec.rb +205 -0
  110. data/spec/Classes/CAField_spec.rb +39 -0
  111. data/spec/Classes/CAGrid_spec.rb +75 -0
  112. data/spec/Classes/CAMap_spec.rb +0 -0
  113. data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
  114. data/spec/Classes/CAObject_attribute_spec.rb +33 -0
  115. data/spec/Classes/CAObject_spec.rb +33 -0
  116. data/spec/Classes/CARefer_spec.rb +93 -0
  117. data/spec/Classes/CARepeat_spec.rb +65 -0
  118. data/spec/Classes/CASelect_spec.rb +22 -0
  119. data/spec/Classes/CAShift_spec.rb +16 -0
  120. data/spec/Classes/CAStruct_spec.rb +71 -0
  121. data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
  122. data/spec/Classes/CAUnboudRepeat_spec.rb +102 -0
  123. data/spec/Classes/CAWindow_spec.rb +54 -0
  124. data/spec/Classes/CAWrap_spec.rb +8 -0
  125. data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
  126. data/spec/Classes/CScalar_spec.rb +55 -0
  127. data/spec/Features/feature_130_spec.rb +19 -0
  128. data/spec/Features/feature_attributes_spec.rb +280 -0
  129. data/spec/Features/feature_boolean_spec.rb +98 -0
  130. data/spec/Features/feature_broadcast.rb +116 -0
  131. data/spec/Features/feature_cast_function.rb +19 -0
  132. data/spec/Features/feature_cast_spec.rb +33 -0
  133. data/spec/Features/feature_class_spec.rb +84 -0
  134. data/spec/Features/feature_complex_spec.rb +42 -0
  135. data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
  136. data/spec/Features/feature_convert_spec.rb +46 -0
  137. data/spec/Features/feature_copy_spec.rb +123 -0
  138. data/spec/Features/feature_creation_spec.rb +84 -0
  139. data/spec/Features/feature_element_spec.rb +144 -0
  140. data/spec/Features/feature_extream_spec.rb +54 -0
  141. data/spec/Features/feature_generate_spec.rb +74 -0
  142. data/spec/Features/feature_index_spec.rb +69 -0
  143. data/spec/Features/feature_mask_spec.rb +580 -0
  144. data/spec/Features/feature_math_spec.rb +97 -0
  145. data/spec/Features/feature_order_spec.rb +146 -0
  146. data/spec/Features/feature_ref_store_spec.rb +209 -0
  147. data/spec/Features/feature_serialization_spec.rb +125 -0
  148. data/spec/Features/feature_stat_spec.rb +397 -0
  149. data/spec/Features/feature_virtual_spec.rb +48 -0
  150. data/spec/Features/method_eq_spec.rb +81 -0
  151. data/spec/Features/method_is_nan_spec.rb +12 -0
  152. data/spec/Features/method_map_spec.rb +54 -0
  153. data/spec/Features/method_max_with.rb +20 -0
  154. data/spec/Features/method_min_with.rb +19 -0
  155. data/spec/Features/method_ne_spec.rb +18 -0
  156. data/spec/Features/method_project_spec.rb +188 -0
  157. data/spec/Features/method_ref_spec.rb +27 -0
  158. data/spec/Features/method_round_spec.rb +11 -0
  159. data/spec/Features/method_s_linspace_spec.rb +48 -0
  160. data/spec/Features/method_s_span_spec.rb +14 -0
  161. data/spec/Features/method_seq_spec.rb +47 -0
  162. data/spec/Features/method_sort_with.rb +43 -0
  163. data/spec/Features/method_sorted_with.rb +29 -0
  164. data/spec/Features/method_span_spec.rb +42 -0
  165. data/spec/Features/method_wrap_readonly_spec.rb +43 -0
  166. data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
  167. data/spec/spec_all.rb +0 -1
  168. data/utils/convert_test.rb +73 -0
  169. data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
  170. data/{devel → utils}/guess_shape.rb +0 -0
  171. data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
  172. metadata +171 -298
  173. data/COPYING +0 -56
  174. data/GPL +0 -340
  175. data/Gemfile +0 -8
  176. data/Gemfile.lock +0 -33
  177. data/LEGAL +0 -50
  178. data/TODO +0 -5
  179. data/carray_random.c +0 -531
  180. data/ext/calculus/carray_calculus.c +0 -931
  181. data/ext/calculus/carray_interp.c +0 -358
  182. data/ext/calculus/extconf.rb +0 -12
  183. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
  184. data/ext/calculus/lib/math/calculus.rb +0 -119
  185. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
  186. data/ext/fortio/extconf.rb +0 -3
  187. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
  188. data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
  189. data/ext/fortio/lib/fortio.rb +0 -3
  190. data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
  191. data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
  192. data/ext/fortio/lib/fortio/fortran_format.y +0 -215
  193. data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
  194. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
  195. data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
  196. data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
  197. data/ext/fortio/ruby_fortio.c +0 -182
  198. data/ext/fortio/test/test_H.rb +0 -5
  199. data/ext/fortio/test/test_T.rb +0 -7
  200. data/ext/fortio/test/test_fortran_format.rb +0 -86
  201. data/ext/fortio/test/test_namelist.rb +0 -25
  202. data/ext/fortio/test/test_namelist_write.rb +0 -10
  203. data/ext/fortio/test/test_sequential.rb +0 -13
  204. data/ext/fortio/test/test_sequential2.rb +0 -13
  205. data/ext/fortio/work/test.rb +0 -10
  206. data/ext/fortio/work/test_e.rb +0 -19
  207. data/ext/fortio/work/test_ep.rb +0 -10
  208. data/ext/fortio/work/test_parse.rb +0 -12
  209. data/ext/mathfunc/extconf.rb +0 -18
  210. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
  211. data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
  212. data/ext/mathfunc/test/test_hypot.rb +0 -5
  213. data/ext/mathfunc/test/test_j0.rb +0 -22
  214. data/ext/mathfunc/test/test_jn.rb +0 -8
  215. data/ext/mathfunc/test/test_sph.rb +0 -9
  216. data/ext/narray/README +0 -22
  217. data/ext/narray/ca_wrap_narray.c +0 -500
  218. data/ext/narray/carray_narray.c +0 -21
  219. data/ext/narray/extconf.rb +0 -57
  220. data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
  221. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
  222. data/ext/narray/lib/math/narray.rb +0 -17
  223. data/ext/narray/lib/math/narray_miss.rb +0 -45
  224. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
  225. data/lib/carray/autoload/autoload_io_csv.rb +0 -14
  226. data/lib/carray/autoload/autoload_io_numo.rb +0 -9
  227. data/lib/carray/autoload/autoload_io_pg.rb +0 -6
  228. data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
  229. data/lib/carray/autoload/autoload_io_table.rb +0 -1
  230. data/lib/carray/autoload/autoload_math_interp.rb +0 -4
  231. data/lib/carray/base/basic.rb +0 -1090
  232. data/lib/carray/base/obsolete.rb +0 -131
  233. data/lib/carray/graphics/gnuplot.rb +0 -2141
  234. data/lib/carray/graphics/zimg.rb +0 -296
  235. data/lib/carray/io/csv.rb +0 -572
  236. data/lib/carray/io/numo.rb +0 -52
  237. data/lib/carray/io/pg.rb +0 -101
  238. data/lib/carray/io/sqlite3.rb +0 -215
  239. data/lib/carray/math/interp.rb +0 -57
  240. data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
  241. data/mt19937ar.c +0 -182
  242. data/mt19937ar.h +0 -86
  243. data/rdoc_main.rb +0 -27
  244. data/rdoc_math.rb +0 -5
  245. data/rdoc_stat.rb +0 -31
  246. data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
  247. data/spec/CArray/bug/store_spec.rb +0 -27
  248. data/spec/CArray/index/repeat_spec.rb +0 -10
  249. data/spec/CArray/method/eq_spec.rb +0 -80
  250. data/spec/CArray/method/is_nan_spec.rb +0 -12
  251. data/spec/CArray/method/ne_spec.rb +0 -18
  252. data/spec/CArray/method/round_spec.rb +0 -11
  253. data/spec/CArray/object/_attribute_spec.rb +0 -32
  254. data/spec/CArray/object/s_new_spec.rb +0 -31
  255. data/spec/CArray/serialize/Serialization_spec.rb +0 -89
  256. data/test/test_130.rb +0 -23
  257. data/test/test_ALL.rb +0 -51
  258. data/test/test_CABitfield.rb +0 -59
  259. data/test/test_CABlock.rb +0 -208
  260. data/test/test_CAField.rb +0 -40
  261. data/test/test_CAGrid.rb +0 -76
  262. data/test/test_CAMmap.rb +0 -11
  263. data/test/test_CARefer.rb +0 -94
  264. data/test/test_CARepeat.rb +0 -66
  265. data/test/test_CASelect.rb +0 -23
  266. data/test/test_CAShift.rb +0 -17
  267. data/test/test_CAWindow.rb +0 -55
  268. data/test/test_CAWrap.rb +0 -9
  269. data/test/test_CComplex.rb +0 -83
  270. data/test/test_CScalar.rb +0 -91
  271. data/test/test_attribute.rb +0 -281
  272. data/test/test_block_iterator.rb +0 -17
  273. data/test/test_boolean.rb +0 -99
  274. data/test/test_cast.rb +0 -33
  275. data/test/test_class.rb +0 -85
  276. data/test/test_complex.rb +0 -43
  277. data/test/test_convert.rb +0 -79
  278. data/test/test_copy.rb +0 -141
  279. data/test/test_creation.rb +0 -85
  280. data/test/test_element.rb +0 -146
  281. data/test/test_extream.rb +0 -55
  282. data/test/test_generate.rb +0 -75
  283. data/test/test_index.rb +0 -71
  284. data/test/test_mask.rb +0 -578
  285. data/test/test_math.rb +0 -98
  286. data/test/test_narray.rb +0 -64
  287. data/test/test_order.rb +0 -147
  288. data/test/test_random.rb +0 -15
  289. data/test/test_ref_store.rb +0 -211
  290. data/test/test_stat.rb +0 -414
  291. data/test/test_struct.rb +0 -72
  292. data/test/test_virtual.rb +0 -49
  293. data/utils/create_rdoc.sh +0 -9
  294. data/utils/make_tgz.sh +0 -3
  295. data/version.h +0 -18
@@ -1,931 +0,0 @@
1
- /* ---------------------------------------------------------------------------
2
-
3
- carray/carray_calculus.c
4
-
5
- This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
-
9
- Copyright (C) 2005 Hiroki Motoyoshi
10
-
11
- ---------------------------------------------------------------------------- */
12
-
13
- #include "ruby.h"
14
- #include "carray.h"
15
- #include <math.h>
16
- #include <float.h>
17
-
18
- /* ----------------------------------------------------------------- */
19
-
20
- static double
21
- simpson (double *x, double *y, ca_size_t n)
22
- {
23
- double s;
24
-
25
- if ( n < 2 ) {
26
- return 0.0/0.0;
27
- }
28
- else if ( n == 2 ) {
29
- s = (x[1]-x[0])*(y[1]+y[0])*0.5;
30
- return s;
31
- }
32
- else if ( n % 2 == 0 ) {
33
- double x0, x1, x2, x3;
34
- double h, m, a1, a2, c0, c1, c2, c3;
35
- x0 = x[0];
36
- x1 = x[1];
37
- x2 = x[2];
38
- x3 = x[3];
39
- h = x3 - x0;
40
- m = (x3 + x0)/2;
41
- a1 = x1 - m;
42
- a2 = x2 - m;
43
- c0 = 1.0 + 2.0*a1*a2/((x0-x1)*(x0-x2));
44
- c1 = h*h*a2/((x1-x2)*(x1-x0)*(x1-x3));
45
- c2 = h*h*a1/((x2-x1)*(x2-x0)*(x2-x3));
46
- c3 = 1.0 + 2.0*a1*a2/((x3-x1)*(x3-x2));
47
- s = (c0*y[0]+c1*y[1]+c2*y[2]+c3*y[3])*h/6.0;
48
- if ( n > 4 ) {
49
- s += simpson(x+3, y+3, n-3);
50
- }
51
- return s;
52
- }
53
- else {
54
- double x0, x1, x2;
55
- double h, m, c0, c1, c2;
56
- ca_size_t i;
57
- s = 0.0;
58
- for (i=0; i<n-2; i+=2) {
59
- x0 = x[i];
60
- x1 = x[i+1];
61
- x2 = x[i+2];
62
- h = x2-x0;
63
- m = 0.5*(x2+x0);
64
- c0 = 3.0 - h/(x1-x0);
65
- c1 = h*(x2-x0)/((x2-x1)*(x1-x0));
66
- c2 = 3.0 - h/(x2-x1);
67
- s += (c0*y[i]+c1*y[i+1]+c2*y[i+2])*h/6.0;
68
- }
69
- return s;
70
- }
71
- }
72
-
73
- static VALUE
74
- rb_ca_integrate (volatile VALUE self, volatile VALUE vsc)
75
- {
76
- CArray *sc, *ca;
77
- double ans;
78
-
79
- ca = ca_wrap_readonly(self, CA_DOUBLE);
80
- sc = ca_wrap_readonly(vsc, CA_DOUBLE);
81
-
82
- if ( ca->elements != sc->elements ) {
83
- rb_raise(rb_eRuntimeError, "data num mismatch");
84
- }
85
-
86
- if ( ca_is_any_masked(ca) || ca_is_any_masked(sc) ) {
87
- rb_raise(rb_eRuntimeError,
88
- "can't calculate integrattion when masked elements exist");
89
- }
90
-
91
- ca_attach_n(2, ca, sc);
92
-
93
- ans = simpson((double*)sc->ptr, (double*)ca->ptr, ca->elements);
94
-
95
- ca_detach_n(2, ca, sc);
96
-
97
- return rb_float_new(ans);
98
- }
99
-
100
-
101
- /* ----------------------------------------------------------------- */
102
-
103
- static ca_size_t
104
- linear_index (ca_size_t n, double *y, double yy, double *idx)
105
- {
106
- ca_size_t a, b, c, x1;
107
- double ya, yb, yc;
108
- double y1, y2;
109
- double rest;
110
-
111
- if ( yy <= y[0] ) {
112
- x1 = 0;
113
- goto found;
114
- }
115
-
116
- if ( yy >= y[n-1] ) {
117
- x1 = n-2;
118
- goto found;
119
- }
120
-
121
- /* check for equally spaced scale */
122
-
123
- a = (ca_size_t)((yy-y[0])/(y[n-1]-y[0])*(n-1));
124
-
125
- if ( a >= 0 && a < n-1 ) {
126
- if ( (y[a] - yy) * (y[a+1] - yy) <= 0 ) { /* lucky case */
127
- x1 = a;
128
- goto found;
129
- }
130
- }
131
-
132
- /* binary section method */
133
-
134
- a = 0;
135
- b = n-1;
136
-
137
- ya = y[a];
138
- yb = y[b];
139
-
140
- if ( ya > yb ) {
141
- return -1; /* input scale array should have accending order */
142
- }
143
-
144
- while ( (b - a) >= 1 ) {
145
-
146
- c = (a + b)/2;
147
- yc = y[c];
148
- if ( a == c ) {
149
- break;
150
- }
151
-
152
- if ( yc == yy ) {
153
- a = c;
154
- break;
155
- }
156
- else if ( (ya - yy) * (yc - yy) <= 0 ) {
157
- b = c;
158
- yb = yc;
159
- }
160
- else {
161
- a = c;
162
- ya = yc;
163
- }
164
-
165
- if ( ya > yb ) {
166
- return -1; /* input scale array should have accending order */
167
- }
168
- }
169
-
170
- x1 = a;
171
-
172
- found:
173
-
174
- y1 = y[x1];
175
- y2 = y[x1+1];
176
- rest = (yy-y1)/(y2-y1);
177
-
178
- if ( fabs(y2-yy)/fabs(y2) < DBL_EPSILON*100 ) {
179
- *idx = (double) (x1 + 1);
180
- }
181
- else if ( fabs(y1-yy)/fabs(y1) < DBL_EPSILON*100 ) {
182
- *idx = (double) x1;
183
- }
184
- else {
185
- *idx = rest + (double) x1;
186
- }
187
-
188
- return 0;
189
- }
190
-
191
- static VALUE
192
- rb_ca_binary_search_linear_index (volatile VALUE self, volatile VALUE vx)
193
- {
194
- volatile VALUE out, out0;
195
- CArray *ca, *sc, *cx, *co0, *co;
196
- ca_size_t n;
197
- double *x;
198
- double *px;
199
- double *po;
200
- ca_size_t i;
201
-
202
- Data_Get_Struct(self, CArray, ca);
203
-
204
- if ( rb_ca_is_any_masked(self) ) {
205
- rb_raise(rb_eRuntimeError, "self should not have any masked elements");
206
- }
207
-
208
- sc = ca_wrap_readonly(self, CA_FLOAT64);
209
- cx = ca_wrap_readonly(vx, CA_FLOAT64);
210
-
211
- co0 = carray_new(ca->data_type, cx->rank, cx->dim, 0, NULL);
212
- out = out0 = ca_wrap_struct(co0);
213
- co = ca_wrap_writable(out, CA_FLOAT64);
214
-
215
- ca_attach_n(3, sc, cx, co);
216
-
217
- n = sc->elements;
218
- x = (double*) sc->ptr;
219
- px = (double*) cx->ptr;
220
- po = (double*) co->ptr;
221
-
222
- ca_update_mask(cx);
223
- if ( cx->mask ) {
224
- boolean8_t *mx, *mo;
225
- ca_create_mask(co);
226
- mx = (boolean8_t *) cx->mask->ptr;
227
- mo = (boolean8_t *) co->mask->ptr;
228
- for (i=0; i<cx->elements; i++) {
229
- if ( ! *mx ) {
230
- linear_index(n, x, *px, po);
231
- }
232
- else {
233
- *mo = 1;
234
- }
235
- mx++; mo++; px++, po++;
236
- }
237
- }
238
- else {
239
- for (i=0; i<cx->elements; i++) {
240
- linear_index(n, x, *px, po);
241
- px++, po++;
242
- }
243
- }
244
-
245
- ca_sync(co);
246
- ca_detach_n(3, sc, cx, co);
247
-
248
- if ( rb_ca_is_scalar(vx) ) {
249
- return rb_funcall(out0, rb_intern("[]"), 1, INT2NUM(0));
250
- }
251
- else {
252
- return out0;
253
- }
254
- }
255
-
256
- static double
257
- interp_lin (double *x, double *y, double xx)
258
- {
259
- double a, b;
260
- double xa, xb;
261
- double ab;
262
- double fa, fb;
263
- a = x[0];
264
- b = x[1];
265
- fa = y[0];
266
- fb = y[1];
267
- xa = xx - a;
268
- xb = xx - b;
269
- ab = a - b;
270
- return -xa*fb/ab + xb*fa/ab;
271
- }
272
-
273
- static double
274
- deriv_lin (double *x, double *y, double xx)
275
- {
276
- double a, b;
277
- double ab;
278
- double fa, fb;
279
- a = x[0];
280
- b = x[1];
281
- fa = y[0];
282
- fb = y[1];
283
- ab = a - b;
284
- return -fb/ab + fa/ab;
285
- }
286
-
287
- static double
288
- interp_qual (double *x, double *y, double xx)
289
- {
290
- double a, b, c;
291
- double xa, xb, xc;
292
- double ab, bc, ca;
293
- double fa, fb, fc;
294
- a = x[0];
295
- b = x[1];
296
- c = x[2];
297
- fa = y[0];
298
- fb = y[1];
299
- fc = y[2];
300
- xa = xx - a;
301
- xb = xx - b;
302
- xc = xx - c;
303
- ab = a - b;
304
- bc = b - c;
305
- ca = c - a;
306
- return -(xa*xb*fc/ca/bc + xb*xc*fa/ab/ca + xc*xa*fb/bc/ab);
307
- }
308
-
309
- static double
310
- deriv_qual (double *x, double *y, double xx)
311
- {
312
- double a, b, c;
313
- double xa, xb, xc;
314
- double ab, bc, ca;
315
- double fa, fb, fc;
316
- a = x[0];
317
- b = x[1];
318
- c = x[2];
319
- fa = y[0];
320
- fb = y[1];
321
- fc = y[2];
322
- xa = xx - a;
323
- xb = xx - b;
324
- xc = xx - c;
325
- ab = a - b;
326
- bc = b - c;
327
- ca = c - a;
328
- return - (xa+xb)*fc/ca/bc
329
- - (xb+xc)*fa/ab/ca
330
- - (xc+xa)*fb/bc/ab;
331
- }
332
-
333
- static double
334
- interp_cubic (double *x, double *y, double xx)
335
- {
336
- double a, b, c, d;
337
- double xa, xb, xc, xd;
338
- double ab, bc, cd, da, db, ac;
339
- double fa, fb, fc, fd;
340
- a = x[0];
341
- b = x[1];
342
- c = x[2];
343
- d = x[3];
344
- fa = y[0];
345
- fb = y[1];
346
- fc = y[2];
347
- fd = y[3];
348
- xa = xx - a;
349
- xb = xx - b;
350
- xc = xx - c;
351
- xd = xx - d;
352
- ab = a - b;
353
- bc = b - c;
354
- cd = c - d;
355
- da = d - a;
356
- db = d - b;
357
- ac = a - c;
358
- return -xa*xb*xc*fd/da/db/cd - xb*xc*xd*fa/ab/ac/da +
359
- xc*xd*xa*fb/bc/db/ab + xd*xa*xb*fc/cd/ac/bc;
360
- }
361
-
362
- static double
363
- deriv_cubic (double *x, double *y, double xx)
364
- {
365
- double a, b, c, d;
366
- double xa, xb, xc, xd;
367
- double ab, bc, cd, da, db, ac;
368
- double fa, fb, fc, fd;
369
- a = x[0];
370
- b = x[1];
371
- c = x[2];
372
- d = x[3];
373
- fa = y[0];
374
- fb = y[1];
375
- fc = y[2];
376
- fd = y[3];
377
- xa = xx - a;
378
- xb = xx - b;
379
- xc = xx - c;
380
- xd = xx - d;
381
- ab = a - b;
382
- bc = b - c;
383
- cd = c - d;
384
- da = d - a;
385
- db = d - b;
386
- ac = a - c;
387
- return - (xb*xc+xa*xc+xa*xb)*fd/da/db/cd
388
- - (xc*xd+xb*xd+xb*xc)*fa/ab/ac/da
389
- + (xd*xa+xc*xa+xc*xd)*fb/bc/db/ab
390
- + (xa*xb+xd*xb+xd*xa)*fc/cd/ac/bc;
391
- }
392
-
393
- static double
394
- interp_penta (double *x, double *y, double xx)
395
- {
396
- double a, b, c, d, e, f;
397
- double xa, xb, xc, xd, xe, xf;
398
- double ya, yb, yc, yd, ye, yf;
399
- double ab, ac, ad, ae, af;
400
- double bc, bd, be, bf;
401
- double cd, ce, cf;
402
- double de, df;
403
- double ef;
404
- a = x[0];
405
- b = x[1];
406
- c = x[2];
407
- d = x[3];
408
- e = x[4];
409
- f = x[5];
410
- ya = y[0];
411
- yb = y[1];
412
- yc = y[2];
413
- yd = y[3];
414
- ye = y[4];
415
- yf = y[5];
416
- xa = xx - a;
417
- xb = xx - b;
418
- xc = xx - c;
419
- xd = xx - d;
420
- xe = xx - e;
421
- xf = xx - f;
422
- ab = a - b;
423
- ac = a - c;
424
- ad = a - d;
425
- ae = a - e;
426
- af = a - f;
427
- bc = b - c;
428
- bd = b - d;
429
- be = b - e;
430
- bf = b - f;
431
- cd = c - d;
432
- ce = c - e;
433
- cf = c - f;
434
- de = d - e;
435
- df = d - f;
436
- ef = e - f;
437
- return ya*xb*xc*xd*xe*xf/(ab*ac*ad*ae*af)
438
- - xa*yb*xc*xd*xe*xf/(ab*bc*bd*be*bf)
439
- + xa*xb*yc*xd*xe*xf/(ac*bc*cd*ce*cf)
440
- - xa*xb*xc*yd*xe*xf/(ad*bd*cd*de*df)
441
- + xa*xb*xc*xd*ye*xf/(ae*be*ce*de*ef)
442
- - xa*xb*xc*xd*xe*yf/(af*bf*cf*df*ef);
443
- }
444
-
445
-
446
- static double
447
- deriv_penta (double *x, double *y, double xx)
448
- {
449
- double a, b, c, d, e, f;
450
- double xa, xb, xc, xd, xe, xf;
451
- double ya, yb, yc, yd, ye, yf;
452
- double ab, ac, ad, ae, af;
453
- double bc, bd, be, bf;
454
- double cd, ce, cf;
455
- double de, df;
456
- double ef;
457
- a = x[0];
458
- b = x[1];
459
- c = x[2];
460
- d = x[3];
461
- e = x[4];
462
- f = x[5];
463
- ya = y[0];
464
- yb = y[1];
465
- yc = y[2];
466
- yd = y[3];
467
- ye = y[4];
468
- yf = y[5];
469
- xa = xx - a;
470
- xb = xx - b;
471
- xc = xx - c;
472
- xd = xx - d;
473
- xe = xx - e;
474
- xf = xx - f;
475
- ab = a - b;
476
- ac = a - c;
477
- ad = a - d;
478
- ae = a - e;
479
- af = a - f;
480
- bc = b - c;
481
- bd = b - d;
482
- be = b - e;
483
- bf = b - f;
484
- cd = c - d;
485
- ce = c - e;
486
- cf = c - f;
487
- de = d - e;
488
- df = d - f;
489
- ef = e - f;
490
- return (xc*xd*xe*xf+xb*xd*xe*xf+xb*xc*xe*xf+xb*xc*xd*xf+xb*xc*xd*xe)*ya/(ab*ac*ad*ae*af)
491
- - (xc*xd*xe*xf+xa*xd*xe*xf+xa*xc*xe*xf+xa*xc*xd*xf+xa*xc*xd*xe)*yb/(ab*bc*bd*be*bf)
492
- + (xb*xd*xe*xf+xa*xd*xe*xf+xa*xb*xe*xf+xa*xb*xd*xf+xa*xb*xd*xe)*yc/(ac*bc*cd*ce*cf)
493
- - (xb*xc*xe*xf+xa*xc*xe*xf+xa*xb*xe*xf+xa*xb*xc*xf+xa*xb*xc*xe)*yd/(ad*bd*cd*de*df)
494
- + (xb*xc*xd*xf+xa*xc*xd*xf+xa*xb*xd*xf+xa*xb*xc*xf+xa*xb*xc*xd)*ye/(ae*be*ce*de*ef)
495
- - (xb*xc*xd*xe+xa*xc*xd*xe+xa*xb*xd*xe+xa*xb*xc*xe+xa*xb*xc*xd)*yf/(af*bf*cf*df*ef);
496
- }
497
-
498
- static double
499
- interpolate_linear (double *x, double *y, ca_size_t n, double xx)
500
- {
501
- double xt[2];
502
- double ri;
503
- ca_size_t i0;
504
- if ( n == 1) {
505
- return y[0];
506
- }
507
- if ( x != NULL ) {
508
- if ( xx == x[0] ) {
509
- return y[0];
510
- }
511
- if ( xx == x[1] ) {
512
- return y[1];
513
- }
514
- if ( n == 2 ) {
515
- return interp_lin(x, y, xx);
516
- }
517
- linear_index(n, x, xx, &ri);
518
- i0 = floor(ri);
519
- if ( i0 <= 0 ) {
520
- i0 = 0;
521
- }
522
- else if ( i0 + 1 >= n - 1 ) {
523
- i0 = n - 2;
524
- }
525
- return interp_lin(&x[i0], &y[i0], xx);
526
- }
527
- else {
528
- if ( xx == 0 ) {
529
- return y[0];
530
- }
531
- if ( xx == 1 ) {
532
- return y[1];
533
- }
534
- if ( n == 2 ) {
535
- xt[0] = 0.0;
536
- xt[1] = 1.0;
537
- return interp_lin(xt, y, xx);
538
- }
539
- i0 = floor(xx);
540
- if ( i0 <= 0 ) {
541
- i0 = 0;
542
- }
543
- else if ( i0 + 1 >= n - 1 ) {
544
- i0 = n - 2;
545
- }
546
- xt[0] = i0;
547
- xt[1] = i0+1;
548
- return interp_lin(xt, &y[i0], xx);
549
- }
550
- }
551
-
552
- static double
553
- interpolate_cubic (double *x, double *y, ca_size_t n, double xx)
554
- {
555
- static double xt[4];
556
- double ri;
557
- ca_size_t i0;
558
- if ( n == 1) {
559
- return y[0];
560
- }
561
- if ( x != NULL ) {
562
- if ( xx == x[0] ) {
563
- return y[0];
564
- }
565
- if ( xx == x[1] ) {
566
- return y[1];
567
- }
568
- if ( xx == x[2] ) {
569
- return y[2];
570
- }
571
- if ( n == 2 ) {
572
- return interp_lin(x, y, xx);
573
- }
574
- if ( n == 3 ) {
575
- return interp_qual(x, y, xx);
576
- }
577
- linear_index(n, x, xx, &ri);
578
- i0 = floor(ri) - 1;
579
- if ( i0 <= 0 ) {
580
- i0 = 0;
581
- }
582
- else if ( i0 + 3 >= n - 1 ) {
583
- i0 = n - 4;
584
- }
585
- return interp_cubic(&x[i0], &y[i0], xx);
586
- }
587
- else {
588
- if ( xx == 0 ) {
589
- return y[0];
590
- }
591
- if ( xx == 1 ) {
592
- return y[1];
593
- }
594
- if ( xx == 2 ) {
595
- return y[2];
596
- }
597
- if ( n == 2 ) {
598
- xt[0] = 0.0;
599
- xt[1] = 1.0;
600
- return interp_lin(xt, y, xx);
601
- }
602
- if ( n == 3 ) {
603
- xt[0] = 0.0;
604
- xt[1] = 1.0;
605
- xt[2] = 2.0;
606
- return interp_qual(xt, y, xx);
607
- }
608
- ri = xx;
609
- i0 = floor(ri) - 1;
610
- if ( i0 <= 0 ) {
611
- i0 = 0;
612
- }
613
- else if ( i0 + 3 >= n - 1 ) {
614
- i0 = n - 4;
615
- }
616
- xt[0] = i0;
617
- xt[1] = i0+1;
618
- xt[2] = i0+2;
619
- xt[3] = i0+3;
620
- return interp_cubic(xt, &y[i0], xx);
621
- }
622
- }
623
-
624
- static double
625
- differentiate (double *x, double *y, ca_size_t n, double xx)
626
- {
627
- double ri;
628
- ca_size_t i0;
629
- switch ( n ) {
630
- case 1:
631
- return 0.0/0.0;
632
- case 2:
633
- return deriv_lin(x, y, xx);
634
- case 3:
635
- return deriv_qual(x, y, xx);
636
- case 4:
637
- return deriv_cubic(x, y, xx);
638
- }
639
- linear_index(n, x, xx, &ri);
640
- i0 = floor(ri) - 1;
641
- if ( i0 <= 0 ) {
642
- i0 = 0;
643
- }
644
- else if ( n == 5 && i0 + 4 > n - 1 ) {
645
- i0 = n - 5;
646
- }
647
- else if ( i0 + 5 > n - 1 ) {
648
- i0 = n - 6;
649
- }
650
- if ( n == 5 ) {
651
- return deriv_cubic(&x[i0], &y[i0], xx);
652
- }
653
- else {
654
- return deriv_penta(&x[i0], &y[i0], xx);
655
- }
656
- }
657
-
658
- static VALUE
659
- rb_ca_interpolate (int argc, VALUE *argv, VALUE self)
660
- {
661
- volatile VALUE rval = self;
662
- volatile VALUE vsc, vx, ropt, rtype = Qnil, out0, out;
663
- CArray *ca, *sc, *cv, *cx, *co0, *co;
664
- char *typename = NULL;
665
- int type = 0;
666
- double *px, *po;
667
- ca_size_t i;
668
-
669
- Data_Get_Struct(self, CArray, ca);
670
-
671
- rb_scan_args(argc, argv, "21", &vsc, &vx, &ropt);
672
- rb_scan_options(ropt, "type", &rtype);
673
-
674
- if ( ! NIL_P(rtype) ) {
675
- Check_Type(rtype, T_STRING);
676
- typename = StringValuePtr(rtype);
677
- }
678
-
679
- if ( typename == NULL || ! strncmp("cubic", typename, 5) ) {
680
- type = 3;
681
- }
682
- else if ( ! strncmp("linear", typename, 6) ) {
683
- type = 1;
684
- }
685
- else {
686
- volatile VALUE inspect = rb_inspect(rtype);
687
- rb_raise(rb_eRuntimeError,
688
- "invalid interpolation type <%s>", StringValuePtr(inspect));
689
- }
690
-
691
- if ( ! NIL_P(vsc) ) {
692
-
693
- cv = ca_wrap_readonly(rval, CA_DOUBLE);
694
- sc = ca_wrap_readonly(vsc, CA_DOUBLE);
695
-
696
- if ( ca_is_any_masked(cv) || ca_is_any_masked(sc) ) {
697
- rb_raise(rb_eRuntimeError,
698
- "can't calculate interpolation when masked elements exist");
699
- }
700
-
701
- if ( cv->elements != sc->elements ) {
702
- rb_raise(rb_eRuntimeError, "data num mismatch with scale");
703
- }
704
-
705
- cx = ca_wrap_readonly(vx, CA_DOUBLE);
706
-
707
- co0 = carray_new(ca->data_type, cx->rank, cx->dim, 0, NULL);
708
- out = out0 = ca_wrap_struct(co0);
709
- co = ca_wrap_writable(out, CA_DOUBLE);
710
-
711
- ca_attach_n(4, cv, sc, cx, co);
712
-
713
- px = (double*) cx->ptr;
714
- po = (double*) co->ptr;
715
-
716
- ca_update_mask(cx);
717
- if ( cx->mask ) {
718
- boolean8_t *mx, *mo;
719
- ca_create_mask(co);
720
- mx = (boolean8_t *) cx->mask->ptr;
721
- mo = (boolean8_t *) co->mask->ptr;
722
- if ( type == 3 ) {
723
- for (i=0; i<cx->elements; i++) {
724
- if ( ! *mx ) {
725
- *po = interpolate_cubic((double*)sc->ptr, (double*)cv->ptr,
726
- cv->elements, *px);
727
- }
728
- else {
729
- *mo = 1;
730
- }
731
- mx++; mo++; po++; px++;
732
- }
733
- }
734
- else {
735
- for (i=0; i<cx->elements; i++) {
736
- if ( ! *mx ) {
737
- *po = interpolate_linear((double*)sc->ptr, (double*)cv->ptr,
738
- cv->elements, *px);
739
- }
740
- else {
741
- *mo = 1;
742
- }
743
- mx++; mo++; po++; px++;
744
- }
745
- }
746
- }
747
- else {
748
- if ( type == 3 ) {
749
- for (i=0; i<cx->elements; i++) {
750
- *po++ = interpolate_cubic((double*)sc->ptr, (double*)cv->ptr,
751
- cv->elements, *px++);
752
- }
753
- }
754
- else {
755
- for (i=0; i<cx->elements; i++) {
756
- *po++ = interpolate_linear((double*)sc->ptr, (double*)cv->ptr,
757
- cv->elements, *px++);
758
- }
759
- }
760
- }
761
-
762
- ca_sync(co);
763
- ca_detach_n(4, cv, sc, cx, co);
764
-
765
- }
766
- else {
767
-
768
-
769
- cv = ca_wrap_readonly(rval, CA_DOUBLE);
770
-
771
-
772
- if ( ca_is_any_masked(cv) ) {
773
- rb_raise(rb_eRuntimeError,
774
- "can't calculate interpolation when masked elements exist");
775
- }
776
-
777
- cx = ca_wrap_readonly(vx, CA_DOUBLE);
778
-
779
- co0 = carray_new(ca->data_type, cx->rank, cx->dim, 0, NULL);
780
- out = out0 = ca_wrap_struct(co0);
781
- co = ca_wrap_writable(out, CA_DOUBLE);
782
-
783
- ca_attach_n(3, cv, cx, co);
784
-
785
- px = (double*) cx->ptr;
786
- po = (double*) co->ptr;
787
-
788
- ca_update_mask(cx);
789
- if ( cx->mask ) {
790
- boolean8_t *mx, *mo;
791
- ca_create_mask(co);
792
- mx = (boolean8_t *) cx->mask->ptr;
793
- mo = (boolean8_t *) co->mask->ptr;
794
- if ( type == 3 ) {
795
- for (i=0; i<cx->elements; i++) {
796
- if ( ! *mx ) {
797
- *po = interpolate_cubic(NULL, (double*)cv->ptr,
798
- cv->elements, *px);
799
- }
800
- else {
801
- *mo = 1;
802
- }
803
- mx++; mo++; po++; px++;
804
- }
805
- }
806
- else {
807
- for (i=0; i<cx->elements; i++) {
808
- if ( ! *mx ) {
809
- *po = interpolate_linear(NULL, (double*)cv->ptr,
810
- cv->elements, *px);
811
- }
812
- else {
813
- *mo = 1;
814
- }
815
- mx++; mo++; po++; px++;
816
- }
817
- }
818
- }
819
- else {
820
- if ( type == 3 ) {
821
- for (i=0; i<cx->elements; i++) {
822
- *po++ = interpolate_cubic(NULL, (double*)cv->ptr,
823
- cv->elements, *px++);
824
- }
825
- }
826
- else {
827
- for (i=0; i<cx->elements; i++) {
828
- *po++ = interpolate_linear(NULL, (double*)cv->ptr,
829
- cv->elements, *px++);
830
- }
831
- }
832
- }
833
-
834
- ca_sync(co);
835
- ca_detach_n(3, cv, cx, co);
836
-
837
- }
838
-
839
- if ( rb_ca_is_scalar(vx) ) {
840
- return rb_funcall(out0, rb_intern("[]"), 1, INT2NUM(0));
841
- }
842
- else {
843
- return out0;
844
- }
845
- }
846
-
847
- static VALUE
848
- rb_ca_differentiate (volatile VALUE self,
849
- volatile VALUE vsc, volatile VALUE vx)
850
- {
851
- volatile VALUE rval = self;
852
- volatile VALUE out0, out;
853
- CArray *ca, *cv, *sc, *cx, *co0, *co;
854
- double *px, *po;
855
- ca_size_t i;
856
-
857
- Data_Get_Struct(self, CArray, ca);
858
-
859
- sc = ca_wrap_readonly(vsc, CA_DOUBLE);
860
-
861
- if ( ca_is_any_masked(ca) || ca_is_any_masked(sc) ) {
862
- rb_raise(rb_eRuntimeError,
863
- "can't calculate differentiation when masked elements exist");
864
- }
865
-
866
- if ( ca->elements != sc->elements ) {
867
- rb_raise(rb_eRuntimeError, "data num mismatch with scale");
868
- }
869
-
870
- cv = ca_wrap_readonly(rval, CA_DOUBLE);
871
- cx = ca_wrap_readonly(vx, CA_DOUBLE);
872
-
873
- co0 = carray_new(ca->data_type, cx->rank, cx->dim, 0, NULL);
874
- out = out0 = ca_wrap_struct(co0);
875
- co = ca_wrap_writable(out, CA_DOUBLE);
876
-
877
- ca_attach_n(4, cv, sc, cx, co);
878
-
879
- px = (double*) cx->ptr;
880
- po = (double*) co->ptr;
881
-
882
- ca_update_mask(cx);
883
- if ( cx->mask ) {
884
- boolean8_t *mx, *mo;
885
- ca_create_mask(co);
886
- mx = (boolean8_t *) cx->mask->ptr;
887
- mo = (boolean8_t *) co->mask->ptr;
888
- for (i=0; i<cx->elements; i++) {
889
- if ( ! *mx ) {
890
- *po = differentiate((double*)sc->ptr, (double*)cv->ptr,
891
- cv->elements, *px);
892
- }
893
- else {
894
- *mo = 1;
895
- }
896
- mx++; mo++; px++, po++;
897
- }
898
- }
899
- else {
900
- for (i=0; i<cx->elements; i++) {
901
- *po = differentiate((double*)sc->ptr, (double*)cv->ptr,
902
- cv->elements, *px);
903
- px++, po++;
904
- }
905
- }
906
-
907
- ca_sync(co);
908
- ca_detach_n(4, cv, sc, cx, co);
909
-
910
- if ( rb_ca_is_scalar(vx) ) {
911
- return rb_funcall(out0, rb_intern("[]"), 1, INT2NUM(0));
912
- }
913
- else {
914
- return out0;
915
- }
916
- }
917
-
918
- void
919
- Init_carray_interpolate ();
920
-
921
- void
922
- Init_carray_calculus ()
923
- {
924
- rb_define_method(rb_cCArray, "section",
925
- rb_ca_binary_search_linear_index, 1);
926
- rb_define_method(rb_cCArray, "integrate", rb_ca_integrate, 1);
927
- rb_define_method(rb_cCArray, "interpolate", rb_ca_interpolate, -1);
928
- rb_define_method(rb_cCArray, "differentiate", rb_ca_differentiate, 2);
929
-
930
- Init_carray_interpolate();
931
- }