Skip to content

Commit

Permalink
feat(utils): Deprecate target format constraints
Browse files Browse the repository at this point in the history
And simplify reorder_constraints
  • Loading branch information
Jacob-Stevens-Haas committed Jan 10, 2024
1 parent 638e4bb commit bd95524
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions pysindy/utils/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from itertools import repeat
from typing import Sequence

Expand Down Expand Up @@ -136,24 +137,17 @@ def drop_nan_samples(x, y):
return x, y


def reorder_constraints(c, n_features, output_order="row"):
"""Reorder constraint matrix."""
ret = c.copy()

if ret.ndim == 1:
ret = ret.reshape(1, -1)

n_targets = ret.shape[1] // n_features
shape = (n_targets, n_features)

if output_order == "row":
for i in range(ret.shape[0]):
ret[i] = ret[i].reshape(shape).flatten(order="F")
def reorder_constraints(arr, n_features, output_order="feature"):
"""Switch between 'feature' and 'target' constraint order."""
warnings.warn("Target format constraints are deprecated.", stacklevel=2)
n_constraints = arr.shape[0] if arr.ndim > 1 else 1
n_tgt = arr.size // n_features // n_constraints
if output_order == "feature":
starting_shape = (n_constraints, n_tgt, n_features)
else:
for i in range(ret.shape[0]):
ret[i] = ret[i].reshape(shape, order="F").flatten()
starting_shape = (n_constraints, n_features, n_tgt)

return ret
return arr.reshape(starting_shape).transpose([0, 2, 1]).reshape((n_constraints, -1))


def prox_l0(x, threshold):
Expand Down

0 comments on commit bd95524

Please sign in to comment.