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

Flexible scalar assignment. #3

Open
ldalessa opened this issue Aug 3, 2018 · 0 comments
Open

Flexible scalar assignment. #3

ldalessa opened this issue Aug 3, 2018 · 0 comments
Assignees

Comments

@ldalessa
Copy link
Contributor

ldalessa commented Aug 3, 2018

Right now a fully bound tensor operator= supports assignment from scalar types. For instance

Tensor<2,2,double> T;
T(0,0) = 0.0;
T(0,1) = 1.0;

This support happens because there is a special operator=(ScalarType) defined for the result of operator()() in the tensor. In addition, there is a completely generic operator=(T&&) version as well, which matches every right-hand-side that isn't a double.

This alternate operator=(T&&) is, in fact, overly generic. It's supposed to match any right-hand-side type that looks like a tensor... either an actual tensor or some expression that can be evaluated. This means that scalar assignments for scalar types that aren't specifically the ScalarType for the tensor won't work, even if they can implicitly be converted to the ScalarType. The will all match the generic operator=(T&&) and fail to compile because they're not tensors of the right dimension.

Tensor<2,2,double> T;
T(0,0) = 0; // <-- fails because 0 is an int

We would like to support assignment from compatible scalar types where it makes sense. This can be accomplished with some form of SFINAE on the operator= API that correctly selects the scalar assignment for compatible scalars.

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

No branches or pull requests

1 participant