carray 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +5 -25
  3. data/CHANGELOG.md +16 -0
  4. data/LICENSE +1 -1
  5. data/NEWS.md +3 -0
  6. data/README.md +128 -44
  7. data/carray.gemspec +22 -24
  8. data/ext/ca_array_pool.c +91 -0
  9. data/ext/ca_axis_descriptor.h +186 -0
  10. data/ext/ca_axis_dispatch.c +924 -0
  11. data/ext/ca_axis_group.c +1208 -0
  12. data/ext/ca_bincmp_dispatch.c +76 -0
  13. data/ext/ca_bincmp_dispatch.h +85 -0
  14. data/ext/ca_binop_dispatch.c +125 -0
  15. data/ext/ca_binop_dispatch.h +159 -0
  16. data/ext/ca_categorical_iterator.c +1375 -0
  17. data/ext/ca_compare.c +94 -0
  18. data/ext/ca_compare.h +26 -0
  19. data/ext/ca_composite_dispatch.c +414 -0
  20. data/ext/ca_composite_dispatch.h +116 -0
  21. data/ext/ca_for_buffer.h +96 -0
  22. data/ext/ca_for_each_element.h +241 -0
  23. data/ext/ca_group_iter.c +304 -0
  24. data/ext/ca_iter_substrate.h +325 -0
  25. data/ext/ca_kernel_iterator.c +4321 -0
  26. data/ext/ca_kernel_iterator.h +2603 -0
  27. data/ext/ca_moncmp_dispatch.c +37 -0
  28. data/ext/ca_moncmp_dispatch.h +62 -0
  29. data/ext/ca_monop_dispatch.c +200 -0
  30. data/ext/ca_monop_dispatch.h +235 -0
  31. data/ext/ca_obj_array.c +355 -359
  32. data/ext/ca_obj_bincmp.c +809 -0
  33. data/ext/ca_obj_binop.c +892 -0
  34. data/ext/ca_obj_bitarray.c +369 -164
  35. data/ext/ca_obj_bitfield.c +294 -234
  36. data/ext/ca_obj_block.c +189 -711
  37. data/ext/ca_obj_byte_swap.c +766 -0
  38. data/ext/ca_obj_const_string.c +965 -0
  39. data/ext/ca_obj_face.c +670 -0
  40. data/ext/ca_obj_face.h +247 -0
  41. data/ext/ca_obj_fake.c +228 -100
  42. data/ext/ca_obj_farray.c +54 -441
  43. data/ext/ca_obj_field.c +82 -529
  44. data/ext/ca_obj_fixlen_string.c +306 -0
  45. data/ext/ca_obj_grid.c +858 -440
  46. data/ext/ca_obj_meld.c +1034 -0
  47. data/ext/ca_obj_moncmp.c +569 -0
  48. data/ext/ca_obj_monop.c +1111 -0
  49. data/ext/ca_obj_object.c +774 -298
  50. data/ext/ca_obj_record.c +468 -0
  51. data/ext/ca_obj_reduce.c +97 -82
  52. data/ext/ca_obj_refer.c +569 -459
  53. data/ext/ca_obj_remap.c +475 -0
  54. data/ext/ca_obj_repeat.c +92 -477
  55. data/ext/ca_obj_roll.c +616 -0
  56. data/ext/ca_obj_select.c +344 -296
  57. data/ext/ca_obj_select_axis.c +1296 -0
  58. data/ext/ca_obj_shift.c +230 -792
  59. data/ext/ca_obj_source.c +78 -0
  60. data/ext/ca_obj_stack.c +1173 -0
  61. data/ext/ca_obj_stride.c +2501 -0
  62. data/ext/ca_obj_string.c +268 -0
  63. data/ext/ca_obj_tile.c +614 -0
  64. data/ext/ca_obj_time.c +546 -0
  65. data/ext/ca_obj_timedelta.c +435 -0
  66. data/ext/ca_obj_transpose.c +62 -516
  67. data/ext/ca_obj_triop.c +746 -0
  68. data/ext/ca_obj_unbound_repeat.c +208 -241
  69. data/ext/ca_obj_window.c +1131 -563
  70. data/ext/ca_op_byte_swap.c +175 -0
  71. data/ext/ca_op_ipower.c +319 -0
  72. data/ext/ca_op_powi.h +88 -0
  73. data/ext/ca_sort_kernels.h +132 -0
  74. data/ext/ca_sweep_engine.c +430 -0
  75. data/ext/ca_sweep_engine.h +157 -0
  76. data/ext/ca_transform_common.c +228 -0
  77. data/ext/ca_triop_dispatch.c +55 -0
  78. data/ext/ca_triop_dispatch.h +62 -0
  79. data/ext/carray.h +795 -402
  80. data/ext/carray_access.c +831 -711
  81. data/ext/carray_attribute.c +98 -330
  82. data/ext/carray_bincount.c +255 -0
  83. data/ext/carray_broadcast.c +283 -0
  84. data/ext/carray_call_cfunc.c +1360 -828
  85. data/ext/carray_call_cfunc.h +160 -0
  86. data/ext/carray_cast.c +1212 -301
  87. data/ext/carray_cast_func.rb +81 -40
  88. data/ext/carray_class.c +53 -63
  89. data/ext/carray_config.h +28 -0
  90. data/ext/carray_conversion.c +350 -346
  91. data/ext/carray_copy.c +156 -268
  92. data/ext/carray_core.c +1342 -199
  93. data/ext/carray_count.c +312 -0
  94. data/ext/carray_data_type.c +43 -19
  95. data/ext/carray_element.c +585 -213
  96. data/ext/carray_factorize.c +2542 -0
  97. data/ext/carray_generate.c +230 -559
  98. data/ext/carray_histogram.c +490 -0
  99. data/ext/carray_hold.c +228 -0
  100. data/ext/carray_index_classifier.c +1035 -0
  101. data/ext/carray_index_classifier.h +27 -0
  102. data/ext/carray_internal.h +120 -0
  103. data/ext/carray_kernels_bincmp.c +4445 -0
  104. data/ext/carray_kernels_binop.c +10979 -0
  105. data/ext/carray_kernels_init.c +36 -0
  106. data/ext/carray_kernels_map.c +3466 -0
  107. data/ext/carray_kernels_moncmp.c +2096 -0
  108. data/ext/carray_kernels_monop.c +18312 -0
  109. data/ext/carray_kernels_reduce_aggregate.c +25836 -0
  110. data/ext/carray_kernels_reduce_boolean.c +329 -0
  111. data/ext/carray_kernels_reduce_cumulative.c +14592 -0
  112. data/ext/carray_kernels_reduce_extreme.c +16947 -0
  113. data/ext/carray_kernels_reduce_variance.c +3909 -0
  114. data/ext/carray_kernels_scan.c +3692 -0
  115. data/ext/carray_kernels_search.c +32137 -0
  116. data/ext/carray_kernels_sort.c +10625 -0
  117. data/ext/carray_kernels_triop.c +1391 -0
  118. data/ext/carray_lazy.c +567 -0
  119. data/ext/carray_loop.c +88 -200
  120. data/ext/carray_mask.c +848 -154
  121. data/ext/carray_math_kernel.h +120 -0
  122. data/ext/carray_mathfunc.c +10 -241
  123. data/ext/carray_median_percentile.c +1257 -0
  124. data/ext/carray_memory_view.c +1625 -0
  125. data/ext/carray_operator.c +1526 -318
  126. data/ext/carray_order.c +664 -1394
  127. data/ext/carray_partition.c +416 -0
  128. data/ext/carray_random.c +518 -0
  129. data/ext/carray_scatter.c +357 -0
  130. data/ext/carray_slab.c +1219 -0
  131. data/ext/carray_slab.h +84 -0
  132. data/ext/carray_sort.c +829 -0
  133. data/ext/carray_sort_kernel.c +620 -0
  134. data/ext/carray_struct.c +695 -0
  135. data/ext/carray_test.c +343 -229
  136. data/ext/carray_undef.c +34 -17
  137. data/ext/carray_utils.c +175 -74
  138. data/ext/extconf.rb +216 -55
  139. data/ext/mk_call_cfunc.rb +480 -0
  140. data/ext/mkkernel.rb +8842 -0
  141. data/ext/ruby_carray.c +202 -101
  142. data/ext/version.h +4 -14
  143. data/ext/version.rb +5 -13
  144. data/lib/carray/arrow_tensor.rb +401 -0
  145. data/lib/carray/attribute.rb +166 -0
  146. data/lib/carray/autoload_carray.rb +220 -0
  147. data/lib/carray/autoload_method_extension.rb +44 -0
  148. data/lib/carray/axis_group.rb +711 -0
  149. data/lib/carray/basics.rb +481 -0
  150. data/lib/carray/bincount_nd.rb +358 -0
  151. data/lib/carray/block_iterator.rb +604 -0
  152. data/lib/carray/boolean_reduce.rb +109 -0
  153. data/lib/carray/categorical.rb +561 -0
  154. data/lib/carray/categorical_iterator.rb +1062 -0
  155. data/lib/carray/complex.rb +150 -0
  156. data/lib/carray/conditional.rb +216 -0
  157. data/lib/carray/const_string.rb +228 -0
  158. data/lib/carray/construct.rb +139 -328
  159. data/lib/carray/core_extensions.rb +240 -0
  160. data/lib/carray/data_type_extension.rb +233 -0
  161. data/lib/carray/fixlen_string.rb +95 -0
  162. data/lib/carray/frame/concat.rb +132 -0
  163. data/lib/carray/frame/convert.rb +95 -0
  164. data/lib/carray/frame/csv_parser.rb +211 -0
  165. data/lib/carray/frame/frame.rb +649 -0
  166. data/lib/carray/frame/group.rb +186 -0
  167. data/lib/carray/frame/io.rb +164 -0
  168. data/lib/carray/frame/join.rb +248 -0
  169. data/lib/carray/frame/records.rb +99 -0
  170. data/lib/carray/frame/sort.rb +113 -0
  171. data/lib/carray/frame/verbs.rb +299 -0
  172. data/lib/carray/frame.rb +16 -0
  173. data/lib/carray/histogram.rb +512 -0
  174. data/lib/carray/inspect.rb +37 -20
  175. data/lib/carray/iterator.rb +57 -349
  176. data/lib/carray/lazy.rb +889 -0
  177. data/lib/carray/mask_gap_fill.rb +200 -0
  178. data/lib/carray/math.rb +78 -342
  179. data/lib/carray/meld_reduce.rb +289 -0
  180. data/lib/carray/methods/align_addr.rb +116 -0
  181. data/lib/carray/methods/bin.rb +128 -0
  182. data/lib/carray/methods/bincount.rb +87 -0
  183. data/lib/carray/methods/bit_string.rb +92 -0
  184. data/lib/carray/methods/broadcast.rb +63 -0
  185. data/lib/carray/methods/choose.rb +39 -0
  186. data/lib/carray/methods/composition.rb +280 -0
  187. data/lib/carray/methods/gather_nd.rb +206 -0
  188. data/lib/carray/methods/index.rb +39 -0
  189. data/lib/carray/methods/insert_block.rb +99 -0
  190. data/lib/carray/methods/is_in.rb +141 -0
  191. data/lib/carray/methods/join.rb +90 -0
  192. data/lib/carray/methods/locate_addr.rb +47 -0
  193. data/lib/carray/methods/mask_duplicates.rb +41 -0
  194. data/lib/carray/methods/meshgrid.rb +91 -0
  195. data/lib/carray/methods/mode.rb +126 -0
  196. data/lib/carray/methods/nunique.rb +46 -0
  197. data/lib/carray/methods/resize.rb +56 -0
  198. data/lib/carray/methods/snap.rb +156 -0
  199. data/lib/carray/methods/string_format.rb +57 -0
  200. data/lib/carray/methods/unique.rb +47 -0
  201. data/lib/carray/methods/value_counts.rb +71 -0
  202. data/lib/carray/mkmf.rb +124 -101
  203. data/lib/carray/runtime.rb +108 -0
  204. data/lib/carray/serialize.rb +478 -167
  205. data/lib/carray/slab_iterator.rb +292 -0
  206. data/lib/carray/stack.rb +291 -0
  207. data/lib/carray/string.rb +56 -180
  208. data/lib/carray/string_operation_extension.rb +289 -0
  209. data/lib/carray/struct.rb +335 -323
  210. data/lib/carray/struct_builder.rb +697 -0
  211. data/lib/carray/table.rb +41 -2
  212. data/lib/carray/time.rb +2255 -38
  213. data/lib/carray/window_iterator.rb +655 -0
  214. data/lib/carray.rb +55 -57
  215. metadata +163 -130
  216. data/Rakefile +0 -51
  217. data/TODO.md +0 -18
  218. data/ext/ca_iter_block.c +0 -257
  219. data/ext/ca_iter_dimension.c +0 -299
  220. data/ext/ca_iter_window.c +0 -214
  221. data/ext/ca_obj_mapping.c +0 -644
  222. data/ext/carray_iterator.c +0 -641
  223. data/ext/carray_math.rb +0 -850
  224. data/ext/carray_numeric.c +0 -259
  225. data/ext/carray_sort_addr.c +0 -254
  226. data/ext/carray_stat.c +0 -2100
  227. data/ext/carray_stat_proc.rb +0 -1999
  228. data/ext/mkmath.rb +0 -741
  229. data/ext/ruby_ccomplex.c +0 -509
  230. data/ext/ruby_float_func.c +0 -86
  231. data/lib/carray/array.rb +0 -8
  232. data/lib/carray/autoload/autoload_base.rb +0 -19
  233. data/lib/carray/autoload/autoload_gem_cairo.rb +0 -9
  234. data/lib/carray/autoload/autoload_gem_ffi.rb +0 -9
  235. data/lib/carray/autoload/autoload_gem_gnuplot.rb +0 -2
  236. data/lib/carray/autoload/autoload_gem_io_csv.rb +0 -14
  237. data/lib/carray/autoload/autoload_gem_io_pg.rb +0 -6
  238. data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +0 -12
  239. data/lib/carray/autoload/autoload_gem_narray.rb +0 -10
  240. data/lib/carray/autoload/autoload_gem_numo_narray.rb +0 -15
  241. data/lib/carray/autoload/autoload_gem_opencv.rb +0 -16
  242. data/lib/carray/autoload/autoload_gem_random.rb +0 -8
  243. data/lib/carray/autoload/autoload_gem_rmagick.rb +0 -23
  244. data/lib/carray/autoload/autoload_gem_zimg.rb +0 -3
  245. data/lib/carray/autoload/autoload_io_imagemagick.rb +0 -6
  246. data/lib/carray/autoload/autoload_math_histogram.rb +0 -5
  247. data/lib/carray/autoload/autoload_math_recurrence.rb +0 -6
  248. data/lib/carray/autoload/autoload_object_iterator.rb +0 -1
  249. data/lib/carray/autoload/autoload_object_link.rb +0 -1
  250. data/lib/carray/autoload/autoload_object_pack.rb +0 -2
  251. data/lib/carray/autoload.rb +0 -141
  252. data/lib/carray/basic.rb +0 -191
  253. data/lib/carray/broadcast.rb +0 -101
  254. data/lib/carray/compose.rb +0 -315
  255. data/lib/carray/convert.rb +0 -115
  256. data/lib/carray/info.rb +0 -110
  257. data/lib/carray/io/imagemagick.rb +0 -235
  258. data/lib/carray/mask.rb +0 -102
  259. data/lib/carray/math/histogram.rb +0 -177
  260. data/lib/carray/math/recurrence.rb +0 -93
  261. data/lib/carray/object/ca_obj_iterator.rb +0 -50
  262. data/lib/carray/object/ca_obj_link.rb +0 -50
  263. data/lib/carray/object/ca_obj_pack.rb +0 -99
  264. data/lib/carray/obsolete.rb +0 -256
  265. data/lib/carray/ordering.rb +0 -181
  266. data/lib/carray/testing.rb +0 -51
  267. data/lib/carray/transform.rb +0 -109
  268. data/misc/Methods.ja.md +0 -182
  269. data/misc/NOTE +0 -51
  270. data/spec/Classes/CABitfield_spec.rb +0 -58
  271. data/spec/Classes/CABlockIterator_spec.rb +0 -114
  272. data/spec/Classes/CABlock_spec.rb +0 -205
  273. data/spec/Classes/CAField_spec.rb +0 -39
  274. data/spec/Classes/CAGrid_spec.rb +0 -75
  275. data/spec/Classes/CAMap_spec.rb +0 -0
  276. data/spec/Classes/CAMapping_spec.rb +0 -105
  277. data/spec/Classes/CAObject_attribute_spec.rb +0 -33
  278. data/spec/Classes/CAObject_spec.rb +0 -33
  279. data/spec/Classes/CARefer_spec.rb +0 -93
  280. data/spec/Classes/CARepeat_spec.rb +0 -65
  281. data/spec/Classes/CASelect_spec.rb +0 -22
  282. data/spec/Classes/CAShift_spec.rb +0 -16
  283. data/spec/Classes/CAStruct_spec.rb +0 -71
  284. data/spec/Classes/CATranspose_spec.rb +0 -60
  285. data/spec/Classes/CAUnboudRepeat_spec.rb +0 -102
  286. data/spec/Classes/CAWindow_spec.rb +0 -54
  287. data/spec/Classes/CAWrap_spec.rb +0 -8
  288. data/spec/Classes/CArray_spec.rb +0 -184
  289. data/spec/Classes/CScalar_spec.rb +0 -55
  290. data/spec/Classes/ex1.rb +0 -46
  291. data/spec/Features/feature_130_spec.rb +0 -19
  292. data/spec/Features/feature_attributes_spec.rb +0 -280
  293. data/spec/Features/feature_boolean_spec.rb +0 -98
  294. data/spec/Features/feature_broadcast.rb +0 -116
  295. data/spec/Features/feature_cast_function.rb +0 -19
  296. data/spec/Features/feature_cast_spec.rb +0 -33
  297. data/spec/Features/feature_class_spec.rb +0 -84
  298. data/spec/Features/feature_complex_spec.rb +0 -42
  299. data/spec/Features/feature_composite_spec.rb +0 -124
  300. data/spec/Features/feature_convert_spec.rb +0 -46
  301. data/spec/Features/feature_copy_spec.rb +0 -123
  302. data/spec/Features/feature_creation_spec.rb +0 -84
  303. data/spec/Features/feature_element_spec.rb +0 -144
  304. data/spec/Features/feature_extream_spec.rb +0 -54
  305. data/spec/Features/feature_generate_spec.rb +0 -74
  306. data/spec/Features/feature_index_spec.rb +0 -69
  307. data/spec/Features/feature_mask_spec.rb +0 -580
  308. data/spec/Features/feature_math_spec.rb +0 -97
  309. data/spec/Features/feature_order_spec.rb +0 -146
  310. data/spec/Features/feature_ref_store_spec.rb +0 -209
  311. data/spec/Features/feature_serialization_spec.rb +0 -125
  312. data/spec/Features/feature_stat_spec.rb +0 -397
  313. data/spec/Features/feature_virtual_spec.rb +0 -48
  314. data/spec/Features/method_eq_spec.rb +0 -81
  315. data/spec/Features/method_is_nan_spec.rb +0 -12
  316. data/spec/Features/method_map_spec.rb +0 -54
  317. data/spec/Features/method_max_with.rb +0 -20
  318. data/spec/Features/method_min_with.rb +0 -19
  319. data/spec/Features/method_ne_spec.rb +0 -18
  320. data/spec/Features/method_project_spec.rb +0 -188
  321. data/spec/Features/method_ref_spec.rb +0 -27
  322. data/spec/Features/method_round_spec.rb +0 -11
  323. data/spec/Features/method_s_linspace_spec.rb +0 -48
  324. data/spec/Features/method_s_span_spec.rb +0 -14
  325. data/spec/Features/method_seq_spec.rb +0 -47
  326. data/spec/Features/method_sort_with.rb +0 -43
  327. data/spec/Features/method_sorted_with.rb +0 -29
  328. data/spec/Features/method_span_spec.rb +0 -42
  329. data/spec/Features/method_wrap_readonly_spec.rb +0 -43
  330. data/spec/UnitTest/test_CAVirtual.rb +0 -214
  331. data/spec/spec_all.rb +0 -10
  332. data/utils/ca_ase.rb +0 -21
  333. data/utils/ca_methods.rb +0 -15
  334. data/utils/cast_checker.rb +0 -30
  335. data/utils/convert_test.rb +0 -73
  336. data/utils/extract_yard.rb +0 -22
  337. data/utils/guess_shape.rb +0 -76
  338. data/utils/monkey_patch_methods.rb +0 -62
  339. data/utils/remove_resource_fork.sh +0 -5
data/ext/ruby_ccomplex.c DELETED
@@ -1,509 +0,0 @@
1
- /* ---------------------------------------------------------------------------
2
-
3
- ruby_ccomplex.c
4
-
5
- This file is part of Ruby/CArray extension library.
6
-
7
- Copyright (C) 2005-2020 Hiroki Motoyoshi
8
-
9
- ---------------------------------------------------------------------------- */
10
-
11
- #include "ruby.h"
12
- #include "carray.h"
13
- #include "math.h"
14
-
15
- #ifdef HAVE_COMPLEX_H
16
-
17
- #if RUBY_VERSION_CODE >= 190
18
- #else
19
- static VALUE rb_cComplex;
20
- #endif
21
-
22
- extern const rb_data_type_t ccomplex_data_type;
23
-
24
- const rb_data_type_t ccomplex_data_type = {
25
- .parent = NULL,
26
- .wrap_struct_name = "CComplex",
27
- .function = {
28
- .dmark = NULL,
29
- .dfree = xfree,
30
- .dsize = NULL,
31
- .dcompact = NULL
32
- },
33
- .flags = RUBY_TYPED_FREE_IMMEDIATELY,
34
- };
35
-
36
- VALUE rb_cCComplex;
37
-
38
- VALUE rb_ccomplex_new2 (double re, double im);
39
-
40
- #if RUBY_VERSION_CODE >= 220
41
- struct RComplex {
42
- struct RBasic basic;
43
- const VALUE real;
44
- const VALUE imag;
45
- };
46
- static double complex
47
- rb_complex_to_cval (VALUE self)
48
- {
49
- struct RComplex *dat;
50
- double re, im;
51
- dat = ((struct RComplex *)(self));
52
- re = NUM2DBL(dat->real);
53
- im = NUM2DBL(dat->imag);
54
- return re + I * im;
55
- }
56
- #else
57
- #if RUBY_VERSION_CODE >= 190
58
- static double complex
59
- rb_complex_to_cval (VALUE self)
60
- {
61
- double re = NUM2DBL(RCOMPLEX(self)->real);
62
- double im = NUM2DBL(RCOMPLEX(self)->imag);
63
- return re + I * im;
64
- }
65
- #else
66
- static double complex
67
- rb_complex_to_cval (VALUE self)
68
- {
69
- double re = NUM2DBL(rb_ivar_get(self, rb_intern("@real")));
70
- double im = NUM2DBL(rb_ivar_get(self, rb_intern("@image")));
71
- return re + I * im;
72
- }
73
- static VALUE
74
- rb_Complex (VALUE x, VALUE y)
75
- {
76
- return rb_funcall(rb_cComplex, rb_intern("new"), 2, x, y);
77
- }
78
- #endif
79
- #endif
80
-
81
- double complex
82
- rb_num2cc(VALUE num)
83
- {
84
- if ( rb_obj_is_kind_of(num, rb_cCComplex) ) {
85
- double complex *cp;
86
- TypedData_Get_Struct(num, double complex, &ccomplex_data_type, cp);
87
- return *cp;
88
- }
89
- switch ( TYPE(num) ) {
90
- case T_FIXNUM:
91
- return (double complex) NUM2LONG(num);
92
- case T_BIGNUM:
93
- return (double complex) rb_big2dbl(num);
94
- case T_FLOAT:
95
- return (double complex) NUM2DBL(num);
96
- }
97
- if ( rb_obj_is_kind_of(num, rb_cComplex) ) {
98
- return rb_complex_to_cval(num);
99
- }
100
- if ( rb_respond_to(num, rb_intern("to_c")) ) {
101
- return rb_complex_to_cval(rb_funcall(num, rb_intern("to_c"), 0));
102
- }
103
- if ( rb_respond_to(num, rb_intern("to_cc")) ) {
104
- return rb_funcall(num, rb_intern("to_cc"), 0);
105
- }
106
- if ( rb_respond_to(num, rb_intern("to_f")) ) {
107
- return rb_num2cc(rb_funcall(num, rb_intern("to_f"), 0));
108
- }
109
- rb_raise(rb_eRuntimeError, "can not convert to CComplex");
110
- }
111
-
112
- static VALUE
113
- rb_num_to_cc (VALUE num)
114
- {
115
- if ( rb_obj_is_kind_of(num, rb_cCComplex) ) {
116
- double complex cc = 0.0, *cp;
117
- cp = &cc;
118
- TypedData_Get_Struct(num, double complex, &ccomplex_data_type, cp);
119
- return rb_ccomplex_new(cc);
120
- }
121
- switch ( TYPE(num) ) {
122
- case T_FIXNUM:
123
- return rb_ccomplex_new((double complex) NUM2LONG(num));
124
- case T_BIGNUM:
125
- return rb_ccomplex_new((double complex) rb_big2dbl(num));
126
- case T_FLOAT:
127
- return rb_ccomplex_new((double complex) NUM2DBL(num));
128
- }
129
- if ( rb_obj_is_kind_of(num, rb_cComplex) ) {
130
- return rb_ccomplex_new(rb_complex_to_cval(num));
131
- }
132
- if ( rb_respond_to(num, rb_intern("to_c")) ) {
133
- return rb_ccomplex_new(rb_complex_to_cval(rb_funcall(num, rb_intern("to_c"), 0)));
134
- }
135
- if ( rb_respond_to(num, rb_intern("to_f")) ) {
136
- return rb_ccomplex_new(NUM2DBL(rb_funcall(num, rb_intern("to_f"), 0)));
137
- }
138
- rb_raise(rb_eRuntimeError, "can not convert to CComplex");
139
- }
140
-
141
- VALUE
142
- rb_ccomplex_new (double complex c)
143
- {
144
- VALUE obj;
145
- double complex *cp;
146
- obj = TypedData_Make_Struct(rb_cCComplex, double complex, &ccomplex_data_type, cp);
147
- *cp = c;
148
- return obj;
149
- }
150
-
151
- VALUE
152
- rb_ccomplex_new2 (double re, double im)
153
- {
154
- VALUE obj;
155
- double complex *cp;
156
- obj = Data_Make_Struct(rb_cCComplex, double complex, 0, xfree, cp);
157
- *cp = re + I * im;
158
- return obj;
159
- }
160
-
161
- VALUE
162
- rb_CComplex (int argc, VALUE *argv, VALUE self)
163
- {
164
- if ( argc == 1 ) {
165
- return rb_ccomplex_new(NUM2CC(argv[0]));
166
- }
167
- else if ( argc == 2 ) {
168
- return rb_ccomplex_new2(NUM2DBL(argv[0]), NUM2DBL(argv[1]));
169
- }
170
- else {
171
- rb_raise(rb_eArgError, "invalid # of arguments");
172
- }
173
- }
174
-
175
- static VALUE
176
- rb_cc_s_allocate (VALUE klass)
177
- {
178
- double complex *cp;
179
- return Data_Make_Struct(klass, double complex, 0, xfree, cp);
180
- }
181
-
182
- static VALUE
183
- rb_cc_initialize (int argc, VALUE *argv, VALUE self)
184
- {
185
- volatile VALUE rre, rim;
186
- double complex *cp;
187
-
188
- TypedData_Get_Struct(self, double complex, &ccomplex_data_type, cp);
189
-
190
- rb_scan_args(argc, argv, "11", (VALUE *)&rre, (VALUE *)&rim);
191
-
192
- if ( NIL_P(rim) ) {
193
- *cp = NUM2DBL(rre);
194
- }
195
- else {
196
- *cp = NUM2DBL(rre) + I * NUM2DBL(rim);
197
- }
198
-
199
- return Qnil;
200
- }
201
-
202
- static VALUE
203
- rb_cc_to_c (VALUE self)
204
- {
205
- double complex *cp;
206
- TypedData_Get_Struct(self, double complex, &ccomplex_data_type, cp);
207
- return rb_Complex(rb_float_new(creal(*cp)), rb_float_new(cimag(*cp)));
208
- }
209
-
210
- static VALUE
211
- rb_complex_to_cc (VALUE self)
212
- {
213
- if ( rb_obj_is_kind_of(self, rb_cCComplex) ) {
214
- return self;
215
- }
216
- else {
217
- return rb_ccomplex_new(rb_complex_to_cval(self));
218
- }
219
- }
220
-
221
-
222
- static VALUE
223
- rb_cc_real(VALUE self)
224
- {
225
- double complex *cp;
226
-
227
- TypedData_Get_Struct(self, double complex, &ccomplex_data_type, cp);
228
-
229
- return rb_float_new(creal(*cp));
230
- }
231
-
232
- static VALUE
233
- rb_cc_imag(VALUE self)
234
- {
235
- double complex *cp;
236
-
237
- TypedData_Get_Struct(self, double complex, &ccomplex_data_type, cp);
238
-
239
- return rb_float_new(cimag(*cp));
240
- }
241
-
242
- static VALUE
243
- rb_cc_inspect (VALUE self)
244
- {
245
- volatile VALUE vary = rb_ary_new(), rim;
246
- double complex *cp;
247
- double re, im;
248
-
249
- TypedData_Get_Struct(self, double complex, &ccomplex_data_type, cp);
250
-
251
- re = creal(*cp);
252
- im = cimag(*cp);
253
-
254
- rb_ary_push(vary, rb_inspect(rb_float_new(re)));
255
-
256
- rim = rb_inspect(rb_float_new(im));
257
-
258
- if ( StringValuePtr(rim)[0] != '-' ) {
259
- rb_ary_push(vary, rb_str_new2("+"));
260
- }
261
-
262
- rb_ary_push(vary, rim);
263
- rb_ary_push(vary, rb_str_new2("i"));
264
-
265
- return rb_ary_join(vary, Qnil);
266
- }
267
-
268
- static VALUE
269
- rb_cc_conj(VALUE self)
270
- {
271
- double complex *cp;
272
-
273
- TypedData_Get_Struct(self, double complex, &ccomplex_data_type, cp);
274
-
275
- return CC2NUM(conj(*cp));
276
- }
277
-
278
- static VALUE
279
- rb_cc_arg(VALUE self)
280
- {
281
- double complex *cp;
282
-
283
- TypedData_Get_Struct(self, double complex, &ccomplex_data_type, cp);
284
-
285
- return rb_float_new(carg(*cp));
286
- }
287
-
288
- static VALUE
289
- rb_cc_abs(VALUE self)
290
- {
291
- double complex *cp;
292
-
293
- TypedData_Get_Struct(self, double complex, &ccomplex_data_type, cp);
294
-
295
- return rb_float_new(cabs(*cp));
296
- }
297
-
298
- static VALUE
299
- rb_cc_coerce(VALUE self, VALUE other)
300
- {
301
- VALUE argv[1];
302
-
303
- if ( rb_obj_is_kind_of(other, rb_cNumeric) ) {
304
- return rb_assoc_new(CC2NUM(NUM2CC(other)), self);
305
- }
306
-
307
- argv[0] = other;
308
- return rb_call_super(1, argv);
309
- }
310
-
311
- static VALUE
312
- rb_cc_equal(VALUE self, VALUE other)
313
- {
314
- double complex a, b;
315
-
316
- if ( rb_obj_is_kind_of(other, rb_cNumeric) ) {
317
- a = NUM2CC(self);
318
- b = NUM2CC(other);
319
- return ( a == b ) ? Qtrue : Qfalse;
320
- }
321
- else {
322
- return rb_funcall(other, rb_intern("=="), 1, self);
323
- }
324
- }
325
-
326
- static VALUE
327
- rb_cc_uminus(VALUE self)
328
- {
329
- return CC2NUM( - NUM2CC(self) );
330
- }
331
-
332
- static VALUE
333
- rb_cc_plus(VALUE self, VALUE other)
334
- {
335
- double complex a, b;
336
-
337
- if ( rb_obj_is_kind_of(other, rb_cNumeric) ) {
338
- a = NUM2CC(self);
339
- b = NUM2CC(other);
340
- return CC2NUM( a + b );
341
- }
342
- else {
343
- #if RUBY_VERSION_CODE >= 190
344
- return rb_num_coerce_bin(self, other, '+');
345
- #else
346
- return rb_num_coerce_bin(self, other);
347
- #endif
348
- }
349
- }
350
-
351
- static VALUE
352
- rb_cc_minus(VALUE self, VALUE other)
353
- {
354
- double complex a, b;
355
-
356
- if ( rb_obj_is_kind_of(other, rb_cNumeric) ) {
357
- a = NUM2CC(self);
358
- b = NUM2CC(other);
359
- return CC2NUM( a - b );
360
- }
361
- else {
362
- #if RUBY_VERSION_CODE >= 190
363
- return rb_num_coerce_bin(self, other, '-');
364
- #else
365
- return rb_num_coerce_bin(self, other);
366
- #endif
367
- }
368
- }
369
-
370
- static VALUE
371
- rb_cc_asterisk(VALUE self, VALUE other)
372
- {
373
- double complex a, b;
374
-
375
- if ( rb_obj_is_kind_of(other, rb_cNumeric) ) {
376
- a = NUM2CC(self);
377
- b = NUM2CC(other);
378
- return CC2NUM( a * b );
379
- }
380
- else {
381
- #if RUBY_VERSION_CODE >= 190
382
- return rb_num_coerce_bin(self, other, '*');
383
- #else
384
- return rb_num_coerce_bin(self, other);
385
- #endif
386
- }
387
- }
388
-
389
- static VALUE
390
- rb_cc_slash(VALUE self, VALUE other)
391
- {
392
- double complex a, b;
393
-
394
- if ( rb_obj_is_kind_of(other, rb_cNumeric) ) {
395
- a = NUM2CC(self);
396
- b = NUM2CC(other);
397
- return CC2NUM( a / b );
398
- }
399
- else {
400
- #if RUBY_VERSION_CODE >= 190
401
- return rb_num_coerce_bin(self, other, '/');
402
- #else
403
- return rb_num_coerce_bin(self, other);
404
- #endif
405
- }
406
- }
407
-
408
- static VALUE
409
- rb_cc_star2(VALUE self, VALUE other)
410
- {
411
- double complex a, b;
412
-
413
- if ( rb_obj_is_kind_of(other, rb_cNumeric) ) {
414
- a = NUM2CC(self);
415
- b = NUM2CC(other);
416
- return CC2NUM( cpow(a, b) );
417
- }
418
- else {
419
- #if RUBY_VERSION_CODE >= 190
420
- return rb_num_coerce_bin(self, other, rb_intern("**"));
421
- #else
422
- return rb_num_coerce_bin(self, other);
423
- #endif
424
- }
425
- }
426
-
427
- static VALUE rb_cc_cos (VALUE self) { return CC2NUM(ccos(NUM2CC(self))); }
428
- static VALUE rb_cc_sin (VALUE self) { return CC2NUM(csin(NUM2CC(self))); }
429
- static VALUE rb_cc_tan (VALUE self) { return CC2NUM(ctan(NUM2CC(self))); }
430
-
431
- static VALUE rb_cc_acos (VALUE self) { return CC2NUM(cacos(NUM2CC(self))); }
432
- static VALUE rb_cc_asin (VALUE self) { return CC2NUM(casin(NUM2CC(self))); }
433
- static VALUE rb_cc_atan (VALUE self) { return CC2NUM(catan(NUM2CC(self))); }
434
-
435
- static VALUE rb_cc_cosh (VALUE self) { return CC2NUM(ccosh(NUM2CC(self))); }
436
- static VALUE rb_cc_sinh (VALUE self) { return CC2NUM(csinh(NUM2CC(self))); }
437
- static VALUE rb_cc_tanh (VALUE self) { return CC2NUM(ctanh(NUM2CC(self))); }
438
-
439
- static VALUE rb_cc_acosh (VALUE self) { return CC2NUM(cacosh(NUM2CC(self))); }
440
- static VALUE rb_cc_asinh (VALUE self) { return CC2NUM(casinh(NUM2CC(self))); }
441
- static VALUE rb_cc_atanh (VALUE self) { return CC2NUM(catanh(NUM2CC(self))); }
442
-
443
- static VALUE rb_cc_exp (VALUE self) { return CC2NUM(cexp(NUM2CC(self))); }
444
- static VALUE rb_cc_log (VALUE self) { return CC2NUM(clog(NUM2CC(self))); }
445
- static VALUE rb_cc_sqrt (VALUE self) { return CC2NUM(csqrt(NUM2CC(self))); }
446
-
447
- void
448
- Init_ccomplex ()
449
- {
450
- #if RUBY_VERSION_CODE >= 190
451
- #else
452
- rb_cComplex = rb_const_get(rb_cObject, rb_intern("Complex"));
453
- #endif
454
-
455
- rb_cCComplex = rb_define_class("CComplex", rb_cNumeric);
456
-
457
- rb_define_method(rb_cComplex, "to_cc", rb_complex_to_cc, 0);
458
- rb_define_method(rb_cNumeric, "to_cc", rb_num_to_cc, 0);
459
-
460
- rb_define_global_function("CComplex", rb_CComplex, -1);
461
-
462
- rb_define_alloc_func(rb_cCComplex, rb_cc_s_allocate);
463
- rb_define_method(rb_cCComplex, "initialize", rb_cc_initialize, -1);
464
- rb_define_method(rb_cCComplex, "to_c", rb_cc_to_c, 0);
465
- rb_define_method(rb_cCComplex, "real", rb_cc_real, 0);
466
- rb_define_method(rb_cCComplex, "imag", rb_cc_imag, 0);
467
- rb_define_method(rb_cCComplex, "inspect", rb_cc_inspect, 0);
468
- rb_define_method(rb_cCComplex, "to_s", rb_cc_inspect, 0);
469
-
470
- rb_define_method(rb_cCComplex, "conj", rb_cc_conj, 0);
471
- rb_define_method(rb_cCComplex, "arg", rb_cc_arg, 0);
472
- rb_define_method(rb_cCComplex, "abs", rb_cc_abs, 0);
473
-
474
- rb_define_method(rb_cCComplex, "coerce", rb_cc_coerce, 1);
475
-
476
- rb_define_method(rb_cCComplex, "==", rb_cc_equal, 1);
477
- rb_define_method(rb_cCComplex, "-@", rb_cc_uminus, 0);
478
- rb_define_method(rb_cCComplex, "+", rb_cc_plus, 1);
479
- rb_define_method(rb_cCComplex, "-", rb_cc_minus, 1);
480
- rb_define_method(rb_cCComplex, "*", rb_cc_asterisk, 1);
481
- rb_define_method(rb_cCComplex, "/", rb_cc_slash, 1);
482
- rb_define_method(rb_cCComplex, "**", rb_cc_star2, 1);
483
-
484
- rb_define_method(rb_cCComplex, "sqrt", rb_cc_sqrt, 0);
485
- rb_define_method(rb_cCComplex, "exp", rb_cc_exp, 0);
486
- rb_define_method(rb_cCComplex, "log", rb_cc_log, 0);
487
- rb_define_method(rb_cCComplex, "cos", rb_cc_cos, 0);
488
- rb_define_method(rb_cCComplex, "sin", rb_cc_sin, 0);
489
- rb_define_method(rb_cCComplex, "tan", rb_cc_tan, 0);
490
- rb_define_method(rb_cCComplex, "cosh", rb_cc_cosh, 0);
491
- rb_define_method(rb_cCComplex, "sinh", rb_cc_sinh, 0);
492
- rb_define_method(rb_cCComplex, "tanh", rb_cc_tanh, 0);
493
- rb_define_method(rb_cCComplex, "acos", rb_cc_acos, 0);
494
- rb_define_method(rb_cCComplex, "asin", rb_cc_asin, 0);
495
- rb_define_method(rb_cCComplex, "atan", rb_cc_atan, 0);
496
- rb_define_method(rb_cCComplex, "acosh", rb_cc_acosh, 0);
497
- rb_define_method(rb_cCComplex, "asinh", rb_cc_asinh, 0);
498
- rb_define_method(rb_cCComplex, "atanh", rb_cc_atanh, 0);
499
-
500
- rb_define_const(rb_cObject, "CI", CC2NUM(I));
501
-
502
- }
503
-
504
- #else
505
-
506
- void
507
- Init_ccomplex () {}
508
-
509
- #endif
@@ -1,86 +0,0 @@
1
- /* ---------------------------------------------------------------------------
2
-
3
- ruby_numeric.c
4
-
5
- This file is part of Ruby/CArray extension library.
6
-
7
- Copyright (C) 2005-2020 Hiroki Motoyoshi
8
-
9
- ---------------------------------------------------------------------------- */
10
-
11
- #include "ruby.h"
12
- #include <math.h>
13
-
14
- #define rb_num_func(name) \
15
- static VALUE rb_num_ ## name (VALUE self) \
16
- { return rb_float_new(name(NUM2DBL(self))); }
17
-
18
- rb_num_func(sqrt);
19
- rb_num_func(exp);
20
- rb_num_func(log);
21
- rb_num_func(log10);
22
-
23
- rb_num_func(sin);
24
- rb_num_func(cos);
25
- rb_num_func(tan);
26
- rb_num_func(sinh);
27
- rb_num_func(cosh);
28
- rb_num_func(tanh);
29
-
30
- rb_num_func(asin);
31
- rb_num_func(acos);
32
- rb_num_func(atan);
33
- rb_num_func(asinh);
34
- rb_num_func(acosh);
35
- rb_num_func(atanh);
36
-
37
- static VALUE
38
- rb_num_rad (VALUE self)
39
- { return rb_float_new(0.0174532925199433*NUM2DBL(self)); }
40
-
41
- static VALUE
42
- rb_num_deg (VALUE self)
43
- { return rb_float_new(57.2957795130823*NUM2DBL(self)); }
44
-
45
- static VALUE
46
- rb_num_distance (VALUE self, VALUE other)
47
- {
48
- double fs = NUM2DBL(self), fo = NUM2DBL(other);
49
- return rb_float_new(fabs(fs - fo));
50
- }
51
-
52
- void
53
- Init_numeric_float_function ()
54
- {
55
- VALUE mod = rb_define_module_under(rb_cNumeric, "FloatFunction");
56
-
57
- rb_define_method(mod, "sqrt", rb_num_sqrt, 0);
58
- rb_define_method(mod, "exp", rb_num_exp, 0);
59
- rb_define_method(mod, "log", rb_num_log, 0);
60
- rb_define_method(mod, "log10", rb_num_log10, 0);
61
- rb_define_method(mod, "sin", rb_num_sin, 0);
62
- rb_define_method(mod, "cos", rb_num_cos, 0);
63
- rb_define_method(mod, "tan", rb_num_tan, 0);
64
- rb_define_method(mod, "sinh", rb_num_sinh, 0);
65
- rb_define_method(mod, "cosh", rb_num_cosh, 0);
66
- rb_define_method(mod, "tanh", rb_num_tanh, 0);
67
- rb_define_method(mod, "asin", rb_num_asin, 0);
68
- rb_define_method(mod, "acos", rb_num_acos, 0);
69
- rb_define_method(mod, "atan", rb_num_atan, 0);
70
- rb_define_method(mod, "asinh", rb_num_asinh, 0);
71
- rb_define_method(mod, "acosh", rb_num_acosh, 0);
72
- rb_define_method(mod, "atanh", rb_num_atanh, 0);
73
- rb_define_method(mod, "rad", rb_num_rad, 0);
74
- rb_define_method(mod, "deg", rb_num_deg, 0);
75
- rb_define_method(mod, "distance", rb_num_distance, 1);
76
-
77
- rb_include_module(rb_cFloat, mod);
78
- #if RUBY_VERSION_CODE >= 240
79
- rb_include_module(rb_cInteger, mod);
80
- #else
81
- rb_include_module(rb_cFixnum, mod);
82
- rb_include_module(rb_cBignum, mod);
83
- #endif
84
-
85
- }
86
-
data/lib/carray/array.rb DELETED
@@ -1,8 +0,0 @@
1
-
2
- class CArray
3
-
4
- def zip (*others)
5
- return to_a.zip(*others.map(&:to_a))
6
- end
7
-
8
- end
@@ -1,19 +0,0 @@
1
- class CArray
2
- serialize_rb = "carray/serialize"
3
- autoload :Serializer, serialize_rb
4
- autoload_method "self.save", serialize_rb
5
- autoload_method "self.load", serialize_rb
6
- autoload_method "self.dump", serialize_rb
7
- autoload_method "marshal_dump", serialize_rb
8
- autoload_method "marshal_load", serialize_rb
9
-
10
- autoload_method "save_binary", serialize_rb
11
- autoload_method "save_binary_io", serialize_rb
12
- autoload_method "self.load_binary", serialize_rb
13
- autoload_method "self.load_binary_io", serialize_rb
14
- autoload_method "self.load_from_file", serialize_rb
15
- end
16
-
17
- class Rational < Numeric
18
- include FloatFunction
19
- end
@@ -1,9 +0,0 @@
1
-
2
- module Cairo
3
- class Surface
4
- end
5
- class ImageSurface < Surface
6
- autoload_method "self.new_from_ca", "carray-cairo"
7
- autoload_method "ca", "carray-cairo"
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class CArray
2
- autoload_method "mp", "carray-ffi"
3
- end
4
-
5
- module FFI
6
- class MemoryPointer
7
- autoload_method "ca", "carray-ffi"
8
- end
9
- end
@@ -1,2 +0,0 @@
1
- autoload_method "CA.gnuplot", "carray-gnuplot"
2
-
@@ -1,14 +0,0 @@
1
- autoload_method "CArray.load_csv", "carray-io-csv"
2
- autoload_method "CArray.from_csv", "carray-io-csv"
3
-
4
- class CArray
5
- autoload_method "save_csv", "carray-io-csv"
6
- autoload_method "to_csv", "carray-io-csv"
7
- autoload_method "to_tabular", "carray-io-csv"
8
- end
9
-
10
- module CA
11
- autoload :CSVReader, "carray-io-csv"
12
- autoload :CSVWriter, "carray-io-csv"
13
- end
14
-
@@ -1,6 +0,0 @@
1
- autoload_method "CArray.load_pg", "carray-io-pg"
2
-
3
- class CArray
4
- autoload_method "unescape_bytea", "carray-io-pg"
5
- autoload_method "escape_bytea", "carray-io-pg"
6
- end
@@ -1,12 +0,0 @@
1
- autoload_method "CArray.load_sqlite3", "carray-io-sqlite3"
2
-
3
- class CArray
4
- autoload_method "unblob", "carray-io-sqlite3"
5
- autoload_method "to_sqlite3", "carray-io-sqlite3"
6
- end
7
-
8
- if Object.const_defined?(:SQLite3)
9
- require "carray-io-sqlite3"
10
- else
11
- autoload :SQLite3, "carray-io-sqlite3"
12
- end
@@ -1,10 +0,0 @@
1
- class CArray
2
- autoload_method :na, "carray-narray"
3
- autoload_method :to_na, "carray-narray"
4
- end
5
-
6
- class NArray
7
- autoload_method :ca, "carray-narray"
8
- autoload_method :to_ca, "carray-narray"
9
- end
10
-
@@ -1,15 +0,0 @@
1
- class CArray
2
- autoload_method :to_numo, "carray-numo-narray"
3
- autoload_method :numo, "carray-numo-narray"
4
- autoload_method "self.as_numo", "carray-numo-narray"
5
- autoload_method "self.as_numo!", "carray-numo-narray"
6
- autoload_method :as_numo, "carray-numo-narray"
7
- autoload_method :as_numo!, "carray-numo-narray"
8
- end
9
-
10
- module Numo
11
- class NArray
12
- autoload_method :to_ca, "carray-numo-narray"
13
- autoload_method :ca, "carray-numo-narray"
14
- end
15
- end