Copilot commented on code in PR #50827:
URL: https://github.com/apache/arrow/pull/50827#discussion_r3801730963
##########
cpp/src/arrow/c/dlpack_test.cc:
##########
@@ -190,29 +265,47 @@ TEST_F(TestExportTensor, TestTensor) {
std::shared_ptr<Tensor> tensor = TensorFromJSON(
arrow_type, "[1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]",
shape);
- CheckDLTensor(tensor, arrow_type, dlpack_type, shape, dlpack_strides);
+ CheckDLTensor<TypeParam>(tensor, arrow_type, dlpack_type, shape,
dlpack_strides);
}
ASSERT_EQ(allocated_bytes, arrow::default_memory_pool()->bytes_allocated());
}
-TEST_F(TestExportTensor, TestTensorStrided) {
+TYPED_TEST(TestExportTensor, TestTensorReadOnly) {
+ const std::vector<int64_t> shape = {2, 2};
+ const std::vector<int64_t> dlpack_strides = {2, 1};
+ std::shared_ptr<Tensor> tensor = TensorFromJSON(float32(), "[1, 2, 3, 4]",
shape);
+ ASSERT_TRUE(tensor->is_mutable());
+
+ // Slicing yields an immutable view of the same data
+ ASSERT_OK_AND_ASSIGN(auto read_only_buffer, SliceBufferSafe(tensor->data(),
0));
+ ASSERT_OK_AND_ASSIGN(auto read_only_tensor,
+ Tensor::Make(float32(), read_only_buffer, shape));
+ ASSERT_FALSE(read_only_tensor->is_mutable());
+
+ CheckDLTensor<TypeParam>(read_only_tensor, float32(),
DLDataTypeCode::kDLFloat, shape,
+ dlpack_strides);
+}
Review Comment:
`TestTensorReadOnly` is instantiated for `LegacyProducer`, but
`ExportTensor()` intentionally returns `NotImplemented` for immutable tensors.
As written, this test will fail for the legacy producer type.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]