diff options
| author | Tomáš Jusko | 2023-09-30 16:44:18 +0200 |
|---|---|---|
| committer | Tomáš Jusko | 2023-09-30 16:44:18 +0200 |
| commit | d66c3dc971846c490a9f846e12be299a27856e69 (patch) | |
| tree | ff27f08ec719e6c6a6f234e5725b9733308b9ec1 | |
| parent | 74ea8bcad4408663598985440589abbc062df55e (diff) | |
| download | pyecsca-d66c3dc971846c490a9f846e12be299a27856e69.tar.gz pyecsca-d66c3dc971846c490a9f846e12be299a27856e69.tar.zst pyecsca-d66c3dc971846c490a9f846e12be299a27856e69.zip | |
fix: PR requested changes
| -rw-r--r-- | pyecsca/sca/stacked_traces/combine.py | 3 | ||||
| -rw-r--r-- | pyecsca/sca/stacked_traces/correlate.py | 5 | ||||
| -rw-r--r-- | test/sca/test_stacked_correlate.py | 12 |
3 files changed, 7 insertions, 13 deletions
diff --git a/pyecsca/sca/stacked_traces/combine.py b/pyecsca/sca/stacked_traces/combine.py index 6e11162..15d5235 100644 --- a/pyecsca/sca/stacked_traces/combine.py +++ b/pyecsca/sca/stacked_traces/combine.py @@ -224,7 +224,8 @@ class GPUTraceManager(BaseTraceManager): return int( chunk_memory_ratio * mem_size / element_size) - def get_traces_shape(self) -> Tuple[int, ...]: + @property + def traces_shape(self) -> Tuple[int, ...]: return self._traces.samples.shape def _gpu_combine1D(self, diff --git a/pyecsca/sca/stacked_traces/correlate.py b/pyecsca/sca/stacked_traces/correlate.py index 3e0f1d2..c5277d9 100644 --- a/pyecsca/sca/stacked_traces/correlate.py +++ b/pyecsca/sca/stacked_traces/correlate.py @@ -22,7 +22,7 @@ def gpu_pearson_corr(intermediate_values: npt.NDArray[np.number], if (len(intermediate_values.shape) != 1 or (intermediate_values.shape[0] - != trace_manager.get_traces_shape()[0])): + != trace_manager.traces_shape[0])): raise ValueError("Intermediate values have to be a vector " "as long as trace_count") @@ -51,6 +51,9 @@ def _gpu_pearson_corr(samples: DeviceNDArray, :type samples: npt.NDArray[np.number] :param intermediate_values: A 1D array of shape (n,) containing the intermediate values. :type intermediate_values: npt.NDArray[np.number] + :param intermed_sum: A 1D array of shape (1,) containing the precomputed sum of the intermediate values. + :type intermed_sum: npt.NDArray[np.number] + :param intermed_sq_sum: A 1D array of shape (1,) containing the precomputed sum of the squares of the intermediate values. :param result: A 1D array of shape (m,) to store the resulting correlation coefficients. :type result: cuda.devicearray.DeviceNDArray """ diff --git a/test/sca/test_stacked_correlate.py b/test/sca/test_stacked_correlate.py index ce5a9ed..954494f 100644 --- a/test/sca/test_stacked_correlate.py +++ b/test/sca/test_stacked_correlate.py @@ -35,17 +35,7 @@ def intermediate_values(): def pearson_corr(samples, intermediate_values): - int_sum = np.sum(intermediate_values) - int_sq_sum = np.sum(np.square(intermediate_values)) - samples_sum = np.sum(samples, axis=0) - samples_sq_sum = np.sum(np.square(samples), axis=0) - samples_intermed_sum = np.sum( - samples * intermediate_values[:, None], axis=0) - n = samples.shape[0] - - return (n * samples_intermed_sum - int_sum * samples_sum) / \ - (np.sqrt(n * int_sq_sum - int_sum ** 2) * - np.sqrt(n * samples_sq_sum - np.square(samples_sum))) + return np.corrcoef(samples, intermediate_values, rowvar=False)[-1, :-1] def test_pearson_coef_no_chunking(samples, gpu_manager, intermediate_values): |
