egobox icon indicating copy to clipboard operation
egobox copied to clipboard

LHS: return iterator instead of Array2

Open jonaspleyer opened this issue 5 months ago • 1 comments

Hi there,

I am currently using egobox for its implementation of the Latin-Hypercube algorithm. The sample(n_points: usize) method returns a fully-allocated Array2<_> and internally uses two Array2<_> of the same size for constructing it. My problem is that with 10_000 sampled points, the memory allocation is quite large and I do not use the produced Array2<_> but simply turn it into an iterator over the individual points.

My question is if there are any plans to support this kind of use-case. The most straight-forward approach would be to extend the SamplingMethod trait.

pub trait SamplingMethod<F: Float> {
    fn sampling_space(&self) -> &Array2<F>;
    fn normalized_sample(&self, ns: usize) -> Array2<F>;
    fn sample(&self, ns: usize) -> Array2<F>;

    // New methods
    fn normalized_sample_iter(&self, ns: usize) -> impl IntoIterator<Item = Array1<F>>;
    fn sample_iter(&self, ns: usize) -> impl IntoIterator<Item = Array1<F>>;

jonaspleyer avatar Jun 15 '25 14:06 jonaspleyer

My use cases do not involve more than a few hundreds points. So, no plan to support this use case on my side, but I would be happy to accept a PR to implement this.

relf avatar Jun 16 '25 08:06 relf