From 950bc9d50cb01bcd4f74cac79858b9cf6db16333 Mon Sep 17 00:00:00 2001 From: sronilsson Date: Fri, 30 Aug 2024 15:16:13 -0400 Subject: [PATCH] cuda docs --- simba/data_processors/cuda/is_inside_rectangle.py | 3 ++- simba/mixins/circular_statistics.py | 9 +++++++-- tests/test_circlular_stats.py | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/simba/data_processors/cuda/is_inside_rectangle.py b/simba/data_processors/cuda/is_inside_rectangle.py index 0d25d1ce4..ccf62d6b5 100644 --- a/simba/data_processors/cuda/is_inside_rectangle.py +++ b/simba/data_processors/cuda/is_inside_rectangle.py @@ -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) diff --git a/simba/mixins/circular_statistics.py b/simba/mixins/circular_statistics.py index 86a8d83e0..f4139a070 100644 --- a/simba/mixins/circular_statistics.py +++ b/simba/mixins/circular_statistics.py @@ -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 @@ -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) @@ -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: diff --git a/tests/test_circlular_stats.py b/tests/test_circlular_stats.py index 90ebeb5fe..e0d3e7f73 100644 --- a/tests/test_circlular_stats.py +++ b/tests/test_circlular_stats.py @@ -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))])