From 23bc40924f32092dc1bca9a405e7c936fc979484 Mon Sep 17 00:00:00 2001 From: Dario Coscia Date: Thu, 7 Nov 2024 15:28:21 +0100 Subject: [PATCH] sorted variables --- pina/geometry/cartesian.py | 12 +++++++----- pina/geometry/ellipsoid.py | 9 +++++++-- pina/geometry/simplex.py | 8 +++++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pina/geometry/cartesian.py b/pina/geometry/cartesian.py index ef1a6fe9..11354b62 100644 --- a/pina/geometry/cartesian.py +++ b/pina/geometry/cartesian.py @@ -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.") diff --git a/pina/geometry/ellipsoid.py b/pina/geometry/ellipsoid.py index e809bf6c..2baea532 100644 --- a/pina/geometry/ellipsoid.py +++ b/pina/geometry/ellipsoid.py @@ -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.") diff --git a/pina/geometry/simplex.py b/pina/geometry/simplex.py index 8a604b79..4f2e3623 100644 --- a/pina/geometry/simplex.py +++ b/pina/geometry/simplex.py @@ -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.")