1 //================================================================================================= 2 /*! 3 // \file blaze/math/typetraits/IsDiagonal.h 4 // \brief Header file for the IsDiagonal type trait 5 // 6 // Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved 7 // 8 // This file is part of the Blaze library. You can redistribute it and/or modify it under 9 // the terms of the New (Revised) BSD License. Redistribution and use in source and binary 10 // forms, with or without modification, are permitted provided that the following conditions 11 // are met: 12 // 13 // 1. Redistributions of source code must retain the above copyright notice, this list of 14 // conditions and the following disclaimer. 15 // 2. Redistributions in binary form must reproduce the above copyright notice, this list 16 // of conditions and the following disclaimer in the documentation and/or other materials 17 // provided with the distribution. 18 // 3. Neither the names of the Blaze development group nor the names of its contributors 19 // may be used to endorse or promote products derived from this software without specific 20 // prior written permission. 21 // 22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 23 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 27 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 28 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 31 // DAMAGE. 32 */ 33 //================================================================================================= 34 35 #ifndef _BLAZE_MATH_TYPETRAITS_ISDIAGONAL_H_ 36 #define _BLAZE_MATH_TYPETRAITS_ISDIAGONAL_H_ 37 38 39 //************************************************************************************************* 40 // Includes 41 //************************************************************************************************* 42 43 #include <blaze/math/typetraits/IsLower.h> 44 #include <blaze/math/typetraits/IsUpper.h> 45 #include <blaze/util/IntegralConstant.h> 46 47 48 namespace blaze { 49 50 //================================================================================================= 51 // 52 // CLASS DEFINITION 53 // 54 //================================================================================================= 55 56 //************************************************************************************************* 57 /*!\brief Compile time check for diagonal matrices. 58 // \ingroup math_type_traits 59 // 60 // This type trait tests whether or not the given template parameter is a diagonal matrix type 61 // (i.e. a matrix type that is guaranteed to be diagonal at compile time). In case the type is 62 // a diagonal matrix type, the \a value member constant is set to \a true, the nested type 63 // definition \a Type is \a TrueType, and the class derives from \a TrueType. Otherwise \a value 64 // is set to \a false, \a Type is \a FalseType, and the class derives from \a FalseType. 65 66 \code 67 using blaze::rowMajor; 68 69 using StaticMatrixType = blaze::StaticMatrix<double,3UL,3UL,rowMajor>; 70 using DynamicMatrixType = blaze::DynamicMatrix<float,rowMajor>; 71 using CompressedMatrixType = blaze::CompressedMatrix<int,rowMajor>; 72 73 using DiagonalStaticType = blaze::DiagonalMatrix<StaticMatrixType>; 74 using DiagonalDynamicType = blaze::DiagonalMatrix<DynamicMatrixType>; 75 using DiagonalCompressedType = blaze::DiagonalMatrix<CompressedMatrixType>; 76 77 using LowerStaticType = blaze::LowerMatrix<StaticMatrixType>; 78 using UpperDynamicType = blaze::UpperMatrix<DynamicMatrixType>; 79 80 blaze::IsDiagonal< DiagonalStaticType >::value // Evaluates to 1 81 blaze::IsDiagonal< const DiagonalDynamicType >::Type // Results in TrueType 82 blaze::IsDiagonal< volatile DiagonalCompressedType > // Is derived from TrueType 83 blaze::IsDiagonal< LowerStaticMatrixType >::value // Evaluates to 0 84 blaze::IsDiagonal< const UpperDynamicMatrixType >::Type // Results in FalseType 85 blaze::IsDiagonal< volatile CompressedMatrixType > // Is derived from FalseType 86 \endcode 87 */ 88 template< typename T > 89 struct IsDiagonal 90 : public BoolConstant< IsLower_v<T> && IsUpper_v<T> > 91 {}; 92 //************************************************************************************************* 93 94 95 //************************************************************************************************* 96 /*! \cond BLAZE_INTERNAL */ 97 /*!\brief Specialization of the IsDiagonal type trait for const types. 98 // \ingroup math_type_traits 99 */ 100 template< typename T > 101 struct IsDiagonal< const T > 102 : public IsDiagonal<T> 103 {}; 104 /*! \endcond */ 105 //************************************************************************************************* 106 107 108 //************************************************************************************************* 109 /*! \cond BLAZE_INTERNAL */ 110 /*!\brief Specialization of the IsDiagonal type trait for volatile types. 111 // \ingroup math_type_traits 112 */ 113 template< typename T > 114 struct IsDiagonal< volatile T > 115 : public IsDiagonal<T> 116 {}; 117 /*! \endcond */ 118 //************************************************************************************************* 119 120 121 //************************************************************************************************* 122 /*! \cond BLAZE_INTERNAL */ 123 /*!\brief Specialization of the IsDiagonal type trait for cv qualified types. 124 // \ingroup math_type_traits 125 */ 126 template< typename T > 127 struct IsDiagonal< const volatile T > 128 : public IsDiagonal<T> 129 {}; 130 /*! \endcond */ 131 //************************************************************************************************* 132 133 134 //************************************************************************************************* 135 /*!\brief Auxiliary variable template for the IsDiagonal type trait. 136 // \ingroup math_type_traits 137 // 138 // The IsDiagonal_v variable template provides a convenient shortcut to access the nested 139 // \a value of the IsDiagonal class template. For instance, given the type \a T the following 140 // two statements are identical: 141 142 \code 143 constexpr bool value1 = blaze::IsDiagonal<T>::value; 144 constexpr bool value2 = blaze::IsDiagonal_v<T>; 145 \endcode 146 */ 147 template< typename T > 148 constexpr bool IsDiagonal_v = IsDiagonal<T>::value; 149 //************************************************************************************************* 150 151 } // namespace blaze 152 153 #endif 154