-
Notifications
You must be signed in to change notification settings - Fork 171
[numpy] add trunc #2316
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
Merged
Merged
[numpy] add trunc #2316
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a5badde
[numpy] add trunc
khushi-411 e2bfbff
clear generated files
khushi-411 d5eab7c
implement IntrinsicFuntion
khushi-411 5192759
add tests.toml & undo unrelated changes
khushi-411 2d49778
use spaces
khushi-411 1c82d34
use macro
khushi-411 f41643a
Merge branch 'main' into lp_trunc
khushi-411 f37c8a5
update refs
khushi-411 95d9f27
fix: build failues in ci
khushi-411 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from lpython import f32, f64 | ||
from numpy import trunc, empty, sqrt, reshape, int32, float32, float64 | ||
|
||
|
||
def elemental_trunc64(): | ||
i: i32 | ||
j: i32 | ||
k: i32 | ||
l: i32 | ||
eps: f32 | ||
eps = f32(1e-6) | ||
|
||
arraynd: f64[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float64) | ||
|
||
newshape: i32[1] = empty(1, dtype = int32) | ||
newshape[0] = 16384 | ||
|
||
for i in range(32): | ||
for j in range(16): | ||
for k in range(8): | ||
for l in range(4): | ||
arraynd[i, j, k, l] = f64((-1)**l) * sqrt(float(i + j + j + l)) | ||
|
||
observed: f64[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float64) | ||
observed = trunc(arraynd) | ||
|
||
observed1d: f64[16384] = empty(16384, dtype=float64) | ||
observed1d = reshape(observed, newshape) | ||
|
||
array: f64[16384] = empty(16384, dtype=float64) | ||
array = reshape(arraynd, newshape) | ||
|
||
for i in range(16384): | ||
assert f32(abs(trunc(array[i]) - observed1d[i])) <= eps | ||
|
||
|
||
def elemental_trunc32(): | ||
i: i32 | ||
j: i32 | ||
k: i32 | ||
l: i32 | ||
eps: f32 | ||
eps = f32(1e-6) | ||
|
||
arraynd: f32[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float32) | ||
|
||
for i in range(32): | ||
for j in range(16): | ||
for k in range(8): | ||
for l in range(4): | ||
arraynd[i, j, k, l] = f32(f64((-1)**l) * sqrt(float(i + j + j + l))) | ||
|
||
observed: f32[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float32) | ||
observed = trunc(arraynd) | ||
|
||
for i in range(32): | ||
for j in range(16): | ||
for k in range(8): | ||
for l in range(4): | ||
assert abs(trunc(arraynd[i, j, k, l]) - observed[i, j, k, l]) <= eps | ||
|
||
|
||
elemental_trunc64() | ||
elemental_trunc32() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.