|
6 | 6 |
|
7 | 7 | ### Imports ###
|
8 | 8 |
|
| 9 | +from typing import List, Union |
| 10 | + |
9 | 11 | import numpy as np
|
10 | 12 | import pytest
|
11 | 13 | from scipy.linalg import solve_banded as scipy_solve_banded
|
12 | 14 |
|
13 | 15 | from chemotools.utils.banded_linalg import (
|
| 16 | + _datacopied, |
14 | 17 | conv_upper_chol_banded_to_lu_banded_storage,
|
15 | 18 | lu_banded,
|
16 | 19 | lu_solve_banded,
|
17 | 20 | slogdet_lu_banded,
|
18 | 21 | )
|
19 | 22 | from tests.test_for_utils.utils_funcs import get_banded_slogdet
|
20 | 23 |
|
| 24 | +### Constants ### |
| 25 | + |
| 26 | +_ARRAY_TO_VIEW: np.ndarray = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) |
| 27 | +_VIEW = _ARRAY_TO_VIEW[::] |
| 28 | + |
21 | 29 | ### Test Suite ###
|
22 | 30 |
|
23 | 31 |
|
| 32 | +@pytest.mark.parametrize( |
| 33 | + "arr, original, expected", |
| 34 | + [ |
| 35 | + ( # Number 0 Different arrays |
| 36 | + np.array([1, 2, 3]), |
| 37 | + np.array([1, 2, 3]), |
| 38 | + True, |
| 39 | + ), |
| 40 | + ( # Number 1 Array and list |
| 41 | + np.array([1, 2, 3]), |
| 42 | + [1, 2, 3], |
| 43 | + True, |
| 44 | + ), |
| 45 | + ( # Number 2 Different data types |
| 46 | + np.array([1, 2, 3]), |
| 47 | + np.array([1, 2, 3], dtype=np.float64), |
| 48 | + True, |
| 49 | + ), |
| 50 | + ( # Number 3 Different view and array |
| 51 | + _ARRAY_TO_VIEW[0:3], |
| 52 | + np.array([1, 2, 3]), |
| 53 | + False, |
| 54 | + ), |
| 55 | + ( # Number 4 Same array |
| 56 | + _ARRAY_TO_VIEW, |
| 57 | + _ARRAY_TO_VIEW, |
| 58 | + False, |
| 59 | + ), |
| 60 | + ( # Number 5 Same view and array |
| 61 | + _VIEW, |
| 62 | + _ARRAY_TO_VIEW, |
| 63 | + False, |
| 64 | + ), |
| 65 | + ], |
| 66 | +) |
| 67 | +def test_datacopied( |
| 68 | + arr: np.ndarray, |
| 69 | + original: Union[np.ndarray, List], |
| 70 | + expected: bool, |
| 71 | +) -> None: |
| 72 | + """ |
| 73 | + Tests the function that checks if a NumPy array has been copied from another array |
| 74 | + or list. |
| 75 | +
|
| 76 | + """ |
| 77 | + |
| 78 | + assert _datacopied(arr, original) == expected |
| 79 | + |
| 80 | + |
24 | 81 | @pytest.mark.parametrize("with_finite_check", [True, False])
|
25 | 82 | @pytest.mark.parametrize("overwrite_b", [True, False])
|
26 | 83 | @pytest.mark.parametrize("n_rhs", [0, 1, 2])
|
|
0 commit comments