Skip to content

Broadcasting for elementwise operations #2

@Sirplentifus

Description

@Sirplentifus

Hi there, first of all, thank you for creating this library, it seems like it's exactly what I need for this project I'm working on at the moment. My application is a bit different than what your library is designed for - I'm working on a differential algebra toolbox which should only need relatively small tensors, which I want to be static, or at least to have the option for this, as well as living in contiguous memory since in my case the tensors are almost always dense. This option isn't offered by the existing packages that I know, such as DACE.

One thing I would need is a way to do element wise multiplication with broadcasting. Here's an example, which won't compile:

tensori<float, storage_vec<ny>> d0(0);
tensori<float, storage_vec<ny>, storage_sym<nx>> d2(0), e2(0);

d2(i,j,k) = (e2(i,j,k) * d0(i)); // even though i appears twice, I don't want it to be summed as the Einstein notation interpretation of this expression implies

I am working around this with the following function, which is a solution I am more than OK with for the time being, I would just like your opinion on whether there is a better way to use your library for this and similar purposes:

template<typename T1, typename T2>
T1 elemMul_3_1(T1 const & a, T2 const & b) {
	return T1([&](int i, int j, int k) -> typename T1::Scalar {
		return a(i,j,k) * b(i);
	});
}

Once again, thank you for creating this library!

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