carray 1.3.5 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSES +22 -0
- data/README.md +18 -21
- data/Rakefile +31 -0
- data/carray.gemspec +13 -26
- data/{ca_iter_block.c → ext/ca_iter_block.c} +13 -13
- data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +16 -16
- data/{ca_iter_window.c → ext/ca_iter_window.c} +10 -10
- data/{ca_obj_array.c → ext/ca_obj_array.c} +60 -55
- data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +12 -12
- data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +7 -7
- data/{ca_obj_block.c → ext/ca_obj_block.c} +42 -42
- data/{ca_obj_fake.c → ext/ca_obj_fake.c} +7 -7
- data/{ca_obj_farray.c → ext/ca_obj_farray.c} +18 -18
- data/{ca_obj_field.c → ext/ca_obj_field.c} +15 -15
- data/{ca_obj_grid.c → ext/ca_obj_grid.c} +27 -27
- data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +9 -9
- data/{ca_obj_object.c → ext/ca_obj_object.c} +37 -37
- data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +1 -1
- data/{ca_obj_refer.c → ext/ca_obj_refer.c} +33 -33
- data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +43 -43
- data/{ca_obj_select.c → ext/ca_obj_select.c} +2 -2
- data/{ca_obj_shift.c → ext/ca_obj_shift.c} +23 -23
- data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +23 -23
- data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +55 -55
- data/{ca_obj_window.c → ext/ca_obj_window.c} +26 -26
- data/{carray.h → ext/carray.h} +77 -51
- data/{carray_access.c → ext/carray_access.c} +133 -91
- data/{carray_attribute.c → ext/carray_attribute.c} +12 -12
- data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +0 -0
- data/{carray_cast.c → ext/carray_cast.c} +6 -6
- data/{carray_cast_func.rb → ext/carray_cast_func.rb} +0 -0
- data/{carray_class.c → ext/carray_class.c} +0 -0
- data/{carray_conversion.c → ext/carray_conversion.c} +11 -13
- data/{carray_copy.c → ext/carray_copy.c} +19 -19
- data/{carray_core.c → ext/carray_core.c} +2 -2
- data/ext/carray_data_type.c +66 -0
- data/{carray_element.c → ext/carray_element.c} +9 -9
- data/{carray_generate.c → ext/carray_generate.c} +67 -1
- data/{carray_iterator.c → ext/carray_iterator.c} +40 -38
- data/{carray_loop.c → ext/carray_loop.c} +24 -24
- data/{carray_mask.c → ext/carray_mask.c} +17 -6
- data/{carray_math.rb → ext/carray_math.rb} +25 -25
- data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +0 -0
- data/{carray_numeric.c → ext/carray_numeric.c} +1 -1
- data/{carray_operator.c → ext/carray_operator.c} +32 -9
- data/{carray_order.c → ext/carray_order.c} +2 -153
- data/{carray_sort_addr.c → ext/carray_sort_addr.c} +0 -0
- data/{carray_stat.c → ext/carray_stat.c} +5 -5
- data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +23 -23
- data/{carray_test.c → ext/carray_test.c} +22 -21
- data/{carray_undef.c → ext/carray_undef.c} +0 -0
- data/{carray_utils.c → ext/carray_utils.c} +0 -0
- data/{extconf.rb → ext/extconf.rb} +0 -5
- data/{mkmath.rb → ext/mkmath.rb} +12 -2
- data/{ruby_carray.c → ext/ruby_carray.c} +9 -2
- data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +0 -0
- data/{ruby_float_func.c → ext/ruby_float_func.c} +0 -0
- data/{version.h → ext/version.h} +5 -5
- data/{version.rb → ext/version.rb} +0 -0
- data/lib/carray.rb +49 -7
- data/lib/carray/{base/autoload.rb → autoload.rb} +48 -6
- 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 +193 -0
- data/lib/carray/compose.rb +291 -0
- data/lib/carray/construct.rb +445 -0
- data/lib/carray/convert.rb +115 -0
- data/lib/carray/{base/inspect.rb → inspect.rb} +6 -6
- data/lib/carray/io/imagemagick.rb +1 -1
- data/lib/carray/{base/iterator.rb → iterator.rb} +3 -3
- data/lib/carray/mask.rb +91 -0
- data/lib/carray/{base/math.rb → math.rb} +17 -47
- data/lib/carray/math/histogram.rb +7 -7
- data/lib/carray/mkmf.rb +8 -0
- data/lib/carray/object/ca_obj_pack.rb +8 -8
- data/lib/carray/obsolete.rb +272 -0
- data/lib/carray/ordering.rb +157 -0
- data/lib/carray/{base/serialize.rb → serialize.rb} +28 -53
- data/lib/carray/string.rb +190 -0
- data/lib/carray/{base/struct.rb → struct.rb} +20 -20
- data/lib/carray/{io/table.rb → table.rb} +1 -9
- data/lib/carray/testing.rb +56 -0
- data/lib/carray/time.rb +78 -0
- data/lib/carray/transform.rb +100 -0
- data/misc/Methods.ja.md +182 -0
- data/{NOTE → misc/NOTE} +0 -0
- data/test/test_ALL.rb +0 -2
- data/test/test_order.rb +7 -7
- data/test/test_ref_store.rb +13 -13
- data/test/test_stat.rb +7 -15
- data/{devel → utils}/guess_shape.rb +0 -0
- data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
- metadata +100 -254
- data/COPYING +0 -56
- data/GPL +0 -340
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -33
- data/LEGAL +0 -50
- data/TODO +0 -5
- data/carray_random.c +0 -531
- 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/mt19937ar.c +0 -182
- data/mt19937ar.h +0 -86
- data/rdoc_main.rb +0 -27
- data/rdoc_math.rb +0 -5
- data/rdoc_stat.rb +0 -31
- data/test/test_narray.rb +0 -64
- data/test/test_random.rb +0 -15
- data/utils/create_rdoc.sh +0 -9
- data/utils/make_tgz.sh +0 -3
data/ext/imagemap/test/test.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'carray'
|
2
|
-
|
3
|
-
#sc = ImageMap::ColorScale.pm3d(13,10,14,256,:interpolation => false)
|
4
|
-
#sc = ImageMap::ColorScale.GMT("GMT_globe.cpt")
|
5
|
-
#sc.set_range(0..Math::PI)
|
6
|
-
#sc.set_upper_color(127,127,127)
|
7
|
-
#sc.set_lower_color(127,127,127)
|
8
|
-
#sc.set_mask_color( 127,127,127)
|
9
|
-
|
10
|
-
ca = CArray.float(640, 480)
|
11
|
-
ca[:i,nil].scale!(-0.1, Math::PI+0.1)
|
12
|
-
ca.mask = 0
|
13
|
-
ca.mask[90..110,90..110] = 1
|
14
|
-
|
15
|
-
if true
|
16
|
-
im = ImageMap.create(ca, sc)
|
17
|
-
require 'carray/RMagick'
|
18
|
-
il = Magick::Image.new_from_ca(im)
|
19
|
-
il.display
|
20
|
-
else
|
21
|
-
im = ImageMap.display(ca, sc)
|
22
|
-
end
|
23
|
-
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'carray'
|
2
|
-
require 'carray/image_map'
|
3
|
-
require 'benchmark'
|
4
|
-
|
5
|
-
lon = CArray.float(37).span!(-90..180)
|
6
|
-
lat = CArray.float(12).span!(0..90)
|
7
|
-
|
8
|
-
u = lon[:%,lat.dim0]
|
9
|
-
v = lat[lon.dim0,:%]
|
10
|
-
val = u.rad.sin! + v.rad
|
11
|
-
|
12
|
-
image = ImageMap.new(CA_DOUBLE, [600, 600]) { -9999 }
|
13
|
-
|
14
|
-
image.set_xrange(-103..103)
|
15
|
-
image.set_yrange(-103..103)
|
16
|
-
|
17
|
-
Benchmark.bm do |o|
|
18
|
-
o.report {
|
19
|
-
image.warp(val, u, v, :grid=>"point", :gradation => true) {
|
20
|
-
|_u,_v,_x,_y|
|
21
|
-
_x[] = (100 - _v/3) * _u.rad.cos!
|
22
|
-
_y[] = (100 - _v/3) * _u.rad.sin!
|
23
|
-
}
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
#image.draw_line(0, 0, 0, 90, 0)
|
28
|
-
image.line(0, 0, 0, 90, 0)
|
29
|
-
|
30
|
-
poly = CArray.float(4,2) {[[-90,90],[0,0],[45,45],[0,90]]}
|
31
|
-
|
32
|
-
image.polyline(poly[nil,1],poly[nil,0], 0)
|
33
|
-
|
34
|
-
image[:lt, -9998] = UNDEF
|
35
|
-
|
36
|
-
#sc = nil
|
37
|
-
#sc = ImageMap::ColorScale.pm3d(11,7,22,12)
|
38
|
-
sc = ColorScale.GMT("GMT_polar.cpt")
|
39
|
-
#sc.set_mask_color(64,64,64)
|
40
|
-
sc.set_range(nil, nil)
|
41
|
-
|
42
|
-
ImageMap.display(image, sc)
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'carray'
|
2
|
-
require 'carray/image_map'
|
3
|
-
|
4
|
-
p img = ImageMap.new(CA_INT8, [200,200]) {0}
|
5
|
-
p img.class
|
6
|
-
|
7
|
-
gx = CArray.float(2,2) { [[10,30],
|
8
|
-
[10,30]] }
|
9
|
-
gy = CArray.float(2,2) { [[10,10],
|
10
|
-
[80,50]] }
|
11
|
-
|
12
|
-
img.fill_rectangle(gy, gx, 255)
|
13
|
-
|
14
|
-
img.display_by_magick
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require "carray"
|
2
|
-
|
3
|
-
img = ImageMap.new(:int16, [300, 300]) {0}
|
4
|
-
img.set_xrange 0...300
|
5
|
-
img.set_yrange 0...300
|
6
|
-
|
7
|
-
data = CArray.int16(16,16).seq!
|
8
|
-
|
9
|
-
x = CArray.float(16).seq![16,:%]
|
10
|
-
y = CArray.float(16).seq!.reverse![:%,16]
|
11
|
-
|
12
|
-
img.warp(data, x, y, :grid=>"area0", :gradation=>false) {|gx,gy,ix,iy|
|
13
|
-
ix[] = 8*(gy+gx) + 24
|
14
|
-
iy[] = 8*(gy-gx) + 150
|
15
|
-
}
|
16
|
-
|
17
|
-
img.as_uint8.display_by_magick
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'carray'
|
2
|
-
|
3
|
-
image = CArray.float(200, 200) { nan }
|
4
|
-
|
5
|
-
y = CArray.float(2,2){[50,50, 65,100]}
|
6
|
-
x = CArray.float(2,2){[70,100,50,90]}
|
7
|
-
z = CArray.float(2,2){[30,40, 50,20]}
|
8
|
-
ImageMap::Image.draw_rectangle_gradation(image, y, x, z)
|
9
|
-
|
10
|
-
#image.draw_line(y[0], x[0], y[1], x[1])
|
11
|
-
#image.draw_line(y[1], x[1], y[2], x[2])
|
12
|
-
#image.draw_line(y[2], x[2], y[0], x[0])
|
13
|
-
#image.draw_line(y[2], x[2], y[0], x[0])
|
14
|
-
|
15
|
-
image.mask = image.is_nan
|
16
|
-
|
17
|
-
sc = ImageMap::ColorScale.pm3d(13,6,10)
|
18
|
-
|
19
|
-
ImageMap.display(image, sc)
|
20
|
-
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'carray'
|
2
|
-
|
3
|
-
lon = CArray.float(121).span!(-180..180)
|
4
|
-
lat = CArray.float(12).span!(0..90)
|
5
|
-
p val = CArray.uint16(121,12).seq!.quantize(256)
|
6
|
-
|
7
|
-
img = ImageMap.uint16(600,600) { 9999 }
|
8
|
-
|
9
|
-
img.warp(val, lon[:%,lat.dim0], lat[lon.dim0,:%],
|
10
|
-
:grid=>"area0", :gradation=>false) { |u,v,x,y|
|
11
|
-
x[] = (100 - v/2) * u.rad.cos!
|
12
|
-
y[] = (100 - v/2) * u.rad.sin!
|
13
|
-
x.mul!(2).add!(300)
|
14
|
-
y.mul!(2).add!(300)
|
15
|
-
}
|
16
|
-
|
17
|
-
img[:eq,9999] = UNDEF
|
18
|
-
|
19
|
-
RGB = CA.struct{ uint8 :r,:g,:b }
|
20
|
-
rgb = CArray.new(RGB, [255,3])
|
21
|
-
rgb["r"].seq!
|
22
|
-
|
23
|
-
out = rgb.project(img)
|
24
|
-
|
25
|
-
out.display_by_magick("rgb")
|
26
|
-
|
data/ext/mathfunc/extconf.rb
DELETED
@@ -1,18 +0,0 @@
|
|
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")
|
@@ -1 +0,0 @@
|
|
1
|
-
require "carray/math/mathfunc"
|
@@ -1,15 +0,0 @@
|
|
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
|
-
|
@@ -1,22 +0,0 @@
|
|
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
DELETED
@@ -1,22 +0,0 @@
|
|
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.)
|
data/ext/narray/ca_wrap_narray.c
DELETED
@@ -1,500 +0,0 @@
|
|
1
|
-
/* ---------------------------------------------------------------------------
|
2
|
-
|
3
|
-
carray/ca_wrap_narray.c
|
4
|
-
|
5
|
-
This file is part of Ruby/CArray extension library.
|
6
|
-
You can redistribute it and/or modify it under the terms of
|
7
|
-
the Ruby Licence.
|
8
|
-
|
9
|
-
Copyright (C) 2005 Hiroki Motoyoshi
|
10
|
-
|
11
|
-
---------------------------------------------------------------------------- */
|
12
|
-
|
13
|
-
#include "ruby.h"
|
14
|
-
#include "carray.h"
|
15
|
-
|
16
|
-
#include "narray_config.h"
|
17
|
-
#ifndef HAVE_U_INT8_T
|
18
|
-
#define HAVE_U_INT8_T
|
19
|
-
#endif
|
20
|
-
#ifndef HAVE_INT16_T
|
21
|
-
#define HAVE_INT16_T
|
22
|
-
#endif
|
23
|
-
#ifndef HAVE_INT16_T
|
24
|
-
#define HAVE_INT32_T
|
25
|
-
#endif
|
26
|
-
#ifndef HAVE_U_INT32_T
|
27
|
-
#define HAVE_U_INT32_T
|
28
|
-
#endif
|
29
|
-
#include "narray.h"
|
30
|
-
|
31
|
-
#include <math.h>
|
32
|
-
|
33
|
-
extern VALUE cNMatrix, cNVector, cNMatrixLU;
|
34
|
-
|
35
|
-
static char EMPTY_ARRAY_PTR;
|
36
|
-
|
37
|
-
/* -------------------------------------------------------------------- */
|
38
|
-
|
39
|
-
static int8_t
|
40
|
-
na_typecode_to_ca_data_type (int typecode)
|
41
|
-
{
|
42
|
-
int8_t data_type;
|
43
|
-
|
44
|
-
switch ( typecode ) {
|
45
|
-
case NA_BYTE:
|
46
|
-
data_type = CA_UINT8; break;
|
47
|
-
case NA_SINT:
|
48
|
-
data_type = CA_INT16; break;
|
49
|
-
case NA_LINT:
|
50
|
-
data_type = CA_INT32; break;
|
51
|
-
case NA_SFLOAT:
|
52
|
-
data_type = CA_FLOAT32; break;
|
53
|
-
case NA_DFLOAT:
|
54
|
-
data_type = CA_FLOAT64; break;
|
55
|
-
#ifdef HAVE_COMPLEX_H
|
56
|
-
case NA_SCOMPLEX:
|
57
|
-
data_type = CA_CMPLX64; break;
|
58
|
-
case NA_DCOMPLEX:
|
59
|
-
data_type = CA_CMPLX128; break;
|
60
|
-
#endif
|
61
|
-
case NA_ROBJ:
|
62
|
-
data_type = CA_OBJECT; break;
|
63
|
-
default:
|
64
|
-
rb_raise(rb_eCADataTypeError,
|
65
|
-
"unknown NArray typecode <%i>", typecode);
|
66
|
-
}
|
67
|
-
return data_type;
|
68
|
-
}
|
69
|
-
|
70
|
-
static int
|
71
|
-
ca_data_type_to_na_typecode(int8_t data_type)
|
72
|
-
{
|
73
|
-
int typecode;
|
74
|
-
|
75
|
-
switch ( data_type ) {
|
76
|
-
case CA_BOOLEAN:
|
77
|
-
case CA_UINT8:
|
78
|
-
typecode = NA_BYTE; break;
|
79
|
-
case CA_INT16:
|
80
|
-
typecode = NA_SINT; break;
|
81
|
-
case CA_INT32:
|
82
|
-
typecode = NA_LINT; break;
|
83
|
-
case CA_FLOAT32:
|
84
|
-
typecode = NA_SFLOAT; break;
|
85
|
-
case CA_FLOAT64:
|
86
|
-
typecode = NA_DFLOAT; break;
|
87
|
-
#ifdef HAVE_COMPLEX_H
|
88
|
-
case CA_CMPLX64:
|
89
|
-
typecode = NA_SCOMPLEX; break;
|
90
|
-
case CA_CMPLX128:
|
91
|
-
typecode = NA_DCOMPLEX; break;
|
92
|
-
#endif
|
93
|
-
case CA_OBJECT:
|
94
|
-
typecode = NA_ROBJ; break;
|
95
|
-
default:
|
96
|
-
rb_raise(rb_eRuntimeError,
|
97
|
-
"no corresponding NArray typecode for CArray data type <%s>",
|
98
|
-
ca_type_name[data_type]);
|
99
|
-
}
|
100
|
-
|
101
|
-
return typecode;
|
102
|
-
}
|
103
|
-
|
104
|
-
/* -------------------------------------------------------------------- */
|
105
|
-
|
106
|
-
static void
|
107
|
-
cary_na_ref_free (struct NARRAY *ary)
|
108
|
-
{
|
109
|
-
xfree(ary->shape);
|
110
|
-
xfree(ary);
|
111
|
-
}
|
112
|
-
|
113
|
-
static void
|
114
|
-
cary_na_ref_mark (struct NARRAY *ary)
|
115
|
-
{
|
116
|
-
rb_gc_mark( ary->ref );
|
117
|
-
}
|
118
|
-
|
119
|
-
/* -------------------------------------------------------------------- */
|
120
|
-
|
121
|
-
static VALUE
|
122
|
-
rb_cary_na_ref_new_i (int argc, VALUE *argv, VALUE self, VALUE klass)
|
123
|
-
{
|
124
|
-
CArray *orig;
|
125
|
-
struct NARRAY *ary;
|
126
|
-
int8_t i;
|
127
|
-
|
128
|
-
Data_Get_Struct(self, CArray, orig);
|
129
|
-
|
130
|
-
if ( ! ca_is_attached(orig) ) {
|
131
|
-
rb_raise(rb_eRuntimeError,
|
132
|
-
"cannot create NArray reference for not attached CArray");
|
133
|
-
}
|
134
|
-
|
135
|
-
ary = ALLOC(struct NARRAY);
|
136
|
-
if ( !ary ) {
|
137
|
-
rb_raise(rb_eRuntimeError, "cannot allocate NArray");
|
138
|
-
}
|
139
|
-
|
140
|
-
if ( orig->elements == 0 ) {
|
141
|
-
ary->rank = 0;
|
142
|
-
ary->shape = NULL;
|
143
|
-
ary->total = 0;
|
144
|
-
ary->ptr = NULL;
|
145
|
-
}
|
146
|
-
else if ( argc == 0 ) {
|
147
|
-
ary->rank = orig->rank;
|
148
|
-
ary->shape = ALLOC_N(int, ary->rank);
|
149
|
-
for (i=0; i<ary->rank; i++) {
|
150
|
-
ary->shape[i] = (int) orig->dim[ary->rank-1-i];
|
151
|
-
}
|
152
|
-
ary->total = (int) orig->elements;
|
153
|
-
ary->ptr = orig->ptr;
|
154
|
-
}
|
155
|
-
else {
|
156
|
-
ca_size_t elements = 1;
|
157
|
-
ary->rank = argc;
|
158
|
-
ary->shape = ALLOC_N(int, ary->rank);
|
159
|
-
for (i=0; i<ary->rank; i++) {
|
160
|
-
ary->shape[i] = NUM2INT(argv[i]);
|
161
|
-
elements *= ary->shape[i];
|
162
|
-
}
|
163
|
-
ary->total = (int) elements;
|
164
|
-
ary->ptr = orig->ptr;
|
165
|
-
if ( elements != orig->elements ) {
|
166
|
-
free(ary->shape);
|
167
|
-
rb_raise(rb_eRuntimeError, "elements mismatch");
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
ary->type = ca_data_type_to_na_typecode(orig->data_type);
|
172
|
-
ary->ref = self;
|
173
|
-
|
174
|
-
return Data_Wrap_Struct(klass, cary_na_ref_mark, cary_na_ref_free, ary);
|
175
|
-
}
|
176
|
-
|
177
|
-
/* rdoc:
|
178
|
-
class CArray
|
179
|
-
def na
|
180
|
-
end
|
181
|
-
def nv
|
182
|
-
end
|
183
|
-
def nm
|
184
|
-
end
|
185
|
-
end
|
186
|
-
*/
|
187
|
-
|
188
|
-
static VALUE
|
189
|
-
rb_cary_na_ref_new (int argc, VALUE *argv, VALUE self)
|
190
|
-
{
|
191
|
-
return rb_cary_na_ref_new_i(argc, argv, self, cNArray);
|
192
|
-
}
|
193
|
-
|
194
|
-
static VALUE
|
195
|
-
rb_cary_nv_ref_new (int argc, VALUE *argv, VALUE self)
|
196
|
-
{
|
197
|
-
return rb_cary_na_ref_new_i(argc, argv, self, cNVector);
|
198
|
-
}
|
199
|
-
|
200
|
-
static VALUE
|
201
|
-
rb_cary_nm_ref_new (int argc, VALUE *argv, VALUE self)
|
202
|
-
{
|
203
|
-
return rb_cary_na_ref_new_i(argc, argv, self, cNMatrix);
|
204
|
-
}
|
205
|
-
|
206
|
-
/* -------------------------------------------------------------------- */
|
207
|
-
|
208
|
-
static VALUE
|
209
|
-
rb_cary_to_na_bang_i (VALUE self, VALUE klass)
|
210
|
-
{
|
211
|
-
volatile VALUE obj, fary;
|
212
|
-
CArray *ca;
|
213
|
-
struct NARRAY *na;
|
214
|
-
int type;
|
215
|
-
|
216
|
-
Data_Get_Struct(self, CArray, ca);
|
217
|
-
|
218
|
-
type = ca_data_type_to_na_typecode(ca->data_type);
|
219
|
-
|
220
|
-
if ( ca->elements == 0 ) {
|
221
|
-
obj = na_make_empty(type, klass);
|
222
|
-
}
|
223
|
-
else {
|
224
|
-
int shape[127];
|
225
|
-
int i;
|
226
|
-
|
227
|
-
for (i=0; i<ca->rank; i++) {
|
228
|
-
shape[i] = (int) ca->dim[ca->rank-i-1];
|
229
|
-
}
|
230
|
-
|
231
|
-
obj = na_make_object(type, ca->rank, shape, klass);
|
232
|
-
GetNArray(obj, na);
|
233
|
-
|
234
|
-
fary = rb_ca_farray(self);
|
235
|
-
Data_Get_Struct(fary, CArray, ca);
|
236
|
-
|
237
|
-
ca_copy_data(ca, na->ptr);
|
238
|
-
}
|
239
|
-
|
240
|
-
return obj;
|
241
|
-
}
|
242
|
-
|
243
|
-
/* rdoc:
|
244
|
-
class CArray
|
245
|
-
def to_na!
|
246
|
-
end
|
247
|
-
def to_nv!
|
248
|
-
end
|
249
|
-
def to_nm!
|
250
|
-
end
|
251
|
-
end
|
252
|
-
*/
|
253
|
-
|
254
|
-
static VALUE
|
255
|
-
rb_cary_to_na_bang (VALUE self)
|
256
|
-
{
|
257
|
-
return rb_cary_to_na_bang_i(self, cNArray);
|
258
|
-
}
|
259
|
-
|
260
|
-
static VALUE
|
261
|
-
rb_cary_to_nv_bang (VALUE self)
|
262
|
-
{
|
263
|
-
return rb_cary_to_na_bang_i(self, cNVector);
|
264
|
-
}
|
265
|
-
|
266
|
-
static VALUE
|
267
|
-
rb_cary_to_nm_bang (VALUE self)
|
268
|
-
{
|
269
|
-
return rb_cary_to_na_bang_i(self, cNMatrix);
|
270
|
-
}
|
271
|
-
|
272
|
-
/* -------------------------------------------------------------------- */
|
273
|
-
|
274
|
-
static VALUE
|
275
|
-
rb_cary_to_na_i (VALUE self, VALUE klass)
|
276
|
-
{
|
277
|
-
volatile VALUE obj;
|
278
|
-
CArray *ca;
|
279
|
-
struct NARRAY *na;
|
280
|
-
int type;
|
281
|
-
int i;
|
282
|
-
|
283
|
-
Data_Get_Struct(self, CArray, ca);
|
284
|
-
|
285
|
-
type = ca_data_type_to_na_typecode(ca->data_type);
|
286
|
-
|
287
|
-
if ( ca->elements == 0 ) {
|
288
|
-
obj = na_make_empty(type, klass);
|
289
|
-
}
|
290
|
-
else {
|
291
|
-
int shape[127];
|
292
|
-
|
293
|
-
for (i=0; i<ca->rank; i++) {
|
294
|
-
shape[i] = (int) ca->dim[ca->rank-i-1];
|
295
|
-
}
|
296
|
-
|
297
|
-
obj = na_make_object(type, ca->rank, shape, klass);
|
298
|
-
GetNArray(obj, na);
|
299
|
-
|
300
|
-
ca_copy_data(ca, na->ptr);
|
301
|
-
}
|
302
|
-
|
303
|
-
return obj;
|
304
|
-
}
|
305
|
-
|
306
|
-
/* rdoc:
|
307
|
-
class CArray
|
308
|
-
def to_na
|
309
|
-
end
|
310
|
-
def to_nv
|
311
|
-
end
|
312
|
-
def to_nm
|
313
|
-
end
|
314
|
-
end
|
315
|
-
*/
|
316
|
-
|
317
|
-
static VALUE
|
318
|
-
rb_cary_to_na (VALUE self, VALUE klass)
|
319
|
-
{
|
320
|
-
return rb_cary_to_na_i(self, cNArray);
|
321
|
-
}
|
322
|
-
|
323
|
-
static VALUE
|
324
|
-
rb_cary_to_nv (VALUE self, VALUE klass)
|
325
|
-
{
|
326
|
-
return rb_cary_to_na_i(self, cNVector);
|
327
|
-
}
|
328
|
-
|
329
|
-
static VALUE
|
330
|
-
rb_cary_to_nm (VALUE self, VALUE klass)
|
331
|
-
{
|
332
|
-
return rb_cary_to_na_i(self, cNMatrix);
|
333
|
-
}
|
334
|
-
|
335
|
-
/* -------------------------------------------------------------------- */
|
336
|
-
|
337
|
-
/* rdoc:
|
338
|
-
class NArray
|
339
|
-
def ca
|
340
|
-
end
|
341
|
-
end
|
342
|
-
*/
|
343
|
-
|
344
|
-
static VALUE
|
345
|
-
rb_na_ca_ref_new (int argc, VALUE *argv, VALUE self)
|
346
|
-
{
|
347
|
-
volatile VALUE obj;
|
348
|
-
struct NARRAY *na;
|
349
|
-
ca_size_t dim[CA_RANK_MAX];
|
350
|
-
int8_t data_type;
|
351
|
-
int i;
|
352
|
-
|
353
|
-
GetNArray(self, na);
|
354
|
-
|
355
|
-
data_type = na_typecode_to_ca_data_type(na->type);
|
356
|
-
|
357
|
-
if ( na->total == 0 ) {
|
358
|
-
ca_size_t zero = 0;
|
359
|
-
obj = rb_carray_wrap_ptr(data_type, 1, &zero, 0, NULL,
|
360
|
-
&EMPTY_ARRAY_PTR, self); /* avoid ca->ptr == NULL */
|
361
|
-
}
|
362
|
-
else {
|
363
|
-
if ( argc == 0 ) {
|
364
|
-
CA_CHECK_RANK(na->rank);
|
365
|
-
for (i=0; i<na->rank; i++) {
|
366
|
-
dim[i] = na->shape[na->rank-i-1];
|
367
|
-
}
|
368
|
-
obj = rb_carray_wrap_ptr(data_type,
|
369
|
-
na->rank, dim, 0, NULL, na->ptr, self);
|
370
|
-
}
|
371
|
-
else {
|
372
|
-
CA_CHECK_RANK(argc);
|
373
|
-
for (i=0; i<argc; i++) {
|
374
|
-
dim[i] = NUM2INT(argv[i]);
|
375
|
-
}
|
376
|
-
obj = rb_carray_wrap_ptr(data_type, argc, dim, 0, NULL, na->ptr, self);
|
377
|
-
}
|
378
|
-
}
|
379
|
-
|
380
|
-
return obj;
|
381
|
-
}
|
382
|
-
|
383
|
-
/* -------------------------------------------------------------------- */
|
384
|
-
|
385
|
-
/* rdoc:
|
386
|
-
class NArray
|
387
|
-
def to_ca
|
388
|
-
end
|
389
|
-
end
|
390
|
-
*/
|
391
|
-
|
392
|
-
|
393
|
-
static VALUE
|
394
|
-
rb_na_to_ca (VALUE self)
|
395
|
-
{
|
396
|
-
volatile VALUE obj;
|
397
|
-
CArray *ca;
|
398
|
-
struct NARRAY *na;
|
399
|
-
ca_size_t dim[CA_RANK_MAX];
|
400
|
-
ca_size_t data_type;
|
401
|
-
ca_size_t i;
|
402
|
-
|
403
|
-
GetNArray(self, na);
|
404
|
-
|
405
|
-
data_type = na_typecode_to_ca_data_type(na->type);
|
406
|
-
|
407
|
-
if ( na->total == 0 ) {
|
408
|
-
ca_size_t zero = 0;
|
409
|
-
obj = rb_carray_new(data_type, 1, &zero, 0, NULL);
|
410
|
-
}
|
411
|
-
else {
|
412
|
-
CA_CHECK_RANK(na->rank);
|
413
|
-
|
414
|
-
for (i=0; i<na->rank; i++) {
|
415
|
-
dim[i] = na->shape[na->rank-i-1];
|
416
|
-
}
|
417
|
-
|
418
|
-
obj = rb_carray_new(data_type, na->rank, dim, 0, NULL);
|
419
|
-
Data_Get_Struct(obj, CArray, ca);
|
420
|
-
|
421
|
-
ca_sync_data(ca, na->ptr);
|
422
|
-
}
|
423
|
-
|
424
|
-
return obj;
|
425
|
-
}
|
426
|
-
|
427
|
-
/* -------------------------------------------------------------------- */
|
428
|
-
|
429
|
-
/* rdoc:
|
430
|
-
class NArray
|
431
|
-
def to_ca!
|
432
|
-
end
|
433
|
-
end
|
434
|
-
*/
|
435
|
-
|
436
|
-
static VALUE
|
437
|
-
rb_na_to_ca_bang (VALUE self)
|
438
|
-
{
|
439
|
-
volatile VALUE obj, fary;
|
440
|
-
CArray *ca;
|
441
|
-
struct NARRAY *na;
|
442
|
-
ca_size_t dim[CA_RANK_MAX];
|
443
|
-
ca_size_t data_type;
|
444
|
-
ca_size_t i;
|
445
|
-
|
446
|
-
GetNArray(self, na);
|
447
|
-
|
448
|
-
data_type = na_typecode_to_ca_data_type(na->type);
|
449
|
-
|
450
|
-
if ( na->total == 0 ) {
|
451
|
-
ca_size_t zero = 0;
|
452
|
-
obj = rb_carray_new(data_type, 1, &zero, 0, NULL);
|
453
|
-
}
|
454
|
-
else {
|
455
|
-
CA_CHECK_RANK(na->rank);
|
456
|
-
|
457
|
-
for (i=0; i<na->rank; i++) {
|
458
|
-
dim[i] = na->shape[na->rank-i-1];
|
459
|
-
}
|
460
|
-
|
461
|
-
obj = rb_carray_new(data_type, na->rank, dim, 0, NULL);
|
462
|
-
fary = rb_ca_farray(obj);
|
463
|
-
Data_Get_Struct(fary, CArray, ca);
|
464
|
-
|
465
|
-
ca_sync_data(ca, na->ptr);
|
466
|
-
}
|
467
|
-
|
468
|
-
return obj;
|
469
|
-
}
|
470
|
-
|
471
|
-
/* -------------------------------------------------------------------- */
|
472
|
-
|
473
|
-
void
|
474
|
-
Init_ca_wrap_narray ()
|
475
|
-
{
|
476
|
-
/* rb_require("narray"); */ /* "narray" should be loaded in config.rb */
|
477
|
-
|
478
|
-
rb_define_const(rb_cCArray, "HAVE_NARRAY", Qtrue);
|
479
|
-
|
480
|
-
/* CArray -> NArray */
|
481
|
-
rb_define_method(rb_cCArray, "na", rb_cary_na_ref_new, -1);
|
482
|
-
rb_define_method(rb_cCArray, "to_na", rb_cary_to_na, 0);
|
483
|
-
rb_define_method(rb_cCArray, "to_na!", rb_cary_to_na_bang, 0);
|
484
|
-
|
485
|
-
/* CArray -> NVector */
|
486
|
-
rb_define_method(rb_cCArray, "nv", rb_cary_nv_ref_new, -1);
|
487
|
-
rb_define_method(rb_cCArray, "to_nv", rb_cary_to_nv, 0);
|
488
|
-
rb_define_method(rb_cCArray, "to_nv!", rb_cary_to_nv_bang, 0);
|
489
|
-
|
490
|
-
/* CArray -> NMatrix */
|
491
|
-
rb_define_method(rb_cCArray, "nm", rb_cary_nm_ref_new, -1);
|
492
|
-
rb_define_method(rb_cCArray, "to_nm", rb_cary_to_nm, 0);
|
493
|
-
rb_define_method(rb_cCArray, "to_nm!", rb_cary_to_nm_bang, 0);
|
494
|
-
|
495
|
-
/* NArray -> CArray */
|
496
|
-
rb_define_method(cNArray, "ca", rb_na_ca_ref_new, -1);
|
497
|
-
rb_define_method(cNArray, "to_ca", rb_na_to_ca, 0);
|
498
|
-
rb_define_method(cNArray, "to_ca!", rb_na_to_ca_bang, 0);
|
499
|
-
}
|
500
|
-
|