carray 1.4.0 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +32 -0
- data/LICENSE +22 -0
- data/NEWS.md +83 -0
- data/README.md +38 -18
- data/Rakefile +2 -2
- data/TODO.md +17 -0
- data/carray.gemspec +13 -18
- data/{ca_iter_block.c → ext/ca_iter_block.c} +16 -18
- data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +20 -21
- data/{ca_iter_window.c → ext/ca_iter_window.c} +12 -14
- data/{ca_obj_array.c → ext/ca_obj_array.c} +451 -176
- data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +18 -23
- data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +12 -16
- data/{ca_obj_block.c → ext/ca_obj_block.c} +47 -54
- data/{ca_obj_fake.c → ext/ca_obj_fake.c} +10 -12
- data/{ca_obj_farray.c → ext/ca_obj_farray.c} +21 -23
- data/{ca_obj_field.c → ext/ca_obj_field.c} +30 -32
- data/{ca_obj_grid.c → ext/ca_obj_grid.c} +32 -33
- data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +11 -13
- data/{ca_obj_object.c → ext/ca_obj_object.c} +40 -42
- data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +3 -5
- data/{ca_obj_refer.c → ext/ca_obj_refer.c} +44 -48
- data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +45 -47
- data/{ca_obj_select.c → ext/ca_obj_select.c} +4 -6
- data/{ca_obj_shift.c → ext/ca_obj_shift.c} +26 -28
- data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +26 -28
- data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +106 -160
- data/{ca_obj_window.c → ext/ca_obj_window.c} +33 -35
- data/{carray.h → ext/carray.h} +86 -59
- data/{carray_access.c → ext/carray_access.c} +194 -101
- data/{carray_attribute.c → ext/carray_attribute.c} +161 -207
- data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +1 -3
- data/{carray_cast.c → ext/carray_cast.c} +351 -150
- data/{carray_cast_func.rb → ext/carray_cast_func.rb} +1 -2
- data/{carray_class.c → ext/carray_class.c} +28 -36
- data/{carray_conversion.c → ext/carray_conversion.c} +63 -68
- data/{carray_copy.c → ext/carray_copy.c} +34 -50
- data/{carray_core.c → ext/carray_core.c} +75 -62
- data/ext/carray_data_type.c +66 -0
- data/{carray_element.c → ext/carray_element.c} +34 -53
- data/{carray_generate.c → ext/carray_generate.c} +71 -50
- data/{carray_iterator.c → ext/carray_iterator.c} +53 -53
- data/{carray_loop.c → ext/carray_loop.c} +77 -106
- data/{carray_mask.c → ext/carray_mask.c} +105 -114
- data/{carray_math.rb → ext/carray_math.rb} +29 -13
- data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +1 -3
- data/{carray_numeric.c → ext/carray_numeric.c} +43 -46
- data/{carray_operator.c → ext/carray_operator.c} +49 -36
- data/{carray_order.c → ext/carray_order.c} +232 -217
- data/{carray_sort_addr.c → ext/carray_sort_addr.c} +14 -21
- data/{carray_stat.c → ext/carray_stat.c} +6 -8
- data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +25 -27
- data/{carray_test.c → ext/carray_test.c} +63 -51
- data/{carray_undef.c → ext/carray_undef.c} +1 -11
- data/{carray_utils.c → ext/carray_utils.c} +12 -4
- data/{extconf.rb → ext/extconf.rb} +10 -7
- data/{mkmath.rb → ext/mkmath.rb} +2 -2
- data/{ruby_carray.c → ext/ruby_carray.c} +20 -8
- data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +2 -4
- data/{ruby_float_func.c → ext/ruby_float_func.c} +1 -3
- data/ext/version.h +16 -0
- data/{version.rb → ext/version.rb} +0 -0
- data/lib/carray.rb +51 -40
- data/lib/carray/{base/autoload.rb → autoload.rb} +1 -3
- data/lib/carray/autoload/autoload_base.rb +1 -1
- data/lib/carray/autoload/autoload_gem_numo_narray.rb +7 -6
- data/lib/carray/autoload/autoload_gem_random.rb +8 -0
- data/lib/carray/basic.rb +191 -0
- data/lib/carray/broadcast.rb +101 -0
- data/lib/carray/compose.rb +315 -0
- data/lib/carray/construct.rb +484 -0
- data/lib/carray/convert.rb +115 -0
- data/lib/carray/info.rb +1 -3
- data/lib/carray/{base/inspect.rb → inspect.rb} +9 -11
- data/lib/carray/io/imagemagick.rb +2 -4
- data/lib/carray/{base/iterator.rb → iterator.rb} +6 -6
- data/lib/carray/mask.rb +102 -0
- data/lib/carray/{base/math.rb → math.rb} +20 -52
- data/lib/carray/math/histogram.rb +8 -10
- data/lib/carray/math/recurrence.rb +1 -3
- data/lib/carray/mkmf.rb +9 -3
- data/lib/carray/object/ca_obj_iterator.rb +1 -3
- data/lib/carray/object/ca_obj_link.rb +1 -3
- data/lib/carray/object/ca_obj_pack.rb +9 -11
- data/lib/carray/obsolete.rb +256 -0
- data/lib/carray/ordering.rb +181 -0
- data/lib/carray/{base/serialize.rb → serialize.rb} +60 -76
- data/lib/carray/{base/string.rb → string.rb} +10 -64
- data/lib/carray/{base/struct.rb → struct.rb} +19 -21
- data/lib/carray/{io/table.rb → table.rb} +1 -10
- data/lib/carray/testing.rb +51 -0
- data/lib/carray/time.rb +76 -0
- data/lib/carray/transform.rb +109 -0
- data/misc/Methods.ja.md +182 -0
- data/{NOTE → misc/NOTE} +16 -38
- data/spec/Classes/CABitfield_spec.rb +58 -0
- data/spec/Classes/CABlockIterator_spec.rb +114 -0
- data/spec/Classes/CABlock_spec.rb +205 -0
- data/spec/Classes/CAField_spec.rb +39 -0
- data/spec/Classes/CAGrid_spec.rb +75 -0
- data/spec/Classes/CAMap_spec.rb +0 -0
- data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
- data/spec/Classes/CAObject_attribute_spec.rb +33 -0
- data/spec/Classes/CAObject_spec.rb +33 -0
- data/spec/Classes/CARefer_spec.rb +93 -0
- data/spec/Classes/CARepeat_spec.rb +65 -0
- data/spec/Classes/CASelect_spec.rb +22 -0
- data/spec/Classes/CAShift_spec.rb +16 -0
- data/spec/Classes/CAStruct_spec.rb +71 -0
- data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
- data/spec/Classes/CAUnboudRepeat_spec.rb +102 -0
- data/spec/Classes/CAWindow_spec.rb +54 -0
- data/spec/Classes/CAWrap_spec.rb +8 -0
- data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
- data/spec/Classes/CScalar_spec.rb +55 -0
- data/spec/Features/feature_130_spec.rb +19 -0
- data/spec/Features/feature_attributes_spec.rb +280 -0
- data/spec/Features/feature_boolean_spec.rb +98 -0
- data/spec/Features/feature_broadcast.rb +116 -0
- data/spec/Features/feature_cast_function.rb +19 -0
- data/spec/Features/feature_cast_spec.rb +33 -0
- data/spec/Features/feature_class_spec.rb +84 -0
- data/spec/Features/feature_complex_spec.rb +42 -0
- data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
- data/spec/Features/feature_convert_spec.rb +46 -0
- data/spec/Features/feature_copy_spec.rb +123 -0
- data/spec/Features/feature_creation_spec.rb +84 -0
- data/spec/Features/feature_element_spec.rb +144 -0
- data/spec/Features/feature_extream_spec.rb +54 -0
- data/spec/Features/feature_generate_spec.rb +74 -0
- data/spec/Features/feature_index_spec.rb +69 -0
- data/spec/Features/feature_mask_spec.rb +580 -0
- data/spec/Features/feature_math_spec.rb +97 -0
- data/spec/Features/feature_order_spec.rb +146 -0
- data/spec/Features/feature_ref_store_spec.rb +209 -0
- data/spec/Features/feature_serialization_spec.rb +125 -0
- data/spec/Features/feature_stat_spec.rb +397 -0
- data/spec/Features/feature_virtual_spec.rb +48 -0
- data/spec/Features/method_eq_spec.rb +81 -0
- data/spec/Features/method_is_nan_spec.rb +12 -0
- data/spec/Features/method_map_spec.rb +54 -0
- data/spec/Features/method_max_with.rb +20 -0
- data/spec/Features/method_min_with.rb +19 -0
- data/spec/Features/method_ne_spec.rb +18 -0
- data/spec/Features/method_project_spec.rb +188 -0
- data/spec/Features/method_ref_spec.rb +27 -0
- data/spec/Features/method_round_spec.rb +11 -0
- data/spec/Features/method_s_linspace_spec.rb +48 -0
- data/spec/Features/method_s_span_spec.rb +14 -0
- data/spec/Features/method_seq_spec.rb +47 -0
- data/spec/Features/method_sort_with.rb +43 -0
- data/spec/Features/method_sorted_with.rb +29 -0
- data/spec/Features/method_span_spec.rb +42 -0
- data/spec/Features/method_wrap_readonly_spec.rb +43 -0
- data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
- data/spec/spec_all.rb +0 -1
- data/utils/convert_test.rb +73 -0
- data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
- data/{devel → utils}/guess_shape.rb +0 -0
- data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
- metadata +159 -206
- data/COPYING +0 -56
- data/GPL +0 -340
- data/LEGAL +0 -50
- data/TODO +0 -5
- data/carray_random.c +0 -531
- data/devel/im2col.rb +0 -17
- data/ext/calculus/carray_calculus.c +0 -931
- data/ext/calculus/carray_interp.c +0 -358
- data/ext/calculus/extconf.rb +0 -12
- data/ext/calculus/lib/math/calculus.rb +0 -119
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
- data/ext/mathfunc/extconf.rb +0 -18
- data/ext/mathfunc/test/test_hypot.rb +0 -5
- data/ext/mathfunc/test/test_j0.rb +0 -22
- data/ext/mathfunc/test/test_jn.rb +0 -8
- data/ext/mathfunc/test/test_sph.rb +0 -9
- data/lib/carray/autoload/autoload_io_table.rb +0 -1
- data/lib/carray/autoload/autoload_math_interp.rb +0 -4
- data/lib/carray/base/basic.rb +0 -1146
- data/lib/carray/base/obsolete.rb +0 -131
- data/lib/carray/math/interp.rb +0 -57
- data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
- data/mt19937ar.c +0 -182
- data/mt19937ar.h +0 -86
- data/rdoc_main.rb +0 -27
- data/rdoc_math.rb +0 -5
- data/rdoc_stat.rb +0 -31
- data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
- data/spec/CArray/bug/store_spec.rb +0 -27
- data/spec/CArray/index/repeat_spec.rb +0 -10
- data/spec/CArray/method/eq_spec.rb +0 -80
- data/spec/CArray/method/is_nan_spec.rb +0 -12
- data/spec/CArray/method/ne_spec.rb +0 -18
- data/spec/CArray/method/round_spec.rb +0 -11
- data/spec/CArray/object/_attribute_spec.rb +0 -32
- data/spec/CArray/object/s_new_spec.rb +0 -31
- data/spec/CArray/serialize/Serialization_spec.rb +0 -89
- data/test/test_130.rb +0 -23
- data/test/test_ALL.rb +0 -51
- data/test/test_CABitfield.rb +0 -59
- data/test/test_CABlock.rb +0 -208
- data/test/test_CAField.rb +0 -40
- data/test/test_CAGrid.rb +0 -76
- data/test/test_CAMmap.rb +0 -11
- data/test/test_CARefer.rb +0 -94
- data/test/test_CARepeat.rb +0 -66
- data/test/test_CASelect.rb +0 -23
- data/test/test_CAShift.rb +0 -17
- data/test/test_CAWindow.rb +0 -55
- data/test/test_CAWrap.rb +0 -9
- data/test/test_CComplex.rb +0 -83
- data/test/test_CScalar.rb +0 -91
- data/test/test_attribute.rb +0 -281
- data/test/test_block_iterator.rb +0 -17
- data/test/test_boolean.rb +0 -99
- data/test/test_cast.rb +0 -33
- data/test/test_class.rb +0 -85
- data/test/test_complex.rb +0 -43
- data/test/test_convert.rb +0 -79
- data/test/test_copy.rb +0 -141
- data/test/test_creation.rb +0 -85
- data/test/test_element.rb +0 -146
- data/test/test_extream.rb +0 -55
- data/test/test_generate.rb +0 -75
- data/test/test_index.rb +0 -71
- data/test/test_mask.rb +0 -578
- data/test/test_math.rb +0 -98
- data/test/test_narray.rb +0 -64
- data/test/test_order.rb +0 -147
- data/test/test_random.rb +0 -15
- data/test/test_ref_store.rb +0 -211
- data/test/test_stat.rb +0 -414
- data/test/test_struct.rb +0 -72
- data/test/test_virtual.rb +0 -49
- data/utils/create_rdoc.sh +0 -9
- data/utils/make_tgz.sh +0 -3
- data/version.h +0 -18
@@ -3,10 +3,8 @@
|
|
3
3
|
ca_obj_grid.c
|
4
4
|
|
5
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
6
|
|
9
|
-
Copyright (C) 2005 Hiroki Motoyoshi
|
7
|
+
Copyright (C) 2005-2020 Hiroki Motoyoshi
|
10
8
|
|
11
9
|
---------------------------------------------------------------------------- */
|
12
10
|
|
@@ -15,7 +13,7 @@
|
|
15
13
|
typedef struct {
|
16
14
|
int16_t obj_type;
|
17
15
|
int8_t data_type;
|
18
|
-
int8_t
|
16
|
+
int8_t ndim;
|
19
17
|
int32_t flags;
|
20
18
|
ca_size_t bytes;
|
21
19
|
ca_size_t elements;
|
@@ -32,7 +30,7 @@ typedef struct {
|
|
32
30
|
|
33
31
|
static VALUE rb_cCAGrid;
|
34
32
|
|
35
|
-
/*
|
33
|
+
/* yard:
|
36
34
|
class CAGrid < CAVirtual # :nodoc:
|
37
35
|
end
|
38
36
|
*/
|
@@ -43,20 +41,21 @@ int
|
|
43
41
|
ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
|
44
42
|
CArray **grid, int8_t *contig, int share)
|
45
43
|
{
|
46
|
-
int8_t
|
44
|
+
int8_t ndim, data_type;
|
47
45
|
ca_size_t *dim0;
|
48
46
|
ca_size_t elements, bytes;
|
47
|
+
ca_size_t j, k;
|
49
48
|
double length;
|
50
|
-
|
49
|
+
int8_t i;
|
51
50
|
|
52
51
|
data_type = parent->data_type;
|
53
|
-
|
52
|
+
ndim = parent->ndim;
|
54
53
|
bytes = parent->bytes;
|
55
54
|
dim0 = parent->dim;
|
56
55
|
|
57
56
|
elements = 1;
|
58
57
|
length = bytes;
|
59
|
-
for (i=0; i<
|
58
|
+
for (i=0; i<ndim; i++) {
|
60
59
|
if ( dim[i] < 0 ) {
|
61
60
|
rb_raise(rb_eRuntimeError, "negative size for %i-th dimension", i);
|
62
61
|
}
|
@@ -71,12 +70,12 @@ ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
|
|
71
70
|
ca->obj_type = CA_OBJ_GRID;
|
72
71
|
ca->data_type = data_type;
|
73
72
|
ca->flags = 0;
|
74
|
-
ca->
|
73
|
+
ca->ndim = ndim;
|
75
74
|
ca->bytes = bytes;
|
76
75
|
ca->elements = elements;
|
77
76
|
ca->ptr = NULL;
|
78
77
|
ca->mask = NULL;
|
79
|
-
ca->dim = ALLOC_N(ca_size_t,
|
78
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
80
79
|
|
81
80
|
ca->parent = parent;
|
82
81
|
ca->attach = 0;
|
@@ -88,14 +87,14 @@ ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
|
|
88
87
|
ca->contig = contig;
|
89
88
|
}
|
90
89
|
else {
|
91
|
-
ca->grid = ALLOC_N(CArray *,
|
92
|
-
ca->contig = ALLOC_N(int8_t,
|
90
|
+
ca->grid = ALLOC_N(CArray *, ndim);
|
91
|
+
ca->contig = ALLOC_N(int8_t, ndim);
|
93
92
|
}
|
94
93
|
|
95
|
-
memcpy(ca->dim, dim,
|
94
|
+
memcpy(ca->dim, dim, ndim * sizeof(ca_size_t));
|
96
95
|
|
97
96
|
if ( ! share ) {
|
98
|
-
for (i=0; i<
|
97
|
+
for (i=0; i<ndim; i++) {
|
99
98
|
if ( grid[i] ) {
|
100
99
|
if ( ca_is_any_masked(grid[i]) ) {
|
101
100
|
ca_size_t gsize = grid[i]->elements - ca_count_masked(grid[i]);
|
@@ -137,7 +136,7 @@ ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
|
|
137
136
|
}
|
138
137
|
}
|
139
138
|
|
140
|
-
if ( ca->
|
139
|
+
if ( ca->ndim == 1 && ca_is_scalar(grid[0]) ) {
|
141
140
|
ca_set_flag(ca, CA_FLAG_SCALAR);
|
142
141
|
}
|
143
142
|
|
@@ -169,7 +168,7 @@ free_ca_grid (void *ap)
|
|
169
168
|
ca_free(ca->mask);
|
170
169
|
if ( ! (ca->flags & CA_FLAG_SHARE_INDEX)) {
|
171
170
|
xfree(ca->contig);
|
172
|
-
for (i=0; i<ca->
|
171
|
+
for (i=0; i<ca->ndim; i++) {
|
173
172
|
ca_free(ca->grid[i]);
|
174
173
|
}
|
175
174
|
xfree(ca->grid);
|
@@ -217,7 +216,7 @@ ca_grid_func_ptr_at_index (void *ap, ca_size_t *idx)
|
|
217
216
|
ca_size_t n;
|
218
217
|
|
219
218
|
n = 0;
|
220
|
-
for (i=0; i<ca->
|
219
|
+
for (i=0; i<ca->ndim; i++) {
|
221
220
|
n = dim0[i]*n + *(ca_size_t*) ca_ptr_at_addr(grid[i], idx[i]);
|
222
221
|
}
|
223
222
|
|
@@ -240,7 +239,7 @@ ca_grid_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
240
239
|
CArray **grid = ca->grid;
|
241
240
|
ca_size_t idx0[CA_RANK_MAX];
|
242
241
|
int8_t i;
|
243
|
-
for (i=0; i<ca->
|
242
|
+
for (i=0; i<ca->ndim; i++) {
|
244
243
|
ca_fetch_addr(grid[i], idx[i], &idx0[i]);
|
245
244
|
}
|
246
245
|
ca_fetch_index(ca->parent, idx0, ptr);
|
@@ -253,7 +252,7 @@ ca_grid_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
253
252
|
CArray **grid = ca->grid;
|
254
253
|
ca_size_t idx0[CA_RANK_MAX];
|
255
254
|
int8_t i;
|
256
|
-
for (i=0; i<ca->
|
255
|
+
for (i=0; i<ca->ndim; i++) {
|
257
256
|
ca_fetch_addr(grid[i], idx[i], &idx0[i]);
|
258
257
|
}
|
259
258
|
ca_store_index(ca->parent, idx0, ptr);
|
@@ -386,7 +385,7 @@ ca_grid_attach_loop (CAGrid *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
386
385
|
CArray **grid = ca->grid;
|
387
386
|
ca_size_t i, k;
|
388
387
|
|
389
|
-
if ( level == ca->
|
388
|
+
if ( level == ca->ndim - 1 ) {
|
390
389
|
idx[level] = 0;
|
391
390
|
idx0[level] = 0;
|
392
391
|
if ( ca->contig[level] ) {
|
@@ -460,7 +459,7 @@ ca_grid_sync_loop (CAGrid *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
460
459
|
CArray **grid = ca->grid;
|
461
460
|
ca_size_t i, k;
|
462
461
|
|
463
|
-
if ( level == ca->
|
462
|
+
if ( level == ca->ndim - 1 ) {
|
464
463
|
idx[level] = 0;
|
465
464
|
idx0[level] = 0;
|
466
465
|
if ( ca->contig[level] ) {
|
@@ -532,7 +531,7 @@ ca_grid_fill_loop (CAGrid *ca, char *ptr,
|
|
532
531
|
{
|
533
532
|
CArray **grid = ca->grid;
|
534
533
|
ca_size_t i, k;
|
535
|
-
if ( level == ca->
|
534
|
+
if ( level == ca->ndim - 1 ) {
|
536
535
|
idx0[level] = 0;
|
537
536
|
if ( ca->contig[level] ) {
|
538
537
|
char *p = ca_ptr_at_index(ca->parent, idx0);
|
@@ -602,7 +601,7 @@ rb_ca_grid_new (VALUE cary, ca_size_t *dim, CArray **grid)
|
|
602
601
|
return obj;
|
603
602
|
}
|
604
603
|
|
605
|
-
/*
|
604
|
+
/* yard:
|
606
605
|
class CArray
|
607
606
|
def grid
|
608
607
|
end
|
@@ -624,21 +623,21 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
|
|
624
623
|
|
625
624
|
ridx = rb_ary_new4(argc, argv);
|
626
625
|
|
627
|
-
if ( RARRAY_LEN(ridx) > ca->
|
628
|
-
rb_raise(rb_eArgError, "# of arguments doesn't equal to the
|
626
|
+
if ( RARRAY_LEN(ridx) > ca->ndim ) {
|
627
|
+
rb_raise(rb_eArgError, "# of arguments doesn't equal to the ndim");
|
629
628
|
}
|
630
|
-
else if ( RARRAY_LEN(ridx) < ca->
|
629
|
+
else if ( RARRAY_LEN(ridx) < ca->ndim ) {
|
631
630
|
volatile VALUE ref;
|
632
631
|
CArray *cv;
|
633
632
|
ca_size_t rdim[CA_RANK_MAX];
|
634
|
-
ca_size_t
|
633
|
+
ca_size_t rndim = RARRAY_LEN(ridx);
|
635
634
|
ca_size_t j = 0, k;
|
636
|
-
for (i=0; i<
|
635
|
+
for (i=0; i<rndim; i++) {
|
637
636
|
rval = rb_ary_entry(ridx, i);
|
638
637
|
if ( rb_obj_is_carray(rval) ) {
|
639
638
|
Data_Get_Struct(rval, CArray, cv);
|
640
639
|
rdim[i] = 1;
|
641
|
-
for (k=0; k<cv->
|
640
|
+
for (k=0; k<cv->ndim; k++) {
|
642
641
|
rdim[i] *= ca->dim[j];
|
643
642
|
j += 1;
|
644
643
|
}
|
@@ -648,10 +647,10 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
|
|
648
647
|
j += 1;
|
649
648
|
}
|
650
649
|
}
|
651
|
-
if ( j != ca->
|
652
|
-
rb_raise(rb_eArgError, "invalid total
|
650
|
+
if ( j != ca->ndim ) {
|
651
|
+
rb_raise(rb_eArgError, "invalid total ndim of args");
|
653
652
|
}
|
654
|
-
ref = rb_ca_refer_new(self, ca->data_type,
|
653
|
+
ref = rb_ca_refer_new(self, ca->data_type, rndim, rdim, ca->bytes, 0);
|
655
654
|
return rb_ca_grid(argc, argv, ref);
|
656
655
|
}
|
657
656
|
|
@@ -3,10 +3,8 @@
|
|
3
3
|
ca_obj_mapping.c
|
4
4
|
|
5
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
6
|
|
9
|
-
Copyright (C) 2005 Hiroki Motoyoshi
|
7
|
+
Copyright (C) 2005-2020 Hiroki Motoyoshi
|
10
8
|
|
11
9
|
---------------------------------------------------------------------------- */
|
12
10
|
|
@@ -21,7 +19,7 @@
|
|
21
19
|
typedef struct {
|
22
20
|
int16_t obj_type;
|
23
21
|
int8_t data_type;
|
24
|
-
int8_t
|
22
|
+
int8_t ndim;
|
25
23
|
int32_t flags;
|
26
24
|
ca_size_t bytes;
|
27
25
|
ca_size_t elements;
|
@@ -39,7 +37,7 @@ static int8_t CA_OBJ_MAPPING;
|
|
39
37
|
|
40
38
|
static VALUE rb_cCAMapping;
|
41
39
|
|
42
|
-
/*
|
40
|
+
/* yard:
|
43
41
|
class CAMapping < CAVirtual # :nodoc:
|
44
42
|
end
|
45
43
|
*/
|
@@ -49,7 +47,7 @@ static VALUE rb_cCAMapping;
|
|
49
47
|
int
|
50
48
|
ca_mapping_setup (CAMapping *ca, CArray *parent, CArray *mapper, int share)
|
51
49
|
{
|
52
|
-
int8_t
|
50
|
+
int8_t ndim, data_type;
|
53
51
|
ca_size_t elements, bytes;
|
54
52
|
ca_size_t *p;
|
55
53
|
ca_size_t i;
|
@@ -66,19 +64,19 @@ ca_mapping_setup (CAMapping *ca, CArray *parent, CArray *mapper, int share)
|
|
66
64
|
ca->bytes = bytes;
|
67
65
|
ca->ptr = NULL;
|
68
66
|
|
69
|
-
|
67
|
+
ndim = mapper->ndim;
|
70
68
|
elements = mapper->elements;
|
71
69
|
|
72
|
-
ca->
|
70
|
+
ca->ndim = ndim;
|
73
71
|
ca->elements = elements;
|
74
72
|
ca->mask = NULL;
|
75
|
-
ca->dim = ALLOC_N(ca_size_t,
|
73
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
76
74
|
|
77
75
|
ca->parent = parent;
|
78
76
|
ca->attach = 0;
|
79
77
|
ca->nosync = 0;
|
80
78
|
|
81
|
-
memcpy(ca->dim, mapper->dim,
|
79
|
+
memcpy(ca->dim, mapper->dim, ndim * sizeof(ca_size_t));
|
82
80
|
|
83
81
|
if ( share ) {
|
84
82
|
ca_set_flag(ca, CA_FLAG_SHARE_INDEX);
|
@@ -176,7 +174,7 @@ ca_mapping_func_ptr_at_index (void *ap, ca_size_t *idx)
|
|
176
174
|
int8_t i;
|
177
175
|
ca_size_t n;
|
178
176
|
n = idx[0];
|
179
|
-
for (i=1; i<ca->
|
177
|
+
for (i=1; i<ca->ndim; i++) {
|
180
178
|
n = dim[i]*n+idx[i];
|
181
179
|
}
|
182
180
|
n = *(ca_size_t*) ca_ptr_at_addr(ca->mapper, n);
|
@@ -200,7 +198,7 @@ ca_mapping_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
200
198
|
int8_t i;
|
201
199
|
ca_size_t n;
|
202
200
|
n = idx[0];
|
203
|
-
for (i=1; i<ca->
|
201
|
+
for (i=1; i<ca->ndim; i++) {
|
204
202
|
n = dim[i]*n+idx[i];
|
205
203
|
}
|
206
204
|
n = *(ca_size_t*) ca_ptr_at_addr(ca->mapper, n);
|
@@ -215,7 +213,7 @@ ca_mapping_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
215
213
|
int8_t i;
|
216
214
|
ca_size_t n;
|
217
215
|
n = idx[0];
|
218
|
-
for (i=1; i<ca->
|
216
|
+
for (i=1; i<ca->ndim; i++) {
|
219
217
|
n = dim[i]*n+idx[i];
|
220
218
|
}
|
221
219
|
n = *(ca_size_t*) ca_ptr_at_addr(ca->mapper, n);
|
@@ -3,10 +3,8 @@
|
|
3
3
|
ca_obj_object.c
|
4
4
|
|
5
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
6
|
|
9
|
-
Copyright (C) 2005 Hiroki Motoyoshi
|
7
|
+
Copyright (C) 2005-2020 Hiroki Motoyoshi
|
10
8
|
|
11
9
|
---------------------------------------------------------------------------- */
|
12
10
|
|
@@ -41,7 +39,7 @@
|
|
41
39
|
VALUE rb_cCAObject;
|
42
40
|
|
43
41
|
|
44
|
-
/*
|
42
|
+
/* yard:
|
45
43
|
class CAObject < CAVirtual # :nodoc:
|
46
44
|
end
|
47
45
|
*/
|
@@ -52,17 +50,17 @@ VALUE rb_cCAObject;
|
|
52
50
|
static int8_t CA_OBJ_OBJECT_MASK;
|
53
51
|
static VALUE rb_cCAObjectMask;
|
54
52
|
|
55
|
-
/*
|
53
|
+
/* yard:
|
56
54
|
class CAObjectMask < CAVirtual # :nodoc:
|
57
55
|
end
|
58
56
|
*/
|
59
57
|
|
60
58
|
|
61
59
|
static CAObjectMask *
|
62
|
-
ca_objmask_new (VALUE array, int8_t
|
60
|
+
ca_objmask_new (VALUE array, int8_t ndim, ca_size_t *dim)
|
63
61
|
{
|
64
62
|
CAObjectMask *ca = ALLOC(CAObjectMask);
|
65
|
-
ca_wrap_setup_null((CArray *)ca, CA_BOOLEAN,
|
63
|
+
ca_wrap_setup_null((CArray *)ca, CA_BOOLEAN, ndim, dim, 0, NULL);
|
66
64
|
ca->obj_type = CA_OBJ_OBJECT_MASK;
|
67
65
|
ca->array = array;
|
68
66
|
|
@@ -81,7 +79,7 @@ static void *
|
|
81
79
|
ca_objmask_func_clone (void *ap)
|
82
80
|
{
|
83
81
|
CAObjectMask *ca = (CAObjectMask *) ap;
|
84
|
-
return ca_objmask_new(ca->array, ca->
|
82
|
+
return ca_objmask_new(ca->array, ca->ndim, ca->dim);
|
85
83
|
}
|
86
84
|
|
87
85
|
void
|
@@ -100,8 +98,8 @@ ca_objmask_func_fetch_addr (void *ap, ca_size_t addr, void *ptr)
|
|
100
98
|
else if ( rb_obj_respond_to(ca->array, rb_intern("mask_fetch_index"), Qtrue) ) {
|
101
99
|
ca_size_t idx[CA_RANK_MAX];
|
102
100
|
ca_addr2index(ca, addr, idx);
|
103
|
-
ridx = rb_ary_new2(ca->
|
104
|
-
for (i=0; i<ca->
|
101
|
+
ridx = rb_ary_new2(ca->ndim);
|
102
|
+
for (i=0; i<ca->ndim; i++) {
|
105
103
|
rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
|
106
104
|
}
|
107
105
|
rval = rb_funcall(ca->array, rb_intern("mask_fetch_index"), 1, ridx);
|
@@ -121,8 +119,8 @@ ca_objmask_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
121
119
|
int i;
|
122
120
|
|
123
121
|
if ( rb_obj_respond_to(ca->array, rb_intern("mask_fetch_index"), Qtrue) ) {
|
124
|
-
ridx = rb_ary_new2(ca->
|
125
|
-
for (i=0; i<ca->
|
122
|
+
ridx = rb_ary_new2(ca->ndim);
|
123
|
+
for (i=0; i<ca->ndim; i++) {
|
126
124
|
rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
|
127
125
|
}
|
128
126
|
rval = rb_funcall(ca->array, rb_intern("mask_fetch_index"), 1, ridx);
|
@@ -158,8 +156,8 @@ ca_objmask_func_store_addr (void *ap, ca_size_t addr, void *ptr)
|
|
158
156
|
else if ( rb_obj_respond_to(ca->array, rb_intern("mask_store_index"), Qtrue) ) {
|
159
157
|
ca_size_t idx[CA_RANK_MAX];
|
160
158
|
ca_addr2index(ca, addr, idx);
|
161
|
-
ridx = rb_ary_new2(ca->
|
162
|
-
for (i=0; i<ca->
|
159
|
+
ridx = rb_ary_new2(ca->ndim);
|
160
|
+
for (i=0; i<ca->ndim; i++) {
|
163
161
|
rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
|
164
162
|
}
|
165
163
|
rb_funcall(ca->array, rb_intern("mask_store_index"), 2, ridx, rval);
|
@@ -177,8 +175,8 @@ ca_objmask_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
177
175
|
rval = INT2NUM( *(uint8_t*)ptr );
|
178
176
|
|
179
177
|
if ( rb_obj_respond_to(ca->array, rb_intern("mask_store_index"), Qtrue) ) {
|
180
|
-
ridx = rb_ary_new2(ca->
|
181
|
-
for (i=0; i<ca->
|
178
|
+
ridx = rb_ary_new2(ca->ndim);
|
179
|
+
for (i=0; i<ca->ndim; i++) {
|
182
180
|
rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
|
183
181
|
}
|
184
182
|
rb_funcall(ca->array, rb_intern("mask_store_index"), 2, ridx, rval);
|
@@ -290,7 +288,7 @@ rb_ca_objmask_initialize_copy (VALUE self, VALUE other)
|
|
290
288
|
Data_Get_Struct(self, CAObjectMask, ca);
|
291
289
|
Data_Get_Struct(other, CAObjectMask, cs);
|
292
290
|
|
293
|
-
carray_setup((CArray *)ca, CA_BOOLEAN, cs->
|
291
|
+
carray_setup((CArray *)ca, CA_BOOLEAN, cs->ndim, cs->dim, 0, NULL);
|
294
292
|
ca->obj_type = CA_OBJ_OBJECT_MASK;
|
295
293
|
ca->array = cs->array;
|
296
294
|
|
@@ -301,7 +299,7 @@ rb_ca_objmask_initialize_copy (VALUE self, VALUE other)
|
|
301
299
|
|
302
300
|
static int
|
303
301
|
ca_object_setup (CAObject *ca,
|
304
|
-
int8_t data_type, int8_t
|
302
|
+
int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes)
|
305
303
|
{
|
306
304
|
ca_size_t elements;
|
307
305
|
double length;
|
@@ -310,15 +308,15 @@ ca_object_setup (CAObject *ca,
|
|
310
308
|
/* check arguments */
|
311
309
|
|
312
310
|
CA_CHECK_DATA_TYPE(data_type);
|
313
|
-
CA_CHECK_RANK(
|
314
|
-
CA_CHECK_DIM(
|
311
|
+
CA_CHECK_RANK(ndim);
|
312
|
+
CA_CHECK_DIM(ndim, dim);
|
315
313
|
CA_CHECK_BYTES(data_type, bytes);
|
316
314
|
|
317
315
|
/* calculate total number of elements */
|
318
316
|
|
319
317
|
elements = 1;
|
320
318
|
length = bytes;
|
321
|
-
for (i=0; i<
|
319
|
+
for (i=0; i<ndim; i++) {
|
322
320
|
elements *= dim[i];
|
323
321
|
length *= dim[i];
|
324
322
|
}
|
@@ -330,7 +328,7 @@ ca_object_setup (CAObject *ca,
|
|
330
328
|
ca->obj_type = CA_OBJ_OBJECT;
|
331
329
|
ca->data_type = data_type;
|
332
330
|
ca->flags = 0;
|
333
|
-
ca->
|
331
|
+
ca->ndim = ndim;
|
334
332
|
ca->bytes = bytes;
|
335
333
|
ca->elements = elements;
|
336
334
|
ca->ptr = NULL;
|
@@ -339,20 +337,20 @@ ca_object_setup (CAObject *ca,
|
|
339
337
|
ca->attach = 0;
|
340
338
|
ca->nosync = 0;
|
341
339
|
|
342
|
-
ca->dim = ALLOC_N(ca_size_t,
|
340
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
343
341
|
|
344
|
-
ca->data = ca_wrap_new_null(data_type,
|
342
|
+
ca->data = ca_wrap_new_null(data_type, ndim, dim, bytes, NULL);
|
345
343
|
|
346
|
-
memcpy(ca->dim, dim,
|
344
|
+
memcpy(ca->dim, dim, ndim * sizeof(ca_size_t));
|
347
345
|
|
348
346
|
return 0;
|
349
347
|
}
|
350
348
|
|
351
349
|
static CAObject *
|
352
|
-
ca_object_new (int8_t data_type, int8_t
|
350
|
+
ca_object_new (int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes)
|
353
351
|
{
|
354
352
|
CAObject *ca = ALLOC(CAObject);
|
355
|
-
ca_object_setup(ca, data_type,
|
353
|
+
ca_object_setup(ca, data_type, ndim, dim, bytes);
|
356
354
|
return ca;
|
357
355
|
}
|
358
356
|
|
@@ -373,7 +371,7 @@ static void *
|
|
373
371
|
ca_object_func_clone (void *ap)
|
374
372
|
{
|
375
373
|
CAObject *ca = (CAObject *) ap;
|
376
|
-
return ca_object_new(ca->bytes, ca->
|
374
|
+
return ca_object_new(ca->bytes, ca->ndim, ca->dim, ca->bytes);
|
377
375
|
}
|
378
376
|
|
379
377
|
#define ca_object_func_ptr_at_addr ca_array_func_ptr_at_addr
|
@@ -408,8 +406,8 @@ ca_object_func_fetch_addr (void *ap, ca_size_t addr, void *ptr)
|
|
408
406
|
else {
|
409
407
|
ca_size_t idx[CA_RANK_MAX];
|
410
408
|
ca_addr2index(ca, addr, idx);
|
411
|
-
ridx = rb_ary_new2(ca->
|
412
|
-
for (i=0; i<ca->
|
409
|
+
ridx = rb_ary_new2(ca->ndim);
|
410
|
+
for (i=0; i<ca->ndim; i++) {
|
413
411
|
rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
|
414
412
|
}
|
415
413
|
rval = rb_funcall(ca->self, rb_intern("fetch_index"), 1, ridx);
|
@@ -439,8 +437,8 @@ ca_object_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
439
437
|
volatile VALUE ridx, raddr, rval;
|
440
438
|
int i;
|
441
439
|
if ( rb_obj_respond_to(ca->self, rb_intern("fetch_index"), Qtrue) ) {
|
442
|
-
ridx = rb_ary_new2(ca->
|
443
|
-
for (i=0; i<ca->
|
440
|
+
ridx = rb_ary_new2(ca->ndim);
|
441
|
+
for (i=0; i<ca->ndim; i++) {
|
444
442
|
rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
|
445
443
|
}
|
446
444
|
rval = rb_funcall(ca->self, rb_intern("fetch_index"), 1, ridx);
|
@@ -498,8 +496,8 @@ ca_object_func_store_addr (void *ap, ca_size_t addr, void *ptr)
|
|
498
496
|
else {
|
499
497
|
ca_size_t idx[CA_RANK_MAX];
|
500
498
|
ca_addr2index(ca, addr, idx);
|
501
|
-
ridx = rb_ary_new2(ca->
|
502
|
-
for (i=0; i<ca->
|
499
|
+
ridx = rb_ary_new2(ca->ndim);
|
500
|
+
for (i=0; i<ca->ndim; i++) {
|
503
501
|
rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
|
504
502
|
}
|
505
503
|
rval = rb_ca_ptr2obj(ca->self, ptr);
|
@@ -514,8 +512,8 @@ ca_object_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
514
512
|
volatile VALUE ridx, raddr, rval;
|
515
513
|
int i;
|
516
514
|
if ( rb_obj_respond_to(ca->self, rb_intern("store_index"), Qtrue) ) {
|
517
|
-
ridx = rb_ary_new2(ca->
|
518
|
-
for (i=0; i<ca->
|
515
|
+
ridx = rb_ary_new2(ca->ndim);
|
516
|
+
for (i=0; i<ca->ndim; i++) {
|
519
517
|
rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
|
520
518
|
}
|
521
519
|
rval = rb_ca_ptr2obj(ca->self, ptr);
|
@@ -634,7 +632,7 @@ ca_object_func_create_mask (void *ap)
|
|
634
632
|
if ( ! ca->data->mask ) {
|
635
633
|
ca_create_mask(ca->data);
|
636
634
|
}
|
637
|
-
ca->mask = (CArray*) ca_objmask_new(ca->self, ca->
|
635
|
+
ca->mask = (CArray*) ca_objmask_new(ca->self, ca->ndim, ca->dim);
|
638
636
|
ca->mask->ptr = ca->data->mask->ptr;
|
639
637
|
rmask = ca_wrap_struct(ca->mask);
|
640
638
|
rb_ivar_set(ca->self, rb_intern("mask"), rmask);
|
@@ -679,7 +677,7 @@ rb_ca_object_initialize_copy (VALUE self, VALUE other)
|
|
679
677
|
Data_Get_Struct(self, CAObject, ca);
|
680
678
|
Data_Get_Struct(other, CAObject, cs);
|
681
679
|
|
682
|
-
ca_object_setup(ca, cs->data_type, cs->
|
680
|
+
ca_object_setup(ca, cs->data_type, cs->ndim, cs->dim, cs->bytes);
|
683
681
|
ca->self = self;
|
684
682
|
|
685
683
|
rb_ca_data_type_inherit(self, other);
|
@@ -703,7 +701,7 @@ rb_ca_object_initialize (int argc, VALUE *argv, VALUE self)
|
|
703
701
|
{
|
704
702
|
volatile VALUE rtype, rdim, ropt, rbytes = Qnil, rrdonly = Qnil, rparent = Qnil, rdata;
|
705
703
|
CAObject *ca;
|
706
|
-
int8_t data_type,
|
704
|
+
int8_t data_type, ndim;
|
707
705
|
ca_size_t dim[CA_RANK_MAX];
|
708
706
|
ca_size_t bytes;
|
709
707
|
int i;
|
@@ -721,13 +719,13 @@ rb_ca_object_initialize (int argc, VALUE *argv, VALUE self)
|
|
721
719
|
|
722
720
|
Check_Type(rdim, T_ARRAY);
|
723
721
|
|
724
|
-
|
725
|
-
for (i=0; i<
|
722
|
+
ndim = RARRAY_LEN(rdim);
|
723
|
+
for (i=0; i<ndim; i++) {
|
726
724
|
dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
|
727
725
|
}
|
728
726
|
|
729
727
|
Data_Get_Struct(self, CAObject, ca);
|
730
|
-
ca_object_setup(ca, data_type,
|
728
|
+
ca_object_setup(ca, data_type, ndim, dim, bytes);
|
731
729
|
ca->self = self;
|
732
730
|
|
733
731
|
rdata = ca_wrap_struct(ca->data);
|