pitrou commented on code in PR #47586:
URL: https://github.com/apache/arrow/pull/47586#discussion_r2409959105
##########
cpp/src/arrow/sparse_tensor_test.cc:
##########
@@ -413,6 +413,99 @@ TEST_F(TestSparseCOOTensor, TestToTensor) {
ASSERT_TRUE(tensor.Equals(*dense_tensor));
}
+template <typename ValueType>
+class TestSparseCOOTensorCreationFromNegativeZero
+ : public TestSparseTensorBase<ValueType> {
+ public:
+ using ValueCType = typename ValueType::c_type;
+
+ void SetUp() override { type_ = TypeTraits<ValueType>::type_singleton(); }
+
+ void FromVector() {
+ std::vector<ValueCType> data{
+ -0.0, -0.0, 0.0, -0.0, 4.0, +0.0, -0.0, -0.0, -0.0, -1.0, 0.0, -0.0,
+ };
+ std::vector<int64_t> shape = {12};
+ auto buffer = Buffer::FromVector(data);
+ ASSERT_OK_AND_ASSIGN(auto dense_tensor, Tensor::Make(type_, buffer,
shape));
+ ASSERT_OK_AND_ASSIGN(auto sparse_coo_tensor,
+ SparseCOOTensor::Make(*dense_tensor, int64()));
+ ASSERT_EQ(2, sparse_coo_tensor->non_zero_length());
+ auto si =
+
internal::checked_pointer_cast<SparseCOOIndex>(sparse_coo_tensor->sparse_index());
+ AssertCOOIndex(si->indices(), 0, {4});
+ AssertCOOIndex(si->indices(), 1, {9});
+ ASSERT_OK_AND_ASSIGN(auto new_tensor, sparse_coo_tensor->ToTensor());
+ ASSERT_TRUE(new_tensor->Equals(*dense_tensor));
Review Comment:
Can you please call `Tensor::Validate` on `new_tensor`?
##########
cpp/src/arrow/sparse_tensor_test.cc:
##########
@@ -413,6 +413,99 @@ TEST_F(TestSparseCOOTensor, TestToTensor) {
ASSERT_TRUE(tensor.Equals(*dense_tensor));
}
+template <typename ValueType>
+class TestSparseCOOTensorCreationFromNegativeZero
+ : public TestSparseTensorBase<ValueType> {
+ public:
+ using ValueCType = typename ValueType::c_type;
+
+ void SetUp() override { type_ = TypeTraits<ValueType>::type_singleton(); }
+
+ void FromVector() {
+ std::vector<ValueCType> data{
+ -0.0, -0.0, 0.0, -0.0, 4.0, +0.0, -0.0, -0.0, -0.0, -1.0, 0.0, -0.0,
+ };
+ std::vector<int64_t> shape = {12};
+ auto buffer = Buffer::FromVector(data);
+ ASSERT_OK_AND_ASSIGN(auto dense_tensor, Tensor::Make(type_, buffer,
shape));
+ ASSERT_OK_AND_ASSIGN(auto sparse_coo_tensor,
+ SparseCOOTensor::Make(*dense_tensor, int64()));
+ ASSERT_EQ(2, sparse_coo_tensor->non_zero_length());
Review Comment:
Ok, so negative zeros are lost in translation?
##########
cpp/src/arrow/sparse_tensor_test.cc:
##########
@@ -413,6 +413,99 @@ TEST_F(TestSparseCOOTensor, TestToTensor) {
ASSERT_TRUE(tensor.Equals(*dense_tensor));
}
+template <typename ValueType>
+class TestSparseCOOTensorCreationFromNegativeZero
+ : public TestSparseTensorBase<ValueType> {
+ public:
+ using ValueCType = typename ValueType::c_type;
+
+ void SetUp() override { type_ = TypeTraits<ValueType>::type_singleton(); }
+
+ void FromVector() {
+ std::vector<ValueCType> data{
+ -0.0, -0.0, 0.0, -0.0, 4.0, +0.0, -0.0, -0.0, -0.0, -1.0, 0.0, -0.0,
+ };
+ std::vector<int64_t> shape = {12};
+ auto buffer = Buffer::FromVector(data);
+ ASSERT_OK_AND_ASSIGN(auto dense_tensor, Tensor::Make(type_, buffer,
shape));
+ ASSERT_OK_AND_ASSIGN(auto sparse_coo_tensor,
+ SparseCOOTensor::Make(*dense_tensor, int64()));
+ ASSERT_EQ(2, sparse_coo_tensor->non_zero_length());
+ auto si =
+
internal::checked_pointer_cast<SparseCOOIndex>(sparse_coo_tensor->sparse_index());
+ AssertCOOIndex(si->indices(), 0, {4});
+ AssertCOOIndex(si->indices(), 1, {9});
+ ASSERT_OK_AND_ASSIGN(auto new_tensor, sparse_coo_tensor->ToTensor());
+ ASSERT_TRUE(new_tensor->Equals(*dense_tensor));
+ }
+
+ void FromContiguousTensor() {
+ // clang-format off
+ std::vector<ValueCType> data{
+ -0.0, 0.0, -0.0,
+ +0.0, 4.0, -0.0,
+ -0.0, -0.0, 0.0,
+ -1.0, -0.0, -0.0,
+ };
+ // clang-format on
+ std::vector<int64_t> shape = {4, 3};
+ auto buffer = Buffer::FromVector(data);
+ ASSERT_OK_AND_ASSIGN(auto dense_tensor, Tensor::Make(type_, buffer,
shape));
+ ASSERT_OK_AND_ASSIGN(auto sparse_coo_tensor,
+ SparseCOOTensor::Make(*dense_tensor, int64()));
+ ASSERT_EQ(2, sparse_coo_tensor->non_zero_length());
+ auto si =
+
internal::checked_pointer_cast<SparseCOOIndex>(sparse_coo_tensor->sparse_index());
+ AssertCOOIndex(si->indices(), 0, {1, 1});
+ AssertCOOIndex(si->indices(), 1, {3, 0});
+ ASSERT_OK_AND_ASSIGN(auto new_tensor, sparse_coo_tensor->ToTensor());
+ ASSERT_TRUE(new_tensor->Equals(*dense_tensor));
Review Comment:
Same here and below, obviously.
--
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]