carray 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/NEWS.md +13 -0
- data/README.md +34 -18
- data/carray.gemspec +6 -9
- data/ext/ca_obj_refer.c +6 -8
- data/ext/carray_conversion.c +8 -1
- data/ext/carray_mask.c +12 -2
- data/ext/carray_order.c +159 -0
- data/ext/extconf.rb +5 -1
- data/ext/mkmath.rb +1 -1
- data/ext/ruby_ccomplex.c +1 -1
- data/ext/version.h +4 -4
- data/lib/carray/broadcast.rb +22 -3
- data/lib/carray/construct.rb +35 -11
- data/lib/carray/obsolete.rb +0 -14
- data/lib/carray/transform.rb +11 -0
- data/misc/NOTE +16 -38
- metadata +9 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bcafe56b32f0ad6542bab2d0236d82a8b4bf0a30fa94bd595dfad9bde4c4c55
|
4
|
+
data.tar.gz: dbf49a82458355e015b61055dfdede6ef68540baa95677834f65ad39b689acbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36328e14797d232525715cfd635a64e5526cc667168498cb603248b8210de92ab0ad7dbc4ee07c4b586dda1ed2b34e55cdc52d0ca0da7f9dc5984e9600ee8cbc
|
7
|
+
data.tar.gz: 10a03a1938771eda7f821052bac82ecae05496c4ef463530e2160421547b0364cccec09e11bc86f029dcd6ad9233aa13cdae4e322b22513b39263333f1d68804
|
data/.yardopts
CHANGED
data/NEWS.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
ChangeLog of Ruby/CArray
|
2
2
|
========================
|
3
3
|
|
4
|
+
1.5.3 -> 1.5.4
|
5
|
+
--------------
|
6
|
+
|
7
|
+
* [New] Import method 'CArray#section' from gem 'carray-calculus'
|
8
|
+
* [New] Add new method 'CArray#pull', 'CArray#pulled'
|
9
|
+
* [New] Add new option 'expand_scalar' to 'CArray.broadcast'
|
10
|
+
* [Mod] Modify the method 'CArray.broadcast' to accept block.
|
11
|
+
* [Mod] Modify the method 'CArray.meshgrid' to accept block.
|
12
|
+
* [Mod] Modify 'CScalar#broadcast_to' to return CArray
|
13
|
+
* [Mod] Modify 'CScalar#is_masked' and 'CScalar#is_masked' to return CScalar
|
14
|
+
* [Fix] Fix order of repetitive dimensions in 'CArray#meshgrid'
|
15
|
+
* [Fix] Fix errors in installing on MinGW+msys2
|
16
|
+
|
4
17
|
1.5.2 -> 1.5.3
|
5
18
|
--------------
|
6
19
|
|
data/README.md
CHANGED
@@ -6,16 +6,16 @@ Ruby/CArray is an extension library for the multi-dimensional array class.
|
|
6
6
|
Features
|
7
7
|
--------
|
8
8
|
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
* Indirect data manipulation
|
9
|
+
* Collection class for multidimensional array storing the value with uniform data type
|
10
|
+
* Element-wise mathematical operations and functions
|
11
|
+
* Statistical operation for the elements
|
12
|
+
* Various methods for referencing data elements
|
13
|
+
* Internally included element-wise mask to handle missing values
|
14
|
+
* Indirect data manipulation to referent by virtual array
|
15
15
|
* Special iterators (dimension, block, window, categorical)
|
16
|
-
* User-defined array
|
17
|
-
*
|
18
|
-
*
|
16
|
+
* User-defined array class with same multi-dimensional interfaces as CArray
|
17
|
+
* Accessing the partial data in fixed length data via data_class interface
|
18
|
+
* Wrapping the memory block owned by the other object (such as NArray).
|
19
19
|
|
20
20
|
Requirements
|
21
21
|
------------
|
@@ -25,16 +25,32 @@ Requirements
|
|
25
25
|
+ IEEE754 floating point number
|
26
26
|
+ C99 complex number
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
What is Ruby/CArray
|
29
|
+
------------------
|
30
30
|
|
31
|
-
|
32
|
-
ext - C extension source codes
|
33
|
-
utils - support tools for development
|
34
|
-
spec - rspec files
|
35
|
-
misc - misc files
|
31
|
+
Ruby/CArray is an extension library for the multi-dimensional numerical array class. The name "CArray" comes from a wrapper's meaning to a numerical array handled by the C language. CArray stores integers or floating-point numbers in memory block and treats them collectively to ensure efficient performance. Therefore, Ruby/CArray is suitable for numerical computation and data analysis.
|
36
32
|
|
37
|
-
|
38
|
-
|
33
|
+
#### Multi-dimensional uniform array ####
|
34
|
+
|
35
|
+
CArray is a collection class that can store the array of values with a uniform data type of one of fixed-width integer (8,16,32,64bits), floating-point number (32,64bits), complex number (64,128bits), fixed-length string, ruby object. These values are stored in memory block as binary data. CArray has multi-dimensional interfaces for the array to access their values. The multi-dimensional array has the attributes of the dimension size (1,2,3,...) and the shape of dimension ([dim0], [dim0,dim1], [dim0,dim1,dim2],...) which define the size of array.
|
36
|
+
|
37
|
+
#### Collective mathematical operations ####
|
38
|
+
|
39
|
+
CArray supports the collective calculation for the element-wise arithmetic operations and elementary mathematical functions. Additionally, some basic statistical summarization along specific dimensions are also provided.
|
40
|
+
|
41
|
+
#### Referencing data and virtual arrays ####
|
42
|
+
|
43
|
+
CArray provides various methods for referencing data, such as addressing, slicing, selection by condition, address mapping, grid reference, transposing, shifting, rolling, data type conversion, reshaping, and so on. These data referencing are realized by the creation of virtual arrays, so-called 'view'. The virtual array doesn't have its data and retrieves the data from the referent only on-demand, including dereferencing, copying, or calculation. Since virtual array classes are sub-class of CArray, it has the same interfaces to access data as CArray. The changes in a virtual array by storing data are also reflected in the referent (if not a read_only array). Multiple heterogeneous chains of reference are also allowed, although the trade-offs with performance must be carefully considered.
|
44
|
+
|
45
|
+
#### Built-in element-wise mask handling ####
|
46
|
+
|
47
|
+
CArray possesses masked states about each element (so-called "element-wise mask"). By referring the element-wise mask, CArray can perform mathematical and statistical calculations on the data with missing values by appropriate handling of masked elements. , which include the propagation of mask state to result in element-wise arithmetics and ignoring the masked elements in a statistical calculation, and so on.
|
48
|
+
|
49
|
+
#### User-defined array ####
|
50
|
+
|
51
|
+
Users can define a new virtual array class in Ruby level or C-extension level with TemplateMethod pattern. They are defined as a subclass of CAObject in Ruby level and as a subclass of CAVirtual in C-extension level. In particular, at the Ruby level, you can easily define a CArray-like class by implementing just a few template methods.
|
52
|
+
|
53
|
+
License
|
54
|
+
-------
|
39
55
|
|
40
56
|
MIT (after version 1.5.0)
|
data/carray.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification::new do |s|
|
2
2
|
|
3
|
-
version = "1.5.
|
3
|
+
version = "1.5.4"
|
4
4
|
|
5
5
|
files = Dir.glob("**/*") + [".yardopts"] -
|
6
6
|
[
|
@@ -16,14 +16,11 @@ Gem::Specification::new do |s|
|
|
16
16
|
s.name = "carray"
|
17
17
|
s.summary = "Multi-dimesional array class for Ruby"
|
18
18
|
s.description = <<-HERE
|
19
|
-
Ruby/CArray is an extension library for the multi-dimensional numerical array
|
20
|
-
CArray
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
creation of reference arrays that can reflect changes to the referent,
|
25
|
-
the ability to access memory pointers of other objects, user-defined arrays,
|
26
|
-
and so on.
|
19
|
+
Ruby/CArray is an extension library for the multi-dimensional numerical array
|
20
|
+
class. The name "CArray" comes from the meaning of a wrapper to a numerical array
|
21
|
+
handled by the C language. CArray stores integers or floating-point numbers in
|
22
|
+
memory block and treats them collectively to ensure efficient performance.
|
23
|
+
Therefore, Ruby/CArray is suitable for numerical computation and data analysis.
|
27
24
|
HERE
|
28
25
|
s.version = version
|
29
26
|
s.author = "Hiroki Motoyoshi"
|
data/ext/ca_obj_refer.c
CHANGED
@@ -32,11 +32,11 @@ ca_refer_setup (CARefer *ca, CArray *parent,
|
|
32
32
|
CA_CHECK_BYTES(data_type, bytes);
|
33
33
|
|
34
34
|
if ( ca_is_object_type(parent) && data_type != CA_OBJECT ) {
|
35
|
-
rb_raise(rb_eRuntimeError, "object
|
35
|
+
rb_raise(rb_eRuntimeError, "object array can't be referred by other data type");
|
36
36
|
}
|
37
37
|
|
38
38
|
if ( parent->elements && bytes > parent->bytes * parent->elements ) {
|
39
|
-
rb_raise(rb_eRuntimeError, "
|
39
|
+
rb_raise(rb_eRuntimeError, "bytes exceeds the data size of referent");
|
40
40
|
}
|
41
41
|
|
42
42
|
/* calc datanum and check deformation */
|
@@ -51,27 +51,25 @@ ca_refer_setup (CARefer *ca, CArray *parent,
|
|
51
51
|
}
|
52
52
|
if ( bytes < parent->bytes ) {
|
53
53
|
if ( parent->bytes % bytes != 0 ) {
|
54
|
-
rb_raise(
|
54
|
+
rb_raise(rb_eRuntimeError, "bytes of reference array must be a multiple of that of referent");
|
55
55
|
}
|
56
56
|
is_deformed = -2;
|
57
57
|
ratio = parent->bytes / bytes;
|
58
58
|
}
|
59
59
|
else if ( bytes > parent->bytes ) {
|
60
60
|
if ( bytes % parent->bytes != 0 ) {
|
61
|
-
rb_raise(
|
61
|
+
rb_raise(rb_eRuntimeError, "bytes of reference array must be a multiple of that of referent");
|
62
62
|
}
|
63
63
|
is_deformed = 2;
|
64
64
|
ratio = bytes / parent->bytes;
|
65
65
|
}
|
66
|
-
|
67
66
|
if ( offset < 0 ) {
|
68
|
-
rb_raise(rb_eRuntimeError,
|
69
|
-
"negative offset for CARefer");
|
67
|
+
rb_raise(rb_eRuntimeError, "negative offset is not permitted for CARefer");
|
70
68
|
}
|
71
69
|
|
72
70
|
if ( ( bytes * elements + parent->bytes * offset ) >
|
73
71
|
( parent->bytes * parent->elements ) ) {
|
74
|
-
rb_raise(rb_eRuntimeError, "data size
|
72
|
+
rb_raise(rb_eRuntimeError, "data size of reference array must not exceed that of referent");
|
75
73
|
}
|
76
74
|
|
77
75
|
ca->obj_type = CA_OBJ_REFER;
|
data/ext/carray_conversion.c
CHANGED
@@ -342,6 +342,8 @@ rb_ca_format (int argc, VALUE *argv, VALUE self)
|
|
342
342
|
|
343
343
|
#include <time.h>
|
344
344
|
|
345
|
+
#ifdef HAVE_STRPTIME
|
346
|
+
|
345
347
|
/* @overload str_strptime (fmt)
|
346
348
|
|
347
349
|
(Conversion)
|
@@ -404,7 +406,9 @@ rb_ca_strptime (VALUE self, VALUE rfmt)
|
|
404
406
|
return obj;
|
405
407
|
}
|
406
408
|
|
407
|
-
|
409
|
+
#endif
|
410
|
+
|
411
|
+
/* @overload time_strftime (fmt)
|
408
412
|
|
409
413
|
(Conversion)
|
410
414
|
Creates object type array consist of strings
|
@@ -498,7 +502,10 @@ Init_carray_conversion ()
|
|
498
502
|
|
499
503
|
rb_define_method(rb_cCArray, "str_format", rb_ca_format, -1);
|
500
504
|
|
505
|
+
#ifdef HAVE_STRPTIME
|
501
506
|
rb_define_method(rb_cCArray, "str_strptime", rb_ca_strptime, 1);
|
507
|
+
#endif
|
508
|
+
|
502
509
|
rb_define_method(rb_cCArray, "time_strftime", rb_ca_strftime, 1);
|
503
510
|
|
504
511
|
rb_define_method(rb_cCArray, "test_ca_to_cptr", rb_test_ca_to_cptr, 0);
|
data/ext/carray_mask.c
CHANGED
@@ -757,7 +757,12 @@ rb_ca_is_masked (VALUE self)
|
|
757
757
|
|
758
758
|
Data_Get_Struct(self, CArray, ca);
|
759
759
|
|
760
|
-
|
760
|
+
if ( ca_is_scalar(ca) ) {
|
761
|
+
co = cscalar_new(CA_BOOLEAN, ca->bytes, NULL);
|
762
|
+
}
|
763
|
+
else {
|
764
|
+
co = carray_new(CA_BOOLEAN, ca->ndim, ca->dim, ca->bytes, NULL);
|
765
|
+
}
|
761
766
|
|
762
767
|
ca_update_mask(ca);
|
763
768
|
if ( ! ca->mask ) {
|
@@ -798,7 +803,12 @@ rb_ca_is_not_masked (VALUE self)
|
|
798
803
|
|
799
804
|
Data_Get_Struct(self, CArray, ca);
|
800
805
|
|
801
|
-
|
806
|
+
if ( ca_is_scalar(ca) ) {
|
807
|
+
co = cscalar_new(CA_BOOLEAN, ca->bytes, NULL);
|
808
|
+
}
|
809
|
+
else {
|
810
|
+
co = carray_new(CA_BOOLEAN, ca->ndim, ca->dim, ca->bytes, NULL);
|
811
|
+
}
|
802
812
|
|
803
813
|
ca_update_mask(ca);
|
804
814
|
if ( ! ca->mask ) {
|
data/ext/carray_order.c
CHANGED
@@ -869,6 +869,162 @@ rb_ca_linear_search_nearest_index (VALUE self, VALUE value)
|
|
869
869
|
return ( NIL_P(raddr) ) ? Qnil : rb_ca_addr2index(self, raddr);
|
870
870
|
}
|
871
871
|
|
872
|
+
/* ----------------------------------------------------------------- */
|
873
|
+
|
874
|
+
static ca_size_t
|
875
|
+
linear_index (ca_size_t n, double *y, double yy, double *idx)
|
876
|
+
{
|
877
|
+
ca_size_t a, b, c, x1;
|
878
|
+
double ya, yb, yc;
|
879
|
+
double y1, y2;
|
880
|
+
double rest;
|
881
|
+
|
882
|
+
if ( yy <= y[0] ) {
|
883
|
+
x1 = 0;
|
884
|
+
goto found;
|
885
|
+
}
|
886
|
+
|
887
|
+
if ( yy >= y[n-1] ) {
|
888
|
+
x1 = n-2;
|
889
|
+
goto found;
|
890
|
+
}
|
891
|
+
|
892
|
+
/* check for equally spaced scale */
|
893
|
+
|
894
|
+
a = (ca_size_t)((yy-y[0])/(y[n-1]-y[0])*(n-1));
|
895
|
+
|
896
|
+
if ( a >= 0 && a < n-1 ) {
|
897
|
+
if ( (y[a] - yy) * (y[a+1] - yy) <= 0 ) { /* lucky case */
|
898
|
+
x1 = a;
|
899
|
+
goto found;
|
900
|
+
}
|
901
|
+
}
|
902
|
+
|
903
|
+
/* binary section method */
|
904
|
+
|
905
|
+
a = 0;
|
906
|
+
b = n-1;
|
907
|
+
|
908
|
+
ya = y[a];
|
909
|
+
yb = y[b];
|
910
|
+
|
911
|
+
if ( ya > yb ) {
|
912
|
+
return -1; /* input scale array should have accending order */
|
913
|
+
}
|
914
|
+
|
915
|
+
while ( (b - a) >= 1 ) {
|
916
|
+
|
917
|
+
c = (a + b)/2;
|
918
|
+
yc = y[c];
|
919
|
+
if ( a == c ) {
|
920
|
+
break;
|
921
|
+
}
|
922
|
+
|
923
|
+
if ( yc == yy ) {
|
924
|
+
a = c;
|
925
|
+
break;
|
926
|
+
}
|
927
|
+
else if ( (ya - yy) * (yc - yy) <= 0 ) {
|
928
|
+
b = c;
|
929
|
+
yb = yc;
|
930
|
+
}
|
931
|
+
else {
|
932
|
+
a = c;
|
933
|
+
ya = yc;
|
934
|
+
}
|
935
|
+
|
936
|
+
if ( ya > yb ) {
|
937
|
+
return -1; /* input scale array should have accending order */
|
938
|
+
}
|
939
|
+
}
|
940
|
+
|
941
|
+
x1 = a;
|
942
|
+
|
943
|
+
found:
|
944
|
+
|
945
|
+
y1 = y[x1];
|
946
|
+
y2 = y[x1+1];
|
947
|
+
rest = (yy-y1)/(y2-y1);
|
948
|
+
|
949
|
+
if ( fabs(y2-yy)/fabs(y2) < DBL_EPSILON*100 ) {
|
950
|
+
*idx = (double) (x1 + 1);
|
951
|
+
}
|
952
|
+
else if ( fabs(y1-yy)/fabs(y1) < DBL_EPSILON*100 ) {
|
953
|
+
*idx = (double) x1;
|
954
|
+
}
|
955
|
+
else {
|
956
|
+
*idx = rest + (double) x1;
|
957
|
+
}
|
958
|
+
|
959
|
+
return 0;
|
960
|
+
}
|
961
|
+
|
962
|
+
static VALUE
|
963
|
+
rb_ca_binary_search_linear_index (volatile VALUE self, volatile VALUE vx)
|
964
|
+
{
|
965
|
+
volatile VALUE out, out0;
|
966
|
+
CArray *ca, *sc, *cx, *co0, *co;
|
967
|
+
ca_size_t n;
|
968
|
+
double *x;
|
969
|
+
double *px;
|
970
|
+
double *po;
|
971
|
+
ca_size_t i;
|
972
|
+
|
973
|
+
Data_Get_Struct(self, CArray, ca);
|
974
|
+
|
975
|
+
if ( rb_ca_is_any_masked(self) ) {
|
976
|
+
rb_raise(rb_eRuntimeError, "self should not have any masked elements");
|
977
|
+
}
|
978
|
+
|
979
|
+
sc = ca_wrap_readonly(self, CA_FLOAT64);
|
980
|
+
cx = ca_wrap_readonly(vx, CA_FLOAT64);
|
981
|
+
|
982
|
+
co0 = carray_new(ca->data_type, cx->ndim, cx->dim, 0, NULL);
|
983
|
+
out = out0 = ca_wrap_struct(co0);
|
984
|
+
co = ca_wrap_writable(out, CA_FLOAT64);
|
985
|
+
|
986
|
+
ca_attach_n(3, sc, cx, co);
|
987
|
+
|
988
|
+
n = sc->elements;
|
989
|
+
x = (double*) sc->ptr;
|
990
|
+
px = (double*) cx->ptr;
|
991
|
+
po = (double*) co->ptr;
|
992
|
+
|
993
|
+
ca_update_mask(cx);
|
994
|
+
if ( cx->mask ) {
|
995
|
+
boolean8_t *mx, *mo;
|
996
|
+
ca_create_mask(co);
|
997
|
+
mx = (boolean8_t *) cx->mask->ptr;
|
998
|
+
mo = (boolean8_t *) co->mask->ptr;
|
999
|
+
for (i=0; i<cx->elements; i++) {
|
1000
|
+
if ( ! *mx ) {
|
1001
|
+
linear_index(n, x, *px, po);
|
1002
|
+
}
|
1003
|
+
else {
|
1004
|
+
*mo = 1;
|
1005
|
+
}
|
1006
|
+
mx++; mo++; px++, po++;
|
1007
|
+
}
|
1008
|
+
}
|
1009
|
+
else {
|
1010
|
+
for (i=0; i<cx->elements; i++) {
|
1011
|
+
linear_index(n, x, *px, po);
|
1012
|
+
px++, po++;
|
1013
|
+
}
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
ca_sync(co);
|
1017
|
+
ca_detach_n(3, sc, cx, co);
|
1018
|
+
|
1019
|
+
if ( rb_ca_is_scalar(vx) ) {
|
1020
|
+
return rb_funcall(out0, rb_intern("[]"), 1, INT2NUM(0));
|
1021
|
+
}
|
1022
|
+
else {
|
1023
|
+
return out0;
|
1024
|
+
}
|
1025
|
+
}
|
1026
|
+
|
1027
|
+
|
872
1028
|
void
|
873
1029
|
Init_carray_order ()
|
874
1030
|
{
|
@@ -893,4 +1049,7 @@ Init_carray_order ()
|
|
893
1049
|
rb_define_method(rb_cCArray, "search_nearest_index",
|
894
1050
|
rb_ca_linear_search_nearest_index, 1);
|
895
1051
|
|
1052
|
+
rb_define_method(rb_cCArray, "section",
|
1053
|
+
rb_ca_binary_search_linear_index, 1);
|
1054
|
+
|
896
1055
|
}
|
data/ext/extconf.rb
CHANGED
@@ -140,6 +140,10 @@ have_header("tgmath.h")
|
|
140
140
|
|
141
141
|
have_func("mergesort", "stdlib.h")
|
142
142
|
|
143
|
+
# --- check mergesort routine
|
144
|
+
|
145
|
+
have_func("strptime", "time.h")
|
146
|
+
|
143
147
|
# --- setup install files
|
144
148
|
|
145
149
|
$INSTALLFILES = []
|
@@ -153,7 +157,7 @@ $INSTALLFILES << ['carray_config.h', '$(archdir)']
|
|
153
157
|
#
|
154
158
|
|
155
159
|
if /cygwin|mingw/ =~ RUBY_PLATFORM
|
156
|
-
sitearchdir =
|
160
|
+
sitearchdir = RbConfig::CONFIG["sitearchdir"]
|
157
161
|
$DLDFLAGS << " -L#{sitearchdir} -Wl,--out-implib=libcarray.a "
|
158
162
|
unless File.exist? "libcarray.a"
|
159
163
|
$TOUCHED_LIBCARRAY_A = true
|
data/ext/mkmath.rb
CHANGED
@@ -385,7 +385,7 @@ ca_moncmp_#{name}_#{type} (ca_size_t n, boolean8_t *m, char *ptr1, ca_size_t i1,
|
|
385
385
|
io.puts "};"
|
386
386
|
io.puts
|
387
387
|
io.print %{
|
388
|
-
static VALUE rb_ca_#{name} (VALUE self
|
388
|
+
static VALUE rb_ca_#{name} (VALUE self)
|
389
389
|
{ return rb_ca_call_moncmp(self, ca_moncmp_#{name}); }
|
390
390
|
}
|
391
391
|
DEFINITIONS << io.string
|
data/ext/ruby_ccomplex.c
CHANGED
@@ -460,7 +460,7 @@ Init_ccomplex ()
|
|
460
460
|
rb_define_method(rb_cCComplex, "coerce", rb_cc_coerce, 1);
|
461
461
|
|
462
462
|
rb_define_method(rb_cCComplex, "==", rb_cc_equal, 1);
|
463
|
-
rb_define_method(rb_cCComplex, "-@", rb_cc_uminus,
|
463
|
+
rb_define_method(rb_cCComplex, "-@", rb_cc_uminus, 0);
|
464
464
|
rb_define_method(rb_cCComplex, "+", rb_cc_plus, 1);
|
465
465
|
rb_define_method(rb_cCComplex, "-", rb_cc_minus, 1);
|
466
466
|
rb_define_method(rb_cCComplex, "*", rb_cc_asterisk, 1);
|
data/ext/version.h
CHANGED
@@ -8,9 +8,9 @@
|
|
8
8
|
|
9
9
|
---------------------------------------------------------------------------- */
|
10
10
|
|
11
|
-
#define CA_VERSION "1.5.
|
12
|
-
#define CA_VERSION_CODE
|
11
|
+
#define CA_VERSION "1.5.4"
|
12
|
+
#define CA_VERSION_CODE 154
|
13
13
|
#define CA_VERSION_MAJOR 1
|
14
14
|
#define CA_VERSION_MINOR 5
|
15
|
-
#define CA_VERSION_TEENY
|
16
|
-
#define CA_VERSION_DATE "2020/
|
15
|
+
#define CA_VERSION_TEENY 4
|
16
|
+
#define CA_VERSION_DATE "2020/09/06"
|
data/lib/carray/broadcast.rb
CHANGED
@@ -56,7 +56,9 @@ end
|
|
56
56
|
class CScalar
|
57
57
|
|
58
58
|
def broadcast_to (*newdim)
|
59
|
-
|
59
|
+
out = CArray.new(data_type, newdim, bytes: bytes)
|
60
|
+
out[] = self
|
61
|
+
out
|
60
62
|
end
|
61
63
|
|
62
64
|
end
|
@@ -67,7 +69,8 @@ class CAUnboundRepeat
|
|
67
69
|
|
68
70
|
end
|
69
71
|
|
70
|
-
def CArray.broadcast (*argv)
|
72
|
+
def CArray.broadcast (*argv, expand_scalar: false, &block)
|
73
|
+
|
71
74
|
sel = argv.select { |arg| arg.is_a?(CArray) }
|
72
75
|
return argv if sel.empty?
|
73
76
|
|
@@ -77,6 +80,22 @@ def CArray.broadcast (*argv)
|
|
77
80
|
dim[k] = sel.map { |arg| arg.dim[k] || 1 }.max
|
78
81
|
end
|
79
82
|
|
80
|
-
|
83
|
+
if not expand_scalar
|
84
|
+
list = argv.map { |arg|
|
85
|
+
case arg
|
86
|
+
when CScalar
|
87
|
+
arg
|
88
|
+
when CArray
|
89
|
+
arg.broadcast_to(*dim)
|
90
|
+
else
|
91
|
+
arg
|
92
|
+
end
|
93
|
+
}
|
94
|
+
else
|
95
|
+
list = argv.map { |arg| arg.is_a?(CArray) ? arg.broadcast_to(*dim) : arg }
|
96
|
+
end
|
97
|
+
|
98
|
+
return block.call(*list) if block
|
99
|
+
return list
|
81
100
|
end
|
82
101
|
|
data/lib/carray/construct.rb
CHANGED
@@ -395,7 +395,7 @@ class CArray
|
|
395
395
|
def eye (n, m = nil, k = 0)
|
396
396
|
m ||= n
|
397
397
|
mat = CArray.new(self::DataType || CA_FLOAT64, [n, m])
|
398
|
-
start = k > 0 ? k : m - k - 1
|
398
|
+
start = ( k == 0 ) ? k : ( k > 0 ? k : m - k - 1 )
|
399
399
|
mat[[start..-1,m+1]] = 1
|
400
400
|
mat
|
401
401
|
end
|
@@ -430,7 +430,7 @@ class CArray
|
|
430
430
|
end
|
431
431
|
data_type = self::DataType
|
432
432
|
data_type ||= guess_data_type_from_values(start, stop, step)
|
433
|
-
CArray.__new__(data_type, start..stop, step)
|
433
|
+
CArray.__new__(data_type, start..stop-step, step)
|
434
434
|
end
|
435
435
|
|
436
436
|
def full (shape, fill_value)
|
@@ -445,16 +445,40 @@ class CArray
|
|
445
445
|
end
|
446
446
|
|
447
447
|
class CArray
|
448
|
-
|
449
|
-
def self.meshgrid (*
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
448
|
+
|
449
|
+
def self.meshgrid (*axes, indexing: "xy", copy: true, sparse: false, &block)
|
450
|
+
case indexing
|
451
|
+
when "xy"
|
452
|
+
### no operation
|
453
|
+
when "ij"
|
454
|
+
axes = axes.map{|axis| axis.seq }
|
455
|
+
else
|
456
|
+
raise ArgumentError, %{indexing option should be one of "xy" and "ij"}
|
457
|
+
end
|
458
|
+
shape = axes.map(&:size).reverse
|
459
|
+
if sparse ### => CAUnboundRepeat
|
460
|
+
list = axes.map.with_index do |axis, k|
|
461
|
+
extended_shape = (shape.size-1).downto(0).map { |i| ( i == k ) ? nil : :* }
|
462
|
+
if copy
|
463
|
+
axis[*extended_shape].to_ca
|
464
|
+
else
|
465
|
+
axis[*extended_shape]
|
466
|
+
end
|
467
|
+
end
|
468
|
+
else ### => CARepeat
|
469
|
+
naxes = shape.size
|
470
|
+
list = axes.map.with_index do |axis, k|
|
471
|
+
extended_shape = shape.dup
|
472
|
+
extended_shape[naxes - k - 1] = :%
|
473
|
+
if copy
|
474
|
+
axis[*extended_shape].to_ca
|
475
|
+
else
|
476
|
+
axis[*extended_shape]
|
477
|
+
end
|
478
|
+
end
|
456
479
|
end
|
457
|
-
return *
|
480
|
+
return block.call(*list) if block
|
481
|
+
return list
|
458
482
|
end
|
459
483
|
|
460
484
|
end
|
data/lib/carray/obsolete.rb
CHANGED
@@ -23,20 +23,6 @@ class CArray
|
|
23
23
|
self
|
24
24
|
end
|
25
25
|
|
26
|
-
# pulled
|
27
|
-
|
28
|
-
def pulled (*args)
|
29
|
-
warn "CArray#pulled will be obsolete"
|
30
|
-
idx = args.map{|s| s.nil? ? :% : s}
|
31
|
-
return self[*idx]
|
32
|
-
end
|
33
|
-
|
34
|
-
def pull (*args)
|
35
|
-
warn "CArray#pull will be obsolete"
|
36
|
-
idx = args.map{|s| s.nil? ? :% : s}
|
37
|
-
return self[*idx].to_ca
|
38
|
-
end
|
39
|
-
|
40
26
|
# Returns the array eliminated all the duplicated elements.
|
41
27
|
def duplicated_values
|
42
28
|
warn "CArray#duplicated_values will be obsolete"
|
data/lib/carray/transform.rb
CHANGED
@@ -94,5 +94,16 @@ class CArray
|
|
94
94
|
return self[:%,1]
|
95
95
|
end
|
96
96
|
|
97
|
+
# pulled
|
98
|
+
|
99
|
+
def pulled (*args)
|
100
|
+
idx = args.map{|s| s.nil? ? :% : s}
|
101
|
+
return self[*idx]
|
102
|
+
end
|
97
103
|
|
104
|
+
def pull (*args)
|
105
|
+
idx = args.map{|s| s.nil? ? :% : s}
|
106
|
+
return self[*idx].to_ca
|
107
|
+
end
|
108
|
+
|
98
109
|
end
|
data/misc/NOTE
CHANGED
@@ -1,42 +1,6 @@
|
|
1
1
|
Note for developper
|
2
2
|
===================
|
3
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
4
|
Utility scripts
|
41
5
|
---------------
|
42
6
|
|
@@ -53,8 +17,11 @@ Check Points for Debug
|
|
53
17
|
|
54
18
|
* 'elements' should be checked with double float number
|
55
19
|
|
56
|
-
*
|
57
|
-
|
20
|
+
* One of the following methods should be called before ca->mask refered
|
21
|
+
+ ca_attach
|
22
|
+
+ ca_has_mask
|
23
|
+
+ ca_update_mask
|
24
|
+
+ ca_create_mask
|
58
25
|
|
59
26
|
* Avoid the exposition of raw VALUE data in object array
|
60
27
|
|
@@ -71,3 +38,14 @@ OpenMP
|
|
71
38
|
------
|
72
39
|
|
73
40
|
* '--with-cc="gcc -fopenmp"' ... and so on.
|
41
|
+
|
42
|
+
Range
|
43
|
+
-----
|
44
|
+
|
45
|
+
int rb_arithmetic_sequence_extract(VALUE, VALUE *, VALUE *, VALUE *, int *);
|
46
|
+
|
47
|
+
/* range.c */
|
48
|
+
#define RANGE_BEG(r) (RSTRUCT(r)->as.ary[0])
|
49
|
+
#define RANGE_END(r) (RSTRUCT(r)->as.ary[1])
|
50
|
+
#define RANGE_EXCL(r) (RSTRUCT(r)->as.ary[2])
|
51
|
+
|
metadata
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carray
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroki Motoyoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
\n the ability to access memory pointers of other objects, user-defined arrays,\n
|
20
|
-
\ and so on.\n"
|
13
|
+
description: |2
|
14
|
+
Ruby/CArray is an extension library for the multi-dimensional numerical array
|
15
|
+
class. The name "CArray" comes from the meaning of a wrapper to a numerical array
|
16
|
+
handled by the C language. CArray stores integers or floating-point numbers in
|
17
|
+
memory block and treats them collectively to ensure efficient performance.
|
18
|
+
Therefore, Ruby/CArray is suitable for numerical computation and data analysis.
|
21
19
|
email: ''
|
22
20
|
executables: []
|
23
21
|
extensions:
|
@@ -223,8 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
223
221
|
- !ruby/object:Gem::Version
|
224
222
|
version: '0'
|
225
223
|
requirements: []
|
226
|
-
|
227
|
-
rubygems_version: 2.7.7
|
224
|
+
rubygems_version: 3.1.2
|
228
225
|
signing_key:
|
229
226
|
specification_version: 4
|
230
227
|
summary: Multi-dimesional array class for Ruby
|