struct

ML::Shape

Inherits Struct / Value / Object

Immutable shape descriptor

Constants

MAX_DIMS = 8

Constructors

new(dimensions : Array(Int32))
Source
new(*dimensions : Int32)
Source

Instance methods

==(other : Shape) : Bool

Shape equality

Source
[](index : Int32) : Int32

Access dimension by index (supports negative indices)

Source
broadcast_with(other : Shape) : Shape

Compute broadcast result shape

Source
broadcastable_with?(other : Shape) : Bool

Check if shapes are broadcastable

Source
can_reshape_to?(new_shape : Shape) : Bool

Reshape validation

Source
dims
Source
each

Iterate over dimensions

Source
each_with_index
Source
inspect(io : IO) : Nil

Appends this struct's name and instance variables names and values to the given IO.

struct Point
  def initialize(@x : Int32, @y : Int32)
  end
end

p1 = Point.new 1, 2
p1.to_s    # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
Source
ndim
Source
numel

Total number of elements

Source
to_a

Convert to array

Source
to_s(io : IO) : Nil

String representation

Source