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

G3VectorQuat from buffer doesn't catch odd strides #65

Closed
mhasself opened this issue Aug 31, 2021 · 2 comments
Closed

G3VectorQuat from buffer doesn't catch odd strides #65

mhasself opened this issue Aug 31, 2021 · 2 comments
Assignees

Comments

@mhasself
Copy link
Member

When creating G3VectorQuat from numpy array, it seems to check for shape (-1, 4) but does not handle non-trivial strides.

Consider test program:

from spt3g import core
import numpy as np

quats = np.array([[1., 2., 3., 4., 5.],   # a                                                           
                  [0., 0., 0., 0., 0.],   # b                                                           
                  [0., 0., 0., 0., 0.],   # c                                                           
                  [0., 0., 0., 0., 0.]])  # d                                                           

for test in [
    quats,             # bad shape
    quats[:,:4],       # ok shape, non-trivial strides
    quats.T,           # ok shape, non-trivial strides
    quats.T.copy(),    # ok shape, trivial strides
    ]:
    try:
        print(repr(core.G3VectorQuat(test)))
    except TypeError:
        print('(TypeError)')

Produces output (on version 0.3-71-g613d0d4):

(TypeError)
(TypeError)
spt3g.core.G3VectorQuat([(1,2,3,4), (5,0,0,0), (0,0,0,0), (0,0,0,0), (0,0,0,0)])
spt3g.core.G3VectorQuat([(1,0,0,0), (2,0,0,0), (3,0,0,0), (4,0,0,0), (5,0,0,0)])

But expected output is:

(TypeError)
spt3g.core.G3VectorQuat([(1,2,3,4), (0,0,0,0), (0,0,0,0), (0,0,0,0)])
spt3g.core.G3VectorQuat([(1,0,0,0), (2,0,0,0), (3,0,0,0), (4,0,0,0), (5,0,0,0)])
spt3g.core.G3VectorQuat([(1,0,0,0), (2,0,0,0), (3,0,0,0), (4,0,0,0), (5,0,0,0)])

OR

(TypeError)
(TypeError)
(TypeError)
spt3g.core.G3VectorQuat([(1,0,0,0), (2,0,0,0), (3,0,0,0), (4,0,0,0), (5,0,0,0)])

(In the latter case, the code would simply rejecting anything that doesn't have simple C ordering.)

@arahlin
Copy link
Member

arahlin commented Jan 26, 2022

Is this fixed with acf0337?

@nwhitehorn
Copy link
Member

Nope. That commit fixes all scalar types. This one still requires some more work, though. Will take care of it today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants