carray 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +56 -0
- data/GPL +340 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +33 -0
- data/LEGAL +50 -0
- data/NOTE +73 -0
- data/Rakefile +20 -0
- data/TODO +5 -0
- data/ca_iter_block.c +242 -0
- data/ca_iter_dimension.c +287 -0
- data/ca_iter_window.c +202 -0
- data/ca_obj_array.c +1189 -0
- data/ca_obj_bitarray.c +523 -0
- data/ca_obj_bitfield.c +636 -0
- data/ca_obj_block.c +885 -0
- data/ca_obj_fake.c +405 -0
- data/ca_obj_farray.c +482 -0
- data/ca_obj_field.c +625 -0
- data/ca_obj_grid.c +738 -0
- data/ca_obj_mapping.c +614 -0
- data/ca_obj_object.c +777 -0
- data/ca_obj_reduce.c +299 -0
- data/ca_obj_refer.c +627 -0
- data/ca_obj_repeat.c +640 -0
- data/ca_obj_select.c +558 -0
- data/ca_obj_shift.c +952 -0
- data/ca_obj_transpose.c +582 -0
- data/ca_obj_unbound_repeat.c +557 -0
- data/ca_obj_window.c +1023 -0
- data/carray.h +1381 -0
- data/carray_access.c +1798 -0
- data/carray_attribute.c +903 -0
- data/carray_call_cfunc.c +1107 -0
- data/carray_cast.c +1155 -0
- data/carray_cast_func.rb +498 -0
- data/carray_class.c +132 -0
- data/carray_conversion.c +518 -0
- data/carray_copy.c +453 -0
- data/carray_core.c +1307 -0
- data/carray_element.c +572 -0
- data/carray_generate.c +681 -0
- data/carray_iterator.c +630 -0
- data/carray_loop.c +462 -0
- data/carray_mask.c +1174 -0
- data/carray_math.rb +834 -0
- data/carray_numeric.c +257 -0
- data/carray_operator.c +582 -0
- data/carray_order.c +1040 -0
- data/carray_random.c +529 -0
- data/carray_sort_addr.c +261 -0
- data/carray_stat.c +2102 -0
- data/carray_stat_proc.rb +1990 -0
- data/carray_test.c +602 -0
- data/carray_undef.c +69 -0
- data/carray_utils.c +740 -0
- data/ext/calculus/carray_calculus.c +792 -0
- data/ext/calculus/carray_interp.c +355 -0
- data/ext/calculus/extconf.rb +12 -0
- data/ext/calculus/lib/autoload/autoload_math_calculus.rb +2 -0
- data/ext/calculus/lib/math/calculus.rb +119 -0
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +31 -0
- data/ext/dataframe/API.txt +11 -0
- data/ext/dataframe/extconf.rb +3 -0
- data/ext/dataframe/lib/carray/autoload/autoload_dataframe_dataframe.rb +14 -0
- data/ext/dataframe/lib/carray/dataframe/dataframe.rb +1104 -0
- data/ext/dataframe/sample/test_uniq_sort.rb +5 -0
- data/ext/fortio/extconf.rb +3 -0
- data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +5 -0
- data/ext/fortio/lib/carray/io/fortran_format.rb +43 -0
- data/ext/fortio/lib/fortio.rb +3 -0
- data/ext/fortio/lib/fortio/fortran_format.rb +603 -0
- data/ext/fortio/lib/fortio/fortran_format.tab.rb +536 -0
- data/ext/fortio/lib/fortio/fortran_format.y +215 -0
- data/ext/fortio/lib/fortio/fortran_namelist.rb +151 -0
- data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +470 -0
- data/ext/fortio/lib/fortio/fortran_namelist.y +213 -0
- data/ext/fortio/lib/fortio/fortran_sequential.rb +345 -0
- data/ext/fortio/ruby_fortio.c +182 -0
- data/ext/fortio/test/test_H.rb +5 -0
- data/ext/fortio/test/test_T.rb +7 -0
- data/ext/fortio/test/test_fortran_format.rb +86 -0
- data/ext/fortio/test/test_namelist.rb +25 -0
- data/ext/fortio/test/test_sequential.rb +13 -0
- data/ext/fortio/test/test_sequential2.rb +13 -0
- data/ext/fortio/work/test.rb +10 -0
- data/ext/fortio/work/test_e.rb +19 -0
- data/ext/fortio/work/test_ep.rb +10 -0
- data/ext/fortio/work/test_parse.rb +12 -0
- data/ext/imagemap/carray_imagemap.c +495 -0
- data/ext/imagemap/doc/call_graph.dot +28 -0
- data/ext/imagemap/draw.c +567 -0
- data/ext/imagemap/extconf.rb +13 -0
- data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +1 -0
- data/ext/imagemap/lib/graphics/imagemap.rb +273 -0
- data/ext/imagemap/lib/image_map.rb +4 -0
- data/ext/imagemap/test/swath_index.rb +83 -0
- data/ext/imagemap/test/swath_warp.rb +99 -0
- data/ext/imagemap/test/test.rb +23 -0
- data/ext/imagemap/test/test_image.rb +42 -0
- data/ext/imagemap/test/test_line.rb +14 -0
- data/ext/imagemap/test/test_rotate.rb +17 -0
- data/ext/imagemap/test/test_triangle.rb +20 -0
- data/ext/imagemap/test/test_warp.rb +26 -0
- data/ext/mathfunc/carray_mathfunc.c +321 -0
- data/ext/mathfunc/extconf.rb +18 -0
- data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +1 -0
- data/ext/mathfunc/lib/math/mathfunc.rb +15 -0
- data/ext/mathfunc/test/test_hypot.rb +5 -0
- data/ext/mathfunc/test/test_j0.rb +22 -0
- data/ext/mathfunc/test/test_jn.rb +8 -0
- data/ext/mathfunc/test/test_sph.rb +9 -0
- data/ext/narray/README +22 -0
- data/ext/narray/ca_wrap_narray.c +491 -0
- data/ext/narray/carray_narray.c +21 -0
- data/ext/narray/extconf.rb +57 -0
- data/ext/narray/lib/autoload/autoload_math_narray.rb +1 -0
- data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +11 -0
- data/ext/narray/lib/math/narray.rb +17 -0
- data/ext/narray/lib/math/narray_miss.rb +45 -0
- data/extconf.rb +3 -25
- data/lib/carray.rb +28 -0
- data/lib/carray/autoload/autoload_base.rb +23 -0
- data/lib/carray/autoload/autoload_graphics_gnuplot.rb +2 -0
- data/lib/carray/autoload/autoload_io_csv.rb +14 -0
- data/lib/carray/autoload/autoload_io_excel.rb +5 -0
- data/lib/carray/autoload/autoload_io_imagemagick.rb +6 -0
- data/lib/carray/autoload/autoload_io_pg.rb +6 -0
- data/lib/carray/autoload/autoload_io_sqlite3.rb +12 -0
- data/lib/carray/autoload/autoload_io_table.rb +1 -0
- data/lib/carray/autoload/autoload_math_histogram.rb +5 -0
- data/lib/carray/autoload/autoload_math_interp.rb +4 -0
- data/lib/carray/autoload/autoload_math_recurrence.rb +6 -0
- data/lib/carray/autoload/autoload_object_iterator.rb +1 -0
- data/lib/carray/autoload/autoload_object_link.rb +1 -0
- data/lib/carray/autoload/autoload_object_pack.rb +2 -0
- data/lib/carray/base/autoload.rb +94 -0
- data/lib/carray/base/basic.rb +1051 -0
- data/lib/carray/base/inspect.rb +252 -0
- data/lib/carray/base/iterator.rb +367 -0
- data/lib/carray/base/math.rb +403 -0
- data/lib/carray/base/obsolete.rb +93 -0
- data/lib/carray/base/serialize.rb +260 -0
- data/lib/carray/base/struct.rb +634 -0
- data/lib/carray/graphics/gnuplot.rb +2116 -0
- data/lib/carray/info.rb +112 -0
- data/lib/carray/io/csv.rb +560 -0
- data/lib/carray/io/excel.rb +26 -0
- data/lib/carray/io/imagemagick.rb +231 -0
- data/lib/carray/io/pg.rb +101 -0
- data/lib/carray/io/sqlite3.rb +202 -0
- data/lib/carray/io/table.rb +77 -0
- data/lib/carray/math/histogram.rb +179 -0
- data/lib/carray/math/interp.rb +57 -0
- data/lib/carray/math/interp/adapter_gsl_spline.rb +47 -0
- data/lib/carray/math/recurrence.rb +95 -0
- data/lib/carray/mkmf.rb +145 -0
- data/lib/carray/object/ca_obj_iterator.rb +52 -0
- data/lib/carray/object/ca_obj_link.rb +52 -0
- data/lib/carray/object/ca_obj_pack.rb +101 -0
- data/mkmath.rb +731 -0
- data/mt19937ar.c +182 -0
- data/mt19937ar.h +86 -0
- data/rdoc_main.rb +27 -0
- data/rdoc_math.rb +5 -0
- data/rdoc_stat.rb +31 -0
- data/ruby_carray.c +242 -0
- data/ruby_ccomplex.c +497 -0
- data/ruby_float_func.c +83 -0
- data/spec/CABlockIterator/CABlockIterator_spec.rb +113 -0
- data/spec/CArray/bug/store_spec.rb +27 -0
- data/spec/CArray/index/repeat_spec.rb +10 -0
- data/spec/CArray/method/eq_spec.rb +80 -0
- data/spec/CArray/method/is_nan_spec.rb +12 -0
- data/spec/CArray/method/ne_spec.rb +18 -0
- data/spec/CArray/method/round_spec.rb +11 -0
- data/spec/CArray/object/_attribute_spec.rb +32 -0
- data/spec/CArray/object/s_new_spec.rb +31 -0
- data/spec/CArray/serialize/Serialization_spec.rb +89 -0
- data/spec/spec_all.rb +11 -0
- data/test/test_ALL.rb +50 -0
- data/test/test_CABitfield.rb +59 -0
- data/test/test_CABlock.rb +208 -0
- data/test/test_CAField.rb +40 -0
- data/test/test_CAGrid.rb +76 -0
- data/test/test_CAMapping.rb +106 -0
- data/test/test_CAMmap.rb +11 -0
- data/test/test_CARefer.rb +94 -0
- data/test/test_CARepeat.rb +66 -0
- data/test/test_CASelect.rb +23 -0
- data/test/test_CAShift.rb +17 -0
- data/test/test_CATranspose.rb +61 -0
- data/test/test_CAVirtual.rb +214 -0
- data/test/test_CAWindow.rb +55 -0
- data/test/test_CAWrap.rb +9 -0
- data/test/test_CArray.rb +228 -0
- data/test/test_CComplex.rb +83 -0
- data/test/test_CScalar.rb +91 -0
- data/test/test_attribute.rb +281 -0
- data/test/test_block_iterator.rb +17 -0
- data/test/test_boolean.rb +99 -0
- data/test/test_cast.rb +33 -0
- data/test/test_class.rb +85 -0
- data/test/test_complex.rb +43 -0
- data/test/test_composite.rb +125 -0
- data/test/test_convert.rb +79 -0
- data/test/test_copy.rb +141 -0
- data/test/test_creation.rb +85 -0
- data/test/test_element.rb +146 -0
- data/test/test_extream.rb +55 -0
- data/test/test_generate.rb +75 -0
- data/test/test_index.rb +71 -0
- data/test/test_mask.rb +578 -0
- data/test/test_math.rb +98 -0
- data/test/test_narray.rb +64 -0
- data/test/test_order.rb +147 -0
- data/test/test_random.rb +15 -0
- data/test/test_ref_store.rb +211 -0
- data/test/test_stat.rb +414 -0
- data/test/test_struct.rb +72 -0
- data/test/test_virtual.rb +49 -0
- data/utils/ca_ase.rb +21 -0
- data/utils/ca_methods.rb +15 -0
- data/utils/cast_checker.rb +30 -0
- data/utils/create_rdoc.sh +9 -0
- data/utils/diff_method.rb +52 -0
- data/utils/extract_rdoc.rb +27 -0
- data/utils/make_tgz.sh +3 -0
- data/utils/remove_resource_fork.sh +5 -0
- data/version.h +3 -3
- metadata +266 -1
data/LEGAL
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
LEGAL NOTICE INFORMATION
|
2
|
+
========================
|
3
|
+
|
4
|
+
All the files in this distribution are covered under
|
5
|
+
the Ruby Licence except some files under public-domain mentioned below.
|
6
|
+
|
7
|
+
mt19937ar.c, mt19937ar.h:
|
8
|
+
-------------------------
|
9
|
+
|
10
|
+
A C-program for MT19937, with initialization improved 2002/1/26.
|
11
|
+
Coded by Takuji Nishimura and Makoto Matsumoto.
|
12
|
+
|
13
|
+
Before using, initialize the state by using init_genrand(seed)
|
14
|
+
or init_by_array(init_key, key_length).
|
15
|
+
|
16
|
+
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
17
|
+
All rights reserved.
|
18
|
+
Copyright (C) 2005, Mutsuo Saito,
|
19
|
+
All rights reserved.
|
20
|
+
|
21
|
+
Redistribution and use in source and binary forms, with or without
|
22
|
+
modification, are permitted provided that the following conditions
|
23
|
+
are met:
|
24
|
+
1. Redistributions of source code must retain the above copyright
|
25
|
+
notice, this list of conditions and the following disclaimer.
|
26
|
+
|
27
|
+
2. Redistributions in binary form must reproduce the above copyright
|
28
|
+
notice, this list of conditions and the following disclaimer in the
|
29
|
+
documentation and/or other materials provided with the distribution.
|
30
|
+
|
31
|
+
3. The names of its contributors may not be used to endorse or promote
|
32
|
+
products derived from this software without specific prior written
|
33
|
+
permission.
|
34
|
+
|
35
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
36
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
37
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
38
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER O
|
39
|
+
R
|
40
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
41
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
42
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
43
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
44
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
45
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
46
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
47
|
+
|
48
|
+
Any feedback is very welcome.
|
49
|
+
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
|
50
|
+
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
|
data/NOTE
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
Note for developper
|
2
|
+
===================
|
3
|
+
|
4
|
+
Make targets
|
5
|
+
------------
|
6
|
+
|
7
|
+
### create Makefile
|
8
|
+
|
9
|
+
ruby extconf.rb
|
10
|
+
|
11
|
+
### build extensions
|
12
|
+
|
13
|
+
make all
|
14
|
+
|
15
|
+
### install via RubyGems
|
16
|
+
|
17
|
+
make build-gem
|
18
|
+
make install-gem
|
19
|
+
make uninstall-gem ### for uninstall this version
|
20
|
+
|
21
|
+
### install via extconf.rb
|
22
|
+
|
23
|
+
ruby extconf.rb
|
24
|
+
make all
|
25
|
+
make install
|
26
|
+
|
27
|
+
### cleaning temporary files
|
28
|
+
|
29
|
+
make clean
|
30
|
+
make distclean
|
31
|
+
|
32
|
+
### create gem package
|
33
|
+
|
34
|
+
make package ### -> rake package
|
35
|
+
|
36
|
+
### run test
|
37
|
+
|
38
|
+
make test ### -> rake test
|
39
|
+
|
40
|
+
Utility scripts
|
41
|
+
---------------
|
42
|
+
|
43
|
+
### check version.h
|
44
|
+
|
45
|
+
ruby version.rb
|
46
|
+
|
47
|
+
### check installed ruby-carray environment
|
48
|
+
|
49
|
+
ruby -v -e "require 'carray/info'"
|
50
|
+
|
51
|
+
Check Points for Debug
|
52
|
+
----------------------
|
53
|
+
|
54
|
+
* 'elements' should be checked with double float number
|
55
|
+
|
56
|
+
* ca_update_mask/ca_attach/ca_create_mask/ca_has_mask should be called
|
57
|
+
before ca->mask refered
|
58
|
+
|
59
|
+
* Avoid the exposition of raw VALUE data in object array
|
60
|
+
|
61
|
+
+ CArray#refer, CArray#member, CArray#bitarray, CArray#bitfield
|
62
|
+
+ CArray#transform, CArray#load, CArray#dump
|
63
|
+
+ CArray#swap_bytes!, CArray#swap_bytes
|
64
|
+
|
65
|
+
* inherit data_class when copy
|
66
|
+
|
67
|
+
+ rb_ca_copy, rb_ca_template
|
68
|
+
+ rb_ca_unmask_copy
|
69
|
+
|
70
|
+
OpenMP
|
71
|
+
------
|
72
|
+
|
73
|
+
* '--with-cc="gcc -fopenmp"' ... and so on.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
#
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'rake'
|
6
|
+
require 'rake/testtask'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
task :default => :test
|
10
|
+
|
11
|
+
desc "Run the tests"
|
12
|
+
Rake::TestTask::new(:test) do |t|
|
13
|
+
t.test_files = FileList['test/test_ALL.rb']
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
18
|
+
t.pattern = "spec/**/*_spec.rb"
|
19
|
+
t.rspec_opts = ["-c", "-fs"]
|
20
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
- CArray#section should treat mask (-> currently CArray#bin uses inherit_mask)
|
2
|
+
- CArray#differentiate should treat mask
|
3
|
+
* CArray#search should permit a CArray argument (use lfind ?)
|
4
|
+
* append API ca_get_range(vrange, size, *first, *last)
|
5
|
+
* ca_cast_self_or_other should treat NArray directly
|
data/ca_iter_block.c
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
ca_iter_block.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 "carray.h"
|
14
|
+
|
15
|
+
/* rdoc:
|
16
|
+
class CABlockIterator < CAIterator # :nodoc:
|
17
|
+
end
|
18
|
+
*/
|
19
|
+
|
20
|
+
VALUE rb_cCABlockIterator;
|
21
|
+
|
22
|
+
/*
|
23
|
+
typedef struct {
|
24
|
+
int16_t obj_type;
|
25
|
+
int8_t data_type;
|
26
|
+
int8_t rank;
|
27
|
+
int32_t flags;
|
28
|
+
int32_t bytes;
|
29
|
+
int32_t elements;
|
30
|
+
int32_t *dim;
|
31
|
+
char *ptr;
|
32
|
+
CArray *mask;
|
33
|
+
CArray *parent;
|
34
|
+
uint32_t attach;
|
35
|
+
uint8_t nosync;
|
36
|
+
// ----------
|
37
|
+
int8_t maxdim_index;
|
38
|
+
int32_t maxdim_step;
|
39
|
+
int32_t maxdim_step0;
|
40
|
+
int32_t offset;
|
41
|
+
int32_t *start;
|
42
|
+
int32_t *step;
|
43
|
+
int32_t *count;
|
44
|
+
int32_t *size0;
|
45
|
+
} CABlock; // 68 + 20*(rank) (bytes)
|
46
|
+
*/
|
47
|
+
|
48
|
+
typedef struct {
|
49
|
+
int8_t rank;
|
50
|
+
int32_t dim[CA_RANK_MAX];
|
51
|
+
CArray *reference;
|
52
|
+
CArray * (*kernel_at_addr)(void *, int32_t, CArray *);
|
53
|
+
CArray * (*kernel_at_index)(void *, int32_t *, CArray *);
|
54
|
+
CArray * (*kernel_move_to_addr)(void *, int32_t, CArray *);
|
55
|
+
CArray * (*kernel_move_to_index)(void *, int32_t *, CArray *);
|
56
|
+
/* ----------- */
|
57
|
+
CABlock *kernel;
|
58
|
+
} CABlockIterator;
|
59
|
+
|
60
|
+
/* ----------------------------------------------------------------- */
|
61
|
+
|
62
|
+
static CArray *
|
63
|
+
ca_bi_kernel_at_index (void *it, int32_t *idx, CArray *ref)
|
64
|
+
{
|
65
|
+
CABlockIterator *bit = (CABlockIterator *) it;
|
66
|
+
CABlock *kernel;
|
67
|
+
int32_t i, j;
|
68
|
+
|
69
|
+
if ( ref == bit->reference ) {
|
70
|
+
kernel = (CABlock *)ca_clone(bit->kernel);
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
CABlock *ck = (CABlock *)bit->kernel;
|
74
|
+
kernel = ca_block_new(ref,
|
75
|
+
ck->rank, ck->size0,
|
76
|
+
ck->start, ck->step, ck->count,
|
77
|
+
ck->offset);
|
78
|
+
}
|
79
|
+
|
80
|
+
ca_update_mask(kernel);
|
81
|
+
|
82
|
+
for (i=0; i<kernel->rank; i++) {
|
83
|
+
j = idx[i];
|
84
|
+
CA_CHECK_INDEX(j, bit->dim[i]);
|
85
|
+
kernel->start[i] += j * kernel->dim[i];
|
86
|
+
if ( kernel->mask ) {
|
87
|
+
((CABlock*)(kernel->mask))->start[i] += j * kernel->dim[i];
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
return (CArray*) kernel;
|
92
|
+
}
|
93
|
+
|
94
|
+
static CArray *
|
95
|
+
ca_bi_kernel_at_addr (void *it, int32_t addr, CArray *ref)
|
96
|
+
{
|
97
|
+
CABlockIterator *bit = (CABlockIterator *) it;
|
98
|
+
int32_t *dim = bit->dim;
|
99
|
+
int32_t idx[CA_RANK_MAX];
|
100
|
+
int32_t i;
|
101
|
+
for (i=bit->rank-1; i>=0; i--) {
|
102
|
+
idx[i] = addr % dim[i];
|
103
|
+
addr /= dim[i];
|
104
|
+
}
|
105
|
+
return ca_bi_kernel_at_index(it, idx, ref);
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
static CArray *
|
110
|
+
ca_bi_kernel_move_to_index (void *it, int32_t *idx, CArray *kern)
|
111
|
+
{
|
112
|
+
CABlockIterator *bit = (CABlockIterator *) it;
|
113
|
+
CABlock *kernel = (CABlock *) kern;
|
114
|
+
int32_t i, j;
|
115
|
+
|
116
|
+
ca_update_mask(kernel);
|
117
|
+
|
118
|
+
for (i=0; i<kernel->rank; i++) {
|
119
|
+
j = idx[i];
|
120
|
+
CA_CHECK_INDEX(j, bit->dim[i]);
|
121
|
+
kernel->start[i] = j * kernel->dim[i];
|
122
|
+
if ( kernel->mask ) {
|
123
|
+
((CABlock*)(kernel->mask))->start[i] = j * kernel->dim[i];
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
return (CArray*) kernel;
|
128
|
+
}
|
129
|
+
|
130
|
+
static CArray *
|
131
|
+
ca_bi_kernel_move_to_addr (void *it, int32_t addr, CArray *ref)
|
132
|
+
{
|
133
|
+
CABlockIterator *bit = (CABlockIterator *) it;
|
134
|
+
int32_t *dim = bit->dim;
|
135
|
+
int32_t idx[CA_RANK_MAX];
|
136
|
+
int32_t i;
|
137
|
+
for (i=bit->rank-1; i>=0; i--) {
|
138
|
+
idx[i] = addr % dim[i];
|
139
|
+
addr /= dim[i];
|
140
|
+
}
|
141
|
+
return ca_bi_kernel_move_to_index(it, idx, ref);
|
142
|
+
}
|
143
|
+
|
144
|
+
void
|
145
|
+
ca_bi_setup (VALUE self, VALUE rref, VALUE rker)
|
146
|
+
{
|
147
|
+
CABlockIterator *it;
|
148
|
+
CArray *ref;
|
149
|
+
CABlock *ker;
|
150
|
+
int32_t dim[CA_RANK_MAX];
|
151
|
+
int32_t i;
|
152
|
+
|
153
|
+
rker = rb_obj_clone(rker);
|
154
|
+
|
155
|
+
Data_Get_Struct(self, CABlockIterator, it);
|
156
|
+
Data_Get_Struct(rref, CArray, ref);
|
157
|
+
Data_Get_Struct(rker, CABlock, ker);
|
158
|
+
|
159
|
+
if ( ref->rank != ker->rank ) {
|
160
|
+
rb_raise(rb_eRuntimeError, "rank mismatch between reference and kernel");
|
161
|
+
}
|
162
|
+
|
163
|
+
for (i=0; i<ref->rank; i++) {
|
164
|
+
if ( ker->step[i] != 1 ) {
|
165
|
+
rb_raise(rb_eRuntimeError, "block should be contiguous");
|
166
|
+
}
|
167
|
+
dim[i] = ( ref->dim[i] - ker->start[i] ) / ker->dim[i];
|
168
|
+
/*
|
169
|
+
if ( ref->dim[i] % ker->dim[i] != 0 ) {
|
170
|
+
rb_raise(rb_eRuntimeError, "invalid block size");
|
171
|
+
}
|
172
|
+
*/
|
173
|
+
}
|
174
|
+
|
175
|
+
it->rank = ref->rank;
|
176
|
+
memcpy(it->dim, dim, it->rank * sizeof(int32_t));
|
177
|
+
it->reference = ref;
|
178
|
+
it->kernel = ker;
|
179
|
+
it->kernel_at_addr = ca_bi_kernel_at_addr;
|
180
|
+
it->kernel_at_index = ca_bi_kernel_at_index;
|
181
|
+
it->kernel_move_to_addr = ca_bi_kernel_move_to_addr;
|
182
|
+
it->kernel_move_to_index = ca_bi_kernel_move_to_index;
|
183
|
+
|
184
|
+
rb_ivar_set(self, rb_intern("@reference"), rref); /* required ivar */
|
185
|
+
rb_ivar_set(self, rb_intern("@kernel"), rker);
|
186
|
+
}
|
187
|
+
|
188
|
+
static VALUE
|
189
|
+
rb_bi_s_allocate (VALUE klass)
|
190
|
+
{
|
191
|
+
CABlockIterator *it;
|
192
|
+
return Data_Make_Struct(klass, CABlockIterator, 0, free, it);
|
193
|
+
}
|
194
|
+
|
195
|
+
static VALUE
|
196
|
+
rb_bi_initialize_copy (VALUE self, VALUE other)
|
197
|
+
{
|
198
|
+
ca_bi_setup(other, rb_ivar_get(self, rb_intern("@reference")),
|
199
|
+
rb_ivar_get(self, rb_intern("@kernel")));
|
200
|
+
return self;
|
201
|
+
}
|
202
|
+
|
203
|
+
/* rdoc:
|
204
|
+
class CArray
|
205
|
+
# Create block iterator.
|
206
|
+
def blocks (*args)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
*/
|
210
|
+
|
211
|
+
static VALUE
|
212
|
+
rb_ca_block_iterator (int argc, VALUE *argv, VALUE self)
|
213
|
+
{
|
214
|
+
VALUE obj, rker;
|
215
|
+
CArray *ker;
|
216
|
+
|
217
|
+
rker = rb_ca_fetch2(self, argc, argv);
|
218
|
+
|
219
|
+
rb_check_carray_object(rker);
|
220
|
+
Data_Get_Struct(rker, CArray, ker);
|
221
|
+
|
222
|
+
if ( ker->obj_type != CA_OBJ_BLOCK ) {
|
223
|
+
rb_raise(rb_eRuntimeError, "kernel must be CABlock object");
|
224
|
+
}
|
225
|
+
|
226
|
+
obj = rb_bi_s_allocate(rb_cCABlockIterator);
|
227
|
+
ca_bi_setup(obj, self, rker);
|
228
|
+
|
229
|
+
return obj;
|
230
|
+
}
|
231
|
+
|
232
|
+
void
|
233
|
+
Init_ca_iter_block ()
|
234
|
+
{
|
235
|
+
rb_cCABlockIterator = rb_define_class("CABlockIterator", rb_cCAIterator);
|
236
|
+
rb_define_const(rb_cCABlockIterator, "UNIFORM_KERNEL", Qtrue);
|
237
|
+
rb_define_alloc_func(rb_cCABlockIterator, rb_bi_s_allocate);
|
238
|
+
rb_define_method(rb_cCABlockIterator, "initialize_copy",
|
239
|
+
rb_bi_initialize_copy, 1);
|
240
|
+
rb_define_method(rb_cCArray, "blocks", rb_ca_block_iterator, -1);
|
241
|
+
}
|
242
|
+
|
data/ca_iter_dimension.c
ADDED
@@ -0,0 +1,287 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
ca_iter_dimension.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
|
+
VALUE rb_cCADimIterator;
|
17
|
+
|
18
|
+
/* rdoc:
|
19
|
+
class CADimensionIterator < CAIterator # :nodoc:
|
20
|
+
end
|
21
|
+
*/
|
22
|
+
|
23
|
+
typedef struct {
|
24
|
+
int8_t rank;
|
25
|
+
int32_t dim[CA_RANK_MAX];
|
26
|
+
CArray *reference;
|
27
|
+
CArray * (*kernel_at_addr)(void *, int32_t, CArray *);
|
28
|
+
CArray * (*kernel_at_index)(void *, int32_t *, CArray *);
|
29
|
+
CArray * (*kernel_move_to_addr)(void *, int32_t, CArray *);
|
30
|
+
CArray * (*kernel_move_to_index)(void *, int32_t *, CArray *);
|
31
|
+
/* ----------- */
|
32
|
+
CArray *kernel;
|
33
|
+
int8_t symflag[CA_RANK_MAX];
|
34
|
+
int8_t symindex[CA_RANK_MAX];
|
35
|
+
} CADimIterator;
|
36
|
+
|
37
|
+
/* -------------------------------------------------------------------- */
|
38
|
+
|
39
|
+
static CArray *
|
40
|
+
ca_di_kernel_at_index (void *it, int32_t *idx, CArray *ref)
|
41
|
+
{
|
42
|
+
CADimIterator *dit = (CADimIterator *)it;
|
43
|
+
CABlock *kernel;
|
44
|
+
int32_t i, val;
|
45
|
+
|
46
|
+
if ( ref == dit->reference ) {
|
47
|
+
kernel = ca_clone(dit->kernel);
|
48
|
+
}
|
49
|
+
else {
|
50
|
+
CABlock *ck = (CABlock *)dit->kernel;
|
51
|
+
kernel = ca_block_new(ref,
|
52
|
+
ck->rank, ck->size0,
|
53
|
+
ck->start, ck->step, ck->count,
|
54
|
+
ck->offset);
|
55
|
+
}
|
56
|
+
|
57
|
+
ca_update_mask(kernel);
|
58
|
+
|
59
|
+
for (i=0; i<dit->rank; i++) {
|
60
|
+
val = idx[i];
|
61
|
+
CA_CHECK_INDEX(val, dit->dim[i]);
|
62
|
+
kernel->start[dit->symindex[i]] = val * kernel->step[dit->symindex[i]];
|
63
|
+
if ( kernel->mask ) {
|
64
|
+
((CABlock*)(kernel->mask))->start[dit->symindex[i]] =
|
65
|
+
val * kernel->step[dit->symindex[i]];
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
return (CArray*) kernel;
|
70
|
+
}
|
71
|
+
|
72
|
+
static CArray *
|
73
|
+
ca_di_kernel_at_addr (void *it, int32_t addr, CArray *ref)
|
74
|
+
{
|
75
|
+
CADimIterator *dit = (CADimIterator *) it;
|
76
|
+
int32_t *dim = dit->dim;
|
77
|
+
int32_t idx[CA_RANK_MAX];
|
78
|
+
int32_t i;
|
79
|
+
for (i=dit->rank-1; i>=0; i--) {
|
80
|
+
idx[i] = addr % dim[i];
|
81
|
+
addr /= dim[i];
|
82
|
+
}
|
83
|
+
return ca_di_kernel_at_index(it, idx, ref);
|
84
|
+
}
|
85
|
+
|
86
|
+
static CArray *
|
87
|
+
ca_di_kernel_move_to_index (void *it, int32_t *idx, CArray *kern)
|
88
|
+
{
|
89
|
+
CADimIterator *dit = (CADimIterator *)it;
|
90
|
+
CABlock *kernel = (CABlock *) kern;
|
91
|
+
int32_t i, val;
|
92
|
+
|
93
|
+
ca_update_mask(kernel);
|
94
|
+
|
95
|
+
for (i=0; i<dit->rank; i++) {
|
96
|
+
val = idx[i];
|
97
|
+
CA_CHECK_INDEX(val, dit->dim[i]);
|
98
|
+
kernel->start[dit->symindex[i]] = val * kernel->step[dit->symindex[i]];
|
99
|
+
if ( kernel->mask ) {
|
100
|
+
((CABlock*)(kernel->mask))->start[dit->symindex[i]] =
|
101
|
+
val * kernel->step[dit->symindex[i]];
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
return (CArray*) kernel;
|
106
|
+
}
|
107
|
+
|
108
|
+
static CArray *
|
109
|
+
ca_di_kernel_move_to_addr (void *it, int32_t addr, CArray *ref)
|
110
|
+
{
|
111
|
+
CADimIterator *dit = (CADimIterator *) it;
|
112
|
+
int32_t *dim = dit->dim;
|
113
|
+
int32_t idx[CA_RANK_MAX];
|
114
|
+
int32_t i;
|
115
|
+
for (i=dit->rank-1; i>=0; i--) {
|
116
|
+
idx[i] = addr % dim[i];
|
117
|
+
addr /= dim[i];
|
118
|
+
}
|
119
|
+
return ca_di_kernel_move_to_index(it, idx, ref);
|
120
|
+
}
|
121
|
+
|
122
|
+
VALUE rb_ca_ref_block (VALUE self, CAIndexInfo *info);
|
123
|
+
|
124
|
+
void
|
125
|
+
ca_di_setup (VALUE self, VALUE rref, CAIndexInfo *info)
|
126
|
+
{
|
127
|
+
volatile VALUE rindex, rker, rsymtbl;
|
128
|
+
CADimIterator *it;
|
129
|
+
CAIndexInfo blk_spec;
|
130
|
+
int8_t rank;
|
131
|
+
int i, j, k;
|
132
|
+
|
133
|
+
Data_Get_Struct(self, CADimIterator, it);
|
134
|
+
|
135
|
+
if ( info->type != CA_REG_ITERATOR ) {
|
136
|
+
rb_raise(rb_eRuntimeError, "given spec is not for dim iteratror");
|
137
|
+
}
|
138
|
+
|
139
|
+
rsymtbl = rb_hash_new();
|
140
|
+
|
141
|
+
blk_spec = *info;
|
142
|
+
blk_spec.type = CA_REG_BLOCK;
|
143
|
+
for (i=0; i<info->rank; i++) {
|
144
|
+
if ( info->index_type[i] == CA_IDX_SYMBOL ) {
|
145
|
+
blk_spec.index_type[i] = CA_IDX_ALL;
|
146
|
+
rb_hash_aset(rsymtbl, ID2SYM(blk_spec.index[i].symbol.id), INT2NUM(i));
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
rref = rb_ca_ref_block(rref, &blk_spec);
|
151
|
+
|
152
|
+
rindex = rb_ary_new2(info->rank);
|
153
|
+
rank = 0;
|
154
|
+
|
155
|
+
j = 0;
|
156
|
+
k = 0;
|
157
|
+
|
158
|
+
for (i=0; i<info->rank; i++) {
|
159
|
+
if ( info->index_type[i] == CA_IDX_SCALAR ) {
|
160
|
+
rb_ary_store(rindex, i, INT2NUM(info->index[i].scalar));
|
161
|
+
continue; /* escape from j++ */
|
162
|
+
}
|
163
|
+
else if ( info->index_type[i] == CA_IDX_SYMBOL ) {
|
164
|
+
rb_ary_store(rindex, i, rb_ary_new3(1,INT2NUM(0)));
|
165
|
+
it->symflag[j] = 1;
|
166
|
+
it->symindex[rank] = j;
|
167
|
+
rank++;
|
168
|
+
}
|
169
|
+
else if ( info->index_type[i] == CA_IDX_ALL ) {
|
170
|
+
rb_ary_store(rindex, i, Qnil);
|
171
|
+
it->symflag[j] = 0;
|
172
|
+
}
|
173
|
+
else if ( info->index_type[i] == CA_IDX_BLOCK ) {
|
174
|
+
rb_ary_store(rindex, i,
|
175
|
+
rb_ary_new3(3, INT2NUM(0),
|
176
|
+
INT2NUM(info->index[i].block.count),
|
177
|
+
INT2NUM(1)));
|
178
|
+
it->symflag[j] = 0;
|
179
|
+
}
|
180
|
+
j++;
|
181
|
+
}
|
182
|
+
|
183
|
+
rker = rb_apply(rref, rb_intern("[]"), rindex);
|
184
|
+
|
185
|
+
it->rank = rank;
|
186
|
+
Data_Get_Struct(rref, CArray, it->reference);
|
187
|
+
Data_Get_Struct(rker, CArray, it->kernel);
|
188
|
+
it->kernel_at_addr = ca_di_kernel_at_addr;
|
189
|
+
it->kernel_at_index = ca_di_kernel_at_index;
|
190
|
+
it->kernel_move_to_addr = ca_di_kernel_move_to_addr;
|
191
|
+
it->kernel_move_to_index = ca_di_kernel_move_to_index;
|
192
|
+
|
193
|
+
for (i=0; i<it->rank; i++) {
|
194
|
+
it->dim[i] = it->reference->dim[it->symindex[i]];
|
195
|
+
}
|
196
|
+
|
197
|
+
rb_ivar_set(self, rb_intern("@reference"), rref); /* required ivar */
|
198
|
+
rb_ivar_set(self, rb_intern("@kernel"), rker);
|
199
|
+
rb_ivar_set(self, rb_intern("@symtbl"), rsymtbl);
|
200
|
+
}
|
201
|
+
|
202
|
+
static VALUE
|
203
|
+
rb_di_s_allocate (VALUE klass)
|
204
|
+
{
|
205
|
+
CADimIterator *it;
|
206
|
+
return Data_Make_Struct(klass, CADimIterator, 0, free, it);
|
207
|
+
}
|
208
|
+
|
209
|
+
static VALUE
|
210
|
+
rb_di_initialize_copy (VALUE self, VALUE other)
|
211
|
+
{
|
212
|
+
volatile VALUE rref, rker;
|
213
|
+
CADimIterator *is, *io;
|
214
|
+
|
215
|
+
Data_Get_Struct(self, CADimIterator, is);
|
216
|
+
Data_Get_Struct(other, CADimIterator, io);
|
217
|
+
|
218
|
+
rref = rb_ivar_get(self, rb_intern("@reference"));
|
219
|
+
rker = rb_obj_clone(rb_ivar_get(self, rb_intern("@kernel")));
|
220
|
+
|
221
|
+
*io = *is;
|
222
|
+
|
223
|
+
Data_Get_Struct(rker, CArray, io->kernel);
|
224
|
+
|
225
|
+
rb_ivar_set(self, rb_intern("@reference"), rref); /* required ivar */
|
226
|
+
rb_ivar_set(self, rb_intern("@kernel"), rker);
|
227
|
+
|
228
|
+
return self;
|
229
|
+
}
|
230
|
+
|
231
|
+
VALUE
|
232
|
+
rb_ca_dim_iterator (int argc, VALUE *argv, VALUE self)
|
233
|
+
{
|
234
|
+
volatile VALUE obj;
|
235
|
+
CAIndexInfo info;
|
236
|
+
CArray *ca;
|
237
|
+
|
238
|
+
Data_Get_Struct(self, CArray, ca);
|
239
|
+
|
240
|
+
rb_ca_scan_index(ca->rank, ca->dim, ca->elements, argc, argv, &info);
|
241
|
+
|
242
|
+
obj = rb_di_s_allocate(rb_cCADimIterator);
|
243
|
+
ca_di_setup(obj, self, &info);
|
244
|
+
|
245
|
+
return obj;
|
246
|
+
}
|
247
|
+
|
248
|
+
VALUE
|
249
|
+
rb_dim_iter_new (VALUE rref, CAIndexInfo *info)
|
250
|
+
{
|
251
|
+
volatile VALUE obj;
|
252
|
+
|
253
|
+
obj = rb_di_s_allocate(rb_cCADimIterator);
|
254
|
+
ca_di_setup(obj, rref, info);
|
255
|
+
|
256
|
+
return obj;
|
257
|
+
}
|
258
|
+
|
259
|
+
/* rdoc:
|
260
|
+
class CADimensionIterator
|
261
|
+
def sym2dim (sym)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
*/
|
265
|
+
|
266
|
+
|
267
|
+
VALUE
|
268
|
+
rb_dim_iter_sym2dim (VALUE self, VALUE sym)
|
269
|
+
{
|
270
|
+
volatile VALUE rsymtbl;
|
271
|
+
rsymtbl = rb_ivar_get(self, rb_intern("@symtbl"));
|
272
|
+
return rb_hash_aref(rsymtbl, sym);
|
273
|
+
}
|
274
|
+
|
275
|
+
void
|
276
|
+
Init_ca_iter_dimension ()
|
277
|
+
{
|
278
|
+
rb_cCADimIterator = rb_define_class("CADimensionIterator", rb_cCAIterator);
|
279
|
+
rb_define_const(rb_cCADimIterator, "UNIFORM_KERNEL", Qtrue);
|
280
|
+
|
281
|
+
rb_define_alloc_func(rb_cCADimIterator, rb_di_s_allocate);
|
282
|
+
rb_define_method(rb_cCADimIterator, "initialize_copy",
|
283
|
+
rb_di_initialize_copy, 1);
|
284
|
+
/* rb_define_method(rb_cCArray, "dimension_iterator", rb_ca_dim_iterator, -1); */
|
285
|
+
rb_define_method(rb_cCADimIterator, "sym2dim", rb_dim_iter_sym2dim, 1);
|
286
|
+
}
|
287
|
+
|