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

frexp and ldexp definitions: return a pair? #31

Closed
devernay opened this issue May 20, 2019 · 6 comments
Closed

frexp and ldexp definitions: return a pair? #31

devernay opened this issue May 20, 2019 · 6 comments
Assignees

Comments

@devernay
Copy link
Contributor

I think the frexp and ldexp functions should take a single argument and return a pair, just like the standard python version https://docs.python.org/3.5/library/math.html#math.frexp, because python parameters are passed by value. That's more python-friendly.

Another solution would be to pass an array of ints as the second parameter.

@devernay devernay changed the title frexp and ldexp definitions: retuirn a pair? frexp and ldexp definitions: return a pair? May 20, 2019
@Zuzu-Typ
Copy link
Owner

No, I try to maintain compatibility with glm, which does in fact not return a pair.
Instead, it stores one part in the returned object and the other in the second argument.

I'm not sure I've tried the function, but it should work as intended looking at the code.

@devernay
Copy link
Contributor Author

the problem is that the second argument should be passed as reference, which is not possible in python unless it is an array. Note that these are the only functions in GLSL that have an "out" parameter.
I don't see how it would work. And actually when you compile it it doesn't call any implementation in glm. Do a "nm" on the shared library, you'll see that the frexp symbols are undefined.

@Zuzu-Typ
Copy link
Owner

Ah yeah right, sorry about that.
There was an error in the original glm, where the forward reference to frexp and ldexp were incorrectly defined.
I mentioned the issue on their issue tracker and it did get fixed by now, however, I didn't update the PyPI yet.
Hence the missing functions.

Anyway what your saying is not true.
The only objects in Python that are not passed to functions by reference are numbers and strings.
Otherwise if you used a class object as an argument of a function, that is meant to do some changes to that very object, it would only edit a copy, which is not the case.

@devernay
Copy link
Contributor Author

Agreed, class objects are passed by reference, so it would work for vectors of int (remember that the second argument must be an integer type as per the definition, so no vec2, vec3 or vec4), but not with integers.
One of the uses of frexp is:
y = frexp(x, e)
where x is a float/double and e is an int. You cannot do that in Python without changing the way e is returned. Since the second argument is not even used as input, it makes much more sense to return a pair.

And, by the way, I had to comment out the definitions of frexp and ldexp in the current version of PyGLM, because it resulted in undefined symbols (check with nm). The resulting shared object would load fine on Linux, because symbols are resolved when executing them, but not on macOS, where symbols are resolved when loading the shared object:
https://github.com/devernay/PyGLM/tree/disable-frexp-ldexp

@Zuzu-Typ
Copy link
Owner

Zuzu-Typ commented May 23, 2019

I'm working on a future version of PyGLM right now, that does support additional types, including integer types. It will take a while to finish though.
The current version of PyGLM (if it did compile) uses a workaround, which uses a temporary integer vector as e and puts the contents of the temporary vector into the actual vector that you supplied to the function.
Although not a perfect solution, it should still work and comply with glm (more or less).

Nevermind, apparently I never pushed this change, so currently it wouldn't work.
Let me try fixing that really quick.

The reason why it doesn't compile is because there was an issue in glm itself, where the forward declarations were missing (see g-truc/glm#895).
I haven't yet updated the glm version in this repository.

@Zuzu-Typ
Copy link
Owner

Okay. It should work now.

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

No branches or pull requests

2 participants