red-arrow 8.0.0 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/ext/arrow/converters.hpp +3 -0
  3. data/ext/arrow/extconf.rb +8 -4
  4. data/lib/arrow/array-builder.rb +40 -6
  5. data/lib/arrow/array-computable.rb +37 -0
  6. data/lib/arrow/array.rb +28 -0
  7. data/lib/arrow/chunked-array.rb +21 -0
  8. data/lib/arrow/column.rb +28 -0
  9. data/lib/arrow/data-type.rb +8 -3
  10. data/lib/arrow/decimal128-array-builder.rb +16 -6
  11. data/lib/arrow/decimal128.rb +14 -0
  12. data/lib/arrow/decimal256-array-builder.rb +16 -6
  13. data/lib/arrow/decimal256.rb +14 -0
  14. data/lib/arrow/field.rb +44 -3
  15. data/lib/arrow/list-data-type.rb +1 -6
  16. data/lib/arrow/loader.rb +3 -0
  17. data/lib/arrow/raw-table-converter.rb +6 -1
  18. data/lib/arrow/raw-tensor-converter.rb +89 -0
  19. data/lib/arrow/string-array-builder.rb +30 -0
  20. data/lib/arrow/tensor.rb +140 -0
  21. data/lib/arrow/time-unit.rb +31 -0
  22. data/lib/arrow/time32-array-builder.rb +2 -14
  23. data/lib/arrow/time32-data-type.rb +9 -38
  24. data/lib/arrow/time64-array-builder.rb +2 -14
  25. data/lib/arrow/time64-data-type.rb +9 -38
  26. data/lib/arrow/timestamp-array-builder.rb +2 -14
  27. data/lib/arrow/timestamp-data-type.rb +9 -34
  28. data/lib/arrow/version.rb +1 -1
  29. data/red-arrow.gemspec +1 -1
  30. data/test/raw-records/test-dictionary-array.rb +341 -0
  31. data/test/test-array-builder.rb +62 -0
  32. data/test/test-chunked-array.rb +6 -0
  33. data/test/test-column.rb +31 -0
  34. data/test/test-decimal128-array-builder.rb +14 -0
  35. data/test/test-decimal128-array.rb +5 -2
  36. data/test/test-decimal128.rb +26 -2
  37. data/test/test-decimal256-array-builder.rb +14 -0
  38. data/test/test-decimal256-array.rb +5 -2
  39. data/test/test-decimal256.rb +26 -2
  40. data/test/test-field.rb +26 -0
  41. data/test/test-orc.rb +2 -2
  42. data/test/test-table.rb +16 -0
  43. data/test/test-tensor.rb +243 -2
  44. data/test/values/test-dictionary-array.rb +30 -0
  45. metadata +15 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f43d3875f2e48876cd47533124a9fcf9559e263e63e3954c65fedd36b4e59744
4
- data.tar.gz: 2548f661536d3288f4ad8bb25d6587a78ee51d810a85a7d533ccdaf595439a12
3
+ metadata.gz: dc23de72fe60f7f6b71d45d4ec9019b0066da0de1aaef7992af984fa3ee14db3
4
+ data.tar.gz: 5383f405645f394c8af4b35ce537a82a54b207823a1debf755d09ef645bcbe15
5
5
  SHA512:
6
- metadata.gz: caeffbc164f14db7b056263f1ecd449afe2feec3ccbf7b883c147d415199c9ddc6c20398b00c34884248c103fbb7c55aa225719d8b8e75ac7f49337ee89d557e
7
- data.tar.gz: ae5a793e06b63bd80e3499f794193f47f72ff7510a558d2d0e61314068d5bd3a1986e5083bda749b00b73a4615901beb320521eeb360576b93fcb9a1e9d9510a
6
+ metadata.gz: cf9d0c9274059ab09a91af39573c5e4b1a902ca486038e61aff882441d725592bc4143821ba82607979ff09ea7cc9e5220efda1f12478e28b2cf9a9c89cff2d2
7
+ data.tar.gz: 4225c79d4eeb6770175624ef0eb4e90e263715a1d0b817bf34898ad179a85325f0d15e8fca6697d94870b6147bb965ab1644170fdae52eab07c37396214e5549
@@ -773,6 +773,9 @@ namespace red_arrow {
773
773
  VISIT(Time32)
774
774
  VISIT(Time64)
775
775
  VISIT(Timestamp)
776
+ VISIT(MonthInterval)
777
+ VISIT(DayTimeInterval)
778
+ VISIT(MonthDayNanoInterval)
776
779
  VISIT(List)
777
780
  VISIT(Struct)
778
781
  VISIT(Map)
data/ext/arrow/extconf.rb CHANGED
@@ -38,6 +38,8 @@ checking_for(checking_message("Homebrew")) do
38
38
  end
39
39
  end
40
40
 
41
+ $CXXFLAGS += " -std=c++17 "
42
+
41
43
  unless required_pkg_config_package([
42
44
  "arrow",
43
45
  Arrow::Version::MAJOR,
@@ -45,9 +47,10 @@ unless required_pkg_config_package([
45
47
  Arrow::Version::MICRO,
46
48
  ],
47
49
  debian: "libarrow-dev",
48
- redhat: "arrow-devel",
50
+ fedora: "libarrow-devel",
49
51
  homebrew: "apache-arrow",
50
- msys2: "arrow")
52
+ msys2: "arrow",
53
+ redhat: "arrow-devel")
51
54
  exit(false)
52
55
  end
53
56
 
@@ -58,9 +61,10 @@ unless required_pkg_config_package([
58
61
  Arrow::Version::MICRO,
59
62
  ],
60
63
  debian: "libarrow-glib-dev",
61
- redhat: "arrow-glib-devel",
64
+ fedora: "libarrow-glib-devel",
62
65
  homebrew: "apache-arrow-glib",
63
- msys2: "arrow")
66
+ msys2: "arrow",
67
+ redhat: "arrow-glib-devel")
64
68
  exit(false)
65
69
  end
66
70
 
@@ -33,6 +33,11 @@ module Arrow
33
33
  end
34
34
  if builder_info
35
35
  builder = builder_info[:builder]
36
+ if builder.nil? and builder_info[:builder_type]
37
+ builder = create_builder(builder_info)
38
+ end
39
+ end
40
+ if builder
36
41
  builder.build(values)
37
42
  else
38
43
  Arrow::StringArray.new(values)
@@ -121,15 +126,28 @@ module Arrow
121
126
  detected: true,
122
127
  }
123
128
  when BigDecimal
124
- if value.to_arrow.is_a?(Decimal128)
125
- {
126
- builder: Decimal128ArrayBuilder.new,
127
- }
128
- else
129
+ builder_info ||= {}
130
+ if builder_info[:builder] or value.nan? or value.infinite?
129
131
  {
130
- builder: Decimal256ArrayBuilder.new,
132
+ builder: StringArrayBuilder.new,
131
133
  detected: true,
132
134
  }
135
+ else
136
+ precision = [builder_info[:precision] || 0, value.precision].max
137
+ scale = [builder_info[:scale] || 0, value.scale].max
138
+ if precision <= Decimal128DataType::MAX_PRECISION
139
+ {
140
+ builder_type: :decimal128,
141
+ precision: precision,
142
+ scale: scale,
143
+ }
144
+ else
145
+ {
146
+ builder_type: :decimal256,
147
+ precision: precision,
148
+ scale: scale,
149
+ }
150
+ end
133
151
  end
134
152
  when ::Array
135
153
  sub_builder_info = nil
@@ -154,6 +172,22 @@ module Arrow
154
172
  }
155
173
  end
156
174
  end
175
+
176
+ def create_builder(builder_info)
177
+ builder_type = builder_info[:builder_type]
178
+ case builder_type
179
+ when :decimal128
180
+ data_type = Decimal128DataType.new(builder_info[:precision],
181
+ builder_info[:scale])
182
+ Decimal128ArrayBuilder.new(data_type)
183
+ when :decimal256
184
+ data_type = Decimal256DataType.new(builder_info[:precision],
185
+ builder_info[:scale])
186
+ Decimal256ArrayBuilder.new(data_type)
187
+ else
188
+ nil
189
+ end
190
+ end
157
191
  end
158
192
 
159
193
  def build(values)
@@ -0,0 +1,37 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ module ArrayComputable
20
+ def min(options: nil)
21
+ compute("min", options: options).value
22
+ end
23
+
24
+ def max(options: nil)
25
+ compute("max", options: options).value
26
+ end
27
+
28
+ def uniq
29
+ unique.values
30
+ end
31
+
32
+ private
33
+ def compute(name, options: nil)
34
+ Function.find(name).execute([self], options).value
35
+ end
36
+ end
37
+ end
data/lib/arrow/array.rb CHANGED
@@ -18,6 +18,8 @@
18
18
  module Arrow
19
19
  class Array
20
20
  include Enumerable
21
+
22
+ include ArrayComputable
21
23
  include GenericFilterable
22
24
  include GenericTakeable
23
25
 
@@ -34,6 +36,28 @@ module Arrow
34
36
  return nil unless const_defined?(builder_class_name)
35
37
  const_get(builder_class_name)
36
38
  end
39
+
40
+ # @api private
41
+ def try_convert(value)
42
+ case value
43
+ when ::Array
44
+ begin
45
+ new(value)
46
+ rescue ArgumentError
47
+ nil
48
+ end
49
+ else
50
+ if value.respond_to?(:to_arrow_array)
51
+ begin
52
+ value.to_arrow_array
53
+ rescue RangeError
54
+ nil
55
+ end
56
+ else
57
+ nil
58
+ end
59
+ end
60
+ end
37
61
  end
38
62
 
39
63
  # @param i [Integer]
@@ -87,6 +111,10 @@ module Arrow
87
111
  self
88
112
  end
89
113
 
114
+ def to_arrow_array
115
+ self
116
+ end
117
+
90
118
  alias_method :value_data_type_raw, :value_data_type
91
119
  def value_data_type
92
120
  @value_data_type ||= value_data_type_raw
@@ -18,6 +18,8 @@
18
18
  module Arrow
19
19
  class ChunkedArray
20
20
  include Enumerable
21
+
22
+ include ArrayComputable
21
23
  include GenericFilterable
22
24
  include GenericTakeable
23
25
 
@@ -87,5 +89,24 @@ module Arrow
87
89
  first_chunk.class.new(to_a)
88
90
  end
89
91
  end
92
+
93
+ def count(options: nil)
94
+ compute("count", options: options).value
95
+ end
96
+
97
+ def sum(options: nil)
98
+ compute("sum", options: options).value
99
+ end
100
+
101
+ def unique
102
+ compute("unique")
103
+ end
104
+
105
+ def cast(target_data_type, options: nil)
106
+ casted_chunks = chunks.collect do |chunk|
107
+ chunk.cast(target_data_type, options)
108
+ end
109
+ self.class.new(casted_chunks)
110
+ end
90
111
  end
91
112
  end
data/lib/arrow/column.rb CHANGED
@@ -72,5 +72,33 @@ module Arrow
72
72
  @field == other.field and
73
73
  @data == other.data
74
74
  end
75
+
76
+ def count(options: nil)
77
+ @data.count(options: options)
78
+ end
79
+
80
+ def sum(options: nil)
81
+ @data.sum(options: options)
82
+ end
83
+
84
+ def min(options: nil)
85
+ @data.min(options: options)
86
+ end
87
+
88
+ def max(options: nil)
89
+ @data.max(options: options)
90
+ end
91
+
92
+ def unique
93
+ @data.unique
94
+ end
95
+
96
+ def uniq
97
+ @data.uniq
98
+ end
99
+
100
+ def cast(target_data_type, options: nil)
101
+ @data.cast(target_data_type, options: options)
102
+ end
75
103
  end
76
104
  end
@@ -110,7 +110,7 @@ module Arrow
110
110
  description[key] = value
111
111
  end
112
112
  end
113
- if type.nil?
113
+ if type.nil? and self == DataType
114
114
  message =
