carray 1.5.2 → 1.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +32 -0
  3. data/NEWS.md +56 -3
  4. data/README.md +34 -18
  5. data/Rakefile +1 -1
  6. data/TODO.md +5 -4
  7. data/carray.gemspec +10 -11
  8. data/ext/ca_obj_bitarray.c +4 -7
  9. data/ext/ca_obj_bitfield.c +3 -5
  10. data/ext/ca_obj_block.c +1 -6
  11. data/ext/ca_obj_refer.c +6 -8
  12. data/ext/ca_obj_unbound_repeat.c +21 -52
  13. data/ext/carray.h +4 -0
  14. data/ext/carray_access.c +77 -45
  15. data/ext/carray_attribute.c +16 -1
  16. data/ext/carray_cast.c +1 -1
  17. data/ext/carray_conversion.c +8 -1
  18. data/ext/carray_core.c +22 -16
  19. data/ext/carray_generate.c +3 -3
  20. data/ext/carray_mask.c +12 -2
  21. data/ext/carray_math.rb +20 -2
  22. data/ext/carray_numeric.c +32 -51
  23. data/ext/carray_order.c +159 -0
  24. data/ext/carray_test.c +13 -0
  25. data/ext/carray_undef.c +0 -8
  26. data/ext/carray_utils.c +126 -47
  27. data/ext/extconf.rb +13 -1
  28. data/ext/mkmath.rb +1 -1
  29. data/ext/ruby_carray.c +8 -1
  30. data/ext/ruby_ccomplex.c +1 -1
  31. data/ext/version.h +4 -4
  32. data/lib/carray.rb +7 -9
  33. data/lib/carray/autoload.rb +0 -2
  34. data/lib/carray/basic.rb +3 -5
  35. data/lib/carray/broadcast.rb +78 -22
  36. data/lib/carray/compose.rb +34 -10
  37. data/lib/carray/construct.rb +36 -14
  38. data/lib/carray/info.rb +1 -3
  39. data/lib/carray/inspect.rb +3 -5
  40. data/lib/carray/io/imagemagick.rb +1 -3
  41. data/lib/carray/iterator.rb +2 -3
  42. data/lib/carray/mask.rb +18 -7
  43. data/lib/carray/math.rb +4 -6
  44. data/lib/carray/math/histogram.rb +1 -3
  45. data/lib/carray/math/recurrence.rb +1 -3
  46. data/lib/carray/mkmf.rb +1 -3
  47. data/lib/carray/object/ca_obj_iterator.rb +1 -3
  48. data/lib/carray/object/ca_obj_link.rb +1 -3
  49. data/lib/carray/object/ca_obj_pack.rb +1 -3
  50. data/lib/carray/obsolete.rb +1 -17
  51. data/lib/carray/ordering.rb +1 -3
  52. data/lib/carray/serialize.rb +34 -25
  53. data/lib/carray/string.rb +1 -3
  54. data/lib/carray/struct.rb +3 -5
  55. data/lib/carray/testing.rb +5 -10
  56. data/lib/carray/time.rb +1 -3
  57. data/lib/carray/transform.rb +12 -3
  58. data/misc/NOTE +16 -38
  59. data/spec/Classes/CAUnboudRepeat_spec.rb +24 -0
  60. data/spec/Features/feature_attributes_spec.rb +6 -6
  61. data/spec/Features/feature_boolean_spec.rb +15 -14
  62. data/spec/Features/feature_broadcast.rb +16 -0
  63. data/spec/Features/feature_cast_spec.rb +1 -1
  64. data/spec/Features/feature_mask_spec.rb +6 -0
  65. metadata +10 -11
@@ -3,10 +3,8 @@
3
3
  # carray/test.rb
4
4
  #
5
5
  # This file is part of Ruby/CArray extension library.
6
- # You can redistribute it and/or modify it under the terms of
7
- # the Ruby Licence.
8
6
  #
9
- # Copyright (C) 2005 Hiroki Motoyoshi
7
+ # Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
  #
11
9
  # ----------------------------------------------------------------------------
12
10
 
@@ -41,16 +39,13 @@ class CArray
41
39
 
42
40
  # Returns the array eliminated all the duplicated elements.
43
41
  def uniq
44
- ary = to_a.uniq
42
+ ary = flatten.to_a.uniq
45
43
  if has_mask?
46
44
  ary.delete(UNDEF)
47
45
  end
48
- if has_data_class?
49
- return CArray.new(data_class, [ary.length]) { ary }
50
- else
51
- return CArray.new(data_type, [ary.length], :bytes=>bytes) { ary }
52
- end
46
+ out = CArray.new(data_type, [ary.length], :bytes=>bytes) { ary }
47
+ out.data_class = data_class if has_data_class?
48
+ return out
53
49
  end
54
50
 
55
-
56
51
  end
data/lib/carray/time.rb CHANGED
@@ -3,10 +3,8 @@
3
3
  # carray/time.rb
4
4
  #
5
5
  # This file is part of Ruby/CArray extension library.
6
- # You can redistribute it and/or modify it under the terms of
7
- # the Ruby Licence.
8
6
  #
9
- # Copyright (C) 2005 Hiroki Motoyoshi
7
+ # Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
  #
11
9
  # ----------------------------------------------------------------------------
12
10
 
@@ -3,10 +3,8 @@
3
3
  # carray/composition.rb
4
4
  #
5
5
  # This file is part of Ruby/CArray extension library.
6
- # You can redistribute it and/or modify it under the terms of
7
- # the Ruby Licence.
8
6
  #
9
- # Copyright (C) 2005 Hiroki Motoyoshi
7
+ # Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
  #
11
9
  # ----------------------------------------------------------------------------
12
10
 
@@ -96,5 +94,16 @@ class CArray
96
94
  return self[:%,1]
97
95
  end
98
96
 
97
+ # pulled
98
+
99
+ def pulled (*args)
100
+ idx = args.map{|s| s.nil? ? :% : s}
101
+ return self[*idx]
102
+ end
99
103
 
104
+ def pull (*args)
105
+ idx = args.map{|s| s.nil? ? :% : s}
106
+ return self[*idx].to_ca
107
+ end
108
+
100
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
- * ca_update_mask/ca_attach/ca_create_mask/ca_has_mask should be called
57
- before ca->mask refered
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
+
@@ -19,6 +19,20 @@ describe "CAUnboundRepeat" do
19
19
 
20
20
  end
21
21
 
22
+ example "ref" do
23
+ a = CA_INT(0..2)[:*,nil]
24
+ is_asserted_by { a[0] == 0 }
25
+ is_asserted_by { a[1] == 1 }
26
+ is_asserted_by { a[2] == 2 }
27
+ is_asserted_by { a.bind(3,3) == CA_INT([[0,1,2],
28
+ [0,1,2],
29
+ [0,1,2]]) }
30
+ is_asserted_by { a[0,0] == 0 }
31
+ is_asserted_by { a[0,1] == 1 }
32
+ is_asserted_by { a[0,2] == 2 }
33
+ is_asserted_by { a.to_a == [[0,1,2]] }
34
+ end
35
+
22
36
  example "bind" do
23
37
 
24
38
  a = CA_INT([1,2,3])
@@ -75,4 +89,14 @@ describe "CAUnboundRepeat" do
75
89
  is_asserted_by { a[:*,nil][:*,nil,nil].shape == [1,1,3] }
76
90
  end
77
91
 
92
+ example "extra * in arithmetic operation" do
93
+ a = CA_INT(1..3)
94
+ b = CA_INT(1..3)
95
+ aa = a[:*,:*,nil]
96
+ bb = b[:*,nil,:*]
97
+ is_asserted_by { aa.bind_with(bb) == a[3,:%][:*,nil,nil] }
98
+ is_asserted_by { aa + bb == (a[3,:%]+b[:%,3])[:*,nil,nil] }
99
+ end
100
+
101
+
78
102
  end
@@ -255,19 +255,19 @@ describe "TestCArrayAttribute " do
255
255
  a = CArray.int32(3,3)
256
256
  is_asserted_by { true == a.valid_index?(2, 2) }
257
257
  is_asserted_by { true == a.valid_index?(1, 1) }
258
- is_asserted_by { true == a.valid_index?((-1), (-1)) }
259
- is_asserted_by { true == a.valid_index?((-3), (-3)) }
258
+ # is_asserted_by { true == a.valid_index?((-1), (-1)) }
259
+ # is_asserted_by { true == a.valid_index?((-3), (-3)) }
260
260
 
261
261
  is_asserted_by { true == a.valid_addr?(8) }
262
262
  is_asserted_by { true == a.valid_addr?(4) }
263
- is_asserted_by { true == a.valid_addr?((-4)) }
264
- is_asserted_by { true == a.valid_addr?((-8)) }
263
+ # is_asserted_by { true == a.valid_addr?((-4)) }
264
+ # is_asserted_by { true == a.valid_addr?((-8)) }
265
265
 
266
266
  is_asserted_by { false == a.valid_index?(1, 3) }
267
- is_asserted_by { false == a.valid_index?((-4), 1) }
267
+ # is_asserted_by { false == a.valid_index?((-4), 1) }
268
268
 
269
269
  is_asserted_by { false == a.valid_addr?(9) }
270
- is_asserted_by { false == a.valid_addr?((-10)) }
270
+ # is_asserted_by { false == a.valid_addr?((-10)) }
271
271
  end
272
272
 
273
273
  example "same_shape?" do
@@ -75,23 +75,24 @@ describe "TestBooleanType " do
75
75
 
76
76
  end
77
77
 
78
- example "boolean_bit_operation_with_non_boolean_type" do
78
+ example "boolean_bit_operation_with_non_boolean_integer_type" do
79
79
 
80
- a = CArray.int(3,3).seq!
81
- b = CArray.int(3,3).seq! + 1
82
- e0 = a < 4
83
- e1 = a >= 4
84
-
85
- # ---
86
- expect { e0 & b }.not_to raise_error
87
- expect { e0 | b }.not_to raise_error
88
- expect { e0 ^ b }.not_to raise_error
89
- # ---
90
- expect { b & e0 }.not_to raise_error
91
- expect { b | e0 }.not_to raise_error
92
- expect { b ^ e0 }.not_to raise_error
80
+ a = CA_BOOLEAN([1,1,1,1])
81
+ b = CA_INT([0,1,2,3])
82
+
83
+ is_asserted_by { a & b == CA_INT([0, 1, 0, 1]) }
84
+ is_asserted_by { a | b == CA_INT([1, 1, 3, 3]) }
85
+ is_asserted_by { a ^ b == CA_INT([1, 0, 3, 2]) }
93
86
 
94
87
  end
95
88
 
89
+ example "boolean_arithmetic_operation" do
90
+ a = CA_BOOLEAN([1,1,0,0])
91
+ b = CA_INT( [0,1,1,0])
92
+
93
+ expect { a + a }.to raise_error(CArray::DataTypeError)
94
+
95
+ is_asserted_by { a + b == CA_INT([1, 2, 1, 0]) }
96
+ end
96
97
 
97
98
  end
@@ -97,4 +97,20 @@ describe "CArray.broadcast" do
97
97
  is_asserted_by { cc == c }
98
98
  end
99
99
 
100
+ example "extension of dimension" do
101
+ a = CA_INT([[1,2,3],[4,5,6]])
102
+
103
+ is_asserted_by { a.broadcast_to(1,2,1,3) == CA_INT([[[[ 1, 2, 3 ]],
104
+ [[ 4, 5, 6 ]]]]) }
105
+
106
+ is_asserted_by { a.reshape(2,1,3).broadcast_to(1,2,1,3) == CA_INT([[[[ 1, 2, 3 ]],
107
+ [[ 4, 5, 6 ]]]]) }
108
+
109
+ is_asserted_by { a.reshape(1,2,3).broadcast_to(1,2,1,3) == CA_INT([[[[ 1, 2, 3 ]],
110
+ [[ 4, 5, 6 ]]]]) }
111
+
112
+
113
+ end
114
+
115
+
100
116
  end
@@ -26,7 +26,7 @@ describe "TestCast " do
26
26
  # ---
27
27
  a = CA_OBJECT(["a", "b", "c"])
28
28
  expect { a.int32 }.to raise_error(ArgumentError)
29
- expect { a.float32 }.to raise_error(ArgumentError)
29
+ # expect { a.float32 }.to raise_error(ArgumentError)
30
30
  end
31
31
 
32
32
 
@@ -199,6 +199,12 @@ describe "Feature: Masking" do
199
199
  example "count_not_masked" do
200
200
  # test_basic_featrues
201
201
  end
202
+
203
+ example "compare with UNDEF" do
204
+ a = CA_INT([1,UNDEF,2])
205
+ is_asserted_by { a.eq(UNDEF) == a.is_masked }
206
+ is_asserted_by { a.ne(UNDEF) == a.is_not_masked }
207
+ end
202
208
 
203
209
  example "unmask" do
204
210
  # ---
metadata CHANGED
@@ -1,29 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carray
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.7
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-07-22 00:00:00.000000000 Z
11
+ date: 2021-06-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: " Ruby/CArray is an extension library for the multi-dimensional array
14
- class.\n CArray can store integers and floating point numbers to perform calculations\n
15
- \ efficiently. Therefore, Ruby/CArray is suitable for numerical computation and
16
- data\n analysis. Ruby/CArray has different features from other multidimensional
17
- array\n libraries (narray, numo-narray, nmatrix), such as element-specific masks,
18
- \n creation of reference arrays that can reflect changes to the referent, \n
19
- \ 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:
24
22
  - ext/extconf.rb
25
23
  extra_rdoc_files: []
26
24
  files:
25
+ - ".yardopts"
27
26
  - LICENSE
28
27
  - NEWS.md
29
28
  - README.md
@@ -222,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
221
  - !ruby/object:Gem::Version
223
222
  version: '0'
224
223
  requirements: []
225
- rubygems_version: 3.0.3
224
+ rubygems_version: 3.1.2
226
225
  signing_key:
227
226
  specification_version: 4
228
227
  summary: Multi-dimesional array class for Ruby