carray 1.3.7 → 1.4.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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -7
  3. data/Rakefile +31 -0
  4. data/carray.gemspec +9 -14
  5. data/carray.h +4 -0
  6. data/carray_access.c +50 -8
  7. data/carray_conversion.c +3 -3
  8. data/carray_generate.c +67 -1
  9. data/carray_math.rb +22 -22
  10. data/carray_operator.c +23 -0
  11. data/devel/im2col.rb +17 -0
  12. data/lib/carray.rb +32 -1
  13. data/lib/carray/autoload/autoload_base.rb +0 -4
  14. data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
  15. data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
  16. data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
  17. data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
  18. data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
  19. data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
  20. data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
  21. data/lib/carray/autoload/autoload_gem_numo_narray.rb +14 -0
  22. data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
  23. data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
  24. data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
  25. data/lib/carray/base/autoload.rb +47 -5
  26. data/lib/carray/base/basic.rb +58 -2
  27. data/lib/carray/base/math.rb +1 -1
  28. data/lib/carray/base/string.rb +242 -0
  29. data/mkmath.rb +12 -2
  30. data/version.h +5 -5
  31. metadata +29 -109
  32. data/Gemfile +0 -8
  33. data/Gemfile.lock +0 -33
  34. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
  35. data/ext/fortio/extconf.rb +0 -3
  36. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
  37. data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
  38. data/ext/fortio/lib/fortio.rb +0 -3
  39. data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
  40. data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
  41. data/ext/fortio/lib/fortio/fortran_format.y +0 -215
  42. data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
  43. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
  44. data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
  45. data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
  46. data/ext/fortio/ruby_fortio.c +0 -182
  47. data/ext/fortio/test/test_H.rb +0 -5
  48. data/ext/fortio/test/test_T.rb +0 -7
  49. data/ext/fortio/test/test_fortran_format.rb +0 -86
  50. data/ext/fortio/test/test_namelist.rb +0 -25
  51. data/ext/fortio/test/test_namelist_write.rb +0 -10
  52. data/ext/fortio/test/test_sequential.rb +0 -13
  53. data/ext/fortio/test/test_sequential2.rb +0 -13
  54. data/ext/fortio/work/test.rb +0 -10
  55. data/ext/fortio/work/test_e.rb +0 -19
  56. data/ext/fortio/work/test_ep.rb +0 -10
  57. data/ext/fortio/work/test_parse.rb +0 -12
  58. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
  59. data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
  60. data/ext/narray/README +0 -22
  61. data/ext/narray/ca_wrap_narray.c +0 -500
  62. data/ext/narray/carray_narray.c +0 -21
  63. data/ext/narray/extconf.rb +0 -57
  64. data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
  65. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
  66. data/ext/narray/lib/math/narray.rb +0 -17
  67. data/ext/narray/lib/math/narray_miss.rb +0 -45
  68. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
  69. data/lib/carray/autoload/autoload_io_csv.rb +0 -14
  70. data/lib/carray/autoload/autoload_io_numo.rb +0 -9
  71. data/lib/carray/autoload/autoload_io_pg.rb +0 -6
  72. data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
  73. data/lib/carray/graphics/gnuplot.rb +0 -2141
  74. data/lib/carray/graphics/zimg.rb +0 -296
  75. data/lib/carray/io/csv.rb +0 -572
  76. data/lib/carray/io/numo.rb +0 -52
  77. data/lib/carray/io/pg.rb +0 -101
  78. data/lib/carray/io/sqlite3.rb +0 -215
