Skip to content

Commit 6c5a9c8

Browse files
committed
Add assertions
1 parent 408212d commit 6c5a9c8

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

simplex/smplx.pyf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
! be original, slack, surplus, or artificial variables. Slack and surplus variables are automat-
5252
! ically provided for the ≤ and ≥ constraints, and artificial variables for the = constraints.
5353
! The routine defines xₙ₊ᵢ to be the slack, surplus, or artificial variable for the iᵗʰ constraint
54-
! aᵢ₁x₁ + … + aᵢₙxₙ{≤,=,≥}bᵢ. If IND = 0 then the slack, surplus, and artificial variables
54+
! aᵢ₁x₁ + … + aᵢₙxₙ {≤,=,≥} bᵢ. If IND = 0 then the slack, surplus, and artificial variables
5555
! are the initial basic variables that are employed.
5656
!
5757
! On output IND reports the status of the results. The routine assigns IND one of the
@@ -71,7 +71,7 @@
7171
!
7272
! BI is an array of dimension m² that is used for storing the inverse of the basis matrix.
7373
! The order of the column vectors of the basis matrix corresponds to the order of the basic
74-
! variables given in IABIS. If IND ≠ 3,5 on output then BI contains the inverse of the basis
74+
! variables given in IBASIS. If IND ≠ 3,5 on output then BI contains the inverse of the basis
7575
! matrix currently in effect when the routine terminates.
7676
! WK is an array of dimension 2mn or larger, and IWK is an array of dimension 2m + n
7777
! or larger. WK and IWK are work spaces.
@@ -104,7 +104,7 @@ python module simplex ! in
104104
real intent(out), dimension(n0 + numle + numge), depend(n0, numle, numge) :: x
105105
real intent(out) :: z
106106
integer intent(out) :: iter
107-
integer intent(in) :: mxiter
107+
integer intent(in), optional, depend(m) :: mxiter = 8 * m
108108
integer intent(in), optional :: numle = 0
109109
integer intent(in), optional :: numge = 0
110110
real intent(hide), dimension(m, m), depend(m) :: bi

simplex/test_smplx.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,23 @@
9898
"Strawberry Preserves": [6.4, 11, 0.4, 7, 0.2, 0.2, 0.4, 3, 0],
9999
}
100100

101+
101102
def test_smplx():
102103
sol = smplx(
103104
a=np.column_stack([*data.values()]),
104105
b0=np.r_[*nutrients.values()],
105106
c=-np.ones(len(data)),
106107
numge=len(nutrients),
107-
mxiter=100,
108108
)
109109
assert sol[0] == 0
110+
assert sol[1].size == len(nutrients) + len(data)
111+
assert np.count_nonzero(sol[1]) == len(nutrients)
112+
assert [a for a, b in zip(nutrients, sol[1][len(data) :]) if not b] == [
113+
"Calories (kcal)",
114+
"Calcium (g)",
115+
"Vitamin A (KIU)",
116+
"Vitamin B2 (mg)",
117+
"Vitamin C (mg)",
118+
]
110119
assert sol[2] == pytest.approx(-0.10866227746009827)
120+
assert sol[3] == 8

0 commit comments

Comments
 (0)