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

Math functions that output single vs multiple values should be named differently #83

Open
mikekasprzak opened this issue Jun 5, 2015 · 2 comments

Comments

@mikekasprzak
Copy link
Contributor

Besides grabbing the lowest hanging fruit ( #82 ), I actually have a criticism of the design of the math library. The majority of the library are functions that output multiple values, and but there are a few that output single values from multiple inputs (min, max, sum, etc). Especially given that this is a parallel math library, I'd argue that these single output functions are wasting valuable names better given to fully parallel operations.

For example, min and max. Presently, these functions are returning a single min or max value for all values in the input array. This contradicts other functions like abs, add, mul, and many other functions that output multiple values.

I'd recommend instead naming functions like p_min_f32 to p_min_value_f32 or p_minv_f32. That way you know from the name that it's outputting a single value instead of many.

This will then free up p_min_f32 and p_max_f32 to operate on two arrays of input, and output an array of min or max values, consistent with the rest of the functions. This also means the namespace is more open to adding other useful functions like clamp, sign, floor, and ceil to name a few.

@aolofsson
Copy link
Member

Good comment. Agree that it would be good if the functions had easy to recognize functionality based on name. Note that MPI for example has a "complete" set of global reduction operations as a starting point.
MPI_MAX maximum
MPI_MIN minimum
MPI_SUM sum
MPI_PROD product
MPI_LAND logical and
MPI_BAND bit-wise and
MPI_LOR logical or
MPI_BOR bit-wise or
MPI_LXOR logical exclusive or (xor)
MPI_BXOR bit-wise exclusive or (xor)
MPI_MAXLOC max value and location
MPI_MINLOC min value and location

@WesleyCeraso
Copy link
Contributor

OpenGL also uses the function name to indicate how many values are expected in the parameter array and their type. For example:
glVertex3f - Expects 3 floats
glVertex2u - Expects 2 unsigned ints

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