small fix reshape return

This commit is contained in:
lucasdelimanogueira 2024-05-03 13:18:37 -03:00
parent a45b930075
commit 8449575e70
4 changed files with 6 additions and 6 deletions

View file

@ -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]) {

View file

@ -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

View file

@ -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)