addScalarVectorGPU function
Implementation
GPUTensor<Vector> addScalarVectorGPU(GPUTensor<Vector> v, double scalar, CommandBuffer tape) {
int length = v.shape[0];
GPUTensor<Vector> out = GPUTensor<Vector>.empty(<int>[length]);
tape.putInt(OP_ADD_SCALAR);
tape.putString(v.id);
tape.putString(out.id);
tape.putFloat(scalar);
out.creator = GPUNode(
<GPUTensor>[v],
(CommandBuffer bTape) {
// The derivative of (x + c) is 1, so the gradient passes directly through
bTape.putInt(OP_ADD_INTO);
bTape.putString('${out.id}_grad');
bTape.putString('${v.id}_grad');
},
opName: 'addScalarVectorGPU',
cost: length,
);
return out;
}