ARROW-6508: [C++] Add Tensor and SparseTensor factory function with validations#5862
ARROW-6508: [C++] Add Tensor and SparseTensor factory function with validations#5862mrkn wants to merge 19 commits intoapache:masterfrom
Conversation
dd11db5 to
1997d1c
Compare
|
A couple of high level comments before I review the details:
|
OK, I understand. Renaming to
Oh, I forgot to rewrite this to use Thanks! |
52f1d5f to
692c0dc
Compare
|
I finished rewriting by using I search uses of |
|
I would rather have all those methods named |
|
The other (unsafe) Make functions also return Status and use an output parameter. The difference is whether they will logically validate (via Validate) the inputs. We had this discussion previously, not sure if on the ML or in a PR review: |
|
I guess it is enough to see the return type to distinguish whether a But we have to use the different names if we want to introduce two factory functions, which have the same argument types and the different return types, and the one performs validations and the other does not. |
|
Well, why do we need the unsafe APIs here? You're only checking the shape and strides, so it's gonna be fast (unless you have 1000-dimensional tensors?). |
|
We don't need unsafe APIs in tensor and sparse tensor. I just mentioned my anxiety about the potential issue of the naming convention that uses only Result<std::shared_ptr<Table>> Make(
const std::shared_ptr<Schema>& schema,
const std::vector<std::shared_ptr<ChunkedArray>>& columns,
int64_t num_rows = -1
);But we cannot add this because this function differs only the return type from the existing |
|
If we want to add a safe version of |
|
OK, I'll revert the commit to rename I found the previous discussion thread in ML. The discussion hasn't been settled yet. |
pitrou
left a comment
There was a problem hiding this comment.
Thanks for doing this! There's some potential for simplification in some places. Also, the tests would deserve developing a bit.
These static factory functions validate the given arguments and then make a new Tensor object if the arguments are valid.
These static factory functions validate the given arguments and then make a new NumericTensor object if the arguments are valid.
|
@pitrou I finished fixes for all of your comments. Could you please review this again? |
pitrou
left a comment
There was a problem hiding this comment.
+1. Will merge when green, thank you!
…alidations I'd like to add `Make` factory functions in `Tensor` and `SparseTensor`. These functions validate the given parameters. The following validations run in `Tensor::Make`: - Data type (non-null and `is_tensor_supported`) - `data` pointer - the size of `shape` - elements of `shape` are all positive - the consistency of `shape` and `strides` - the consistency of `strides` and the size of `data` - the consistency of the size of `dim_names` and `shape` The following validations run in `SparseTensor::Make`: - Data type - the consistency of the sparse index and `shape` - the consistency of the size of `dim_names` and `shape` --- ## TODO: - [x] Use `Result<T>` as return types. Closes apache#5862 from mrkn/ARROW-6508 and squashes the following commits: 40a723b <Kenta Murata> Let Tensor::Make support 0-dim tensors e03f1f7 <Kenta Murata> Fix tests of Tensor and SparseTensor more appropriately 6130d25 <Kenta Murata> Simplify Tensor::Make and NumericTensor::Make declarations 195cd92 <Kenta Murata> Fix SparseTensorImpl::Make 29913bd <Kenta Murata> Remove a needless condition 4801c3f <Kenta Murata> Make ValidateShape inline 32ef792 <Kenta Murata> Use appropriate macros 16fd011 <Kenta Murata> Rename MakeSafe to Make 03ce831 <Kenta Murata> Fix error messages 0c69d60 <Kenta Murata> Refactoring aa8017b <Kenta Murata> Rname to MakeSafe 9cbe5d8 <Kenta Murata> Use Result<T> bf1a474 <Kenta Murata> SparseCOOIndex::Make and SparseCSRIndex::Make 1a2b5ca <Kenta Murata> Reject negative items in shape a7ac21d <Kenta Murata> Add SparseTensorImpl<T>::Make 9a2bfaf <Kenta Murata> Add NumericTensor::Make functions aec0ac5 <Kenta Murata> Remove Tensor::Make without strides b9fc3c9 <Kenta Murata> Extract internal::ValidateTensorParameters 5aa0e63 <Kenta Murata> Add Tensor::Make functions Authored-by: Kenta Murata <mrkn@mrkn.jp> Signed-off-by: Antoine Pitrou <antoine@python.org>
I'd like to add
Makefactory functions inTensorandSparseTensor. These functions validate the given parameters.The following validations run in
Tensor::Make:is_tensor_supported)datapointershapeshapeare all positiveshapeandstridesstridesand the size ofdatadim_namesandshapeThe following validations run in
SparseTensor::Make:shapedim_namesandshapeTODO:
Result<T>as return types.