@@ -1,500 +0,0 @@
1
- /* ---------------------------------------------------------------------------
2
-
3
- carray/ca_wrap_narray.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
-
16
- #include "narray_config.h"
17
- #ifndef HAVE_U_INT8_T
18
- #define HAVE_U_INT8_T
19
- #endif
20
- #ifndef HAVE_INT16_T
21
- #define HAVE_INT16_T
22
- #endif
23
- #ifndef HAVE_INT16_T
24
- #define HAVE_INT32_T
25
- #endif
26
- #ifndef HAVE_U_INT32_T
27
- #define HAVE_U_INT32_T
28
- #endif
29
- #include "narray.h"
30
-
31
- #include <math.h>
32
-
33
- extern VALUE cNMatrix, cNVector, cNMatrixLU;
34
-
35
- static char EMPTY_ARRAY_PTR;
36
-
37
- /* -------------------------------------------------------------------- */
38
-
39
- static int8_t
40
- na_typecode_to_ca_data_type (int typecode)
41
- {
42
- int8_t data_type;
43
-
44
- switch ( typecode ) {
45
- case NA_BYTE:
46
- data_type = CA_UINT8; break;
47
- case NA_SINT:
48
- data_type = CA_INT16; break;
49
- case NA_LINT:
50
- data_type = CA_INT32; break;
51
- case NA_SFLOAT:
52
- data_type = CA_FLOAT32; break;
53
- case NA_DFLOAT:
54
- data_type = CA_FLOAT64; break;
55
- #ifdef HAVE_COMPLEX_H
56
- case NA_SCOMPLEX:
57
- data_type = CA_CMPLX64; break;
58
- case NA_DCOMPLEX:
59
- data_type = CA_CMPLX128; break;
60
- #endif
61
- case NA_ROBJ:
62
- data_type = CA_OBJECT; break;
63
- default:
64
- rb_raise(rb_eCADataTypeError,
65
- "unknown NArray typecode <%i>", typecode);
66
- }
67
- return data_type;
68
- }
69
-
70
- static int
71
- ca_data_type_to_na_typecode(int8_t data_type)
72
- {
73
- int typecode;
74
-
75
- switch ( data_type ) {
76
- case CA_BOOLEAN:
77
- case CA_UINT8:
78
- typecode = NA_BYTE; break;
79
- case CA_INT16:
80
- typecode = NA_SINT; break;
81
- case CA_INT32:
82
- typecode = NA_LINT; break;
83
- case CA_FLOAT32:
84
- typecode = NA_SFLOAT; break;
85
- case CA_FLOAT64:
86
- typecode = NA_DFLOAT; break;
87
- #ifdef HAVE_COMPLEX_H
88
- case CA_CMPLX64:
89
- typecode = NA_SCOMPLEX; break;
90
- case CA_CMPLX128:
91
- typecode = NA_DCOMPLEX; break;
92
- #endif
93
- case CA_OBJECT:
94
- typecode = NA_ROBJ; break;
95
- default:
96
- rb_raise(rb_eRuntimeError,
97
- "no corresponding NArray typecode for CArray data type <%s>",
98
- ca_type_name[data_type]);
99
- }
100
-
101
- return typecode;
102
- }
103
-
104
- /* -------------------------------------------------------------------- */
105
-
106
- static void
107
- cary_na_ref_free (struct NARRAY *ary)
108
- {
109
- xfree(ary->shape);
110
- xfree(ary);
111
- }
112
-
113
- static void
114
- cary_na_ref_mark (struct NARRAY *ary)
115
- {
116
- rb_gc_mark( ary->ref );
117
- }
118
-
119
- /* -------------------------------------------------------------------- */
120
-
121
- static VALUE
122
- rb_cary_na_ref_new_i (int argc, VALUE *argv, VALUE self, VALUE klass)
123
- {
124
- CArray *orig;
125
- struct NARRAY *ary;
126
- int8_t i;
127
-
128
- Data_Get_Struct(self, CArray, orig);
129
-
130
- if ( ! ca_is_attached(orig) ) {
131
- rb_raise(rb_eRuntimeError,
132
- "cannot create NArray reference for not attached CArray");
133
- }
134
-
135
- ary = ALLOC(struct NARRAY);
136
- if ( !ary ) {
137
- rb_raise(rb_eRuntimeError, "cannot allocate NArray");
138
- }
139
-
140
- if ( orig->elements == 0 ) {
141
- ary->rank = 0;
142
- ary->shape = NULL;
143
- ary->total = 0;
144
- ary->ptr = NULL;
145
- }
146
- else if ( argc == 0 ) {
147
- ary->rank = orig->rank;
148
- ary->shape = ALLOC_N(int, ary->rank);
149
- for (i=0; i<ary->rank; i++) {
150
- ary->shape[i] = (int) orig->dim[ary->rank-1-i];
151
- }
152
- ary->total = (int) orig->elements;
153
- ary->ptr = orig->ptr;
154
- }
155
- else {
156
- ca_size_t elements = 1;
157
- ary->rank = argc;
158
- ary->shape = ALLOC_N(int, ary->rank);
159
- for (i=0; i<ary->rank; i++) {
160
- ary->shape[i] = NUM2INT(argv[i]);
161
- elements *= ary->shape[i];
162
- }
163
- ary->total = (int) elements;
164
- ary->ptr = orig->ptr;
165
- if ( elements != orig->elements ) {
166
- free(ary->shape);
167
- rb_raise(rb_eRuntimeError, "elements mismatch");
168
- }
169
- }
170
-
171
- ary->type = ca_data_type_to_na_typecode(orig->data_type);
172
- ary->ref = self;
173
-
174
- return Data_Wrap_Struct(klass, cary_na_ref_mark, cary_na_ref_free, ary);
175
- }
176
-
177
- /* rdoc:
178
- class CArray
179
- def na
180
- end
181
- def nv
182
- end
183
- def nm
184
- end
185
- end
186
- */
187
-
188
- static VALUE
189
- rb_cary_na_ref_new (int argc, VALUE *argv, VALUE self)
190
- {
191
- return rb_cary_na_ref_new_i(argc, argv, self, cNArray);
192
- }
193
-
194
- static VALUE
195
- rb_cary_nv_ref_new (int argc, VALUE *argv, VALUE self)
196
- {
197
- return rb_cary_na_ref_new_i(argc, argv, self, cNVector);
198
- }
199
-
200
- static VALUE
201
- rb_cary_nm_ref_new (int argc, VALUE *argv, VALUE self)
202
- {
203
- return rb_cary_na_ref_new_i(argc, argv, self, cNMatrix);
204
- }
205
-
206
- /* -------------------------------------------------------------------- */
207
-
208
- static VALUE
209
- rb_cary_to_na_bang_i (VALUE self, VALUE klass)
210
- {
211
- volatile VALUE obj, fary;
212
- CArray *ca;
213
- struct NARRAY *na;
214
- int type;
215
-
216
- Data_Get_Struct(self, CArray, ca);
217
-
218
- type = ca_data_type_to_na_typecode(ca->data_type);
219
-
220
- if ( ca->elements == 0 ) {
221
- obj = na_make_empty(type, klass);
222
- }
223
- else {
224
- int shape[127];
225
- int i;
226
-
227
- for (i=0; i<ca->rank; i++) {
228
- shape[i] = (int) ca->dim[ca->rank-i-1];
229
- }
230
-
231
- obj = na_make_object(type, ca->rank, shape, klass);
232
- GetNArray(obj, na);
233
-
234
- fary = rb_ca_farray(self);
235
- Data_Get_Struct(fary, CArray, ca);
236
-
237
- ca_copy_data(ca, na->ptr);
238
- }
239
-
240
- return obj;
241
- }
242
-
243
- /* rdoc:
244
- class CArray
245
- def to_na!
246
- end
247
- def to_nv!
248
- end
249
- def to_nm!
250
- end
251
- end
252
- */
253
-
254
- static VALUE
255
- rb_cary_to_na_bang (VALUE self)
256
- {
257
- return rb_cary_to_na_bang_i(self, cNArray);
258
- }
259
-
260
- static VALUE
261
- rb_cary_to_nv_bang (VALUE self)
262
- {
263
- return rb_cary_to_na_bang_i(self, cNVector);
264
- }
265
-
266
- static VALUE
267
- rb_cary_to_nm_bang (VALUE self)
268
- {
269
- return rb_cary_to_na_bang_i(self, cNMatrix);
270
- }
271
-
272
- /* -------------------------------------------------------------------- */
273
-
274
- static VALUE
275
- rb_cary_to_na_i (VALUE self, VALUE klass)
276
- {
277
- volatile VALUE obj;
278
- CArray *ca;
279
- struct NARRAY *na;
280
- int type;
281
- int i;
282
-
283
- Data_Get_Struct(self, CArray, ca);
284
-
285
- type = ca_data_type_to_na_typecode(ca->data_type);
286
-
287
- if ( ca->elements == 0 ) {
288
- obj = na_make_empty(type, klass);
289
- }
290
- else {
291
- int shape[127];
292
-
293
- for (i=0; i<ca->rank; i++) {
294
- shape[i] = (int) ca->dim[ca->rank-i-1];
295
- }
296
-
297
- obj = na_make_object(type, ca->rank, shape, klass);
298
- GetNArray(obj, na);
299
-
300
- ca_copy_data(ca, na->ptr);
301
- }
302
-
303
- return obj;
304
- }
305
-
306
- /* rdoc:
307
- class CArray
308
- def to_na
309
- end
310
- def to_nv
311
- end
312
- def to_nm
313
- end
314
- end
315
- */
316
-
317
- static VALUE
318
- rb_cary_to_na (VALUE self, VALUE klass)
319
- {
320
- return rb_cary_to_na_i(self, cNArray);
321
- }
322
-
323
- static VALUE
324
- rb_cary_to_nv (VALUE self, VALUE klass)
325
- {
326
- return rb_cary_to_na_i(self, cNVector);
327
- }
328
-
329
- static VALUE
330
- rb_cary_to_nm (VALUE self, VALUE klass)
331
- {
332
- return rb_cary_to_na_i(self, cNMatrix);
333
- }
334
-
335
- /* -------------------------------------------------------------------- */
336
-
337
- /* rdoc:
338
- class NArray
339
- def ca
340
- end
341
- end
342
- */
343
-
344
- static VALUE
345
- rb_na_ca_ref_new (int argc, VALUE *argv, VALUE self)
346
- {
347
- volatile VALUE obj;
348
- struct NARRAY *na;
349
- ca_size_t dim[CA_RANK_MAX];
350
- int8_t data_type;
351
- int i;
352
-
353
- GetNArray(self, na);
354
-
355
- data_type = na_typecode_to_ca_data_type(na->type);
356
-
357
- if ( na->total == 0 ) {
358
- ca_size_t zero = 0;
359
- obj = rb_carray_wrap_ptr(data_type, 1, &zero, 0, NULL,
360
- &EMPTY_ARRAY_PTR, self); /* avoid ca->ptr == NULL */
361
- }
362
- else {
363
- if ( argc == 0 ) {
364
- CA_CHECK_RANK(na->rank);
365
- for (i=0; i<na->rank; i++) {
366
- dim[i] = na->shape[na->rank-i-1];
367
- }
368
- obj = rb_carray_wrap_ptr(data_type,
369
- na->rank, dim, 0, NULL, na->ptr, self);
370
- }
371
- else {
372
- CA_CHECK_RANK(argc);
373
- for (i=0; i<argc; i++) {
374
- dim[i] = NUM2INT(argv[i]);
375
- }
376
- obj = rb_carray_wrap_ptr(data_type, argc, dim, 0, NULL, na->ptr, self);
377
- }
378
- }
379
-
380
- return obj;
381
- }
382
-
383
- /* -------------------------------------------------------------------- */
384
-
385
- /* rdoc:
386
- class NArray
387
- def to_ca
388
- end
389
- end
390
- */
391
-
392
-
393
- static VALUE
394
- rb_na_to_ca (VALUE self)
395
- {
396
- volatile VALUE obj;
397
- CArray *ca;
398
- struct NARRAY *na;
399
- ca_size_t dim[CA_RANK_MAX];
400
- ca_size_t data_type;
401
- ca_size_t i;
402
-
403
- GetNArray(self, na);
404
-
405
- data_type = na_typecode_to_ca_data_type(na->type);
406
-
407
- if ( na->total == 0 ) {
408
- ca_size_t zero = 0;
409
- obj = rb_carray_new(data_type, 1, &zero, 0, NULL);
410
- }
411
- else {
412
- CA_CHECK_RANK(na->rank);
413
-
414
- for (i=0; i<na->rank; i++) {
415
- dim[i] = na->shape[na->rank-i-1];
416
- }
417
-
418
- obj = rb_carray_new(data_type, na->rank, dim, 0, NULL);
419
- Data_Get_Struct(obj, CArray, ca);
420
-
421
- ca_sync_data(ca, na->ptr);
422
- }
423
-
424
- return obj;
425
- }
426
-
427
- /* -------------------------------------------------------------------- */
428
-
429
- /* rdoc:
430
- class NArray
431
- def to_ca!
432
- end
433
- end
434
- */
435
-
436
- static VALUE
437
- rb_na_to_ca_bang (VALUE self)
438
- {
439
- volatile VALUE obj, fary;
440
- CArray *ca;
441
- struct NARRAY *na;
442
- ca_size_t dim[CA_RANK_MAX];
443
- ca_size_t data_type;
444
- ca_size_t i;
445
-
446
- GetNArray(self, na);
447
-
448
- data_type = na_typecode_to_ca_data_type(na->type);
449
-
450
- if ( na->total == 0 ) {
451
- ca_size_t zero = 0;
452
- obj = rb_carray_new(data_type, 1, &zero, 0, NULL);
453
- }
454
- else {
455
- CA_CHECK_RANK(na->rank);
456
-
457
- for (i=0; i<na->rank; i++) {
458
- dim[i] = na->shape[na->rank-i-1];
459
- }
460
-
461
- obj = rb_carray_new(data_type, na->rank, dim, 0, NULL);
462
- fary = rb_ca_farray(obj);
463
- Data_Get_Struct(fary, CArray, ca);
464
-
465
- ca_sync_data(ca, na->ptr);
466
- }
467
-
468
- return obj;
469
- }
470
-
471
- /* -------------------------------------------------------------------- */
472
-
473
- void
474
- Init_ca_wrap_narray ()
475
- {
476
- /* rb_require("narray"); */ /* "narray" should be loaded in config.rb */
477
-
478
- rb_define_const(rb_cCArray, "HAVE_NARRAY", Qtrue);
479
-
480
- /* CArray -> NArray */
481
- rb_define_method(rb_cCArray, "na", rb_cary_na_ref_new, -1);
482
- rb_define_method(rb_cCArray, "to_na", rb_cary_to_na, 0);
483
- rb_define_method(rb_cCArray, "to_na!", rb_cary_to_na_bang, 0);
484
-
485
- /* CArray -> NVector */
486
- rb_define_method(rb_cCArray, "nv", rb_cary_nv_ref_new, -1);
487
- rb_define_method(rb_cCArray, "to_nv", rb_cary_to_nv, 0);
488
- rb_define_method(rb_cCArray, "to_nv!", rb_cary_to_nv_bang, 0);
489
-
490
- /* CArray -> NMatrix */
491
- rb_define_method(rb_cCArray, "nm", rb_cary_nm_ref_new, -1);
492
- rb_define_method(rb_cCArray, "to_nm", rb_cary_to_nm, 0);
493
- rb_define_method(rb_cCArray, "to_nm!", rb_cary_to_nm_bang, 0);
494
-
495
- /* NArray -> CArray */
496
- rb_define_method(cNArray, "ca", rb_na_ca_ref_new, -1);
497
- rb_define_method(cNArray, "to_ca", rb_na_to_ca, 0);
498
- rb_define_method(cNArray, "to_ca!", rb_na_to_ca_bang, 0);
499
- }
500
-