small fix reshape return
This commit is contained in:
parent
a45b930075
commit
8449575e70
4 changed files with 6 additions and 6 deletions
Binary file not shown.
|
|
@ -127,6 +127,7 @@ void zeros_like_tensor_cpu(Tensor* tensor, float* result_data) {
|
|||
}
|
||||
}*/
|
||||
|
||||
|
||||
void transpose_tensor_cpu(Tensor* tensor, float* result_data) {
|
||||
int* shape = tensor->shape;
|
||||
int ndim = tensor->ndim;
|
||||
|
|
@ -146,7 +147,6 @@ void transpose_tensor_cpu(Tensor* tensor, float* result_data) {
|
|||
}
|
||||
result_data[idx_result] = tensor->data[idx_source];
|
||||
|
||||
// Update indices
|
||||
indices[ndim - 1]++;
|
||||
for (int dim = ndim - 1; dim > 0; dim--) {
|
||||
if (indices[dim] == shape[dim]) {
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ class Tensor:
|
|||
if requires_grad:
|
||||
self.grad_fn = ReshapeBackward(self)
|
||||
|
||||
return self
|
||||
return result_data
|
||||
|
||||
def to(self, device):
|
||||
self.device = device
|
||||
|
|
@ -392,7 +392,7 @@ class Tensor:
|
|||
|
||||
result_data = Tensor()
|
||||
result_data.tensor = result_tensor_ptr
|
||||
result_data.shape = self.shape[::-1]
|
||||
result_data.shape = self.shape.copy()[::-1]
|
||||
result_data.ndim = self.ndim
|
||||
result_data.device = self.device
|
||||
|
||||
|
|
|
|||
6
test.py
6
test.py
|
|
@ -58,9 +58,9 @@ if __name__ == "__main__":
|
|||
b = norch.Tensor([
|
||||
[1.234, 2.123, 1.5]])
|
||||
|
||||
print(a.shape)
|
||||
result = a.T
|
||||
print(result.shape)
|
||||
#print(a.shape)
|
||||
b = a.reshape([2,3,5])
|
||||
print(b.shape)
|
||||
#c = result.sum()
|
||||
#c.backward()
|
||||
#print(a.grad)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue