-
Notifications
You must be signed in to change notification settings - Fork 27
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
Sequence initialization behaviors #153
Comments
Hiya ^^
You're very welcome (: Okay, let me have a look..
Yeah, this is not intentional. When you call one of PyGLM's functions, the first thing it needs to do is find out what kind of arguments you've supplied.
Internally, this macro first checks whether or not the supplied argument is a PyGLM type (e.g.
It then tries to find out what's inside the tuple (i.e. which data types are contained by the tuple).
This might look a bit complicated, but it's actually not.
And indeed, it does find out that neither The problem lies within the
What this does is telling the program to convert whichever numeric type it has to float.
Thus, you get a This is relatively easy to fix, but it might take a while. Sorry, might have gotten a little overboard, but I hope it was interesting to you 😅
This behavior is actually intentional. It is the same way as glm by g-truc handles it.
This is also intentional. This is also the way that glm does it. The idea here is that you can create a smaller matrix from a bigger one, effectively cropping it and discarding all values that the smaller matrix can't fit. >>> print( mat4(mat2(1,2,3,4)) )
[ 1 ][ 3 ][ 0 ][ 0 ]
[ 2 ][ 4 ][ 0 ][ 0 ]
[ 0 ][ 0 ][ 1 ][ 0 ]
[ 0 ][ 0 ][ 0 ][ 1 ] You can also do both - i.e. expand one way and crop the other: >>> print( mat4x2(mat2x4(1,2,3,4,5,6,7,8)) )
[ 1 ][ 5 ][ 0 ][ 0 ]
[ 2 ][ 6 ][ 0 ][ 0 ] Don't ask me what the use case would be though. Hope this helps (: Cheers |
For sure, thanks.
I find that all pretty intuitive. The odd part (for me) is the somewhat arbitrary limit on python sequences being limited to 4 items or less and the rejection of oddly shaped "matrices" composed of sequences. Those limitations in glm are imposed naturally, since the objects themselves can't break out of their assigned shapes, but python lists/tuples/etc can be whatever we want. That said, it's not like I have a use case for requesting those be allowed. I just found them a bit surprising while comparing type checker results 😉. |
Thanks for the quick turnaround on #151, it's refreshing to see a maintainer take action so quickly (no pressure on this one 😄).
I'm writing type stubs for
pyglm
and came across some behaviors I'm not sure are intentional or not regarding sequences. I'm not making any prescriptions here for whatpyglm
should do, but I'm noting these because they differ from how I've put the stubs together (because these behaviors are either difficult to describe with the python typing system or don't appear immediately useful in a typed context) and they seem like the kind of thing that might be artifacts of implementation.Sequences used for initialization that contain items that are not
__float__
/__int__
compatible will be 0:This is contrary to non-sequence initialization where this is a
TypeError
:Sequences used for initialization may be larger than the type's length, but only if the sequence has a length < 5:
This rule also applies to matrix row/columns.
Following that, all matrix columns must have an equal size, even if they extend beyond what that matrix actually requires:
The text was updated successfully, but these errors were encountered: