Skip to content

LHS: return iterator instead of Array2 #277

@jonaspleyer

Description

@jonaspleyer

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>>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions