TorchLean API

NN.Runtime.Autograd.Torch.Core.Ops.ShapeReduction

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 #

Sum-reduce all elements to a scalar. PyTorch: x.sum().

Instances For

    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) :
      IO (TensorRef α sh2)

      Reshape a tensor while preserving total number of elements.

      PyTorch comparison: torch.reshape / view (when valid).

      Instances For

        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) :
          IO (TensorRef α sh2)

          Broadcast a tensor to a larger shape. PyTorch: implicit broadcasting / expand.

          Instances For

            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) :

              Mean-reduce along axis. PyTorch: torch.mean(x, dim=axis).

              Instances For