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

[REQUEST] C and Python Modulus operator for vectorial quantities #282

Closed
fritzio opened this issue Jul 29, 2024 · 3 comments
Closed

[REQUEST] C and Python Modulus operator for vectorial quantities #282

fritzio opened this issue Jul 29, 2024 · 3 comments
Assignees
Labels
feature request Request for something to be added

Comments

@fritzio
Copy link

fritzio commented Jul 29, 2024

Description

  • The modulus operator mod is currently only defined for scalar, i.e., float quantities. I suggest implementing it for vectorial and tensorial quantities, e.g., vec3, so that we can omit a wrapper function, such as,
@wp.func
def mod(a: wp.vec3, b: wp.vec3) -> wp.vec3:
    return wp.vec3(wp.mod(a[0], b[0]), wp.mod(a[1], b[1]), wp.mod(a[2], b[2]))
  • The modulus operator mod gives the modulus as defined in C and not in Python, which might lead to surprising behavior if we are unaware. I suggest adding a Pythonic modulus operator, e.g.,
@wp.func
def pymod(a: float, b: float) -> float:
    return wp.mod(wp.mod(a, b) + b, b)

Context

The motivation for this request is to have less boilerplate code in our application.

@fritzio fritzio added the feature request Request for something to be added label Jul 29, 2024
@sudo-panda
Copy link

Can I take this up?

@shi-eric
Copy link
Contributor

I think @christophercrouzet is actively working on this issue already.

@christophercrouzet
Copy link
Member

We just merged the changes to the branch main. So far we only added support for vectors to wp.mod() and documented the built-in as being implemented as a truncated division to alleviate the ambiguity with Python's implementation. We haven't implemented the floored division variant for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for something to be added
Projects
None yet
Development

No branches or pull requests

5 participants