diff --git a/pyproject.toml b/pyproject.toml index 55f6716..6bd44b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ dependencies = [ "pathsim>=0.22", "numpy>=1.15", - "scipy>=1.2", + "scipy>=1.8", "scikit-rf>=0.30", "ElecSolver>=2.2.1", # If a dependency ships native code that can't be installed in Pyodide, diff --git a/src/pathsim_rf/circuit.py b/src/pathsim_rf/circuit.py index c8f63af..5e08303 100644 --- a/src/pathsim_rf/circuit.py +++ b/src/pathsim_rf/circuit.py @@ -31,7 +31,7 @@ def _source_matrix(builder): Returns ------- - B : scipy.sparse.csr_matrix, shape (n, number of sources) + B : scipy.sparse.csr_array, shape (n, number of sources) superposition matrix, one column per source """ n = builder.number_intensities + builder.size @@ -49,12 +49,12 @@ def _source_matrix(builder): data, (rows,) = builder.build_second_member(check=False) col = np.zeros(n) np.add.at(col, rows, data) - cols.append(sp.csc_matrix(col.reshape(-1, 1))) + cols.append(sp.csc_array(col.reshape(-1, 1))) finally: builder.current_source_data, builder.voltage_source_data = saved builder.build_second_member(check=False) - return sp.hstack(cols, format="csr") if cols else sp.csr_matrix((n, 0)) + return sp.hstack(cols, format="csr") if cols else sp.csr_array((n, 0)) # BLOCKS ================================================================================ @@ -309,8 +309,8 @@ def __init__( labels.append(f"I({name})") ny = len(labels) - C = sp.csr_matrix((vals, (rows, cols)), shape=(ny, n)) - D = sp.csr_matrix((np.ones(len(drows)), (drows, dcols)), shape=(ny, len(self.input_names))) + C = sp.csr_array((vals, (rows, cols)), shape=(ny, n)) + D = sp.csr_array((np.ones(len(drows)), (drows, dcols)), shape=(ny, len(self.input_names))) self.output_names = labels #initial condition by name diff --git a/src/pathsim_rf/netlist_to_statespace.py b/src/pathsim_rf/netlist_to_statespace.py index 0cb3743..2c50107 100644 --- a/src/pathsim_rf/netlist_to_statespace.py +++ b/src/pathsim_rf/netlist_to_statespace.py @@ -526,7 +526,7 @@ def _solve_with_scipy(mat: np.ndarray, rhs: np.ndarray, context: str) -> np.ndar for eps in (0.0, 1e-15, 1e-12, 1e-9, 1e-6): try: matrix = mat if eps == 0.0 else mat + eps * np.eye(mat.shape[0]) - factor = splu(sps.csc_matrix(matrix)) + factor = splu(sps.csc_array(matrix)) columns = [ np.asarray(factor.solve(np.asarray(column, dtype=float)), dtype=float) for column in rhs_2d.T diff --git a/tests/test_circuit.py b/tests/test_circuit.py index 9d9fd19..42f9617 100644 --- a/tests/test_circuit.py +++ b/tests/test_circuit.py @@ -68,7 +68,15 @@ def test_default_ports(self): ) self.assertEqual(len(blk.inputs), 1) self.assertEqual(len(blk.outputs), 5) - + + def test_system_matrices_are_sparse_arrays(self): + import scipy.sparse as sp + blk = NetlistCircuit(RC + "I1 0 out 1m\n") + for name in ("S1", "S2", "B", "C", "D", "_P", "_S2r"): + with self.subTest(name=name): + self.assertIsInstance(getattr(blk, name), sp.sparray) + self.assertEqual(blk.B.shape, (blk.n, 2)) + def test_input_order_voltage_then_current_sources(self): net = RC + "I1 0 out 1m\nV2 x 0 0\nRx x out 1\n" blk = NetlistCircuit(net)