carray 1.3.6 → 1.5.3
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 +65 -0
- data/README.md +23 -26
- data/Rakefile +31 -0
- data/TODO.md +17 -0
- data/carray.gemspec +24 -31
- 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} +38 -40
- 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} +90 -59
- data/{carray_access.c → ext/carray_access.c} +244 -109
- 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} +350 -149
- 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} +58 -70
- 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} +137 -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} +95 -114
- data/{carray_math.rb → ext/carray_math.rb} +47 -31
- 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} +72 -36
- data/{carray_order.c → ext/carray_order.c} +73 -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} +59 -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} +1 -6
- data/{mkmath.rb → ext/mkmath.rb} +13 -3
- data/{ruby_carray.c → ext/ruby_carray.c} +20 -8
- data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +1 -3
- 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 +52 -10
- data/lib/carray/{base/autoload.rb → autoload.rb} +48 -8
- data/lib/carray/autoload/autoload_base.rb +1 -5
- data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
- data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
- data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
- data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
- data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
- data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
- data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
- data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
- data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
- data/lib/carray/autoload/autoload_gem_random.rb +8 -0
- data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
- data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
- data/lib/carray/basic.rb +191 -0
- data/lib/carray/broadcast.rb +82 -0
- data/lib/carray/compose.rb +315 -0
- data/lib/carray/construct.rb +460 -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} +21 -53
- 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 +270 -0
- data/lib/carray/ordering.rb +181 -0
- data/lib/carray/{base/serialize.rb → serialize.rb} +50 -66
- data/lib/carray/string.rb +188 -0
- data/lib/carray/{base/struct.rb → struct.rb} +19 -21
- data/lib/carray/{io/table.rb → table.rb} +1 -9
- data/lib/carray/testing.rb +51 -0
- data/lib/carray/time.rb +76 -0
- data/lib/carray/transform.rb +98 -0
- data/misc/Methods.ja.md +182 -0
- data/{NOTE → misc/NOTE} +0 -0
- 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 +173 -316
- data/COPYING +0 -56
- data/GPL +0 -340
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -33
- data/LEGAL +0 -50
- data/Makefile +0 -451
- data/TODO +0 -5
- data/carray_cast_func.c +0 -8670
- data/carray_config.h +0 -26
- data/carray_math.c +0 -24805
- data/carray_random.c +0 -531
- data/carray_stat_proc.c +0 -12170
- 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/autoload/autoload_math_calculus.rb +0 -2
- data/ext/calculus/lib/math/calculus.rb +0 -119
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
- data/ext/fortio/extconf.rb +0 -3
- data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
- data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
- data/ext/fortio/lib/fortio.rb +0 -3
- data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
- data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
- data/ext/fortio/lib/fortio/fortran_format.y +0 -215
- data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
- data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
- data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
- data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
- data/ext/fortio/ruby_fortio.c +0 -182
- data/ext/fortio/test/test_H.rb +0 -5
- data/ext/fortio/test/test_T.rb +0 -7
- data/ext/fortio/test/test_fortran_format.rb +0 -86
- data/ext/fortio/test/test_namelist.rb +0 -25
- data/ext/fortio/test/test_namelist_write.rb +0 -10
- data/ext/fortio/test/test_sequential.rb +0 -13
- data/ext/fortio/test/test_sequential2.rb +0 -13
- data/ext/fortio/work/test.rb +0 -10
- data/ext/fortio/work/test_e.rb +0 -19
- data/ext/fortio/work/test_ep.rb +0 -10
- data/ext/fortio/work/test_parse.rb +0 -12
- data/ext/imagemap/carray_imagemap.c +0 -495
- data/ext/imagemap/doc/call_graph.dot +0 -28
- data/ext/imagemap/draw.c +0 -567
- data/ext/imagemap/extconf.rb +0 -13
- data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +0 -1
- data/ext/imagemap/lib/graphics/imagemap.rb +0 -273
- data/ext/imagemap/lib/image_map.rb +0 -4
- data/ext/imagemap/test/swath_index.rb +0 -83
- data/ext/imagemap/test/swath_warp.rb +0 -99
- data/ext/imagemap/test/test.rb +0 -23
- data/ext/imagemap/test/test_image.rb +0 -42
- data/ext/imagemap/test/test_line.rb +0 -14
- data/ext/imagemap/test/test_rotate.rb +0 -17
- data/ext/imagemap/test/test_triangle.rb +0 -20
- data/ext/imagemap/test/test_warp.rb +0 -26
- data/ext/mathfunc/extconf.rb +0 -18
- data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
- data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
- 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/ext/narray/README +0 -22
- data/ext/narray/ca_wrap_narray.c +0 -500
- data/ext/narray/carray_narray.c +0 -21
- data/ext/narray/extconf.rb +0 -57
- data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
- data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
- data/ext/narray/lib/math/narray.rb +0 -17
- data/ext/narray/lib/math/narray_miss.rb +0 -45
- data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
- data/lib/carray/autoload/autoload_io_csv.rb +0 -14
- data/lib/carray/autoload/autoload_io_pg.rb +0 -6
- data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
- 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 -1090
- data/lib/carray/base/obsolete.rb +0 -131
- data/lib/carray/graphics/gnuplot.rb +0 -2131
- data/lib/carray/graphics/zimg.rb +0 -296
- data/lib/carray/io/csv.rb +0 -572
- data/lib/carray/io/pg.rb +0 -101
- data/lib/carray/io/sqlite3.rb +0 -215
- data/lib/carray/math/interp.rb +0 -57
- data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
- data/mkmf.log +0 -375
- data/mt19937ar.c +0 -182
- data/mt19937ar.h +0 -86
- data/rdoc_ext.rb +0 -1115
- 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_select.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
|
|
@@ -14,7 +12,7 @@
|
|
14
12
|
|
15
13
|
VALUE rb_cCASelect;
|
16
14
|
|
17
|
-
/*
|
15
|
+
/* yard:
|
18
16
|
class CASelect < CAVirtual # :nodoc:
|
19
17
|
end
|
20
18
|
*/
|
@@ -22,7 +20,7 @@ VALUE rb_cCASelect;
|
|
22
20
|
typedef struct {
|
23
21
|
int16_t obj_type;
|
24
22
|
int8_t data_type;
|
25
|
-
int8_t
|
23
|
+
int8_t ndim;
|
26
24
|
int32_t flags;
|
27
25
|
ca_size_t bytes;
|
28
26
|
ca_size_t elements;
|
@@ -58,7 +56,7 @@ ca_select_setup (CASelect *ca, CArray *parent, CArray *select, int share)
|
|
58
56
|
ca->obj_type = CA_OBJ_SELECT;
|
59
57
|
ca->data_type = data_type;
|
60
58
|
ca->flags = 0;
|
61
|
-
ca->
|
59
|
+
ca->ndim = 1;
|
62
60
|
ca->bytes = bytes;
|
63
61
|
|
64
62
|
if ( share && ca_is_entity(select) ) {
|
@@ -3,16 +3,14 @@
|
|
3
3
|
ca_obj_shift.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
|
|
13
11
|
#include "carray.h"
|
14
12
|
|
15
|
-
/*
|
13
|
+
/* yard:
|
16
14
|
class CAShift < CAVirtual # :nodoc:
|
17
15
|
end
|
18
16
|
*/
|
@@ -22,7 +20,7 @@ static VALUE rb_cCAShift;
|
|
22
20
|
typedef struct {
|
23
21
|
int16_t obj_type;
|
24
22
|
int8_t data_type;
|
25
|
-
int8_t
|
23
|
+
int8_t ndim;
|
26
24
|
int32_t flags;
|
27
25
|
ca_size_t bytes;
|
28
26
|
ca_size_t elements;
|
@@ -47,35 +45,35 @@ int
|
|
47
45
|
ca_shift_setup (CAShift *ca, CArray *parent,
|
48
46
|
ca_size_t *shift, char *fill, int8_t *roll)
|
49
47
|
{
|
50
|
-
int8_t data_type,
|
48
|
+
int8_t data_type, ndim;
|
51
49
|
ca_size_t elements, bytes;
|
52
50
|
|
53
51
|
data_type = parent->data_type;
|
54
52
|
bytes = parent->bytes;
|
55
|
-
|
53
|
+
ndim = parent->ndim;
|
56
54
|
elements = parent->elements;
|
57
55
|
|
58
56
|
|
59
57
|
ca->obj_type = CA_OBJ_SHIFT;
|
60
58
|
ca->data_type = data_type;
|
61
59
|
ca->flags = 0;
|
62
|
-
ca->
|
60
|
+
ca->ndim = ndim;
|
63
61
|
ca->bytes = bytes;
|
64
62
|
ca->elements = elements;
|
65
63
|
ca->ptr = NULL;
|
66
64
|
ca->mask = NULL;
|
67
|
-
ca->dim = ALLOC_N(ca_size_t,
|
65
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
68
66
|
|
69
67
|
ca->parent = parent;
|
70
68
|
ca->attach = 0;
|
71
69
|
ca->nosync = 0;
|
72
|
-
ca->shift = ALLOC_N(ca_size_t,
|
70
|
+
ca->shift = ALLOC_N(ca_size_t, ndim);
|
73
71
|
ca->fill = ALLOC_N(char, ca->bytes);
|
74
|
-
ca->roll = ALLOC_N(int8_t,
|
72
|
+
ca->roll = ALLOC_N(int8_t, ndim);
|
75
73
|
|
76
|
-
memcpy(ca->dim, parent->dim,
|
77
|
-
memcpy(ca->shift, shift,
|
78
|
-
memcpy(ca->roll, roll,
|
74
|
+
memcpy(ca->dim, parent->dim, ndim * sizeof(ca_size_t));
|
75
|
+
memcpy(ca->shift, shift, ndim * sizeof(ca_size_t));
|
76
|
+
memcpy(ca->roll, roll, ndim * sizeof(int8_t));
|
79
77
|
|
80
78
|
if ( fill ) {
|
81
79
|
ca->fill_mask = 0;
|
@@ -194,7 +192,7 @@ ca_shift_func_ptr_at_index (void *ap, ca_size_t *idx)
|
|
194
192
|
int8_t i;
|
195
193
|
ca_size_t k, n;
|
196
194
|
n = 0;
|
197
|
-
for (i=0; i<ca->
|
195
|
+
for (i=0; i<ca->ndim; i++) {
|
198
196
|
k = idx[i];
|
199
197
|
if ( roll[i] ) {
|
200
198
|
k = ca_shift_rolled_index(ca, i, k);
|
@@ -230,7 +228,7 @@ ca_shift_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
230
228
|
int8_t i;
|
231
229
|
ca_size_t k, n;
|
232
230
|
n = 0;
|
233
|
-
for (i=0; i<ca->
|
231
|
+
for (i=0; i<ca->ndim; i++) {
|
234
232
|
k = idx[i];
|
235
233
|
if ( roll[i] ) {
|
236
234
|
k = ca_shift_rolled_index(ca, i, k);
|
@@ -257,7 +255,7 @@ ca_shift_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
257
255
|
int8_t i;
|
258
256
|
ca_size_t k, n;
|
259
257
|
n = 0;
|
260
|
-
for (i=0; i<ca->
|
258
|
+
for (i=0; i<ca->ndim; i++) {
|
261
259
|
k = idx[i];
|
262
260
|
if ( roll[i] ) {
|
263
261
|
k = ca_shift_rolled_index(ca, i, k);
|
@@ -402,7 +400,7 @@ ca_shift_attach_loop (CAShift *ca, int16_t level, ca_size_t *idx, ca_size_t *idx
|
|
402
400
|
int8_t roll = ca->roll[level];
|
403
401
|
ca_size_t i;
|
404
402
|
|
405
|
-
if ( level == ca->
|
403
|
+
if ( level == ca->ndim - 1 ) {
|
406
404
|
if ( fill ) {
|
407
405
|
for (i=0; i<ca->dim[level]; i++) {
|
408
406
|
idx[level] = i;
|
@@ -561,7 +559,7 @@ ca_shift_sync_loop (CAShift *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
561
559
|
int8_t roll = ca->roll[level];
|
562
560
|
ca_size_t i;
|
563
561
|
|
564
|
-
if ( level == ca->
|
562
|
+
if ( level == ca->ndim - 1 ) {
|
565
563
|
if ( ! shift ) {
|
566
564
|
idx[level] = 0;
|
567
565
|
idx0[level] = 0;
|
@@ -705,7 +703,7 @@ ca_shift_fill_loop (CAShift *ca, char *ptr,
|
|
705
703
|
int8_t roll = ca->roll[level];
|
706
704
|
ca_size_t i;
|
707
705
|
|
708
|
-
if ( level == ca->
|
706
|
+
if ( level == ca->ndim - 1 ) {
|
709
707
|
if ( ( ! shift ) || roll ) {
|
710
708
|
for (i=0; i<dim; i++) {
|
711
709
|
idx0[level] = i;
|
@@ -828,7 +826,7 @@ rb_ca_shift_new (VALUE cary, ca_size_t *shift, char *fill, int8_t *roll)
|
|
828
826
|
return obj;
|
829
827
|
}
|
830
828
|
|
831
|
-
/*
|
829
|
+
/* yard:
|
832
830
|
class CArray
|
833
831
|
def shifted
|
834
832
|
end
|
@@ -851,11 +849,11 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
|
|
851
849
|
ropt = rb_pop_options(&argc, &argv);
|
852
850
|
rb_scan_options(ropt, "roll,fill_value", &rroll, &rfval);
|
853
851
|
|
854
|
-
if ( argc != ca->
|
855
|
-
rb_raise(rb_eArgError, "# of arguments mismatch with
|
852
|
+
if ( argc != ca->ndim ) {
|
853
|
+
rb_raise(rb_eArgError, "# of arguments mismatch with ndim");
|
856
854
|
}
|
857
855
|
|
858
|
-
for (i=0; i<ca->
|
856
|
+
for (i=0; i<ca->ndim; i++) {
|
859
857
|
shift[i] = NUM2SIZE(argv[i]);
|
860
858
|
}
|
861
859
|
|
@@ -889,18 +887,18 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
|
|
889
887
|
}
|
890
888
|
|
891
889
|
if ( NIL_P(rroll) ) {
|
892
|
-
for (i=0; i<ca->
|
890
|
+
for (i=0; i<ca->ndim; i++) {
|
893
891
|
roll[i] = 0;
|
894
892
|
}
|
895
893
|
}
|
896
894
|
else {
|
897
895
|
Check_Type(rroll, T_ARRAY);
|
898
896
|
|
899
|
-
if ( RARRAY_LEN(rroll) != ca->
|
900
|
-
rb_raise(rb_eArgError, "# of arguments mismatch with
|
897
|
+
if ( RARRAY_LEN(rroll) != ca->ndim ) {
|
898
|
+
rb_raise(rb_eArgError, "# of arguments mismatch with ndim");
|
901
899
|
}
|
902
900
|
|
903
|
-
for (i=0; i<ca->
|
901
|
+
for (i=0; i<ca->ndim; i++) {
|
904
902
|
roll[i] = NUM2INT(rb_ary_entry(rroll, i));
|
905
903
|
}
|
906
904
|
}
|
@@ -3,10 +3,8 @@
|
|
3
3
|
ca_obj_transpose.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;
|
@@ -34,7 +32,7 @@ static int8_t CA_OBJ_TRANSPOSE;
|
|
34
32
|
|
35
33
|
static VALUE rb_cCATrans;
|
36
34
|
|
37
|
-
/*
|
35
|
+
/* yard:
|
38
36
|
class CATranspose < CAVirtual # :nodoc:
|
39
37
|
end
|
40
38
|
*/
|
@@ -44,7 +42,7 @@ static VALUE rb_cCATrans;
|
|
44
42
|
int
|
45
43
|
ca_trans_setup (CATrans *ca, CArray *parent, ca_size_t *imap)
|
46
44
|
{
|
47
|
-
int8_t data_type,
|
45
|
+
int8_t data_type, ndim;
|
48
46
|
ca_size_t bytes, elements;
|
49
47
|
ca_size_t *dim0;
|
50
48
|
ca_size_t newdim[CA_RANK_MAX];
|
@@ -54,17 +52,17 @@ ca_trans_setup (CATrans *ca, CArray *parent, ca_size_t *imap)
|
|
54
52
|
|
55
53
|
data_type = parent->data_type;
|
56
54
|
bytes = parent->bytes;
|
57
|
-
|
55
|
+
ndim = parent->ndim;
|
58
56
|
elements = parent->elements;
|
59
57
|
dim0 = parent->dim;
|
60
58
|
|
61
|
-
for (i=0; i<
|
59
|
+
for (i=0; i<ndim; i++) {
|
62
60
|
map[i] = -1;
|
63
61
|
}
|
64
62
|
|
65
|
-
for (i=0; i<
|
63
|
+
for (i=0; i<ndim; i++) {
|
66
64
|
idim = imap[i];
|
67
|
-
if ( idim < 0 || idim >=
|
65
|
+
if ( idim < 0 || idim >= ndim ) {
|
68
66
|
rb_raise(rb_eRuntimeError,
|
69
67
|
"specified %i-th dimension number out of range", i);
|
70
68
|
}
|
@@ -78,28 +76,28 @@ ca_trans_setup (CATrans *ca, CArray *parent, ca_size_t *imap)
|
|
78
76
|
}
|
79
77
|
|
80
78
|
step = 1;
|
81
|
-
for (i=imap[
|
79
|
+
for (i=imap[ndim-1]+1; i<ndim; i++) {
|
82
80
|
step *= dim0[i];
|
83
81
|
}
|
84
82
|
|
85
83
|
ca->obj_type = CA_OBJ_TRANSPOSE;
|
86
84
|
ca->data_type = data_type;
|
87
85
|
ca->flags = 0;
|
88
|
-
ca->
|
86
|
+
ca->ndim = ndim;
|
89
87
|
ca->bytes = bytes;
|
90
88
|
ca->elements = elements;
|
91
89
|
ca->ptr = NULL;
|
92
90
|
ca->mask = NULL;
|
93
|
-
ca->dim = ALLOC_N(ca_size_t,
|
91
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
94
92
|
|
95
93
|
ca->parent = parent;
|
96
94
|
ca->attach = 0;
|
97
95
|
ca->nosync = 0;
|
98
|
-
ca->imap = ALLOC_N(ca_size_t,
|
96
|
+
ca->imap = ALLOC_N(ca_size_t, ndim);
|
99
97
|
ca->step = step;
|
100
98
|
|
101
|
-
memcpy(ca->dim, newdim,
|
102
|
-
memcpy(ca->imap, imap,
|
99
|
+
memcpy(ca->dim, newdim, ndim * sizeof(ca_size_t));
|
100
|
+
memcpy(ca->imap, imap, ndim * sizeof(ca_size_t));
|
103
101
|
|
104
102
|
if ( ca_has_mask(parent) ) {
|
105
103
|
ca_create_mask(ca);
|
@@ -167,7 +165,7 @@ ca_trans_func_ptr_at_index (void *ap, ca_size_t *idx)
|
|
167
165
|
ca_size_t *imap = ca->imap;
|
168
166
|
ca_size_t idx0[CA_RANK_MAX];
|
169
167
|
int8_t i;
|
170
|
-
for (i=0; i<ca->
|
168
|
+
for (i=0; i<ca->ndim; i++) {
|
171
169
|
idx0[imap[i]] = idx[i];
|
172
170
|
}
|
173
171
|
return ca_ptr_at_index(ca->parent, idx0);
|
@@ -181,7 +179,7 @@ ca_trans_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
181
179
|
ca_size_t *imap = ca->imap;
|
182
180
|
ca_size_t idx0[CA_RANK_MAX];
|
183
181
|
int8_t i;
|
184
|
-
for (i=0; i<ca->
|
182
|
+
for (i=0; i<ca->ndim; i++) {
|
185
183
|
idx0[imap[i]] = idx[i];
|
186
184
|
}
|
187
185
|
ca_fetch_index(ca->parent, idx0, ptr);
|
@@ -194,7 +192,7 @@ ca_trans_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
194
192
|
ca_size_t *imap = ca->imap;
|
195
193
|
ca_size_t idx0[CA_RANK_MAX];
|
196
194
|
int8_t i;
|
197
|
-
for (i=0; i<ca->
|
195
|
+
for (i=0; i<ca->ndim; i++) {
|
198
196
|
idx0[imap[i]] = idx[i];
|
199
197
|
}
|
200
198
|
ca_store_index(ca->parent, idx0, ptr);
|
@@ -311,7 +309,7 @@ ca_trans_attach_loop (CATrans *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0
|
|
311
309
|
ca_size_t *imap = ca->imap;
|
312
310
|
ca_size_t i;
|
313
311
|
|
314
|
-
if ( level == ca->
|
312
|
+
if ( level == ca->ndim - 1 ) {
|
315
313
|
idx[level] = 0;
|
316
314
|
idx0[imap[level]] = 0;
|
317
315
|
switch ( ca->bytes ) {
|
@@ -392,7 +390,7 @@ ca_trans_sync_loop (CATrans *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
392
390
|
ca_size_t *imap = ca->imap;
|
393
391
|
ca_size_t i;
|
394
392
|
|
395
|
-
if ( level == ca->
|
393
|
+
if ( level == ca->ndim - 1 ) {
|
396
394
|
idx[level] = 0;
|
397
395
|
idx0[imap[level]] = 0;
|
398
396
|
switch ( ca->bytes ) {
|
@@ -473,7 +471,7 @@ ca_trans_fill_loop (CATrans *ca, char *ptr,
|
|
473
471
|
ca_size_t *imap = ca->imap;
|
474
472
|
ca_size_t i;
|
475
473
|
|
476
|
-
if ( level == ca->
|
474
|
+
if ( level == ca->ndim - 1 ) {
|
477
475
|
for (i=0; i<ca->dim[level]; i++) {
|
478
476
|
idx0[imap[level]] = i;
|
479
477
|
memcpy(ca_ptr_at_index(ca->parent, idx0), ptr, ca->bytes);
|
@@ -511,7 +509,7 @@ rb_ca_trans_new (VALUE cary, ca_size_t *imap)
|
|
511
509
|
return obj;
|
512
510
|
}
|
513
511
|
|
514
|
-
/*
|
512
|
+
/* yard:
|
515
513
|
class CArray
|
516
514
|
def transposed
|
517
515
|
end
|
@@ -529,17 +527,17 @@ rb_ca_trans (int argc, VALUE *argv, VALUE self)
|
|
529
527
|
Data_Get_Struct(self, CArray, ca);
|
530
528
|
|
531
529
|
if ( argc == 0 ) {
|
532
|
-
for (i=0; i<ca->
|
533
|
-
imap[i] = ca->
|
530
|
+
for (i=0; i<ca->ndim; i++) {
|
531
|
+
imap[i] = ca->ndim - i - 1;
|
534
532
|
}
|
535
533
|
}
|
536
|
-
else if ( argc == ca->
|
537
|
-
for (i=0; i<ca->
|
534
|
+
else if ( argc == ca->ndim ) {
|
535
|
+
for (i=0; i<ca->ndim; i++) {
|
538
536
|
imap[i] = NUM2SIZE(argv[i]);
|
539
537
|
}
|
540
538
|
}
|
541
539
|
else {
|
542
|
-
rb_raise(rb_eArgError, "# of arguments should be equal to
|
540
|
+
rb_raise(rb_eArgError, "# of arguments should be equal to ndim");
|
543
541
|
}
|
544
542
|
|
545
543
|
obj = rb_ca_trans_new(self, imap);
|
@@ -3,10 +3,8 @@
|
|
3
3
|
ca_obj_unbound_repeat.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
|
|
@@ -14,46 +12,48 @@
|
|
14
12
|
|
15
13
|
VALUE rb_cCAUnboundRepeat;
|
16
14
|
|
17
|
-
/*
|
15
|
+
/* yard:
|
18
16
|
class CAUnboundRepeat < CArray
|
19
17
|
end
|
20
18
|
*/
|
21
19
|
|
22
20
|
int
|
23
21
|
ca_ubrep_setup (CAUnboundRepeat *ca, CArray *parent,
|
24
|
-
int32_t
|
22
|
+
int32_t rep_ndim, ca_size_t *rep_dim)
|
25
23
|
{
|
26
|
-
int8_t data_type
|
24
|
+
int8_t data_type;
|
27
25
|
ca_size_t bytes, elements;
|
26
|
+
int8_t i;
|
28
27
|
|
29
28
|
/* check arguments */
|
30
29
|
|
31
|
-
CA_CHECK_RANK(
|
30
|
+
CA_CHECK_RANK(rep_ndim);
|
32
31
|
|
33
32
|
data_type = parent->data_type;
|
34
33
|
bytes = parent->bytes;
|
35
|
-
rank = parent->rank;
|
36
34
|
elements = parent->elements;
|
37
35
|
|
38
36
|
ca->obj_type = CA_OBJ_UNBOUND_REPEAT;
|
39
37
|
ca->data_type = data_type;
|
40
38
|
ca->flags = 0;
|
41
|
-
ca->
|
39
|
+
ca->ndim = rep_ndim;
|
42
40
|
ca->bytes = bytes;
|
43
41
|
ca->elements = elements;
|
44
42
|
ca->ptr = NULL;
|
45
43
|
ca->mask = NULL;
|
46
|
-
ca->dim = ALLOC_N(ca_size_t,
|
44
|
+
ca->dim = ALLOC_N(ca_size_t, rep_ndim);
|
47
45
|
|
48
46
|
ca->parent = parent;
|
49
47
|
ca->attach = 0;
|
50
48
|
ca->nosync = 0;
|
51
49
|
|
52
|
-
ca->
|
53
|
-
ca->rep_dim = ALLOC_N(ca_size_t,
|
50
|
+
ca->rep_ndim = rep_ndim;
|
51
|
+
ca->rep_dim = ALLOC_N(ca_size_t, rep_ndim);
|
54
52
|
|
55
|
-
|
56
|
-
|
53
|
+
for (i=0; i<rep_ndim; i++) {
|
54
|
+
ca->rep_dim[i] = rep_dim[i];
|
55
|
+
ca->dim[i] = ( rep_dim[i] ) ? rep_dim[i] : 1;
|
56
|
+
}
|
57
57
|
|
58
58
|
if ( ca_has_mask(parent) ) {
|
59
59
|
ca_create_mask(ca);
|
@@ -63,10 +63,10 @@ ca_ubrep_setup (CAUnboundRepeat *ca, CArray *parent,
|
|
63
63
|
}
|
64
64
|
|
65
65
|
CAUnboundRepeat *
|
66
|
-
ca_ubrep_new (CArray *parent, int32_t
|
66
|
+
ca_ubrep_new (CArray *parent, int32_t rep_ndim, ca_size_t *rep_dim)
|
67
67
|
{
|
68
68
|
CAUnboundRepeat *ca = ALLOC(CAUnboundRepeat);
|
69
|
-
ca_ubrep_setup(ca, parent,
|
69
|
+
ca_ubrep_setup(ca, parent, rep_ndim, rep_dim);
|
70
70
|
return ca;
|
71
71
|
}
|
72
72
|
|
@@ -88,7 +88,7 @@ static void *
|
|
88
88
|
ca_ubrep_func_clone (void *ap)
|
89
89
|
{
|
90
90
|
CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
|
91
|
-
return ca_ubrep_new(ca->parent, ca->
|
91
|
+
return ca_ubrep_new(ca->parent, ca->rep_ndim, ca->rep_dim);
|
92
92
|
}
|
93
93
|
|
94
94
|
static char *
|
@@ -98,13 +98,6 @@ ca_ubrep_func_ptr_at_addr (void *ap, ca_size_t addr)
|
|
98
98
|
return ca_ptr_at_addr(ca->parent, addr);
|
99
99
|
}
|
100
100
|
|
101
|
-
static char *
|
102
|
-
ca_ubrep_func_ptr_at_index (void *ap, ca_size_t *idx)
|
103
|
-
{
|
104
|
-
CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
|
105
|
-
return ca_ptr_at_index(ca->parent, idx);
|
106
|
-
}
|
107
|
-
|
108
101
|
static void
|
109
102
|
ca_ubrep_func_fetch_addr (void *ap, ca_size_t addr, void *ptr)
|
110
103
|
{
|
@@ -112,13 +105,6 @@ ca_ubrep_func_fetch_addr (void *ap, ca_size_t addr, void *ptr)
|
|
112
105
|
ca_fetch_addr(ca->parent, addr, ptr);
|
113
106
|
}
|
114
107
|
|
115
|
-
static void
|
116
|
-
ca_ubrep_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
117
|
-
{
|
118
|
-
CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
|
119
|
-
ca_fetch_index(ca->parent, idx, ptr);
|
120
|
-
}
|
121
|
-
|
122
108
|
static void
|
123
109
|
ca_ubrep_func_store_addr (void *ap, ca_size_t addr, void *ptr)
|
124
110
|
{
|
@@ -126,13 +112,6 @@ ca_ubrep_func_store_addr (void *ap, ca_size_t addr, void *ptr)
|
|
126
112
|
ca_store_addr(ca->parent, addr, ptr);
|
127
113
|
}
|
128
114
|
|
129
|
-
static void
|
130
|
-
ca_ubrep_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
131
|
-
{
|
132
|
-
CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
|
133
|
-
ca_store_index(ca->parent, idx, ptr);
|
134
|
-
}
|
135
|
-
|
136
115
|
static void
|
137
116
|
ca_ubrep_func_allocate (void *ap)
|
138
117
|
{
|
@@ -212,7 +191,7 @@ ca_ubrep_func_create_mask (void *ap)
|
|
212
191
|
ca_create_mask(ca->parent);
|
213
192
|
}
|
214
193
|
ca->mask =
|
215
|
-
(CArray *) ca_ubrep_new(ca->parent->mask, ca->
|
194
|
+
(CArray *) ca_ubrep_new(ca->parent->mask, ca->rep_ndim, ca->rep_dim);
|
216
195
|
}
|
217
196
|
|
218
197
|
ca_operation_function_t ca_ubrep_func = {
|
@@ -221,11 +200,11 @@ ca_operation_function_t ca_ubrep_func = {
|
|
221
200
|
free_ca_ubrep,
|
222
201
|
ca_ubrep_func_clone,
|
223
202
|
ca_ubrep_func_ptr_at_addr,
|
224
|
-
|
203
|
+
NULL,
|
225
204
|
ca_ubrep_func_fetch_addr,
|
226
|
-
|
205
|
+
NULL,
|
227
206
|
ca_ubrep_func_store_addr,
|
228
|
-
|
207
|
+
NULL,
|
229
208
|
ca_ubrep_func_allocate,
|
230
209
|
ca_ubrep_func_attach,
|
231
210
|
ca_ubrep_func_sync,
|
@@ -239,14 +218,44 @@ ca_operation_function_t ca_ubrep_func = {
|
|
239
218
|
/* ------------------------------------------------------------------- */
|
240
219
|
|
241
220
|
VALUE
|
242
|
-
|
221
|
+
rb_ca_ubrep_shave (VALUE self, VALUE other)
|
222
|
+
{
|
223
|
+
CAUnboundRepeat *ca;
|
224
|
+
CArray *co;
|
225
|
+
int8_t ndim, i;
|
226
|
+
ca_size_t dim[CA_RANK_MAX];
|
227
|
+
|
228
|
+
rb_check_carray_object(self);
|
229
|
+
rb_check_carray_object(other);
|
230
|
+
|
231
|
+
Data_Get_Struct(self, CAUnboundRepeat, ca);
|
232
|
+
Data_Get_Struct(other, CArray, co);
|
233
|
+
|
234
|
+
if ( ca->elements != co->elements ) {
|
235
|
+
rb_raise(rb_eRuntimeError, "mismatch in # of elements");
|
236
|
+
}
|
237
|
+
|
238
|
+
ndim = 0;
|
239
|
+
for (i=0; i<ca->ndim; i++) {
|
240
|
+
if ( ca->rep_dim[i] ) {
|
241
|
+
dim[ndim] = ca->rep_dim[i];
|
242
|
+
ndim += 1;
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
return rb_ca_refer_new(other, co->data_type, ndim, dim, co->bytes, 0);
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
VALUE
|
251
|
+
rb_ca_ubrep_new (VALUE cary, int32_t rep_ndim, ca_size_t *rep_dim)
|
243
252
|
{
|
244
253
|
volatile VALUE obj;
|
245
254
|
CArray *parent;
|
246
255
|
CAUnboundRepeat *ca;
|
247
256
|
rb_check_carray_object(cary);
|
248
257
|
Data_Get_Struct(cary, CArray, parent);
|
249
|
-
ca = ca_ubrep_new(parent,
|
258
|
+
ca = ca_ubrep_new(parent, rep_ndim, rep_dim);
|
250
259
|
obj = ca_wrap_struct(ca);
|
251
260
|
rb_ca_set_parent(obj, cary);
|
252
261
|
rb_ca_data_type_inherit(obj, cary);
|
@@ -257,80 +266,23 @@ VALUE
|
|
257
266
|
rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
258
267
|
{
|
259
268
|
CArray *ca;
|
260
|
-
|
261
|
-
|
269
|
+
int8_t ndim;
|
270
|
+
ca_size_t dim[CA_RANK_MAX];
|
271
|
+
int32_t rep_ndim;
|
262
272
|
ca_size_t rep_dim[CA_RANK_MAX];
|
263
|
-
ca_size_t count, i;
|
273
|
+
ca_size_t elements, count, i;
|
264
274
|
|
265
275
|
Data_Get_Struct(self, CArray, ca);
|
266
276
|
|
267
|
-
|
268
|
-
CAUnboundRepeat *cr = (CAUnboundRepeat *) ca;
|
269
|
-
volatile VALUE args;
|
270
|
-
int repeatable = 0;
|
271
|
-
args = rb_ary_new();
|
272
|
-
if ( rb_obj_is_kind_of(self, rb_cCAUnboundRepeat) ) {
|
273
|
-
repeatable = 1;
|
274
|
-
for (i=0; i<cr->rep_rank; i++) {
|
275
|
-
if ( cr->rep_dim[i] == 1 ) {
|
276
|
-
rb_ary_push(args, ID2SYM(rb_intern("*")));
|
277
|
-
repeatable = 1;
|
278
|
-
}
|
279
|
-
else if ( cr->rep_dim[i] > 1 ) {
|
280
|
-
rb_ary_push(args, Qnil);
|
281
|
-
}
|
282
|
-
else {
|
283
|
-
rb_ary_push(args, ID2SYM(rb_intern("*")));
|
284
|
-
}
|
285
|
-
}
|
286
|
-
}
|
287
|
-
else {
|
288
|
-
for (i=0; i<ca->rank; i++) {
|
289
|
-
if ( ca->dim[i] == 1 ) {
|
290
|
-
rb_ary_push(args, ID2SYM(rb_intern("*")));
|
291
|
-
repeatable = 1;
|
292
|
-
}
|
293
|
-
else {
|
294
|
-
rb_ary_push(args, Qnil);
|
295
|
-
}
|
296
|
-
}
|
297
|
-
}
|
298
|
-
if ( ! repeatable ) {
|
299
|
-
return self;
|
300
|
-
}
|
301
|
-
else {
|
302
|
-
return rb_ca_unbound_repeat((int)RARRAY_LEN(args), RARRAY_PTR(args), self);
|
303
|
-
}
|
304
|
-
}
|
305
|
-
else if ( argc == 2 &&
|
306
|
-
argv[0] == ID2SYM(rb_intern("*")) &&
|
307
|
-
rb_obj_is_carray(argv[1]) ) {
|
308
|
-
volatile VALUE args, obj;
|
309
|
-
args = ID2SYM(rb_intern("*"));
|
310
|
-
obj = rb_ca_unbound_repeat(1, (VALUE*)&args, self);
|
311
|
-
return ca_ubrep_bind_with(obj, argv[1]);
|
312
|
-
}
|
313
|
-
else if ( argc == 2 &&
|
314
|
-
argv[1] == ID2SYM(rb_intern("*")) &&
|
315
|
-
rb_obj_is_carray(argv[0]) ) {
|
316
|
-
volatile VALUE args, obj;
|
317
|
-
args = ID2SYM(rb_intern("*"));
|
318
|
-
obj = rb_ca_unbound_repeat(1, (VALUE*)&args, self);
|
319
|
-
return ca_ubrep_bind_with(obj, argv[0]);
|
320
|
-
}
|
321
|
-
|
322
|
-
rep_rank = argc;
|
277
|
+
rep_ndim = argc;
|
323
278
|
|
324
279
|
count = 0;
|
325
|
-
|
326
|
-
|
327
|
-
for (i=0; i<
|
328
|
-
if (
|
280
|
+
ndim = 0;
|
281
|
+
elements = 1;
|
282
|
+
for (i=0; i<rep_ndim; i++) {
|
283
|
+
if ( TYPE(argv[i]) == T_SYMBOL ) {
|
329
284
|
if ( argv[i] == ID2SYM(rb_intern("*")) ) {
|
330
285
|
rep_dim[i] = 0;
|
331
|
-
if ( ca->dim[count] == 1 ) {
|
332
|
-
count++;
|
333
|
-
}
|
334
286
|
}
|
335
287
|
else {
|
336
288
|
rb_raise(rb_eArgError, "unknown symbol (!= ':*') in arguments");
|
@@ -341,26 +293,21 @@ rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
|
341
293
|
rb_raise(rb_eArgError, "invalid argument");
|
342
294
|
}
|
343
295
|
rep_dim[i] = ca->dim[count];
|
344
|
-
dim[
|
345
|
-
count
|
296
|
+
dim[ndim] = ca->dim[count];
|
297
|
+
elements *= ca->dim[count];
|
298
|
+
count++; ndim++;
|
346
299
|
}
|
347
300
|
}
|
348
301
|
|
349
|
-
if (
|
350
|
-
rb_raise(
|
302
|
+
if ( elements != ca->elements ) {
|
303
|
+
rb_raise(rb_eArgError, "mismatch in entity elements (%lli for %lli)", elements, ca->elements);
|
351
304
|
}
|
352
305
|
|
353
|
-
if (
|
354
|
-
|
355
|
-
par = rb_ca_refer_new(self, ca->data_type, rank, dim, ca->bytes, 0);
|
356
|
-
obj = rb_ca_ubrep_new(par, rep_rank, rep_dim);
|
357
|
-
rb_ivar_set(obj, rb_intern("__real_parent__"), par);
|
358
|
-
rb_ca_set_parent(obj, self);
|
359
|
-
return obj;
|
360
|
-
}
|
361
|
-
else {
|
362
|
-
return rb_ca_ubrep_new(self, rep_rank, rep_dim);
|
306
|
+
if ( ndim != ca->ndim ) {
|
307
|
+
rb_raise(rb_eArgError, "invalid number of nil's (%i for %i)", ndim, ca->ndim);
|
363
308
|
}
|
309
|
+
|
310
|
+
return rb_ca_ubrep_new(self, rep_ndim, rep_dim);
|
364
311
|
}
|
365
312
|
|
366
313
|
static VALUE
|
@@ -378,21 +325,21 @@ rb_ca_ubrep_initialize_copy (VALUE self, VALUE other)
|
|
378
325
|
Data_Get_Struct(self, CAUnboundRepeat, ca);
|
379
326
|
Data_Get_Struct(other, CAUnboundRepeat, cs);
|
380
327
|
|
381
|
-
ca_ubrep_setup(ca, cs->parent, cs->
|
328
|
+
ca_ubrep_setup(ca, cs->parent, cs->rep_ndim, cs->rep_dim);
|
382
329
|
|
383
330
|
return self;
|
384
331
|
}
|
385
332
|
|
386
333
|
/*
|
387
334
|
static CARepeat *
|
388
|
-
ca_ubrep_bind (CAUnboundRepeat *ca, int32_t
|
335
|
+
ca_ubrep_bind (CAUnboundRepeat *ca, int32_t new_ndim, ca_size_t *new_dim)
|
389
336
|
{
|
390
337
|
ca_size_t rep_spec[CA_RANK_MAX];
|
391
338
|
int i;
|
392
|
-
if ( ca->
|
393
|
-
rb_raise(rb_eArgError, "invalid
|
339
|
+
if ( ca->rep_ndim != new_ndim ) {
|
340
|
+
rb_raise(rb_eArgError, "invalid new_ndim");
|
394
341
|
}
|
395
|
-
for (i=0; i<
|
342
|
+
for (i=0; i<new_ndim; i++) {
|
396
343
|
if ( ca->rep_dim[i] == 0 ) {
|
397
344
|
rep_spec[i] = new_dim[i];
|
398
345
|
}
|
@@ -400,65 +347,66 @@ ca_ubrep_bind (CAUnboundRepeat *ca, int32_t new_rank, ca_size_t *new_dim)
|
|
400
347
|
rep_spec[i] = 0;
|
401
348
|
}
|
402
349
|
}
|
403
|
-
return ca_repeat_new((CArray*)ca,
|
350
|
+
return ca_repeat_new((CArray*)ca, new_ndim, rep_spec);
|
404
351
|
}
|
405
352
|
*/
|
406
353
|
|
407
354
|
VALUE
|
408
|
-
ca_ubrep_bind2 (VALUE self, int32_t
|
355
|
+
ca_ubrep_bind2 (VALUE self, int32_t new_ndim, ca_size_t *new_dim)
|
409
356
|
{
|
410
357
|
CAUnboundRepeat *ca;
|
411
358
|
ca_size_t rep_spec[CA_RANK_MAX];
|
412
359
|
ca_size_t upr_spec[CA_RANK_MAX];
|
413
360
|
ca_size_t srp_spec[CA_RANK_MAX];
|
414
|
-
int uprep = 0,
|
361
|
+
int uprep = 0, srp_ndim;
|
362
|
+
int ndim_real;
|
415
363
|
int i;
|
416
364
|
|
417
365
|
Data_Get_Struct(self, CAUnboundRepeat, ca);
|
418
366
|
|
419
|
-
if ( ca->
|
420
|
-
rb_raise(rb_eArgError, "invalid
|
421
|
-
ca->
|
367
|
+
if ( ca->rep_ndim != new_ndim ) {
|
368
|
+
rb_raise(rb_eArgError, "invalid new_ndim (%i <-> %i)",
|
369
|
+
ca->rep_ndim, new_ndim);
|
422
370
|
}
|
423
371
|
|
424
|
-
|
425
|
-
|
372
|
+
srp_ndim = 0;
|
373
|
+
ndim_real = 0;
|
374
|
+
for (i=0; i<new_ndim; i++) {
|
426
375
|
if ( ca->rep_dim[i] == 0 ) {
|
427
376
|
if ( new_dim[i] == 0 ) {
|
428
377
|
uprep = 1;
|
429
378
|
}
|
430
379
|
else {
|
431
|
-
srp_spec[
|
380
|
+
srp_spec[srp_ndim++] = new_dim[i];
|
432
381
|
}
|
433
382
|
rep_spec[i] = new_dim[i];
|
434
383
|
upr_spec[i] = new_dim[i];
|
435
384
|
}
|
436
385
|
else {
|
386
|
+
ndim_real++;
|
437
387
|
rep_spec[i] = 0;
|
438
|
-
srp_spec[
|
388
|
+
srp_spec[srp_ndim++] = 0;
|
439
389
|
upr_spec[i] = ca->rep_dim[i];
|
440
390
|
}
|
441
391
|
}
|
392
|
+
|
442
393
|
if ( uprep ) {
|
443
394
|
volatile VALUE rep;
|
444
|
-
if (
|
445
|
-
rep = rb_ca_repeat_new(rb_ca_parent(self),
|
395
|
+
if ( srp_ndim >= ndim_real ) {
|
396
|
+
rep = rb_ca_repeat_new(rb_ca_parent(self), srp_ndim, srp_spec);
|
446
397
|
}
|
447
398
|
else {
|
448
399
|
rep = rb_ca_parent(self);
|
449
400
|
}
|
450
|
-
return rb_ca_ubrep_new(rep,
|
401
|
+
return rb_ca_ubrep_new(rep, new_ndim, upr_spec);
|
451
402
|
}
|
452
403
|
else {
|
453
|
-
return rb_ca_repeat_new(self,
|
404
|
+
return rb_ca_repeat_new(rb_ca_parent(self), new_ndim, rep_spec);
|
454
405
|
}
|
455
406
|
}
|
456
407
|
|
457
|
-
/*
|
458
|
-
|
459
|
-
def bind_with(other)
|
460
|
-
end
|
461
|
-
end
|
408
|
+
/* @overload bind_with (other)
|
409
|
+
|
462
410
|
*/
|
463
411
|
|
464
412
|
VALUE
|
@@ -474,21 +422,18 @@ ca_ubrep_bind_with (VALUE self, VALUE other)
|
|
474
422
|
|
475
423
|
if ( co->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
476
424
|
Data_Get_Struct(other, CAUnboundRepeat, cup);
|
477
|
-
return ca_ubrep_bind2(self, cup->
|
425
|
+
return ca_ubrep_bind2(self, cup->rep_ndim, cup->rep_dim);
|
478
426
|
}
|
479
427
|
else if ( ca_is_scalar(co) ) {
|
480
428
|
return self;
|
481
429
|
}
|
482
430
|
else {
|
483
|
-
return ca_ubrep_bind2(self, co->
|
431
|
+
return ca_ubrep_bind2(self, co->ndim, co->dim);
|
484
432
|
}
|
485
433
|
}
|
486
434
|
|
487
|
-
/*
|
488
|
-
|
489
|
-
def bind(*index)
|
490
|
-
end
|
491
|
-
end
|
435
|
+
/* @overload bind (*index)
|
436
|
+
|
492
437
|
*/
|
493
438
|
|
494
439
|
static VALUE
|
@@ -500,9 +445,10 @@ rb_ca_ubrep_bind (int argc, VALUE *argv, VALUE self)
|
|
500
445
|
|
501
446
|
Data_Get_Struct(self, CAUnboundRepeat, ca);
|
502
447
|
|
503
|
-
if ( ca->
|
504
|
-
rb_raise(rb_eArgError, "invalid
|
448
|
+
if ( ca->rep_ndim != argc ) {
|
449
|
+
rb_raise(rb_eArgError, "invalid new_ndim");
|
505
450
|
}
|
451
|
+
|
506
452
|
for (i=0; i<argc; i++) {
|
507
453
|
if ( ca->rep_dim[i] == 0 ) {
|
508
454
|
rep_spec[i] = NUM2SIZE(argv[i]);
|
@@ -512,7 +458,7 @@ rb_ca_ubrep_bind (int argc, VALUE *argv, VALUE self)
|
|
512
458
|
}
|
513
459
|
}
|
514
460
|
|
515
|
-
return rb_ca_repeat_new(self, argc, rep_spec);
|
461
|
+
return rb_ca_repeat_new(rb_ca_parent(self), argc, rep_spec);
|
516
462
|
}
|
517
463
|
|
518
464
|
static VALUE
|
@@ -524,8 +470,8 @@ rb_ca_ubrep_spec (VALUE self)
|
|
524
470
|
|
525
471
|
Data_Get_Struct(self, CAUnboundRepeat, ca);
|
526
472
|
|
527
|
-
spec = rb_ary_new2(ca->
|
528
|
-
for (i=0; i<ca->
|
473
|
+
spec = rb_ary_new2(ca->rep_ndim);
|
474
|
+
for (i=0; i<ca->rep_ndim; i++) {
|
529
475
|
if ( ca->rep_dim[i] ) {
|
530
476
|
rb_ary_store(spec, i, SIZE2NUM(ca->rep_dim[i]));
|
531
477
|
}
|