question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal to standardize element-wise elementary mathematical functions

See original GitHub issue

Based on the analysis of array library APIs, we know that evaluating element-wise elementary mathematical functions is both universally implemented and commonly used. Accordingly, this issue proposes to standardize the following elementary mathematical functions:

Special Functions

  • abs (absolute)
  • exp
  • log
  • sqrt

Rounding

  • ceil
  • floor
  • trunc
  • round

Trigonometry

  • sin
  • cos
  • tan
  • asin (arcsin)
  • acos (arccos)
  • atan (arctan)
  • sinh
  • cosh
  • tanh
  • asinh (arcsinh)
  • acosh (arccosh)
  • atanh (arctanh)

Criterion

  1. Commonly implemented across array libraries.
  2. Commonly used by array library consumers.
  3. Operates on a single array (e.g., this criterion excludes atan2).

Questions

  1. Naming conventions? The above is biased toward C naming conventions (e.g., atan vs arctan).
  2. Are there any APIs listed above which should not be standardized?
  3. Are there elementary mathematical functions not listed above which should be standardized? Preferably, any additions should be supported by usage data.
  4. Should the standard mandate a minimum precision to ensure portability? (e.g., JavaScript’s lack of minimum precision specification offers a cautionary tale)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:40 (38 by maintainers)

github_iconTop GitHub Comments

2reactions
kgrytecommented, Jul 30, 2020

We can also keep the keyword-only requirements. In which case, the universal signature would be

<name>(x, /, *, out=None)
1reaction
shoyercommented, Aug 13, 2020

adequate coverage of non mutating operators (like jax’s non-mutating slice assign, for example).

Read up on that at https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#🔪-In-Place-Updates.

We should update that doc page, but I’ll just note that JAX has a more recent improved syntax for indexing assignment: x.at[idx].set(y) vs x[idx] = y

One advantage of the non-mutating version is that JAX can have reliable assigning arithmetic on array slices with x.at[idx].add(y) (x[idx] += y doesn’t work if x[idx] returns a copy).

A disadvantage is that doing this sort thing inside a loop is almost always a bad idea unless you have a JIT compiler, because every indexing assignment operation makes a full copy. So the naive translation of an efficient Python loop that fills out an array row by row would now make a copy in each step. Instead, you’d have to rewrite that loop to use something like concatenate instead (which in my experience is already about as efficient as using indexing assignment).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposal to standardize element-wise arithmetic operations · Issue ...
Based on the analysis of array library APIs, we know that performing element-wise arithmetic operations is both universally implemented and commonly used.
Read more >
Proposal for a Standardization of Mathematical ... - HAL-Inria
Proposal for a standardization of mathematical functions ... This paper proposes a standard for elementary functions, detailed in.
Read more >
Mathematical Operations and Elementary Functions
Mathematical Operations and Elementary Functions. Julia provides a complete collection of basic arithmetic and bitwise operators across all of its numeric ...
Read more >
Named Tensor Notation - OpenReview
This work proposes a mathematical notation for named tensors and a fully ... Any function from a scalar to a scalar can be...
Read more >
The Standard Library — Julia Language 0.3.0-prerelease 文档
Alternatively, using Module will import all exported Module functions into the current namespace. By convention, function names ending with an exclamation point ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found