115
115
  "data type description must have :type value: #{data_type.inspect}"
116
116
  raise ArgumentError, message
@@ -152,6 +152,7 @@ module Arrow
152
152
 
153
153
  private
154
154
  def resolve_class(data_type)
155
+ return self if data_type.nil?
155
156
  components = data_type.to_s.split("_").collect(&:capitalize)
156
157
  data_type_name = components.join.gsub(/\AUint/, "UInt")
157
158
  data_type_class_name = "#{data_type_name}DataType"
@@ -187,9 +188,13 @@ module Arrow
187
188
  end
188
189
  end
189
190
 
190
- def build_array(values)
191
+ def array_class
191
192
  base_name = self.class.name.gsub(/DataType\z/, "")
192
- builder_class = self.class.const_get("#{base_name}ArrayBuilder")
193
+ ::Arrow.const_get("#{base_name}Array")
194
+ end
195
+
196
+ def build_array(values)
197
+ builder_class = array_class.builder_class
193
198
  args = [values]
194
199
  args.unshift(self) unless builder_class.buildable?(args)
195
200
  builder_class.build(*args)
@@ -42,16 +42,26 @@ module Arrow
42
42
  end
43
43
 
44
44
  private
45
+ def precision
46
+ @precision ||= value_data_type.precision
47
+ end
48
+
49
+ def scale
50
+ @scale ||= value_data_type.scale
51
+ end
52
+
45
53
  def normalize_value(value)
46
54
  case value
47
- when String
48
- Decimal128.new(value)
49
- when Float
50
- Decimal128.new(value.to_s)
51
55
  when BigDecimal
52
- Decimal128.new(value.to_s)
56
+ if value.nan? or value.infinite?
57
+ message = "can't use #{value} as an Arrow::Decimal128Array value"
58
+ raise FloatDomainError, message
59
+ end
60
+ integer, decimal = value.to_s("f").split(".", 2)
61
+ decimal = decimal[0, scale].ljust(scale, "0")
62
+ Decimal128.new("#{integer}.#{decimal}")
53
63
  else
54
- value
64
+ Decimal128.try_convert(value) || value
55
65
  end
56
66
  end
57
67
  end
@@ -17,6 +17,20 @@
17
17
 
18
18
  module Arrow
19
19
  class Decimal128
20
+ class << self
21
+ # @api private
22
+ def try_convert(value)
23
+ case value
24
+ when String
25
+ new(value)
26
+ when Float
27
+ new(value.to_s)
28
+ else
29
+ nil
30
+ end
31
+ end
32
+ end
33
+
20
34
  alias_method :to_s_raw, :to_s
21
35
 
22
36
  # @overload to_s
@@ -45,16 +45,26 @@ module Arrow
45
45
  end
46
46
 
47
47
  private
48
+ def precision
49
+ @precision ||= value_data_type.precision
50
+ end
51
+
52
+ def scale
53
+ @scale ||= value_data_type.scale
54
+ end
55
+
48
56
  def normalize_value(value)
49
57
  case value
50
- when String
51
- Decimal256.new(value)
52
- when Float
53
- Decimal256.new(value.to_s)
54
58
  when BigDecimal
55
- Decimal256.new(value.to_s)
59
+ if value.nan? or value.infinite?
60
+ message = "can't use #{value} as an Arrow::Decimal256Array value"
61
+ raise FloatDomainError, message
62
+ end
63
+ integer, decimal = value.to_s("f").split(".", 2)
64
+ decimal = decimal[0, scale].ljust(scale, "0")
65
+ Decimal256.new("#{integer}.#{decimal}")
56
66
  else
57
- value
67
+ Decimal256.try_convert(value) || value
58
68
  end
59
69
  end
60
70
  end
@@ -17,6 +17,20 @@
17
17
 
18
18
  module Arrow
19
19
  class Decimal256
20
+ class << self
21
+ # @api private
22
+ def try_convert(value)
23
+ case value
24
+ when String
25
+ new(value)
26
+ when Float
27
+ new(value.to_s)
28
+ else
29
+ nil
30
+ end
31
+ end
32
+ end
33
+
20
34
  alias_method :to_s_raw, :to_s
