Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting Variables for Geometries #378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading