Implement NumPy math functions #339

Merged
sb10q merged 1 commits from issue-149 into master 2024-08-17 17:37:20 +08:00
Collaborator

Implements NumPy math functions from ARTIQ for doubles.

Part of #149

Implements NumPy math functions from ARTIQ for doubles. Part of #149
derppening force-pushed issue-149 from 37fe208c33 to eaac49270b 2023-10-11 15:11:45 +08:00 Compare
derppening force-pushed issue-149 from eaac49270b to 278cfd309d 2023-10-11 17:47:41 +08:00 Compare
derppening force-pushed issue-149 from 278cfd309d to ce5ce027df 2023-10-11 18:13:04 +08:00 Compare
derppening force-pushed issue-149 from ce5ce027df to ded31e64ef 2023-10-11 18:15:24 +08:00 Compare
derppening changed title from WIP: Implement NumPy math functions to Implement NumPy math functions 2023-10-12 14:40:59 +08:00
derppening requested review from sb10q 2023-10-12 14:41:10 +08:00
derppening force-pushed issue-149 from ded31e64ef to ad1f0abb55 2023-10-16 16:06:18 +08:00 Compare
Author
Collaborator

v2: Rebased against master

v2: Rebased against `master`
derppening force-pushed issue-149 from ad1f0abb55 to 157854e71f 2023-10-23 10:05:58 +08:00 Compare
Author
Collaborator

v3: Rebased against master

v3: Rebased against `master`
sb10q reviewed 2023-10-28 03:27:59 +08:00
@ -0,0 +15,4 @@
...
def dbl_pi() -> float:
return 3.1415926535897932384626433
Owner

Please use the same indentation as the other files.

Please use the same indentation as the other files.
sb10q reviewed 2023-10-28 03:30:47 +08:00
@ -435,0 +439,4 @@
generator: &dyn CodeGenerator,
ctx: &CodeGenContext<'ctx, 'a>,
v: FloatValue<'ctx>,
to_i1: bool,
Owner

to_i1 sounds a bit ad-hoc and out of place. Can't the caller itself convert as needed?

to_i1 sounds a bit ad-hoc and out of place. Can't the caller itself convert as needed?
sb10q reviewed 2023-10-28 03:31:04 +08:00
@ -435,0 +464,4 @@
generator: &dyn CodeGenerator,
ctx: &CodeGenContext<'ctx, 'a>,
v: FloatValue<'ctx>,
to_i1: bool,
Owner

same here

same here
sb10q reviewed 2023-10-28 03:34:44 +08:00
@ -86,6 +98,48 @@ def patch(module):
module.Some = Some
module.none = none
# NumPy math functions
Owner

Fix the indentation

Some of those are actually Scipy. Edit the comments/naming accordingly (as in the legacy compiler).

Fix the indentation Some of those are actually Scipy. Edit the comments/naming accordingly (as in the legacy compiler).
derppening force-pushed issue-149 from 157854e71f to 86379c8b40 2023-10-30 14:04:05 +08:00 Compare
sb10q reviewed 2023-10-30 15:26:27 +08:00
@ -140,0 +140,4 @@
}
int32_t __nac3_isinf(double x) {
return __builtin_isinf(x);
Owner

Please use the same indentation as the rest of that file.

Please use the same indentation as the rest of that file.
derppening force-pushed issue-149 from 86379c8b40 to 1927035cfc 2023-10-30 17:35:27 +08:00 Compare
derppening force-pushed issue-149 from 1927035cfc to 0818f5804e 2023-10-30 18:13:47 +08:00 Compare
Author
Collaborator

v4: Rebased against master
v5, v6: Fix indentation and remove to_i1 from isnan and isinf

v4: Rebased against master v5, v6: Fix indentation and remove `to_i1` from `isnan` and `isinf`
derppening force-pushed issue-149 from 0818f5804e to bc692aaaf5 2023-11-01 15:02:01 +08:00 Compare
Author
Collaborator

v7: Rebased against mater

v7: Rebased against mater
sb10q reviewed 2023-11-01 15:17:54 +08:00
@ -435,0 +450,4 @@
.into_int_value()
}
/// Generates a call to `isnan` in IR. Returns either an `i32` representing the result.
Owner

either?

Also I thought we used i1 and i8 for booleans. Why i32 now?

either? Also I thought we used i1 and i8 for booleans. Why i32 now?
Author
Collaborator

This is not written anywhere in GCC's Manual or Clang's Manual, but testing it using the following program shows that the return type of both isinf and isnan is int:

int main() {
  std::puts(std::format("{}", typeid(__builtin_isinf(0.0)).name()).c_str());
  std::puts(std::format("{}", typeid(__builtin_isnan(0.0)).name()).c_str());
}
This is not written anywhere in [GCC's Manual](https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html) or [Clang's Manual](https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions), but testing it using the following program shows that the return type of both `isinf` and `isnan` is `int`: ```cpp int main() { std::puts(std::format("{}", typeid(__builtin_isinf(0.0)).name()).c_str()); std::puts(std::format("{}", typeid(__builtin_isnan(0.0)).name()).c_str()); } ```
Author
Collaborator

However, the C++ version (std::isinf and std::isnan) returns a bool instead, so maybe we can coerce it before passing back to the caller.

However, the C++ version (`std::isinf` and `std::isnan`) returns a `bool` instead, so maybe we can coerce it before passing back to the caller.
Owner

This is an internal NAC3 function and I think it should follow NAC3 conventions?

This is an internal NAC3 function and I think it should follow NAC3 conventions?
derppening force-pushed issue-149 from bc692aaaf5 to 7966535677 2023-11-01 15:41:06 +08:00 Compare
Author
Collaborator

v8: Fixed incorrect docstring.

v8: Fixed incorrect docstring.
derppening force-pushed issue-149 from 7966535677 to 2e1d6ab644 2023-11-01 18:02:52 +08:00 Compare
derppening force-pushed issue-149 from 2e1d6ab644 to 7e4dab15ae 2023-11-01 18:03:35 +08:00 Compare
Author
Collaborator

v9: Updated isinf and isnan to return i1
v10: Rebased against master

v9: Updated `isinf` and `isnan` to return `i1` v10: Rebased against master
sb10q merged commit 7e4dab15ae into master 2023-11-01 20:02:08 +08:00
sb10q deleted branch issue-149 2023-11-01 20:02:08 +08:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#339
No description provided.