21
35
 
22
36
  # @overload to_s
data/lib/arrow/field.rb CHANGED
@@ -17,12 +17,28 @@
17
17
 
18
18
  module Arrow
19
19
  class Field
20
+ class << self
21
+ # @api private
22
+ def try_convert(value)
23
+ case value
24
+ when Hash
25
+ begin
26
+ new(value)
27
+ rescue ArgumentError
28
+ nil
29
+ end
30
+ else
31
+ nil
32
+ end
33
+ end
34
+ end
35
+
20
36
  alias_method :initialize_raw, :initialize
21
37
  private :initialize_raw
22
38
 
23
39
  # Creates a new {Arrow::Field}.
24
40
  #
25
- # @overload initialize(name, data_type)
41
+ # @overload initialize(name, data_type, nullable=false)
26
42
  #
27
43
  # @param name [String, Symbol] The name of the field.
28
44
  #
@@ -34,6 +50,11 @@ module Arrow
34
50
  # See {Arrow::DataType.resolve} how to specify data type
35
51
  # description.
36
52
  #
53
+ # @param nullable [Boolean, nil] (false) Whether the field may contain
54
+ # zero or more nulls.
55
+ #
56
+ # `nil` is processed as `true` (null may be contained).
57
+ #
37
58
  # @example Create a field with {Arrow::DataType}s
38
59
  # Arrow::Field.new("visible", Arrow::BooleanDataType.new)
39
60
  #
@@ -75,6 +96,11 @@ module Arrow
75
96
  # See {Arrow::DataType.resolve} how to specify data type
76
97
  # description.
77
98
  #
99
+ # @option description [Boolean, nil] :nullable Whether the field
100
+ # may contain zero or more nulls.
101
+ #
102
+ # `nil` is processed as `true` (null may be contained).
103
+ #
78
104
  # @example Create a field with {Arrow::DataType}s
79
105
  # Arrow::Field.new(name: "visible",
80
106
  # data_type: Arrow::BooleanDataType.new)
@@ -92,6 +118,7 @@ module Arrow
92
118
  name = nil
93
119
  data_type = nil
94
120
  data_type_description = {}
121
+ nullable = nil
95
122
  description.each do |key, value|
96
123
  key = key.to_sym
97
124
  case key
@@ -99,20 +126,34 @@ module Arrow
99
126
  name = value
100
127
  when :data_type
101
128
  data_type = DataType.resolve(value)
129
+ when :nullable
130
+ nullable = value
102
131
  else
103
132
  data_type_description[key] = value
104
133
  end
105
134
  end
106
135
  data_type ||= DataType.resolve(data_type_description)
107
136
  when 2
137
+ name = args[0]
138
+ data_type = args[1]
139
+ if data_type.is_a?(Hash)
140
+ data_type = data_type.dup
141
+ nullable = data_type.delete(:nullable)
142
+ else
143
+ nullable = nil
144
+ end
145
+ data_type = DataType.resolve(data_type)
146
+ when 3
108
147
  name = args[0]
109
148
  data_type = DataType.resolve(args[1])
149
+ nullable = args[2]
110
150
  else
111
- message = "wrong number of arguments (given #{n_args}, expected 1..2)"
151
+ message = "wrong number of arguments (given #{n_args}, expected 1..3)"
112
152
  raise ArgumentError, message
113
153
  end
154
+ nullable = true if nullable.nil?
114
155
 
115
- initialize_raw(name, data_type)
156
+ initialize_raw(name, data_type, nullable)
116
157
  end
117
158
  end
118
159
  end
@@ -107,12 +107,7 @@ module Arrow
107
107
  description = arg
108
108
  arg = description[:field]
109
109
  end
110
- if arg.is_a?(Hash)
111
- field_description = arg
112
- Field.new(field_description)
113
- else
114
- arg
115
- end
110
+ arg
116
111
  end
117
112
  end
118
113
  end
data/lib/arrow/loader.rb CHANGED
@@ -34,6 +34,7 @@ module Arrow
34
34
  end
35
35
 
36
36
  def require_libraries
37
+ require "arrow/array-computable"
37
38
  require "arrow/column-containable"
38
39
  require "arrow/field-containable"
39
40
  require "arrow/generic-filterable"
@@ -106,6 +107,7 @@ module Arrow
106
107
  require "arrow/source-node-options"
107
108
  require "arrow/sparse-union-data-type"
108
109
  require "arrow/string-dictionary-array-builder"
110
+ require "arrow/string-array-builder"
109
111
  require "arrow/struct-array"
110
112
  require "arrow/struct-array-builder"
111
113
  require "arrow/struct-data-type"
@@ -118,6 +120,7 @@ module Arrow
118
120
  require "arrow/table-saver"
119
121
  require "arrow/tensor"
120
122
  require "arrow/time"
123
+ require "arrow/time-unit"
121
124
  require "arrow/time32-array"
122
125
  require "arrow/time32-array-builder"
123
126
  require "arrow/time32-data-type"
@@ -35,7 +35,12 @@ module Arrow
35
35
  fields = []
36
36
  @values = []
37
37
  @raw_table.each do |name, array|
38
- array = ArrayBuilder.build(array) if array.is_a?(::Array)
38
+ if array.respond_to?(:to_arrow_array)
39
+ array = array.to_arrow_array
40
+ else
41
+ array = array.to_ary if array.respond_to?(:to_ary)
42
+ array = ArrayBuilder.build(array)
43
+ end
39
44
  fields << Field.new(name.to_s, array.value_data_type)
40
45
  @values << array
41
46
  end
@@ -0,0 +1,89 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module Arrow
19
+ class RawTensorConverter
20
+ attr_reader :data_type
21
+ attr_reader :data
22
+ attr_reader :shape
23
+ attr_reader :strides
24
+ attr_reader :dimension_names
25
+ def initialize(raw_tensor,
26
+ data_type: nil,
27
+ shape: nil,
28
+ strides: nil,
29
+ dimension_names: nil)
30
+ @raw_tensor = raw_tensor
31
+ @data_type = data_type
32
+ @data = nil
33
+ @shape = shape
34
+ @strides = strides
35
+ @dimension_names = dimension_names
36
+ convert
37
+ end
38
+
39
+ private
40
+ def convert
41
+ case @raw_tensor
42
+ when Buffer
43
+ @data = @raw_tensor
44
+ when String
45
+ unless @raw_tensor.encoding == Encoding::ASCII_8BIT
46
+ message = "raw tensor String must be an ASCII-8BIT encoded string: " +
47
+ "#{@raw_tensor.encoding.inspect}"
48
+ raise ArgumentError, message
49
+ end
50
+ @data = Arrow::Buffer.new(@raw_tensor)
51
+ else
52
+ @shape ||= guess_shape
53
+ build_buffer
54
+ unless @strides.nil?
55
+ message = "strides: is only accepted with " +
56
+ "an Arrow::Buffer or String raw tensor: #{@strides.inspect}"
57
+ raise ArgumentError, message
58
+ end
59
+ end
60
+ if @shape.nil?
61
+ raise ArgumentError, "shape: is missing: #{@raw_tensor.inspect}"
62
+ end
63
+ if @data_type.nil?
64
+ raise ArgumentError, "data_type: is missing: #{@raw_tensor.inspect}"
65
+ end
66
+ end
67
+
68
+ def guess_shape
69
+ shape = [@raw_tensor.size]
70
+ target = @raw_tensor[0]
71
+ while target.is_a?(::Array)
72
+ shape << target.size
73
+ target = target[0]
74
+ end
75
+ shape
76
+ end
77
+
78
+ def build_buffer
79
+ if @data_type
80
+ @data_type = DataType.resolve(@data_type)
81
+ array = @data_type.build_array(@raw_tensor.flatten)
82
+ else
83
+ array = Array.new(@raw_tensor.flatten)
84
+ @data_type = array.value_data_type
85
+ end
86
+ @data = array.data_buffer
87
+ end
88
+ end
89
+ end