From 5c64397fda6c14327e789d0aba8c8a73f899b569 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Tue, 1 Sep 2015 17:43:56 -0500 Subject: [PATCH] Tensor: Remove superfluous operator* variants It is completely sufficient to provide 1 ("one") templated variant. I guess, over time more and more variants were added. This increased the grade of ambiguity for the compiler to chose the one intended implementation. --- include/deal.II/base/tensor.h | 230 ----------------------------- include/deal.II/base/tensor_base.h | 220 ++++++--------------------- 2 files changed, 49 insertions(+), 401 deletions(-) diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index e03b76da2b..2aa0744d7f 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -1977,236 +1977,6 @@ linfty_norm (const Tensor<2,dim,Number> &t) -/** - * Multiplication of a tensor of general rank with a scalar Number from the - * right. - * - * @relates Tensor - */ -template -inline -Tensor -operator * (const Tensor &t, - const Number factor) -{ - Tensor tt = t; - tt *= factor; - return tt; -} - - - -/** - * Multiplication of a tensor of general rank with a scalar Number from the - * left. - * - * @relates Tensor - */ -template -inline -Tensor -operator * (const Number factor, - const Tensor &t) -{ - Tensor tt = t; - tt *= factor; - return tt; -} - - -#ifndef DEAL_II_WITH_CXX11 - -template -struct ProductType > -{ - typedef Tensor::type> type; -}; - -template -struct ProductType,U> -{ - typedef Tensor::type> type; -}; - -#endif - - -/** - * Multiplication of a tensor of general rank with a scalar number from the - * right. - * - * The purpose of this operator is to enable only multiplication of a tensor - * by a scalar number (i.e., a floating point number, a complex floating point - * number, etc.). The function is written in a way that only allows the - * compiler to consider the function if the second argument is indeed a scalar - * number -- in other words, @p OtherNumber will not match, for example - * std::vector@ as the product of a tensor and a vector - * clearly would make no sense. The mechanism by which the compiler is - * prohibited of considering this operator for multiplication with non-scalar - * types are explained in the documentation of the EnableIfScalar class. - * - * The return type of the function is chosen so that it matches the types of - * both the tensor and the scalar argument. For example, if you multiply a - * Tensor@<1,dim,double@> by std::complex@, - * then the result will be a - * Tensor@<1,dim,std::complex@@>. In other words, the - * type with which the returned tensor stores its components equals the type - * you would get if you multiplied an individual component of the input tensor - * by the scalar factor. - * - * @relates Tensor - * @relates EnableIfScalar - */ -template -inline -Tensor::type>::type> -operator * (const Tensor &t, - const OtherNumber factor) -{ - // recurse over the base objects - Tensor::type> tt; - for (unsigned int d=0; d -inline -Tensor::type>::type> -operator * (const Number factor, - const Tensor &t) -{ - // simply forward to the operator above - return t * factor; -} - - - -/** - * Division of a tensor of general rank by a scalar Number. - * - * @relates Tensor - */ -template -inline -Tensor -operator / (const Tensor &t, - const Number factor) -{ - Tensor tt = t; - tt /= factor; - return tt; -} - - - - -/** - * Multiplication of a tensor of general rank with a scalar double from the - * right. - * - * @relates Tensor - */ -template -inline -Tensor -operator * (const Tensor &t, - const double factor) -{ - Tensor tt = t; - tt *= factor; - return tt; -} - - - -/** - * Multiplication of a tensor of general rank with a scalar double from the - * left. - * - * @relates Tensor - */ -template -inline -Tensor -operator * (const double factor, - const Tensor &t) -{ - Tensor tt = t; - tt *= factor; - return tt; -} - - - -/** - * Division of a tensor of general rank by a scalar double. - * - * @relates Tensor - */ -template -inline -Tensor -operator / (const Tensor &t, - const double factor) -{ - Tensor tt = t; - tt /= factor; - return tt; -} - - - -/** - * Multiplication of a tensor of general rank by a scalar complex from - * the left. - * - * @relates Tensor - */ -template -inline -Tensor > -operator * (const std::complex factor, - const Tensor &t) -{ - Tensor > tt; - for (unsigned int d=0; d from - * the right. - * - * @relates Tensor - */ -template -inline -Tensor > -operator * (const Tensor &t, - const std::complex factor) -{ - Tensor > tt; - for (unsigned int d=0; d::memory_consumption () } + template template inline @@ -1294,6 +1295,7 @@ void Tensor<1,dim,Number>::serialize(Archive &ar, const unsigned int) #endif // DOXYGEN + /** * Output operator for tensors of rank 0. Since such tensors are scalars, we * simply print this one value. @@ -1346,61 +1348,26 @@ std::ostream &operator << (std::ostream &out, const Tensor<1,1,double> &p) -/** - * Multiplication of a tensor of rank 1 with a scalar Number from the right. - * - * @relates Tensor<1,dim,Number> - */ -template -inline -Tensor<1,dim,Number> -operator * (const Tensor<1,dim,Number> &t, - const Number factor) -{ - Tensor<1,dim,Number> tt (false); - for (unsigned int d=0; d - */ -template -inline -Tensor<1,dim,Number> -operator * (const Number factor, - const Tensor<1,dim,Number> &t) -{ - Tensor<1,dim,Number> tt (false); - for (unsigned int d=0; d -struct ProductType > +template +struct ProductType > { - typedef Tensor<1,dim,typename ProductType::type> type; + typedef Tensor::type> type; }; -template -struct ProductType,U> +template +struct ProductType,U> { - typedef Tensor<1,dim,typename ProductType::type> type; + typedef Tensor::type> type; }; #endif + + /** - * Multiplication of a tensor of rank 1 with a scalar number from the right. + * Multiplication of a tensor of rank with a scalar number from the right. * * The purpose of this operator is to enable only multiplication of a tensor * by a scalar number (i.e., a floating point number, a complex floating point @@ -1421,80 +1388,20 @@ struct ProductType,U> * you would get if you multiplied an individual component of the input tensor * by the scalar factor. * - * @relates Tensor<1,dim,Number> - * @relates EnableIfScalar - */ -template -inline -Tensor<1,dim,typename ProductType::type>::type> -operator * (const Tensor<1,dim,Number> &t, - const OtherNumber factor) -{ - // form the product. we have to convert the two factors into the final - // type via explicit casts because, for awkward reasons, the C++ - // standard committee saw it fit to not define an - // operator*(float,std::complex) - // (as well as with switched arguments and double<->float). - typedef typename ProductType::type product_type; - Tensor<1,dim,product_type> tt (false); - for (unsigned int d=0; d + * @relates Tensor * @relates EnableIfScalar */ -template +template ::type> inline -Tensor<1,dim,typename ProductType::type>::type> -operator * (const Number factor, - const Tensor<1,dim,OtherNumber> &t) +Tensor::type> +operator * (const Tensor &t, + const OtherNumber factor) { - // simply forward to the other operator with switched arguments - return (t*factor); -} - - - -/** - * Division of a tensor of rank 1 by a scalar Number. - * - * @relates Tensor<1,dim,Number> - */ -template -inline -Tensor<1,dim,Number> -operator / (const Tensor<1,dim,Number> &t, - const Number factor) -{ - Tensor<1,dim,Number> tt (false); - for (unsigned int d=0; d - */ -template -inline -Tensor<1,dim> -operator * (const Tensor<1,dim> &t, - const double factor) -{ - Tensor<1,dim> tt (false); + // recurse over the base objects + Tensor::type> tt; for (unsigned int d=0; d &t, /** - * Multiplication of a tensor of rank 1 with a scalar double from the left. + * Multiplication of a tensor of general rank with a scalar number from the + * left. See the discussion with the operator with switched arguments for more + * information about template arguments and the return type. * - * @relates Tensor<1,dim,Number> + * @relates Tensor + * @relates EnableIfScalar */ -template +template ::type> inline -Tensor<1,dim> -operator * (const double factor, - const Tensor<1,dim> &t) +Tensor::type> +operator * (const Number factor, + const Tensor &t) { - Tensor<1,dim> tt (false); - for (unsigned int d=0; d + * @relates Tensor + * @relates EnableIfScalar */ -template +template ::type> inline -Tensor<1,dim> -operator / (const Tensor<1,dim> &t, - const double factor) +Tensor::type> +operator / (const Tensor &t, + const OtherNumber factor) { - Tensor<1,dim> tt (false); + // recurse over the base objects + Tensor::type> tt; for (unsigned int d=0; d &t, -/** - * Multiplication of a tensor of rank 1 by a scalar complex from the - * right. - * - * @relates Tensor<1,dim,Number> - */ -template -inline -Tensor<1,dim,std::complex > -operator * (const Tensor<1,dim> &t, - const std::complex factor) -{ - Tensor<1,dim,std::complex > tt (false); - for (unsigned int d=0; d from the - * left. - * - * @relates Tensor<1,dim,Number> - */ -template -inline -Tensor<1,dim,std::complex > -operator * (const std::complex factor, - const Tensor<1,dim> &t) -{ - Tensor<1,dim,std::complex > tt (false); - for (unsigned int d=0; d