Skip to content

Commit

Permalink
sorted variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-coscia authored and ndem0 committed Dec 11, 2024
1 parent 59c9a17 commit 23bc409
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
12 changes: 7 additions & 5 deletions pina/geometry/cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,18 @@ def _single_points_sample(n, variables):

return result

if variables == "all":
variables = self.variables
elif isinstance(variables, (list, tuple)):
variables = sorted(variables)

if self.fixed_ and (not self.range_):
return _single_points_sample(n, variables)

if variables == "all":
variables = list(self.range_.keys()) + list(self.fixed_.keys())

if mode in ["grid", "chebyshev"]:
return _1d_sampler(n, mode, variables)
return _1d_sampler(n, mode, variables).extract(variables)
elif mode in ["random", "lh", "latin"]:
return _Nd_sampler(n, mode, variables)
return _Nd_sampler(n, mode, variables).extract(variables)
else:
raise ValueError(f"mode={mode} is not valid.")

Expand Down
9 changes: 7 additions & 2 deletions pina/geometry/ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,18 @@ def _single_points_sample(n, variables):

return result

if variables == "all":
variables = self.variables
elif isinstance(variables, (list, tuple)):
variables = sorted(variables)

if self.fixed_ and (not self.range_):
return _single_points_sample(n, variables)
return _single_points_sample(n, variables).extract(variables)

if variables == "all":
variables = self.variables

if mode in ["random"]:
return _Nd_sampler(n, mode, variables)
return _Nd_sampler(n, mode, variables).extract(variables)
else:
raise NotImplementedError(f"mode={mode} is not implemented.")
8 changes: 7 additions & 1 deletion pina/geometry/simplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,17 @@ def sample(self, n, mode="random", variables="all"):
in ``variables``.
"""

if variables == "all":
variables = self.variables
elif isinstance(variables, (list, tuple)):
variables = sorted(variables)

if mode in ["random"]:
if self._sample_surface:
sample_pts = self._sample_boundary_randomly(n)
else:
sample_pts = self._sample_interior_randomly(n, variables)
sample_pts = self._sample_interior_randomly(n, variables
)

else:
raise NotImplementedError(f"mode={mode} is not implemented.")
Expand Down

0 comments on commit 23bc409

Please sign in to comment.