pytmpinv 1.2.1__tar.gz → 1.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytmpinv
3
- Version: 1.2.1
3
+ Version: 1.3.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 = "1.2.1"
3
+ version = "1.3.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: 1.2.1
3
+ Version: 1.3.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__ = "1.2.1"
1
+ __version__ = "1.3.0"
2
2
 
3
3
  from .tmpinv import tmpinv
4
4
 
@@ -77,7 +77,6 @@ def TMPinvSolve(
77
77
  M: Sequence[Sequence[float]] | None = None,
78
78
  b_row: Sequence[float] | None = None,
79
79
  b_col: Sequence[float] | None = None,
80
- b_lim: Sequence[float] | None = None,
81
80
  b_val: Sequence[float] | None = None,
82
81
  i: int = 1,
83
82
  j: int = 1,
@@ -137,13 +136,13 @@ def TMPinvSolve(
137
136
 
138
137
  Notes
139
138
  ----
140
- In the reduced model, `S` is ignored. Slack behavior is derived implicitly
139
+ - In the reduced model, `S` is ignored. Slack behavior is derived implicitly
141
140
  from block-wise marginal totals. Likewise, `M` must be a unique row subset
142
141
  of an identity matrix (i.e., diagonal-only). Arbitrary or non-diagonal model
143
142
  matrices cannot be mapped to reduced blocks, making the model infeasible.
144
- This function may also receive internally generated keyword arguments
145
- (`b_lim`, `C_lim`) from `tmpinv()`. These arguments are ignored in the
146
- reduced model given its replacement of `S`.
143
+ - This function receives internal keyword arguments ['b_lim' : array_like,
144
+ 'C_lim' : array_like] from `tmpinv()` containing cell value bounds. These
145
+ arguments are ignored in the reduced model given its replacement of `S`.
147
146
  """
148
147
  # (m), (p) Process the parameters, assert conformity, and get dimensions
149
148
  if b_row is None or b_col is None:
@@ -157,9 +156,11 @@ def TMPinvSolve(
157
156
  m = b_row.shape[0] * i
158
157
  p = b_col.shape[0] * j
159
158
  if S is not None:
160
- S = np.asarray(S, dtype=np.float64)
161
- if S.shape != (m + p, m + p):
162
- raise TMPinvInputError(f"S must have shape {(m+p, m+p)}.")
159
+ n_rows = m + p + (kwargs.get("C_lim").shape[0]
160
+ if kwargs.get("C_lim") is not None else 0)
161
+ S = np.asarray(S, dtype=np.float64)
162
+ if S.shape[0] != n_rows:
163
+ raise TMPinvInputError(f"S must have {n_rows} rows.")
163
164
  if (not np.all((S == -1) | (S == 0) | (S == 1)) or
164
165
  np.abs(S).sum(axis=0).max() > 1 or
165
166
  np.abs(S).sum(axis=1).max() > 1):
@@ -355,8 +356,12 @@ def tmpinv(
355
356
  -np.hstack([np.zeros((n_cells, S.shape[1] + n_cells)),
356
357
  np.eye(n_cells)])])
357
358
  finite_rows = np.isfinite(b_lim[:, 0]) # drop rows with ±np.inf
358
- nonzero_cols = ~np.all(S[finite_rows, :] == 0,
359
- axis=0) # reduce S width
359
+ nonzero_cols = ~np.all(S[np.concatenate([
360
+ np.ones(S.shape[0] -
361
+ b_lim.shape[0],
362
+ dtype=bool),
363
+ finite_rows]),
364
+ :] == 0, axis=0) # reduce S width
360
365
  for _ in range(iteration_limit):
361
366
  M_idx, b_val = [], []
362
367
  x = result.x.reshape(-1, 1)
@@ -369,11 +374,16 @@ def tmpinv(
369
374
  b_val.append(v)
370
375
  if len(M_idx) < n_cells:
371
376
  M = np.eye(n_cells, dtype=np.float64)[M_idx]
372
- result = TMPinvSolve(*args, C_lim=(C_lim[finite_rows, :]),
373
- S=(S[finite_rows, :])[:,nonzero_cols],
374
- M=M,
375
- b_lim=(b_lim[finite_rows, :]),
376
- b_val=b_val, **kw)
377
+ result = TMPinvSolve(*args, b_lim=(b_lim[finite_rows, :]),
378
+ b_val=b_val,
379
+ C_lim=(C_lim[finite_rows, :]),
380
+ S=(S[np.concatenate([
381
+ np.ones(S.shape[0] -
382
+ b_lim.shape[0],
383
+ dtype=bool),
384
+ finite_rows]),
385
+ :])[:,nonzero_cols],
386
+ M=M, **kw)
377
387
  else:
378
388
  break
379
389
 
File without changes
File without changes
File without changes