Skip to content

The most effective way to transform each lane for generic dimensions. #1313

Description

@Wleter

Hi, appreciate this crate it's really well thought. I am using it in scientific project where performance is important, so I have a question
whether I implemented transformations of each lane in a generic ndarray the best way possible or not.

I am wondering because when I looked at flamegraph of my calculations and almost 70% of my time is spend on heap allocation and freeing, after adding those operations. I tried many changes but I didn't succeed.

The first transformation is like a generalized matrix multiplying (I am also wondering whether there is a way to multiply not 1d lane but 2d "multi lane" if it is possible)

fn matrix_transform(&mut self, array: &mut Array<Complex64, N>) {
    array.lanes_mut(Axis(self.dimension_no))
        .into_iter()
        .par_bridge()
        .for_each(|mut lane| lane.assign(&self.transformation.dot(&lane)));
}

and the second transformation transform each lane using fft

fn fft_transform(&mut self, array: &mut Array<Complex64, N>) {
    let dimension_size_sqrt = (self.dimension_size as f64).sqrt();

    array.lanes_mut(Axis(self.dimension_no))
        .into_iter()
        .par_bridge()
        .for_each(|mut lane| {
            let mut temp = lane.to_vec();
            self.fft.process(&mut temp);

            lane.iter_mut().zip(temp.iter()).for_each(|(dest, src)| {
                *dest = *src / dimension_size_sqrt;
            });
        });
}

Thanks in advance!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions