Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/pathsim_rf/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ================================================================================
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pathsim_rf/netlist_to_statespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion tests/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading