-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
100 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,26 @@ | ||
from collections import namedtuple | ||
|
||
import numpy as np | ||
from numba import njit | ||
|
||
# Define a namedtuple | ||
Point = namedtuple('Point', ['x', 'y']) | ||
|
||
# Create a list of points | ||
points = [Point(x, y) for x in range(1000) for y in range(1000)] | ||
|
||
# Calculate the distance between each point and the origin | ||
@njit | ||
def distance_to_origin(point): | ||
"""Calculate the distance between a point and the origin.""" | ||
return np.sqrt(point.x**2 + point.y**2) | ||
|
||
|
||
# Calculate the distance between each point and the origin using the function | ||
distances = np.array([distance_to_origin(point) for point in points]) | ||
|
||
# Calculate the distance between each point and the origin manually | ||
expected_distances = np.array([np.sqrt(point.x**2 + point.y**2) for point in points]) | ||
|
||
# Compare the results | ||
np.testing.assert_allclose(distances, expected_distances) |
This file contains 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 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 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