Uh oh!
There was an error while loading. Please reload this page.
GH-37484: [Python] Add a FixedSizeTensorScalar class - #37533
Conversation
alippai
commented
Sep 4, 2023
Would the numpy array api or https://data-apis.org/array-api/latest/purpose_and_scope.html add any value here? |
rok
commented
Sep 5, 2023
@alippai This PR would effectively implement a |
AlenkaF
left a comment
There was a problem hiding this comment.
Thanks for working on this! Added two suggestions, otherwise the Pyhton part LGTM.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
AlenkaF
commented
Sep 19, 2023
I am very much hoping we could implement DLPack in Arrow: #33984. Specially for the new tensor arrays, it would be very beneficial!
+1 |
AlenkaF
commented
Sep 19, 2023
One more thing, can the change in the C++ code ( |
jorisvandenbossche
left a comment
There was a problem hiding this comment.
Didn't yet look in detail, but added some quick drive-by comments. And thanks for working on this!
Can you also add some tests for the new Scalar class?
Currently, for the Python bindings, you added a get_tensor(i) method on the array class, but wouldn't make sense to (also/instead) add a to_tensor() method on the scalar class, since this is to get a Tensor for a single element (scalar) of the array?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
We discussed this here: #33948 (review)
I would personally prefer to_numpy, but perhaps we can have a discussion about this under a separate issue?
cc @jorisvandenbossche@AlenkaF
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
checked_pointer_cast causes a segfault here. Not sure if it's an issue or not.
There was a problem hiding this comment.
As per #37533 (review)ravel shouldn't cause copy if memory layout doesn't change. And we're not actively trying to change the memory layout here.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
pitrou
left a comment
There was a problem hiding this comment.
Thanks a lot for the update. This is really getting good, just a couple comments on specific points.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Hmm, I wouldn't be so sure, example:
>>>obj=np.arange(24).reshape(2,3,4)[:,::2]
>>>objarray([[[ 0, 1, 2, 3],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[20, 21, 22, 23]]])
>>>obj.strides
(96, 64, 8)
>>>permutation= (-np.array(obj.strides)).argsort(kind='stable')
>>>permutationarray([0, 1, 2]) # permutation is ok>>>values=np.ravel(obj, order="K")
>>>valuesarray([ 0, 1, 2, 3, 8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23])
>>>values[0] =999>>>valuesarray([999, 1, 2, 3, 8, 9, 10, 11, 12, 13, 14, 15, 20,
21, 22, 23])
>>>objarray([[[ 0, 1, 2, 3],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[20, 21, 22, 23]]])
# values is a copy! which we can also check using:>>>values.ctypes.data==obj.ctypes.dataFalse# base addresses are differentOf course, we may not really care about this, since the conversion is probably correct anyway. But we may want to add a mention in the docstring that the conversion is only zero-copy if the input array is contiguous.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Not sure if it's an issue either, but it would be worth taking a debugger and understanding exactly what happens :-)
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
rok
commented
Feb 8, 2024
Thanks for the helpful review @pitrou, I'm happy to see this moving forward! I've addressed your points, please let me know if more changes are needed. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
as_strided can be a later PR if desired. The docstring addition is good for now!
pitrou
commented
Feb 8, 2024
@github-actions crossbow submit -g python -g wheel |
pitrou
commented
Feb 8, 2024
It may be nice to later add a doc section for tensors here: |
Revision: bf2ca0e Submitted crossbow builds: ursacomputing/crossbow @ actions-2a16c8cab9 |
rok
commented
Feb 8, 2024
Added an issue for the docs: #39998 |
| and the rest of the dimensions will match the permuted shape of the fixed | ||
| shape tensor. | ||
| The conversion is zero-copy. |
There was a problem hiding this comment.
Small nit: this is only if the conversion to numpy is zero-copy (i.e. primitive numeric data without nulls)
There was a problem hiding this comment.
Good point, added to VariableShapeTensor PR 8ca3bf7
After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit 026188e. There were 9 benchmark results indicating a performance regression:
The full Conbench report has more details. It also includes information about 7 possible false positives for unstable benchmarks that are known to sometimes produce them. |
Rationale for this change
When working with
FixedSizeTensorArraywe want to access individual tensors. This would be enabled by adding:See #37484.
What changes are included in this PR?
This adds
FixedSizeTensorScalarand tests for it.Are there any user-facing changes?
Yes, when calling
FixedSizeTensorArray[i]we would get backFixedSizeTensorScalarinstead ofExtensionScalar.