divideMatrixGPU function

GPUTensor<Matrix> divideMatrixGPU(
  1. GPUTensor<Matrix> a,
  2. GPUTensor<Matrix> b,
  3. CommandBuffer tape, {
  4. GPUTensor<Matrix>? outTensor,
})

Appends the commands for element wise division of two matrices a through b to tape. Creates and allocates a Tensor to store the results.

Implementation

GPUTensor<Matrix> divideMatrixGPU(
    GPUTensor<Matrix> a, GPUTensor<Matrix> b, CommandBuffer tape,
    {GPUTensor<Matrix>? outTensor}) {
  int numRows = a.shape[0];
  int numCols = a.shape[1];
  List<int> shape = <int>[numRows, numCols];
  GPUTensor<Matrix> out = outTensor ?? GPUTensor<Matrix>.empty(shape);

  tape.putInt(OP_DIVIDE);
  tape.putString(a.id);
  tape.putString(b.id);
  tape.putString(out.id);

  out.creator = GPUNode(
    <GPUTensor>[a, b],
    (CommandBuffer bTape) {
      bTape.putInt(OP_DIVIDE_BACKWARD);
      bTape.putString(a.id);
      bTape.putString(b.id);
      bTape.putString(out.gradId);
      bTape.putString(a.gradId);
      bTape.putString(b.gradId);
    },
    opName: 'divideMatrixGPU',
    cost: numRows * numCols,
  );

  return out;
}