sleipnirgroup-jormungandr 0.2.1__cp312-abi3-macosx_14_0_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ """
2
+ A linearity-exploiting sparse nonlinear constrained optimization problem solver
3
+ that uses the interior-point method.
4
+ """
5
+
6
+ from ._jormungandr import *
7
+
8
+ __version__ = "0.2.1"
@@ -0,0 +1 @@
1
+ from . import autodiff as autodiff, optimization as optimization
Binary file
@@ -0,0 +1,58 @@
1
+ import scipy.sparse
2
+
3
+ from .._jormungandr.autodiff import *
4
+
5
+
6
+ def spy(mat: scipy.sparse.csc_matrix):
7
+ """
8
+ Plot the sparsity pattern of a sparse matrix.
9
+
10
+ Green points represent positive values and red points represent negative
11
+ values.
12
+
13
+ Parameter ``mat``:
14
+ The sparse matrix.
15
+ """
16
+ import matplotlib.pyplot as plt
17
+ import matplotlib.ticker as mticker
18
+ from matplotlib.colors import ListedColormap
19
+
20
+ xs = []
21
+ ys = []
22
+ vs = []
23
+
24
+ cmat = mat.tocoo()
25
+ for row, col, value in zip(cmat.row, cmat.col, cmat.data):
26
+ xs.append(col)
27
+ ys.append(row)
28
+ if value > 0.0:
29
+ vs.append(1.0)
30
+ elif value < 0.0:
31
+ vs.append(-1.0)
32
+ else:
33
+ vs.append(0.0)
34
+
35
+ fig = plt.figure()
36
+ ax = fig.add_subplot()
37
+
38
+ # Display scatter plot
39
+ cmap = ListedColormap(["red", "green"])
40
+ sc = ax.scatter(xs, ys, s=1, c=vs, marker=".", cmap=cmap, vmin=-1, vmax=1)
41
+
42
+ # Display colorbar
43
+ colorbar = fig.colorbar(sc)
44
+ ticklabels = ["Negative", "Positive"]
45
+ colorbar.ax.yaxis.set_major_locator(mticker.FixedLocator(ticklabels))
46
+ colorbar.ax.set_yticks([-1, 1])
47
+ colorbar.ax.set_yticklabels(ticklabels)
48
+
49
+ ax.set_title("Sparsity")
50
+ ax.set_xlabel("Cols")
51
+ ax.set_ylabel("Rows")
52
+
53
+ ax.set_xlim([0, mat.shape[1]])
54
+ ax.set_ylim([0, mat.shape[0]])
55
+ ax.invert_yaxis()
56
+ ax.set_aspect(1.0)
57
+
58
+ plt.show()