reshapeVectorToMatrix function
Implementation
Tensor<Matrix> reshapeVectorToMatrix(Tensor<Vector> v, int numRows, int numCols) {
Vector vVec = v.value;
Matrix outValue = [];
int index = 0;
for (int i = 0; i < numRows; i = i + 1) {
Vector row = [];
for (int j = 0; j < numCols; j = j + 1) {
row.add(vVec[index]);
index = index + 1;
}
outValue.add(row);
}
Tensor<Matrix> out = Tensor<Matrix>(outValue);
out.creator = Node(
[v],
() {
int length = v.data.length;
for (int i = 0; i < length; i = i + 1) {
v.grad[i] = v.grad[i] + out.grad[i];
}
},
opName: 'reshape',
extraParams: {'numRows': numRows, 'numCols': numCols},
cost: 0,
);
return out;
}