8000 More fixes to `MakeTensor::computeStorageSize()` (#158813) · pytorch/pytorch@ddd74d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit ddd74d1

Browse files
malfetpytorchmergebot
authored andcommitted
More fixes to MakeTensor::computeStorageSize() (#158813)
Followup after #158690 that fixessimilar logic if `strides` are not explicitly specified Expanded testing to cover both cases Pull Request resolved: #158813 Approved by: https://github.com/ZainRizvi, https://github.com/Skylion007, https://github.com/albanD ghstack dependencies: #158690
1 parent 823e223 commit ddd74d1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

aten/src/ATen/templates/Functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Tensor TensorMaker::make_tensor() {
7575
}
7676
auto storage_size = size * itemsize;
7777
if (storage_offset_) {
78-
storage_size += storage_offset_.value();
78+
storage_size += storage_offset_.value() * itemsize;
7979
}
8080
return storage_size;
8181
}

aten/src/ATen/test/basic.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,15 @@ TEST(BasicTest, BasicStdTestCPU) {
519519
}
520520

521521
TEST(BasicTest, TestForBlobResizeCPU) {
522+
// Checks that for_blob can correctly create tensors with non-empty offset and resize them
523+
std::array<int32_t, 6> storage;
524+
std::iota(storage.begin(), storage.end(), 1);
525+
auto t = at::for_blob(storage.data(), {3,}).storage_offset(3).options(c10::TensorOptions(kInt)).make_tensor();
526+
auto te = *at::expand_size(t, {3, 3});
527+
ASSERT_EQ(te[1][1].item<int32_t>(), 5);
528+
}
529+
530+
TEST(BasicTest, TestForBlobStridesResizeCPU) {
522531
// Checks that for_blob can correctly create tensors with non-empty offset and resize them
523532
std::array<int32_t, 6> storage;
524533
std::iota(storage.begin(), storage.end(), 1);

0 commit comments

Comments
 (0)
0