Class: Executorch::Tensor
- Inherits:
-
Object
- Object
- Executorch::Tensor
- Defined in:
- lib/executorch.rb
Overview
Extend Tensor with Ruby-friendly methods
Class Method Summary collapse
-
.new(data, shape: nil, dtype: :float) ⇒ Tensor
Create a new tensor from data.
Instance Method Summary collapse
-
#to_a ⇒ Array
Convert tensor to a nested Ruby array matching the tensor’s shape.
Class Method Details
.new(data, shape: nil, dtype: :float) ⇒ Tensor
Create a new tensor from data
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/executorch.rb', line 31 def new(data, shape: nil, dtype: :float) if shape.nil? # Infer shape from nested array structure shape = infer_shape(data) flat_data = flatten_nested(data, shape) else # Use flat data directly (backward compatibility) flat_data = data end create(flat_data, shape, dtype) end |
Instance Method Details
#to_a ⇒ Array
Convert tensor to a nested Ruby array matching the tensor’s shape
125 126 127 128 |
# File 'lib/executorch.rb', line 125 def to_a flat = flat_to_a reshape_flat_to_nested(flat, shape) end |