def one_hot

bendtorch-core@0.1.0.0 · src/autograd/loss.bend:296

import bendtorch-core@0.1.0.0/src/autograd/loss.bend as Loss
import Base
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core

296# The one-hot rows of the targets, [rows, columns]: 1.0 where the column is
297# the row's target, +0.0 elsewhere. The [rows, 1] targets and the [1, columns]
298# class numbers broadcast against each other with Matches, which compares
299# their words. With no rows the one-hot rows are empty, and the class
300# numbers are not built: [1, columns] could exceed the capacity that
301# [0, columns] does not.
302def one_hot(+targets: List<&2, U32>, +rows: Nat, +columns: Nat) -> Result<&2, &1, Core.Error, Core.Dynamic>:
303  match rows:
304    case 0n:
305      Core.construct([0, U32.from_nat(columns)], Nil{})
306    case 1n+less:
307      one_hot_pair(Core.construct([U32.from_nat(1n+less), 1], as_words(targets)),
308        Core.construct([1, U32.from_nat(columns)], classes(columns, 0n)))

Uses (11)

Used by (1)