File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -519,6 +519,15 @@ TEST(BasicTest, BasicStdTestCPU) {
519519}
520520
521521TEST (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 );
You can’t perform that action at this time.
0 commit comments