def operated

bendtorch-core@0.1.0.0 · src/autograd/tensor_backward.bend:1224

import bendtorch-core@0.1.0.0/src/autograd/tensor_backward.bend as TensorBackward
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/tensor/elementwise.bend as Elementwise
import bendtorch-core@0.1.0.0/src/tensor/matmul.bend as Matrix
import bendtorch-core@0.1.0.0/src/tensor/batched_matmul.bend as Batched
import bendtorch-core@0.1.0.0/src/autograd/loss.bend as Loss

1224def operated(kind: Binary, +a: Nat, +b: Nat, +left_shape: Shape.Shape, +right_shape: Shape.Shape, entries: List<&1, Entry>,
1225  left: Core.Dynamic, right: Core.Dynamic) -> Tape & Result<&2, &2, Error, Nat>:
1226  match kind:
1227    case Plus{}:
1228      dropped(Add{a, b, left_shape, right_shape}, entries, Elementwise.add(left, right))
1229    case Minus{}:
1230      dropped(Sub{a, b, left_shape, right_shape}, entries, Elementwise.sub(left, right))
1231    case Times{}:
1232      kept(Mul{a, b, left_shape, right_shape}, entries, Elementwise.mul(left, right))
1233    case Product{}:
1234      multiplied_record(Matmul{a, b, left_shape, right_shape}, entries, Matrix.matmul(left, right))
1235    case ProductNT{}:
1236      multiplied_record(MatmulNT{a, b, left_shape, right_shape}, entries, Matrix.matmul_nt(left, right))
1237    case SquaredError{}:
1238      loss_dropped(MseLoss{a, b, left_shape, right_shape}, entries, Loss.mse_loss(left, right))
1239    case BatchedProduct{}:
1240      batched_record(a, b, left_shape, right_shape, entries, left, right,
1241        Batched.both_matrices(left_shape, right_shape))

Uses (23)

Used by (1)