Eager Tensor Operations #
PyTorch-style tensor operations recorded on the session's tape. Each one runs the CPU or the CUDA
kernel of the operation, as the session's device selects, and preserves the typed TensorRef
surface.
Shape and reduction operations #
def
Runtime.Autograd.Torch.Internal.EagerSession.sum
{α : Type}
[TorchLean.Storage α]
(s : EagerSession α)
[Add α]
[Zero α]
{sh : Spec.Shape}
(x : TensorRef α sh)
:
Sum-reduce all elements to a scalar. PyTorch: x.sum().
Instances For
def
Runtime.Autograd.Torch.Internal.EagerSession.flatten
{α : Type}
[TorchLean.Storage α]
(s : EagerSession α)
{sh : Spec.Shape}
(x : TensorRef α sh)
:
Flatten a tensor to a 1D vector. PyTorch: torch.flatten.
Instances For
def
Runtime.Autograd.Torch.Internal.EagerSession.reshape
{α : Type}
[TorchLean.Storage α]
(s : EagerSession α)
{sh1 sh2 : Spec.Shape}
(x : TensorRef α sh1)
(h : sh1.size = sh2.size)
:
Reshape a tensor while preserving total number of elements.
PyTorch comparison: torch.reshape / view (when valid).
Instances For
def
Runtime.Autograd.Torch.Internal.EagerSession.swapAdjacentAtDepth
{α : Type}
[TorchLean.Storage α]
(s : EagerSession α)
{sh : Spec.Shape}
(depth : ℕ)
(x : TensorRef α sh)
:
IO (TensorRef α (sh.swapAdjacentAtDepth depth))
Swap two adjacent axes at a given depth. PyTorch analogue: x.transpose(dim, dim+1).
Instances For
def
Runtime.Autograd.Torch.Internal.EagerSession.broadcastTo
{α : Type}
[TorchLean.Storage α]
(s : EagerSession α)
[Add α]
[Zero α]
{sh1 sh2 : Spec.Shape}
(cb : sh1.CanBroadcastTo sh2)
(x : TensorRef α sh1)
:
Broadcast a tensor to a larger shape. PyTorch: implicit broadcasting / expand.
Instances For
def
Runtime.Autograd.Torch.Internal.EagerSession.reduceSum
{α : Type}
[TorchLean.Storage α]
(s : EagerSession α)
[Add α]
[Zero α]
{sh : Spec.Shape}
(axis : ℕ)
[valid : Spec.Shape.HasNonemptyAxis axis sh]
[wf : sh.WellFormed]
(x : TensorRef α sh)
:
IO (TensorRef α (TorchLean.Tensor.shapeAfterSum sh axis))
Sum-reduce along axis. PyTorch: torch.sum(x, dim=axis).
Instances For
def
Runtime.Autograd.Torch.Internal.EagerSession.reduceMean
{α : Type}
[TorchLean.Storage α]
(s : EagerSession α)
[Add α]
[Zero α]
[Div α]
[Mul α]
[One α]
[NatCast α]
{sh : Spec.Shape}
(axis : ℕ)
[valid : Spec.Shape.HasNonemptyAxis axis sh]
[wf : sh.WellFormed]
(x : TensorRef α sh)
:
IO (TensorRef α (TorchLean.Tensor.shapeAfterSum sh axis))
Mean-reduce along axis. PyTorch: torch.mean(x, dim=axis).