Use an array-of-scalars as the base case for Tensor. #16480
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #16474, I replaced the data structure to store the elements of a tensor from a C-style array to a
std::array
. But for rank-1 tensors, this is still an array ofTensor<0,dim>
. This patch breaks the recursion one level higher: Rather than going to tostd::array<Tensor<0,dim>,dim>
, we now usestd::array<Number,dim>
.The marginally non-trivial part is that we now have to initialize this array where before the default constructor of
Tensor<0,dim>
did that. This is awkward becausestd::array
by default does not initialize its elements if they are built-in types. The first commit letsstd::array
not initialize its elements, and then usesstd::fill
to initialize the elements.The second commit avoids this two-step process by direct initialization of the elements using a brace-enclosed initializer list. This took me a little bit to come up, and I will admit that the solution is perhaps not easy to understand at first read. But it is localized, and I tried to document it well enough. It uses some fun features of C++ :-)
Related to #16465.