scaleMatrixGPU function

GPUTensor<Matrix> scaleMatrixGPU(
  1. GPUTensor<Matrix> m,
  2. double s,
  3. CommandBuffer tape, {
  4. GPUTensor<Matrix>? outTensor,
})

Appends commands for additions of a scalar constant s to every element of matrix m to tape.

Implementation

GPUTensor<Matrix> scaleMatrixGPU(
    GPUTensor<Matrix> m, double s, CommandBuffer tape,
    {GPUTensor<Matrix>? outTensor}) {
  int numRows = m.shape[0];
  int numCols = m.shape[1];

  GPUTensor<Matrix> out =
      outTensor ?? GPUTensor<Matrix>.empty(<int>[numRows, numCols]);

  tape.putInt(OP_SCALE_MATRIX);
  tape.putString(m.id);
  tape.putString(out.id);
  tape.putFloat(s);

  out.creator = GPUNode(
    [m],
    (CommandBuffer bTape) {
      bTape.putInt(OP_SCALE_MATRIX_BACKWARD);
      bTape.putString(out.gradId);
      bTape.putString(m.gradId);
      bTape.putFloat(s);
    },
    opName: 'scaleMatrixGPU',
    cost: numRows * numCols,
    extraParams: {'s': s},
  );

  return out;
}