pytmpinv 2.5.0__tar.gz → 2.7.0__tar.gz

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.

Potentially problematic release.


This version of pytmpinv might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytmpinv
3
- Version: 2.5.0
3
+ Version: 2.7.0
4
4
  Summary: Tabular Matrix Problems via Pseudoinverse Estimation
5
5
  Author-email: The Economist <29724411+econcz@users.noreply.github.com>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pytmpinv"
3
- version = "2.5.0"
3
+ version = "2.7.0"
4
4
  description = "Tabular Matrix Problems via Pseudoinverse Estimation"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytmpinv
3
- Version: 2.5.0
3
+ Version: 2.7.0
4
4
  Summary: Tabular Matrix Problems via Pseudoinverse Estimation
5
5
  Author-email: The Economist <29724411+econcz@users.noreply.github.com>
6
6
  License-Expression: MIT
@@ -1,4 +1,4 @@
1
- __version__ = "2.5.0"
1
+ __version__ = "2.7.0"
2
2
 
3
3
  from .tmpinv import tmpinv
4
4
 
@@ -168,14 +168,14 @@ def TMPinvSolve(
168
168
  arguments are ignored in the reduced model given its replacement of `S`.
169
169
  """
170
170
  # (m), (p) Process the parameters, assert conformity, and get dimensions
171
- if b_row is None or b_col is None:
171
+ if b_row is None or b_col is None:
172
172
  raise TMPinvInputError("Both b_row and b_col must be provided.")
173
- if len(b_row) < 2 or len(b_col) < 2:
173
+ if len(b_row) < 2 or len(b_col) < 2:
174
174
  raise TMPinvInputError("Minimum length for b_row and b_col is 2.")
175
- if not np.isfinite(b_row).all() or not np.isfinite(b_col).all():
176
- raise TMPinvInputError("b_row and b_col must not contain inf or NaN.")
177
175
  b_row = np.asarray(b_row, dtype=np.float64).reshape(-1, 1)
178
176
  b_col = np.asarray(b_col, dtype=np.float64).reshape(-1, 1)
177
+ if not np.isfinite(b_row).all() or not np.isfinite(b_col).all():
178
+ raise TMPinvInputError("b_row and b_col must not contain inf or NaN.")
179
179
  m = b_row.shape[0] * i
180
180
  p = b_col.shape[0] * j
181
181
  if S is not None:
@@ -212,7 +212,7 @@ def TMPinvSolve(
212
212
  "m", "p",
213
213
  "i", "j",
214
214
  "zero_diagonal",
215
- "symmetric"}}
215
+ "symmetric", "bounds"}}
216
216
 
217
217
  # perform full estimation and return the result
218
218
  if reduced is None:
@@ -270,23 +270,17 @@ def TMPinvSolve(
270
270
  for idx, row in enumerate(M):
271
271
  col = np.argmax(row)
272
272
  r, c = divmod(col, p) # M has m * p columns
273
- X_true[r, c] = b_val.ravel()[idx]
274
- if kwargs.get("b_lim") is not None:
273
+ X_true[r, c] = b_val.ravel(order='C')[idx]
274
+ if kwargs.get("bounds") is not None:
275
275
  X_lim = np.full((2*m, p), np.nan, dtype=np.float64)
276
- l_idx = (lambda x: kwargs["b_lim"].shape[0] if not x.size else
277
- x[0,0])(np.argwhere(S[-kwargs["b_lim"].shape[0]:,:] == -1))
278
- if l_idx > 0: # upper bounds
279
- for idx, row in enumerate(kwargs["C_lim"][:l_idx,:]):
280
- col = np.argmax(row)
281
- r, c = divmod(col, p)
282
- X_lim[ r, c] = kwargs["b_lim"].ravel()[ idx]
283
- if l_idx < kwargs["b_lim"].shape[0]: # lower bounds
284
- for idx, row in enumerate(kwargs["C_lim"][l_idx:,:]):
285
- col = np.argmax(row)
286
- r, c = divmod(col, p)
287
- X_lim[m+r, c] = kwargs["b_lim"].ravel()[l_idx+idx]
288
- if S is not None and np.any(S[: S.shape[0] if kwargs.get("b_lim")
289
- is None else -kwargs["b_lim"].shape[0],:] != 0):
276
+ for flat_idx, (l, h) in enumerate(kwargs.get("bounds")):
277
+ r, c = divmod(flat_idx, p)
278
+ if h is not None: # upper bounds
279
+ X_lim[ r, c] = float(h)
280
+ if l is not None: # lower bounds
281
+ X_lim[m+r, c] = float(l)
282
+
283
+ if S is not None and np.size(S) > 0:
290
284
  warnings.warn("User-provided S is ignored in the reduced model.",
291
285
  UserWarning)
292
286
 
@@ -302,11 +296,11 @@ def TMPinvSolve(
302
296
  b_subset = [b_row[m_start:m_end].reshape(-1, 1),
303
297
  b_col[p_start:p_end].reshape(-1, 1)]
304
298
  M_subset = None
305
- if kwargs.get("b_lim") is not None:
299
+ if kwargs.get("bounds") is not None:
306
300
  subset = np.vstack([
307
301
  X_lim[ m_start: m_end, p_start:p_end],
308
302
  X_lim[m+m_start:m+m_end, p_start:p_end]
309
- ]).ravel()
303
+ ]).ravel(order='C')
310
304
  non_empty = ~np.isnan(subset)
311
305
  if non_empty.any():
312
306
  b_subset.append(subset[non_empty].reshape(-1, 1))
@@ -326,8 +320,11 @@ def TMPinvSolve(
326
320
  np.hstack([np.zeros((S.shape[0],
327
321
  S_subset.shape[1])),
328
322
  S]) ])
323
+ S_subset = S_subset[:, ~np.all(S_subset == 0, axis=0)]
329
324
  if M is not None:
330
- subset = X_true[m_start:m_end, p_start:p_end].ravel()
325
+ subset = X_true[m_start:m_end, p_start:p_end].ravel(
326
+ order='C'
327
+ )
331
328
  non_empty = ~np.isnan(subset)
332
329
  if non_empty.any():
333
330
  b_subset.append(subset[non_empty].reshape(-1, 1))
@@ -411,6 +408,7 @@ def tmpinv(
411
408
  # (result) Perform bound-constrained iterative refinement
412
409
  kw = {k: v for k, v in kwargs.items() if k not in {"b_lim", "b_val",
413
410
  "C_lim", "S", "M"}}
411
+ kw.update({"bounds": bounds})
414
412
  b_lim = np.vstack([np.array([h if h is not None else np.inf for l, h
415
413
  in bounds]).reshape(-1, 1),
416
414
  np.array([l if l is not None else -np.inf for l, h
File without changes
File without changes
File without changes