class

Torch::Tensor

Inherits Reference < Object

Constructors

load(filename : String) : self
Source
new(c_tensor : TorchSys::CTensor, owned : Bool = true)
Source
of(values : Slice(T), shape : Array(Int64) | Array(Int32)) : self forall T

Creates a tensor from a contiguous slice of numbers, inferring the kind from the element type.

Source
of(values : Array(Array(T)), shape : Array(Int64) | Array(Int32)) : self forall T
Source
of(values : Array(T), shape) : self forall T
Source
of(values : Array(T) | Slice(T)) : self forall T
Source
zeros(shape, kind : Kind = Kind::Float32) : self

Zero-filled tensor of the given kind and shape.

Source

Instance methods

[](index : Int) : Tensor
Source
[]=(indexes : Array(Int32), value : Float64) : Nil
Source
[]=(indexes : Array(Int32), value : Int64) : Nil
Source
backward(keep_graph : Bool = false, create_graph : Bool = false) : Nil
Source
c_tensor
Source
contiguous?
Source
copy_from(other : Tensor) : self
Source
copy_to(buf : Slice(T)) : Nil forall T

Copies the tensor data into out; the buffer must be at least size elements long and match the tensor's element size. Non-CPU tensors are moved to CPU first.

Source
data_ptr
Source
defined?
Source
device
Source
fill!(value : Float64) : self
Source
fill!(value : Int64) : self
Source
finalize
Source
inspect(io : IO) : Nil

Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
Source
item

Scalar value of a single-element tensor (or at the given indexes).

Source
kind
Source
owned?
Source
requires_grad?
Source
save(filename : String) : Nil
Source
shallow_clone
Source
shape
Source
size
Source
sparse?
Source
strides
Source
to(device : Device) : Tensor

Returns a new tensor on the target device (e.g. Device.cuda(0)).

Source
to(kind : Kind) : Tensor
Source
to_f32
Source
to_f64
Source
to_i64
Source
to_s(io : IO) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Source
value_at(indexes : Array(Int64) | Nil) : Float64
Source
value_i64_at(indexes : Array(Int64) | Nil) : Int64
Source