carray 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +32 -0
  3. data/NEWS.md +26 -3
  4. data/Rakefile +1 -1
  5. data/TODO.md +5 -4
  6. data/carray.gemspec +7 -5
  7. data/ext/ca_obj_bitarray.c +4 -7
  8. data/ext/ca_obj_bitfield.c +3 -5
  9. data/ext/ca_obj_block.c +1 -6
  10. data/ext/ca_obj_unbound_repeat.c +21 -52
  11. data/ext/carray_attribute.c +16 -1
  12. data/ext/carray_core.c +22 -16
  13. data/ext/carray_math.rb +20 -2
  14. data/ext/carray_numeric.c +32 -51
  15. data/ext/carray_test.c +9 -0
  16. data/ext/carray_undef.c +0 -8
  17. data/ext/version.h +4 -4
  18. data/lib/carray.rb +1 -3
  19. data/lib/carray/autoload.rb +0 -2
  20. data/lib/carray/basic.rb +1 -3
  21. data/lib/carray/broadcast.rb +58 -21
  22. data/lib/carray/compose.rb +34 -10
  23. data/lib/carray/construct.rb +1 -3
  24. data/lib/carray/info.rb +1 -3
  25. data/lib/carray/inspect.rb +3 -5
  26. data/lib/carray/io/imagemagick.rb +1 -3
  27. data/lib/carray/iterator.rb +2 -3
  28. data/lib/carray/mask.rb +18 -7
  29. data/lib/carray/math.rb +4 -6
  30. data/lib/carray/math/histogram.rb +1 -3
  31. data/lib/carray/math/recurrence.rb +1 -3
  32. data/lib/carray/mkmf.rb +1 -3
  33. data/lib/carray/object/ca_obj_iterator.rb +1 -3
  34. data/lib/carray/object/ca_obj_link.rb +1 -3
  35. data/lib/carray/object/ca_obj_pack.rb +1 -3
  36. data/lib/carray/obsolete.rb +1 -3
  37. data/lib/carray/ordering.rb +1 -3
  38. data/lib/carray/serialize.rb +22 -13
  39. data/lib/carray/string.rb +1 -3
  40. data/lib/carray/struct.rb +3 -5
  41. data/lib/carray/testing.rb +5 -10
  42. data/lib/carray/time.rb +1 -3
  43. data/lib/carray/transform.rb +1 -3
  44. data/spec/Classes/CAUnboudRepeat_spec.rb +24 -0
  45. data/spec/Features/feature_boolean_spec.rb +15 -14
  46. data/spec/Features/feature_broadcast.rb +16 -0
  47. data/spec/Features/feature_mask_spec.rb +6 -0
  48. metadata +12 -10
@@ -3,10 +3,8 @@
3
3
  # carray/constructor.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/info.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/inspect.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
 
@@ -159,7 +157,7 @@ class CArray::Inspector # :nodoc:
159
157
  dim[level].times do |i|
160
158
  idx[level] = i
161
159
  v = @carray[*idx]
162
- if v.undef?
160
+ if v == UNDEF
163
161
  io << '_'
164
162
  else
165
163
  io << formatter[v]
@@ -178,7 +176,7 @@ class CArray::Inspector # :nodoc:
178
176
  if over
179
177
  idx[level] = dim[level] - 1
180
178
  v = @carray[*idx]
181
- if v.undef?
179
+ if v == UNDEF
182
180
  io << ", _"
183
181
  else
184
182
  io << ", " + formatter[v]
@@ -3,10 +3,8 @@
3
3
  # carray/io/imagemagick.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/iterator.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
 
@@ -318,6 +316,7 @@ class CAClassIterator < CAIterator # :nodoc:
318
316
  @reference = reference
319
317
  @classifier = classifier || @reference.uniq.sort
320
318
  @null = CArray.new(@reference.data_type,[0])
319
+ @null.data_class = @reference.data_class if @reference.has_data_class?
321
320
  @table = {}
322
321
  @ndim = 1
323
322
  @dim = [0]
@@ -3,21 +3,32 @@
3
3
  # carray/mask.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
 
13
11
  class CArray
14
-
15
- # mask
16
-
12
+
13
+ # Guard methods for handling variables that can be UNDEF values.
14
+ # Provide different processing depending on whether
15
+ # the given value is UNDEF or not.
17
16
  #
18
- # Returns the number of masked elements.
17
+ # @param value [Object] target object
18
+ # @param fill_value [Object] alternative value if the given value is UNDEF
19
+ #
20
+ # @return fill_value if the given value is UNDEF, block return value if block
21
+ # is given, or value itself
19
22
  #
23
+ def self.guard_undef (*values, fill_value: UNDEF, &block)
24
+ return fill_value if values.any?{|v| v == UNDEF }
25
+ return block.(*values)
26
+ end
20
27
 
28
+ # mask
29
+ #
30
+ # Returns the number of masked elements.
31
+ #
21
32
  def count_masked (*axis)
22
33
  if has_mask?
23
34
  return mask.int64.accumulate(*axis)
@@ -3,10 +3,8 @@
3
3
  # carray/math.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
 
@@ -318,7 +316,7 @@ class CArray
318
316
  count = x.count_not_masked
319
317
  xm = x.mean(:min_count => min_count)
320
318
  ym = y.mean(:min_count => min_count)
321
- if ( xm.undef? or ym.undef? )
319
+ if ( xm == UNDEF or ym == UNDEF )
322
320
  return fill_value || UNDEF
323
321
  else
324
322
  return (x-xm).wsum(y-ym)/count
@@ -337,7 +335,7 @@ class CArray
337
335
  count = x.count_not_masked
338
336
  xm = x.mean(:min_count=>min_count)
339
337
  ym = y.mean(:min_count=>min_count)
340
- if ( xm.undef? or ym.undef? )
338
+ if ( xm == UNDEF or ym == UNDEF )
341
339
  return fill_value || UNDEF
342
340
  else
343
341
  return (x-xm).wsum(y-ym)/(count-1)
@@ -355,7 +353,7 @@ class CArray
355
353
  y.inherit_mask(x)
356
354
  xm = x.mean(:min_count=>min_count)
357
355
  ym = y.mean(:min_count=>min_count)
358
- if ( xm.undef? or ym.undef? )
356
+ if ( xm == UNDEF or ym == UNDEF )
359
357
  return fill_value || UNDEF
360
358
  else
361
359
  xd, yd = x-xm, y-ym
@@ -3,10 +3,8 @@
3
3
  # carray/math/histogram.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/math/recurrence.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/mkmf.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/object/ca_obj_iterator.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/object/ca_obj_link.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/object/ca_obj_pack.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/obsolete.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/ordering.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/serialize.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,8 +39,10 @@
41
39
  # has_attribute : int32
42
40
  #
43
41
  # offset 256 bytes
44
- # data : bytes*elements : value data
45
- # mask : int8*elements : mask data if has_mask == 1
42
+ # data : bytes*elements : value data
43
+ # mask : int8*elements : mask data if has_mask == 1
44
+ # attribute : object marshal : attribute
45
+ # data_class_name : string marshal : data_class_name
46
46
 
47
47
  require "stringio"
48
48
 
@@ -59,6 +59,7 @@ class CArray::Serializer # :nodoc:
59
59
  int32 :has_mask
60
60
  array :dim, :type => CArray.int64(CA_RANK_MAX)
61
61
  int32 :has_attr
62
+ int32 :has_data_class
62
63
  }
63
64
 
64
65
  Header_Legacy = CA.struct(:pack=>1, :size=>256) {
@@ -95,15 +96,16 @@ class CArray::Serializer # :nodoc:
95
96
  header[:ndim] = ca.ndim
96
97
  header[:elements] = ca.elements
97
98
  header[:has_mask] = ca.has_mask? ? 1 : 0
99
+ header[:has_data_class] = ca.has_data_class? ? 1 : 0
98
100
  header[:dim][[0,ca.ndim]] = ca.dim
99
- attr = nil
101
+ attributes = nil
100
102
  if ca.attribute
101
- attr = ca.attribute.clone
103
+ attributes = ca.attribute.clone
102
104
  end
103
105
  if opt[:attribute]
104
- (attr ||= {}).update(opt[:attribute])
106
+ (attributes ||= {}).update(opt[:attribute])
105
107
  end
106
- header[:has_attr] = attr.empty? ? 0 : 1
108
+ header[:has_attr] = attributes.empty? ? 0 : 1
107
109
  unless CArray.endian == endian
108
110
  header.swap_bytes!
109
111
  end
@@ -121,8 +123,11 @@ class CArray::Serializer # :nodoc:
121
123
  if ca.has_mask?
122
124
  ca.mask.dump_binary(@io)
123
125
  end
124
- if attr
125
- Marshal.dump(attr, @io)
126
+ if attributes
127
+ Marshal.dump(attributes, @io)
128
+ end
129
+ if ca.has_data_class?
130
+ Marshal.dump(ca.data_class.to_s, @io)
126
131
  end
127
132
  return ca
128
133
  end
@@ -151,7 +156,8 @@ class CArray::Serializer # :nodoc:
151
156
  elements = header[:elements]
152
157
  has_mask = header[:has_mask] != 0 ? true : false
153
158
  dim = header[:dim][[0, ndim]].to_a
154
- has_attr = header[:has_attr]
159
+ has_attr = header[:has_attr] != 0 ? true : false
160
+ has_data_class = header[:has_data_class] != 0 ? true : false
155
161
  if data_type == 255
156
162
  data_type = header[:data_type_name].strip.to_sym
157
163
  end
@@ -172,9 +178,12 @@ class CArray::Serializer # :nodoc:
172
178
  ca.mask = 0
173
179
  ca.mask.load_binary(@io)
174
180
  end
175
- if has_attr == 1
181
+ if has_attr
176
182
  ca.attribute = Marshal.load(@io)
177
183
  end
184
+ if has_data_class
185
+ ca.data_class = Kernel.const_get(Marshal.load(@io))
186
+ end
178
187
  return ca
179
188
  end
180
189
 
@@ -3,10 +3,8 @@
3
3
  # carray/string.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,19 +3,17 @@
3
3
  # carray/struct.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
  #
13
11
  # The data class for fixed length carray are required to satisfy only
14
- # four conditions.
12
+ # five conditions.
15
13
  #
16
14
  # * constant data_class::DATA_SIZE -> integer
17
- # * constant data_class::MEMBERS -> array of string
18
15
  # * constant data_class::MEMBER_TABLE -> hash
16
+ # * constant data_class::MEMBERS -> array (MEMBER_TABLE.keys as usual)
19
17
  # * method data_class.decode(data) -> new data_class object
20
18
  # * method data_class#encode() -> string
21
19
  #
@@ -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
@@ -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