Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator* for Tensor of Tensors (ToT) #282

Open
ryanmrichard opened this issue Jun 15, 2021 · 3 comments
Open

operator* for Tensor of Tensors (ToT) #282

ryanmrichard opened this issue Jun 15, 2021 · 3 comments

Comments

@ryanmrichard
Copy link
Contributor

Presently multiplying ToT requires calling einsum. Unfortunately that makes it hard to write generic functions. I originally added einsum because I couldn't figure out how to get ToT multiplication to slide into the existing expression layer. I haven't prototyped it, but maybe you have a ToTMultiplication class which is returned when either tensor is a tot (you can deduce if either side of operator* is a ToT based on the tile types). It could then call einsum when it is assigned to a TsrExpr. The reason I'm thinking a new class is because the left and right sides of the expression generating the ToTMultiplication instance would have to just be annotated tensors, and you would have to immediately assign it to a TsrExpr (so it doesn't fully participate in the expression layer).

This could be somewhat related to #224 in that with general tensor contractions you may also be restricting non-ToT multiplications in a similar manner.

If the above plan sounds reasonable I could try taking a stab at this.

@evaleev
Copy link
Member

evaleev commented Jun 16, 2021

problem is that the expression layer already supports some ToT products, namely where inner or outer index product is a pure contraction (free and contracted indices only) or a pure Hadamard (fused indices only). New einsum in #285 uses that in one of the paths as far as I recall (@asadchev plz correct me if I'm wrong). So I don't see how to "disable" operator* for those cases ... perhaps I'm not following exactly what you are trying to do?

@ryanmrichard
Copy link
Contributor Author

@evaleev I think ToT times ToT can go through operator*, but non-ToT times ToT can't. Regardless, I forgot that operator* already worked for some cases so my redirection solution won't work.

Basically I was hoping to write a generic orbital transform function which superficially looks like:

template<typename ResultType, typename TransformType, typename TensorType>
auto transform(TransformType&& C, TensorType&& t) {
    // function which works out what the annotations are
    auto [result_annotation, lhs_annotation, rhs_annotation] = make_annotations();
    ResultType result;
    result(result_annotation) = C(lhs_annotation) * t(rhs_annotation);
    return result;
}

I can write it in terms of einsum, but assumed that wouldn't be as efficient for non-ToTs.

@asadchev
Copy link
Contributor

asadchev commented Jun 16, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants