Skip to content

Commit

Permalink
cuda docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sronilsson committed Aug 30, 2024
1 parent b8cdf6a commit 950bc9d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion simba/data_processors/cuda/is_inside_rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ def is_inside_rectangle(x: np.ndarray, y: np.ndarray) -> np.ndarray:
:return np.ndarray: 2d numeric boolean (N, 1) with 1s representing the point being inside the rectangle and 0 if the point is outside the rectangle.
.. csv-table:: Function Performance Table with Markup
:file: _tables/is_inside_rectangle.csv
:file: ../_tables/is_inside_rectangle.csv
:widths: 30, 70
:header-rows: 1
"""


x = np.ascontiguousarray(x).astype(np.int32)
y = np.ascontiguousarray(y).astype(np.int32)
x_dev = cuda.to_device(x)
Expand Down
9 changes: 7 additions & 2 deletions simba/mixins/circular_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def circular_range(data: np.ndarray) -> float:
return np.ceil(np.rad2deg(min(2 * np.pi - circular_range, data[-1] - data[0])))

@staticmethod
@njit("(float32[:], float64[:], int64)", parallel=True)
@njit("(float32[:], float64[:], int64)")
def sliding_circular_range(data: np.ndarray, time_windows: np.ndarray, fps: int ) -> np.ndarray:
"""
Jitted compute of sliding circular range for a time series of circular data. The range is defined as the angular span of the
Expand All @@ -911,8 +911,9 @@ def sliding_circular_range(data: np.ndarray, time_windows: np.ndarray, fps: int
"""

results = np.full((data.shape[0], time_windows.shape[0]), 0.0)
for time_window_cnt in prange(time_windows.shape[0]):
for time_window_cnt in range(time_windows.shape[0]):
win_size = int(time_windows[time_window_cnt] * fps)
print('s')
for left, right in zip(range(0, (data.shape[0] - win_size) + 1), range(win_size-1, data.shape[0])):
sample = np.sort(np.deg2rad(data[left : right + 1]))
angular_diffs = np.diff(sample)
Expand Down Expand Up @@ -1164,6 +1165,10 @@ def fit_circle(data: np.ndarray, max_iterations: Optional[int] = 400) -> np.ndar
return results



# data = np.array([260, 280, 300, 340, 360, 0, 10, 350, 0, 15]).astype(np.float32)
# CircularStatisticsMixin().sliding_circular_range(data=data, time_windows=np.array([0.5]), fps=10)

# data_sizes = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000]
# # #
# # for data_size in data_sizes:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_circlular_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def test_circular_range_2(size):

def test_sliding_circular_range_1():
data = np.array([260, 280, 300, 340, 360, 0, 10, 350, 0, 15]).astype(np.float32)
results = CircularStatisticsMixin().sliding_circular_range(data=data, time_windows=np.array([1.0]), fps=1)
expected_results = np.array([[0],[20],[20],[40],[20],[0],[10],[20],[10],[15]])
results = CircularStatisticsMixin().sliding_circular_range(data=data, time_windows=np.array([0.5]), fps=10)
expected_results = np.array([[0.], [0.], [0.], [0.], [100.], [80.], [70.], [30.], [20.], [25.]])
assert np.array_equal(expected_results.astype(np.int32), results.astype(np.int32))

@pytest.mark.parametrize('size, time_windows', [(100, (1.5, 2.0)), (1000, (0.5, 10.0)), (10000, (1.0))])
Expand Down

0 comments on commit 950bc9d

Please sign in to comment.