tanh3DGPU function
Implementation
GPUTensor<Tensor3D> tanh3DGPU(GPUTensor<Tensor3D> t, CommandBuffer tape) {
int depth = t.shape[0];
int height = t.shape[1];
int width = t.shape[2];
List<List<List<double>>> zeros = <List<List<double>>>[];
for (int c = 0; c < depth; c = c + 1) {
List<List<double>> channel = <List<double>>[];
for (int h = 0; h < height; h = h + 1) {
List<double> row = <double>[];
for (int w = 0; w < width; w = w + 1) {
row.add(0.0);
}
channel.add(row);
}
zeros.add(channel);
}
GPUTensor<Tensor3D> out = GPUTensor<Tensor3D>(zeros);
tape.putInt(OP_TANH);
tape.putString(t.id);
tape.putString(out.id);
out.creator = GPUNode(
<GPUTensor>[t],
(CommandBuffer bTape) {
bTape.putInt(OP_TANH_BACKWARD);
bTape.putString(out.id);
bTape.putString('${out.id}_grad');
bTape.putString('${t.id}_grad');
},
opName: 'tanh_3dGPU',
cost: depth * height * width,
);
return out;
}