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
@@ -0,0 +1,18 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
|
3
|
+
dir_config("carray", "../..", "../..")
|
4
|
+
|
5
|
+
have_header("carray.h")
|
6
|
+
|
7
|
+
if /cygwin|mingw/ =~ RUBY_PLATFORM
|
8
|
+
have_library("carray")
|
9
|
+
end
|
10
|
+
|
11
|
+
have_header("tgmath.h")
|
12
|
+
|
13
|
+
have_func("atan2", "math.h")
|
14
|
+
have_func("hypot", "math.h")
|
15
|
+
have_func("lgamma", "math.h")
|
16
|
+
have_func("expm1", "math.h")
|
17
|
+
|
18
|
+
create_makefile("carray/carray_mathfunc")
|
@@ -0,0 +1 @@
|
|
1
|
+
require "carray/math/mathfunc"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# lib/carray/graphics/imagemap.rb
|
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
|
+
require "carray/carray_mathfunc"
|
14
|
+
|
15
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'carray'
|
2
|
+
|
3
|
+
x = CArray.float(101).span(0..10)
|
4
|
+
|
5
|
+
CA.gnuplot { |g|
|
6
|
+
g.plot2d(
|
7
|
+
[x, x.erf],
|
8
|
+
[x, x.erfc]
|
9
|
+
)
|
10
|
+
g.plot2d(
|
11
|
+
[x, x.j0],
|
12
|
+
[x, x.j1],
|
13
|
+
[x, x.jn(2)],
|
14
|
+
[x, x.jn(3)],
|
15
|
+
[x, x.jn(4)],
|
16
|
+
[x, x.jn(5)]
|
17
|
+
)
|
18
|
+
g.plot2d(
|
19
|
+
[x, x.y0],
|
20
|
+
[x, x.y1]
|
21
|
+
)
|
22
|
+
}
|
data/ext/narray/README
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
This directory contains the plugin library used as the interface to NArray
|
3
|
+
and NArrayMiss library from Ruby/CArray.
|
4
|
+
|
5
|
+
---
|
6
|
+
NArray Library (http://narray.rubyforge.org/) by Masahiro Tanaka.
|
7
|
+
|
8
|
+
NArray is an Numerical N-dimensional Array class. Supported element types
|
9
|
+
are 1/2/4-byte Integer, single/double-precision Real/Complex, and Ruby
|
10
|
+
Object. This extension library incorporates fast calculation and easy
|
11
|
+
manipulation of large numerical arrays into the Ruby language. NArray
|
12
|
+
has features similar to NumPy, but NArray has vector and matrix subclasses.
|
13
|
+
|
14
|
+
(License: Ruby License)
|
15
|
+
|
16
|
+
---
|
17
|
+
NArrayMiss Library (http://ruby.gfd-dennou.org/index.htm) by Seiya Nishizawa.
|
18
|
+
|
19
|
+
NArrayMiss is a additional class processing of missing value with to NArray
|
20
|
+
for Ruby.
|
21
|
+
|
22
|
+
(License: GNU Lesser General Public License (LGPL) version 2.)
|
@@ -0,0 +1,491 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
carray/ca_wrap_narray.c
|
4
|
+
|
5
|
+
This file is part of Ruby/CArray extension library.
|
6
|
+
You can redistribute it and/or modify it under the terms of
|
7
|
+
the Ruby Licence.
|
8
|
+
|
9
|
+
Copyright (C) 2005 Hiroki Motoyoshi
|
10
|
+
|
11
|
+
---------------------------------------------------------------------------- */
|
12
|
+
|
13
|
+
#include "ruby.h"
|
14
|
+
#include "carray.h"
|
15
|
+
|
16
|
+
#include "narray_config.h"
|
17
|
+
#ifndef HAVE_U_INT8_T
|
18
|
+
#define HAVE_U_INT8_T
|
19
|
+
#endif
|
20
|
+
#ifndef HAVE_INT16_T
|
21
|
+
#define HAVE_INT16_T
|
22
|
+
#endif
|
23
|
+
#ifndef HAVE_INT16_T
|
24
|
+
#define HAVE_INT32_T
|
25
|
+
#endif
|
26
|
+
#ifndef HAVE_U_INT32_T
|
27
|
+
#define HAVE_U_INT32_T
|
28
|
+
#endif
|
29
|
+
#include "narray.h"
|
30
|
+
|
31
|
+
#include <math.h>
|
32
|
+
|
33
|
+
extern VALUE cNMatrix, cNVector, cNMatrixLU;
|
34
|
+
|
35
|
+
static char EMPTY_ARRAY_PTR;
|
36
|
+
|
37
|
+
/* -------------------------------------------------------------------- */
|
38
|
+
|
39
|
+
static int8_t
|
40
|
+
na_typecode_to_ca_data_type (int typecode)
|
41
|
+
{
|
42
|
+
int8_t data_type;
|
43
|
+
|
44
|
+
switch ( typecode ) {
|
45
|
+
case NA_BYTE:
|
46
|
+
data_type = CA_UINT8; break;
|
47
|
+
case NA_SINT:
|
48
|
+
data_type = CA_INT16; break;
|
49
|
+
case NA_LINT:
|
50
|
+
data_type = CA_INT32; break;
|
51
|
+
case NA_SFLOAT:
|
52
|
+
data_type = CA_FLOAT32; break;
|
53
|
+
case NA_DFLOAT:
|
54
|
+
data_type = CA_FLOAT64; break;
|
55
|
+
#ifdef HAVE_COMPLEX_H
|
56
|
+
case NA_SCOMPLEX:
|
57
|
+
data_type = CA_CMPLX64; break;
|
58
|
+
case NA_DCOMPLEX:
|
59
|
+
data_type = CA_CMPLX128; break;
|
60
|
+
#endif
|
61
|
+
case NA_ROBJ:
|
62
|
+
data_type = CA_OBJECT; break;
|
63
|
+
default:
|
64
|
+
rb_raise(rb_eCADataTypeError,
|
65
|
+
"unknown NArray typecode <%i>", typecode);
|
66
|
+
}
|
67
|
+
return data_type;
|
68
|
+
}
|
69
|
+
|
70
|
+
static int
|
71
|
+
ca_data_type_to_na_typecode(int8_t data_type)
|
72
|
+
{
|
73
|
+
int typecode;
|
74
|
+
|
75
|
+
switch ( data_type ) {
|
76
|
+
case CA_BOOLEAN:
|
77
|
+
case CA_UINT8:
|
78
|
+
typecode = NA_BYTE; break;
|
79
|
+
case CA_INT16:
|
80
|
+
typecode = NA_SINT; break;
|
81
|
+
case CA_INT32:
|
82
|
+
typecode = NA_LINT; break;
|
83
|
+
case CA_FLOAT32:
|
84
|
+
typecode = NA_SFLOAT; break;
|
85
|
+
case CA_FLOAT64:
|
86
|
+
typecode = NA_DFLOAT; break;
|
87
|
+
#ifdef HAVE_COMPLEX_H
|
88
|
+
case CA_CMPLX64:
|
89
|
+
typecode = NA_SCOMPLEX; break;
|
90
|
+
case CA_CMPLX128:
|
91
|
+
typecode = NA_DCOMPLEX; break;
|
92
|
+
#endif
|
93
|
+
case CA_OBJECT:
|
94
|
+
typecode = NA_ROBJ; break;
|
95
|
+
default:
|
96
|
+
rb_raise(rb_eRuntimeError,
|
97
|
+
"no corresponding NArray typecode for CArray data type <%s>",
|
98
|
+
ca_type_name[data_type]);
|
99
|
+
}
|
100
|
+
|
101
|
+
return typecode;
|
102
|
+
}
|
103
|
+
|
104
|
+
/* -------------------------------------------------------------------- */
|
105
|
+
|
106
|
+
static void
|
107
|
+
cary_na_ref_free (struct NARRAY *ary)
|
108
|
+
{
|
109
|
+
xfree(ary->shape);
|
110
|
+
xfree(ary);
|
111
|
+
}
|
112
|
+
|
113
|
+
static void
|
114
|
+
cary_na_ref_mark (struct NARRAY *ary)
|
115
|
+
{
|
116
|
+
rb_gc_mark( ary->ref );
|
117
|
+
}
|
118
|
+
|
119
|
+
/* -------------------------------------------------------------------- */
|
120
|
+
|
121
|
+
static VALUE
|
122
|
+
rb_cary_na_ref_new_i (int argc, VALUE *argv, VALUE self, VALUE klass)
|
123
|
+
{
|
124
|
+
CArray *orig;
|
125
|
+
struct NARRAY *ary;
|
126
|
+
int i;
|
127
|
+
|
128
|
+
Data_Get_Struct(self, CArray, orig);
|
129
|
+
|
130
|
+
if ( ! ca_is_attached(orig) ) {
|
131
|
+
rb_raise(rb_eRuntimeError,
|
132
|
+
"cannot create NArray reference for not attached CArray");
|
133
|
+
}
|
134
|
+
|
135
|
+
ary = ALLOC(struct NARRAY);
|
136
|
+
if ( !ary ) {
|
137
|
+
rb_raise(rb_eRuntimeError, "cannot allocate NArray");
|
138
|
+
}
|
139
|
+
|
140
|
+
if ( orig->elements == 0 ) {
|
141
|
+
ary->rank = 0;
|
142
|
+
ary->shape = NULL;
|
143
|
+
ary->total = 0;
|
144
|
+
ary->ptr = NULL;
|
145
|
+
}
|
146
|
+
else if ( argc == 0 ) {
|
147
|
+
ary->rank = orig->rank;
|
148
|
+
ary->shape = ALLOC_N(int, ary->rank);
|
149
|
+
for (i=0; i<ary->rank; i++) {
|
150
|
+
ary->shape[i] = orig->dim[ary->rank-1-i];
|
151
|
+
}
|
152
|
+
ary->total = orig->elements;
|
153
|
+
ary->ptr = orig->ptr;
|
154
|
+
}
|
155
|
+
else {
|
156
|
+
int32_t elements = 1;
|
157
|
+
ary->rank = argc;
|
158
|
+
ary->shape = ALLOC_N(int, ary->rank);
|
159
|
+
for (i=0; i<ary->rank; i++) {
|
160
|
+
ary->shape[i] = NUM2INT(argv[i]);
|
161
|
+
elements *= ary->shape[i];
|
162
|
+
}
|
163
|
+
ary->total = elements;
|
164
|
+
ary->ptr = orig->ptr;
|
165
|
+
if ( elements != orig->elements ) {
|
166
|
+
free(ary->shape);
|
167
|
+
rb_raise(rb_eRuntimeError, "elements mismatch");
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
ary->type = ca_data_type_to_na_typecode(orig->data_type);
|
172
|
+
ary->ref = self;
|
173
|
+
|
174
|
+
return Data_Wrap_Struct(klass, cary_na_ref_mark, cary_na_ref_free, ary);
|
175
|
+
}
|
176
|
+
|
177
|
+
/* rdoc:
|
178
|
+
class CArray
|
179
|
+
def na
|
180
|
+
end
|
181
|
+
def nv
|
182
|
+
end
|
183
|
+
def nm
|
184
|
+
end
|
185
|
+
end
|
186
|
+
*/
|
187
|
+
|
188
|
+
static VALUE
|
189
|
+
rb_cary_na_ref_new (int argc, VALUE *argv, VALUE self)
|
190
|
+
{
|
191
|
+
return rb_cary_na_ref_new_i(argc, argv, self, cNArray);
|
192
|
+
}
|
193
|
+
|
194
|
+
static VALUE
|
195
|
+
rb_cary_nv_ref_new (int argc, VALUE *argv, VALUE self)
|
196
|
+
{
|
197
|
+
return rb_cary_na_ref_new_i(argc, argv, self, cNVector);
|
198
|
+
}
|
199
|
+
|
200
|
+
static VALUE
|
201
|
+
rb_cary_nm_ref_new (int argc, VALUE *argv, VALUE self)
|
202
|
+
{
|
203
|
+
return rb_cary_na_ref_new_i(argc, argv, self, cNMatrix);
|
204
|
+
}
|
205
|
+
|
206
|
+
/* -------------------------------------------------------------------- */
|
207
|
+
|
208
|
+
static VALUE
|
209
|
+
rb_cary_to_na_bang_i (VALUE self, VALUE klass)
|
210
|
+
{
|
211
|
+
volatile VALUE obj, fary;
|
212
|
+
CArray *ca;
|
213
|
+
struct NARRAY *na;
|
214
|
+
int type;
|
215
|
+
|
216
|
+
Data_Get_Struct(self, CArray, ca);
|
217
|
+
|
218
|
+
type = ca_data_type_to_na_typecode(ca->data_type);
|
219
|
+
|
220
|
+
if ( ca->elements == 0 ) {
|
221
|
+
obj = na_make_empty(type, klass);
|
222
|
+
}
|
223
|
+
else {
|
224
|
+
obj = na_make_object(type, ca->rank, (int *) ca->dim, klass);
|
225
|
+
GetNArray(obj, na);
|
226
|
+
|
227
|
+
fary = rb_ca_farray(self);
|
228
|
+
Data_Get_Struct(fary, CArray, ca);
|
229
|
+
|
230
|
+
ca_copy_data(ca, na->ptr);
|
231
|
+
}
|
232
|
+
|
233
|
+
return obj;
|
234
|
+
}
|
235
|
+
|
236
|
+
/* rdoc:
|
237
|
+
class CArray
|
238
|
+
def to_na!
|
239
|
+
end
|
240
|
+
def to_nv!
|
241
|
+
end
|
242
|
+
def to_nm!
|
243
|
+
end
|
244
|
+
end
|
245
|
+
*/
|
246
|
+
|
247
|
+
static VALUE
|
248
|
+
rb_cary_to_na_bang (VALUE self)
|
249
|
+
{
|
250
|
+
return rb_cary_to_na_bang_i(self, cNArray);
|
251
|
+
}
|
252
|
+
|
253
|
+
static VALUE
|
254
|
+
rb_cary_to_nv_bang (VALUE self)
|
255
|
+
{
|
256
|
+
return rb_cary_to_na_bang_i(self, cNVector);
|
257
|
+
}
|
258
|
+
|
259
|
+
static VALUE
|
260
|
+
rb_cary_to_nm_bang (VALUE self)
|
261
|
+
{
|
262
|
+
return rb_cary_to_na_bang_i(self, cNMatrix);
|
263
|
+
}
|
264
|
+
|
265
|
+
/* -------------------------------------------------------------------- */
|
266
|
+
|
267
|
+
static VALUE
|
268
|
+
rb_cary_to_na_i (VALUE self, VALUE klass)
|
269
|
+
{
|
270
|
+
volatile VALUE obj;
|
271
|
+
CArray *ca;
|
272
|
+
struct NARRAY *na;
|
273
|
+
int type;
|
274
|
+
int i;
|
275
|
+
|
276
|
+
Data_Get_Struct(self, CArray, ca);
|
277
|
+
|
278
|
+
type = ca_data_type_to_na_typecode(ca->data_type);
|
279
|
+
|
280
|
+
if ( ca->elements == 0 ) {
|
281
|
+
obj = na_make_empty(type, klass);
|
282
|
+
}
|
283
|
+
else {
|
284
|
+
obj = na_make_object(type, ca->rank, (int *) ca->dim, klass);
|
285
|
+
GetNArray(obj, na);
|
286
|
+
|
287
|
+
for (i=0; i<ca->rank; i++) {
|
288
|
+
na->shape[i] = ca->dim[ca->rank-i-1];
|
289
|
+
}
|
290
|
+
|
291
|
+
ca_copy_data(ca, na->ptr);
|
292
|
+
}
|
293
|
+
|
294
|
+
return obj;
|
295
|
+
}
|
296
|
+
|
297
|
+
/* rdoc:
|
298
|
+
class CArray
|
299
|
+
def to_na
|
300
|
+
end
|
301
|
+
def to_nv
|
302
|
+
end
|
303
|
+
def to_nm
|
304
|
+
end
|
305
|
+
end
|
306
|
+
*/
|
307
|
+
|
308
|
+
static VALUE
|
309
|
+
rb_cary_to_na (VALUE self, VALUE klass)
|
310
|
+
{
|
311
|
+
return rb_cary_to_na_i(self, cNArray);
|
312
|
+
}
|
313
|
+
|
314
|
+
static VALUE
|
315
|
+
rb_cary_to_nv (VALUE self, VALUE klass)
|
316
|
+
{
|
317
|
+
return rb_cary_to_na_i(self, cNVector);
|
318
|
+
}
|
319
|
+
|
320
|
+
static VALUE
|
321
|
+
rb_cary_to_nm (VALUE self, VALUE klass)
|
322
|
+
{
|
323
|
+
return rb_cary_to_na_i(self, cNMatrix);
|
324
|
+
}
|
325
|
+
|
326
|
+
/* -------------------------------------------------------------------- */
|
327
|
+
|
328
|
+
/* rdoc:
|
329
|
+
class NArray
|
330
|
+
def ca
|
331
|
+
end
|
332
|
+
end
|
333
|
+
*/
|
334
|
+
|
335
|
+
static VALUE
|
336
|
+
rb_na_ca_ref_new (int argc, VALUE *argv, VALUE self)
|
337
|
+
{
|
338
|
+
volatile VALUE obj;
|
339
|
+
struct NARRAY *na;
|
340
|
+
int32_t dim[CA_RANK_MAX];
|
341
|
+
int8_t data_type;
|
342
|
+
int i;
|
343
|
+
|
344
|
+
GetNArray(self, na);
|
345
|
+
|
346
|
+
data_type = na_typecode_to_ca_data_type(na->type);
|
347
|
+
|
348
|
+
if ( na->total == 0 ) {
|
349
|
+
int32_t zero = 0;
|
350
|
+
obj = rb_carray_wrap_ptr(data_type, 1, &zero, 0, NULL,
|
351
|
+
&EMPTY_ARRAY_PTR, self); /* avoid ca->ptr == NULL */
|
352
|
+
}
|
353
|
+
else {
|
354
|
+
if ( argc == 0 ) {
|
355
|
+
CA_CHECK_RANK(na->rank);
|
356
|
+
for (i=0; i<na->rank; i++) {
|
357
|
+
dim[i] = na->shape[na->rank-i-1];
|
358
|
+
}
|
359
|
+
obj = rb_carray_wrap_ptr(data_type,
|
360
|
+
na->rank, dim, 0, NULL, na->ptr, self);
|
361
|
+
}
|
362
|
+
else {
|
363
|
+
CA_CHECK_RANK(argc);
|
364
|
+
for (i=0; i<argc; i++) {
|
365
|
+
dim[i] = NUM2INT(argv[i]);
|
366
|
+
}
|
367
|
+
obj = rb_carray_wrap_ptr(data_type, argc, dim, 0, NULL, na->ptr, self);
|
368
|
+
}
|
369
|
+
}
|
370
|
+
|
371
|
+
return obj;
|
372
|
+
}
|
373
|
+
|
374
|
+
/* -------------------------------------------------------------------- */
|
375
|
+
|
376
|
+
/* rdoc:
|
377
|
+
class NArray
|
378
|
+
def to_ca
|
379
|
+
end
|
380
|
+
end
|
381
|
+
*/
|
382
|
+
|
383
|
+
|
384
|
+
static VALUE
|
385
|
+
rb_na_to_ca (VALUE self)
|
386
|
+
{
|
387
|
+
volatile VALUE obj;
|
388
|
+
CArray *ca;
|
389
|
+
struct NARRAY *na;
|
390
|
+
int32_t dim[CA_RANK_MAX];
|
391
|
+
int32_t data_type;
|
392
|
+
int32_t i;
|
393
|
+
|
394
|
+
GetNArray(self, na);
|
395
|
+
|
396
|
+
data_type = na_typecode_to_ca_data_type(na->type);
|
397
|
+
|
398
|
+
if ( na->total == 0 ) {
|
399
|
+
int32_t zero = 0;
|
400
|
+
obj = rb_carray_new(data_type, 1, &zero, 0, NULL);
|
401
|
+
}
|
402
|
+
else {
|
403
|
+
CA_CHECK_RANK(na->rank);
|
404
|
+
|
405
|
+
for (i=0; i<na->rank; i++) {
|
406
|
+
dim[i] = na->shape[na->rank-i-1];
|
407
|
+
}
|
408
|
+
|
409
|
+
obj = rb_carray_new(data_type, na->rank, dim, 0, NULL);
|
410
|
+
Data_Get_Struct(obj, CArray, ca);
|
411
|
+
|
412
|
+
ca_sync_data(ca, na->ptr);
|
413
|
+
}
|
414
|
+
|
415
|
+
return obj;
|
416
|
+
}
|
417
|
+
|
418
|
+
/* -------------------------------------------------------------------- */
|
419
|
+
|
420
|
+
/* rdoc:
|
421
|
+
class NArray
|
422
|
+
def to_ca!
|
423
|
+
end
|
424
|
+
end
|
425
|
+
*/
|
426
|
+
|
427
|
+
static VALUE
|
428
|
+
rb_na_to_ca_bang (VALUE self)
|
429
|
+
{
|
430
|
+
volatile VALUE obj, fary;
|
431
|
+
CArray *ca;
|
432
|
+
struct NARRAY *na;
|
433
|
+
int32_t dim[CA_RANK_MAX];
|
434
|
+
int32_t data_type;
|
435
|
+
int32_t i;
|
436
|
+
|
437
|
+
GetNArray(self, na);
|
438
|
+
|
439
|
+
data_type = na_typecode_to_ca_data_type(na->type);
|
440
|
+
|
441
|
+
if ( na->total == 0 ) {
|
442
|
+
int32_t zero = 0;
|
443
|
+
obj = rb_carray_new(data_type, 1, &zero, 0, NULL);
|
444
|
+
}
|
445
|
+
else {
|
446
|
+
CA_CHECK_RANK(na->rank);
|
447
|
+
|
448
|
+
for (i=0; i<na->rank; i++) {
|
449
|
+
dim[i] = na->shape[na->rank-i-1];
|
450
|
+
}
|
451
|
+
|
452
|
+
obj = rb_carray_new(data_type, na->rank, na->shape, 0, NULL);
|
453
|
+
fary = rb_ca_farray(obj);
|
454
|
+
Data_Get_Struct(fary, CArray, ca);
|
455
|
+
|
456
|
+
ca_sync_data(ca, na->ptr);
|
457
|
+
}
|
458
|
+
|
459
|
+
return obj;
|
460
|
+
}
|
461
|
+
|
462
|
+
/* -------------------------------------------------------------------- */
|
463
|
+
|
464
|
+
void
|
465
|
+
Init_ca_wrap_narray ()
|
466
|
+
{
|
467
|
+
/* rb_require("narray"); */ /* "narray" should be loaded in config.rb */
|
468
|
+
|
469
|
+
rb_define_const(rb_cCArray, "HAVE_NARRAY", Qtrue);
|
470
|
+
|
471
|
+
/* CArray -> NArray */
|
472
|
+
rb_define_method(rb_cCArray, "na", rb_cary_na_ref_new, -1);
|
473
|
+
rb_define_method(rb_cCArray, "to_na", rb_cary_to_na, 0);
|
474
|
+
rb_define_method(rb_cCArray, "to_na!", rb_cary_to_na_bang, 0);
|
475
|
+
|
476
|
+
/* CArray -> NVector */
|
477
|
+
rb_define_method(rb_cCArray, "nv", rb_cary_nv_ref_new, -1);
|
478
|
+
rb_define_method(rb_cCArray, "to_nv", rb_cary_to_nv, 0);
|
479
|
+
rb_define_method(rb_cCArray, "to_nv!", rb_cary_to_nv_bang, 0);
|
480
|
+
|
481
|
+
/* CArray -> NMatrix */
|
482
|
+
rb_define_method(rb_cCArray, "nm", rb_cary_nm_ref_new, -1);
|
483
|
+
rb_define_method(rb_cCArray, "to_nm", rb_cary_to_nm, 0);
|
484
|
+
rb_define_method(rb_cCArray, "to_nm!", rb_cary_to_nm_bang, 0);
|
485
|
+
|
486
|
+
/* NArray -> CArray */
|
487
|
+
rb_define_method(cNArray, "ca", rb_na_ca_ref_new, -1);
|
488
|
+
rb_define_method(cNArray, "to_ca", rb_na_to_ca, 0);
|
489
|
+
rb_define_method(cNArray, "to_ca!", rb_na_to_ca_bang, 0);
|
490
|
+
}
|
491
|
+
|