Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

np.sum of an array of boolean dtype in tests/test_0115_generic_reducer_operation.py #3160

Closed
ianna opened this issue Jun 19, 2024 · 0 comments · Fixed by #3159
Closed

np.sum of an array of boolean dtype in tests/test_0115_generic_reducer_operation.py #3160

ianna opened this issue Jun 19, 2024 · 0 comments · Fixed by #3159
Assignees
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged

Comments

@ianna
Copy link
Collaborator

ianna commented Jun 19, 2024

Version of Awkward Array

2.6.4 (master branch)

Description and code to reproduce

According to Numpy documentation:

dtype : dtype, optional
        The type of the returned array and of the accumulator in which the
        elements are summed.  The dtype of `a` is used by default unless `a`
        has an integer dtype of less precision than the default platform
        integer.  In that case, if `a` is signed then the platform integer
        is used while if `a` is unsigned then an unsigned integer of the
        same precision as the platform integer is used.

see https://github.com/numpy/numpy/blob/v2.0.0/numpy/_core/fromnumeric.py#L2255-L2392

================================== FAILURES ===================================
__________________________ test_sumprod_types_FIXME ___________________________

    def test_sumprod_types_FIXME():
        array = np.array([[True, False, False], [True, False, False]])
        content2 = ak.contents.NumpyArray(array.reshape(-1))
        offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
        depth1 = ak.contents.ListOffsetArray(offsets3, content2)
>       assert (
            np.sum(array, axis=-1).dtype
            == ak.to_numpy(ak.sum(depth1, axis=-1, highlevel=False)).dtype
        )
E       AssertionError: assert dtype('int32') == dtype('int64')
E        +  where dtype('int32') = array([1, 1]).dtype
E        +    where array([1, 1]) = <function sum at 0x046AF640>(array([[ True, False, False],\n       [ True, False, False]]), axis=-1)
E        +      where <function sum at 0x046AF640> = np.sum
E        +  and   dtype('int64') = array([1, 0, 1, 0], dtype=int64).dtype
E        +    where array([1, 0, 1, 0], dtype=int64) = <function to_numpy at 0x052E71D8>(<NumpyArray dtype='int64' len='4'>[1 0 1 0]</NumpyArray>)
E        +      where <function to_numpy at 0x052E71D8> = ak.to_numpy
E        +      and   <NumpyArray dtype='int64' len='4'>[1 0 1 0]</NumpyArray> = <function sum at 0x052C7D60>(<ListOffsetArray len='4'>\n    <offsets><Index dtype='int64' len='5'>\n        [0 3 3 5 6]\n    </Index></offsets>\n    <content><NumpyArray dtype='bool' len='6'>\n        [ True False False  True False False]\n    </NumpyArray></content>\n</ListOffsetArray>, axis=-1, highlevel=False)
E        +        where <function sum at 0x052C7D60> = ak.sum

array      = array([[ True, False, False],
       [ True, False, False]])
content2   = <NumpyArray dtype='bool' len='6'>
    [ True False False  True False False]
</NumpyArray>
depth1     = <ListOffsetArray len='4'>
    <offsets><Index dtype='int64' len='5'>
        [0 3 3 5 6]
    </Index></offsets>
    <content><NumpyArray dtype='bool' len='6'>
        [ True False False  True False False]
    </NumpyArray></content>
</ListOffsetArray>
offsets3   = <Index dtype='int64' len='5'>
    [0 3 3 5 6]
</Index>

tests\test_0115_generic_reducer_operation.py:1414: AssertionError
_____________________________ test_sumprod_types ______________________________

    def test_sumprod_types():
        def prod(xs):
            out = 1
            for x in xs:
                out *= x
            return out
    
        array = np.array([[True, False, False], [True, False, False]])
        content2 = ak.contents.NumpyArray(array.reshape(-1))
        offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
        depth1 = ak.contents.ListOffsetArray(offsets3, content2)
    
        assert sum(to_list(np.sum(array, axis=-1))) == sum(
            to_list(ak.sum(depth1, axis=-1, highlevel=False))
        )
        assert prod(to_list(np.prod(array, axis=-1))) == prod(
            to_list(ak.prod(depth1, axis=-1, highlevel=False))
        )
    
        array = np.array([[0, 1, 2], [3, 4, 5]], dtype=np.int8)
        content2 = ak.contents.NumpyArray(array.reshape(-1))
        offsets3 = ak.index.Index64(np.array([0, 3, 3, 5, 6], dtype=np.int64))
        depth1 = ak.contents.ListOffsetArray(offsets3, content2)
    
>       assert (
            np.sum(array, axis=-1).dtype
            == ak.to_numpy(ak.sum(depth1, axis=-1, highlevel=False)).dtype
        )
E       AssertionError: assert dtype('int32') == dtype('int64')
E        +  where dtype('int32') = array([ 3, 12]).dtype
E        +    where array([ 3, 12]) = <function sum at 0x046AF640>(array([[0, 1, 2],\n       [3, 4, 5]], dtype=int8), axis=-1)
E        +      where <function sum at 0x046AF640> = np.sum
E        +  and   dtype('int64') = array([3, 0, 7, 5], dtype=int64).dtype
E        +    where array([3, 0, 7, 5], dtype=int64) = <function to_numpy at 0x052E71D8>(<NumpyArray dtype='int64' len='4'>[3 0 7 5]</NumpyArray>)
E        +      where <function to_numpy at 0x052E71D8> = ak.to_numpy
E        +      and   <NumpyArray dtype='int64' len='4'>[3 0 7 5]</NumpyArray> = <function sum at 0x052C7D60>(<ListOffsetArray len='4'>\n    <offsets><Index dtype='int64' len='5'>\n        [0 3 3 5 6]\n    </Index></offsets>\n    <content><NumpyArray dtype='int8' len='6'>[0 1 2 3 4 5]</NumpyArray></content>\n</ListOffsetArray>, axis=-1, highlevel=False)
E        +        where <function sum at 0x052C7D60> = ak.sum

array      = array([[0, 1, 2],
       [3, 4, 5]], dtype=int8)
content2   = <NumpyArray dtype='int8' len='6'>[0 1 2 3 4 5]</NumpyArray>
depth1     = <ListOffsetArray len='4'>
    <offsets><Index dtype='int64' len='5'>
        [0 3 3 5 6]
    </Index></offsets>
    <content><NumpyArray dtype='int8' len='6'>[0 1 2 3 4 5]</NumpyArray></content>
</ListOffsetArray>
offsets3   = <Index dtype='int64' len='5'>
    [0 3 3 5 6]
</Index>
prod       = <function test_sumprod_types.<locals>.prod at 0x044F7C40>

tests\test_0115_generic_reducer_operation.py:1448: AssertionError
@ianna ianna added the bug (unverified) The problem described would be a bug, but needs to be triaged label Jun 19, 2024
@ianna ianna mentioned this issue Jun 19, 2024
13 tasks
@ianna ianna self-assigned this Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant