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
644eaa8
Initial commit
rok Aug 15, 2023
5b1c0f6
Add VariableShapeTensorArray::ToTensor(i)
rok Sep 3, 2023
2b5b81e
:Add ragged_dimensions
rok Sep 12, 2023
5d06f95
Replace ragged_dimensions with uniform_dimensions
rok Sep 15, 2023
dbb4993
Add example for explanation
rok Sep 15, 2023
5848306
Add uniform_shape parameter
rok Sep 24, 2023
adcb51c
Apply suggestions from code review
rok Sep 25, 2023
d00fe2d
Post rebase
rok Oct 11, 2023
5309baf
Remove uniform_dimensions, fix python test
rok Oct 12, 2023
04edd4b
lint
rok Oct 12, 2023
c05d93f
uniform_shape values are optional
rok Oct 12, 2023
910c736
Add scalar test
rok Oct 29, 2023
1d157e7
Create Tensor from scalar
rok Oct 30, 2023
5f3101b
Move get_tensor logic to cpp
rok Nov 28, 2023
01d084c
slice buffer with array offset
rok Nov 28, 2023
c649f98
Update cpp/src/arrow/extension/variable_shape_tensor.h
rok Nov 28, 2023
6c27363
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Nov 28, 2023
372a245
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Nov 28, 2023
bc062d1
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Nov 28, 2023
e5db81e
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Nov 28, 2023
b7f9094
Review feedback
rok Nov 28, 2023
58a3b5a
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Nov 29, 2023
0eff367
Review feedback
rok Nov 29, 2023
fa2689e
import and uint32->int32
rok Nov 29, 2023
1b91b51
permutation check
rok Nov 29, 2023
75185a2
Remove serialization from cython, lint
rok Nov 29, 2023
195d132
Review feedback
rok Nov 30, 2023
85fa3dd
ndim initializer
rok Nov 30, 2023
fdf22fb
Test null values
rok Nov 30, 2023
e069ef1
Remove one GetTensor code paths, permutation handling
rok Dec 2, 2023
ecd7b78
Allow arbitrary memory layout
rok Dec 3, 2023
a31ea20
fix permutation check
rok Dec 3, 2023
f210e33
lint
rok Dec 3, 2023
b4408c9
lint
rok Dec 3, 2023
8781c4e
roundtrip strided
rok Dec 4, 2023
9d42a09
Apply suggestions from code review
rok Dec 13, 2023
a11c96f
remove array.gettensor, simlify
rok Dec 13, 2023
fdfe7f1
work
rok Dec 14, 2023
7ec2e9d
Add repr
rok Dec 14, 2023
994ce76
Review feedback
rok Dec 14, 2023
670904f
GetTensor->MakeTensor, static
rok Dec 23, 2023
0af89f9
Better permutations check
rok Dec 23, 2023
adfe6cb
post rebase changes
rok Feb 8, 2024
7501925
work
rok Feb 9, 2024
7bfda3c
ToString new parameter
rok Mar 4, 2024
2a794b0
Remove Python bindings
rok Mar 4, 2024
88de17f
Review feedback
rok Mar 16, 2024
8ccf1de
Use TensorFromJSON
rok Mar 16, 2024
d531a67
lint
rok Mar 17, 2024
833d915
Apply suggestions from code review
rok Mar 27, 2024
543fd25
Update cpp/src/arrow/extension/variable_shape_tensor.cc
rok Mar 27, 2024
ab4388f
fix
rok Mar 27, 2024
9124057
Review feedback
rok Mar 27, 2024
19aa660
mingw64 issue
rok Mar 28, 2024
a4a2afe
refactor ComputeStrides
rok Mar 29, 2024
3e5bb74
Change to ComputeStrides
rok Apr 1, 2024
e9e3245
Change ToTensor
rok Apr 1, 2024
19bb6b6
Refactoring ComputeStrides
rok Apr 2, 2024
b888bd7
Move RoundtripBatch to gtest_util.cc
rok Apr 14, 2024
ed4ff5a
Post rebase changes
rok Jun 6, 2024
7daa31a
Post rebase changes
rok Sep 11, 2024
440ce55
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 @@ -995,6 +995,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? This doesn't sound logical.

# 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