Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
df439e8
Initial commit
rok Aug 15, 2023
765bbf7
Add VariableShapeTensorArray::ToTensor(i)
rok Sep 3, 2023
46691b6
:Add ragged_dimensions
rok Sep 12, 2023
249cf9f
Replace ragged_dimensions with uniform_dimensions
rok Sep 15, 2023
b031c26
Add example for explanation
rok Sep 15, 2023
aeba04a
Add uniform_shape parameter
rok Sep 24, 2023
173656f
Apply suggestions from code review
rok Sep 25, 2023
7cd9ead
Post rebase
rok Oct 11, 2023
3bbdd46
Remove uniform_dimensions, fix python test
rok Oct 12, 2023
4692166
lint
rok Oct 12, 2023
835acea
uniform_shape values are optional
rok Oct 12, 2023
a3b82a6
Add scalar test
rok Oct 29, 2023
91547fd
Create Tensor from scalar
rok Oct 30, 2023
5bd975d
Move get_tensor logic to cpp
rok Nov 28, 2023
5342642
slice buffer with array offset
rok Nov 28, 2023
659e17c
Update cpp/src/arrow/extension/variable_shape_tensor.h
rok Nov 28, 2023
294479f
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Nov 28, 2023
8198d23
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Nov 28, 2023
ee7b50d
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Nov 28, 2023
bb42481
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Nov 28, 2023
d30cc80
Review feedback
rok Nov 28, 2023
1264a32
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Nov 29, 2023
0c66c31
Review feedback
rok Nov 29, 2023
d6dde83
import and uint32->int32
rok Nov 29, 2023
214ab1f
permutation check
rok Nov 29, 2023
6d4ef16
Remove serialization from cython, lint
rok Nov 29, 2023
d3560ea
Review feedback
rok Nov 30, 2023
2ab1f17
ndim initializer
rok Nov 30, 2023
43b08c2
Test null values
rok Nov 30, 2023
58d5828
Remove one GetTensor code paths, permutation handling
rok Dec 2, 2023
b5dd4f0
Allow arbitrary memory layout
rok Dec 3, 2023
3137e2d
fix permutation check
rok Dec 3, 2023
b6b00fa
lint
rok Dec 3, 2023
b46217f
lint
rok Dec 3, 2023
b7030e2
roundtrip strided
rok Dec 4, 2023
b2a1c34
Apply suggestions from code review
rok Dec 13, 2023
05c63bc
remove array.gettensor, simlify
rok Dec 13, 2023
845a041
work
rok Dec 14, 2023
6681085
Add repr
rok Dec 14, 2023
e1be1b5
Review feedback
rok Dec 14, 2023
e601dc8
GetTensor->MakeTensor, static
rok Dec 23, 2023
88601cc
Better permutations check
rok Dec 23, 2023
f1a7f52
post rebase changes
rok Feb 8, 2024
a88d1d9
work
rok Feb 9, 2024
674d870
ToString new parameter
rok Mar 4, 2024
d69a307
Remove Python bindings
rok Mar 4, 2024
84a93f0
Review feedback
rok Mar 16, 2024
3500b09
Use TensorFromJSON
rok Mar 16, 2024
3ca3f2e
lint
rok Mar 17, 2024
24056e0
Apply suggestions from code review
rok Mar 27, 2024
616a1fb
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Mar 27, 2024
1fad293
fix
rok Mar 27, 2024
2195f2e
Review feedback
rok Mar 27, 2024
d0e16f4
mingw64 issue
rok Mar 28, 2024
adec204
refactor ComputeStrides
rok Mar 29, 2024
419b7c2
Change to ComputeStrides
rok Apr 1, 2024
c699381
Change ToTensor
rok Apr 1, 2024
00c3c39
Refactoring ComputeStrides
rok Apr 2, 2024
faa527f
Move RoundtripBatch to gtest_util.cc
rok Apr 14, 2024
9649d2e
Post rebase changes
rok Jun 6, 2024
7032653
Post rebase changes
rok Sep 11, 2024
add3403
post rebase fixes
rok Nov 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,8 @@ if(ARROW_JSON)
arrow_add_object_library(ARROW_JSON
extension/fixed_shape_tensor.cc
extension/opaque.cc
extension/tensor_internal.cc
extension/variable_shape_tensor.cc
json/options.cc
json/chunked_builder.cc
json/chunker.cc
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/compute/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ arrow_install_all_headers("arrow/compute/kernels")

# Define arrow_compute_kernels_testing object library for common test files
if(ARROW_TESTING)
add_library(arrow_compute_kernels_testing OBJECT test_util_internal.cc)
add_library(arrow_compute_kernels_testing OBJECT
test_util_internal.cc ../../extension/tensor_extension_array_test.cc)
# Even though this is still just an object library we still need to "link" our
# dependencies so that include paths are configured correctly
target_link_libraries(arrow_compute_kernels_testing PUBLIC ${ARROW_GTEST_GMOCK})
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/extension/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
set(CANONICAL_EXTENSION_TESTS bool8_test.cc json_test.cc uuid_test.cc)

if(ARROW_JSON)
list(APPEND CANONICAL_EXTENSION_TESTS fixed_shape_tensor_test.cc opaque_test.cc)
list(APPEND CANONICAL_EXTENSION_TESTS tensor_extension_array_test.cc opaque_test.cc)
endif()

add_arrow_test(test
Expand Down
61 changes: 7 additions & 54 deletions cpp/src/arrow/extension/fixed_shape_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,7 @@

namespace rj = arrow::rapidjson;

namespace arrow {

namespace extension {

namespace {

Status ComputeStrides(const FixedWidthType& type, const std::vector<int64_t>& shape,
const std::vector<int64_t>& permutation,
std::vector<int64_t>* strides) {
if (permutation.empty()) {
return internal::ComputeRowMajorStrides(type, shape, strides);
}

const int byte_width = type.byte_width();

int64_t remaining = 0;
if (!shape.empty() && shape.front() > 0) {
remaining = byte_width;
for (auto i : permutation) {
if (i > 0) {
if (internal::MultiplyWithOverflow(remaining, shape[i], &remaining)) {
return Status::Invalid(
"Strides computed from shape would not fit in 64-bit integer");
}
}
}
}

if (remaining == 0) {
strides->assign(shape.size(), byte_width);
return Status::OK();
}

strides->push_back(remaining);
for (auto i : permutation) {
if (i > 0) {
remaining /= shape[i];
strides->push_back(remaining);
}
}
internal::Permute(permutation, strides);

return Status::OK();
}

} // namespace
namespace arrow::extension {

bool FixedShapeTensorType::ExtensionEquals(const ExtensionType& other) const {
if (extension_name() != other.extension_name()) {
Expand Down Expand Up @@ -237,7 +192,8 @@ Result<std::shared_ptr<Tensor>> FixedShapeTensorType::MakeTensor(
}

std::vector<int64_t> strides;
RETURN_NOT_OK(ComputeStrides(value_type, shape, permutation, &strides));
RETURN_NOT_OK(
internal::ComputeStrides(ext_type.value_type(), shape, permutation, &strides));
const auto start_position = array->offset() * byte_width;
const auto size = std::accumulate(shape.begin(), shape.end(), static_cast<int64_t>(1),
std::multiplies<>());
Expand Down Expand Up @@ -376,9 +332,8 @@ const Result<std::shared_ptr<Tensor>> FixedShapeTensorArray::ToTensor() const {
internal::Permute<int64_t>(permutation, &shape);

std::vector<int64_t> tensor_strides;
const auto* fw_value_type = internal::checked_cast<FixedWidthType*>(value_type.get());
ARROW_RETURN_NOT_OK(
ComputeStrides(*fw_value_type, shape, permutation, &tensor_strides));
internal::ComputeStrides(value_type, shape, permutation, &tensor_strides));

const auto& raw_buffer = this->storage()->data()->child_data[0]->buffers[1];
ARROW_ASSIGN_OR_RAISE(
Expand Down Expand Up @@ -412,10 +367,9 @@ Result<std::shared_ptr<DataType>> FixedShapeTensorType::Make(

const std::vector<int64_t>& FixedShapeTensorType::strides() {
if (strides_.empty()) {
auto value_type = internal::checked_cast<FixedWidthType*>(this->value_type_.get());
std::vector<int64_t> tensor_strides;
ARROW_CHECK_OK(
ComputeStrides(*value_type, this->shape(), this->permutation(), &tensor_strides));
ARROW_CHECK_OK(internal::ComputeStrides(this->value_type_, this->shape(),
this->permutation(), &tensor_strides));
strides_ = tensor_strides;
}
return strides_;
Expand All @@ -430,5 +384,4 @@ std::shared_ptr<DataType> fixed_shape_tensor(const std::shared_ptr<DataType>& va
return maybe_type.MoveValueUnsafe();
}

} // namespace extension
} // namespace arrow
} // namespace arrow::extension
6 changes: 2 additions & 4 deletions cpp/src/arrow/extension/fixed_shape_tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

#include "arrow/extension_type.h"

namespace arrow {
namespace extension {
namespace arrow::extension {

class ARROW_EXPORT FixedShapeTensorArray : public ExtensionArray {
public:
Expand Down Expand Up @@ -126,5 +125,4 @@ ARROW_EXPORT std::shared_ptr<DataType> fixed_shape_tensor(
const std::vector<int64_t>& permutation = {},
const std::vector<std::string>& dim_names = {});

} // namespace extension
} // namespace arrow
} // namespace arrow::extension
Loading
Loading