This commit is contained in:
Hieu Hoang 2016-09-03 02:02:03 +01:00
parent ce121e4ee9
commit 9c18d1c230
1235 changed files with 553444 additions and 4 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
project(amunn CXX)
SET(CMAKE_CXX_FLAGS " -std=c++11 -g -O3 -pthread -funroll-loops -Wno-unused-result -Wno-deprecated")
SET(CMAKE_CXX_FLAGS " -std=c++14 -g -O3 -pthread -funroll-loops -Wno-unused-result -Wno-deprecated")
LIST(APPEND CUDA_NVCC_FLAGS --default-stream per-thread; -std=c++11; -g; -O3; -arch=sm_35; -lineinfo; --use_fast_math;)
add_definitions(-DCUDA_API_PER_THREAD_DEFAULT_STREAM)
SET(CUDA_PROPAGATE_HOST_FLAGS OFF)

View File

@ -67,8 +67,9 @@
</tool>
</toolChain>
</folderInfo>
<fileInfo id="com.nvidia.cuda.ide.seven_five.configuration.debug.2085852150.1621792310" name="kenlm.h" rcbsApplicability="disable" resourcePath="gpu/decoder/kenlm.h" toolsToInvoke=""/>
<sourceEntries>
<entry excluding="decoder/kenlm.h|decoder/kenlm.cpp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
<entry excluding="gpu/decoder/kenlm.h|gpu/decoder/kenlm.cpp|decoder/kenlm.h|decoder/kenlm.cpp" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>
@ -153,10 +154,10 @@
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Release">
<configuration configurationName="Debug">
<resource resourceType="PROJECT" workspacePath="/amunmt"/>
</configuration>
<configuration configurationName="Debug">
<configuration configurationName="Release">
<resource resourceType="PROJECT" workspacePath="/amunmt"/>
</configuration>
</storageModule>

View File

@ -35,6 +35,11 @@
<type>2</type>
<locationURI>PARENT-1-PROJECT_LOC/src/common</locationURI>
</link>
<link>
<name>cpu</name>
<type>2</type>
<locationURI>PARENT-1-PROJECT_LOC/src/cpu</locationURI>
</link>
<link>
<name>gpu</name>
<type>2</type>

View File

@ -1,5 +1,6 @@
include_directories(.)
include_directories(cpu)
add_subdirectory(yaml-cpp)
@ -37,6 +38,9 @@ cuda_add_executable(
common/sentence.cpp
gpu/mblas/matrix.cu
gpu/dl4mt/gru.cu
cpu/mblas/matrix.cpp
cpu/mblas/phoenix_functions.cpp
cpu/dl4mt/encoder.cpp
$<TARGET_OBJECTS:libamun>
$<TARGET_OBJECTS:libcommon>
$<TARGET_OBJECTS:libyaml-cpp>

60
src/cpu/blaze/Blaze.h Normal file
View File

@ -0,0 +1,60 @@
//=================================================================================================
/*!
// \file blaze/Blaze.h
// \brief Primary include file of the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_BLAZE_H_
#define _BLAZE_BLAZE_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/Math.h>
#include <blaze/Util.h>
//=================================================================================================
//
// DOXYGEN DOCUMENTATION
//
//=================================================================================================
//*************************************************************************************************
//! Namespace of the \b Blaze C++ math library.
namespace blaze {}
//*************************************************************************************************
#endif

84
src/cpu/blaze/Math.h Normal file
View File

@ -0,0 +1,84 @@
//=================================================================================================
/*!
// \file blaze/math.h
// \brief Header file for the inclusion of the math module of the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_MODULE_H_
#define _BLAZE_MATH_MODULE_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/Accuracy.h>
#include <blaze/math/Aliases.h>
#include <blaze/math/AlignmentFlag.h>
#include <blaze/math/BLAS.h>
#include <blaze/math/CompressedMatrix.h>
#include <blaze/math/CompressedVector.h>
#include <blaze/math/Constants.h>
#include <blaze/math/Constraints.h>
#include <blaze/math/CustomMatrix.h>
#include <blaze/math/CustomVector.h>
#include <blaze/math/DiagonalMatrix.h>
#include <blaze/math/DynamicMatrix.h>
#include <blaze/math/DynamicVector.h>
#include <blaze/math/Epsilon.h>
#include <blaze/math/Functions.h>
#include <blaze/math/Functors.h>
#include <blaze/math/Infinity.h>
#include <blaze/math/InversionFlag.h>
#include <blaze/math/HermitianMatrix.h>
#include <blaze/math/HybridMatrix.h>
#include <blaze/math/HybridVector.h>
#include <blaze/math/LAPACK.h>
#include <blaze/math/LowerMatrix.h>
#include <blaze/math/PaddingFlag.h>
#include <blaze/math/Serialization.h>
#include <blaze/math/Shims.h>
#include <blaze/math/SMP.h>
#include <blaze/math/StaticMatrix.h>
#include <blaze/math/StaticVector.h>
#include <blaze/math/StorageOrder.h>
#include <blaze/math/StrictlyLowerMatrix.h>
#include <blaze/math/StrictlyUpperMatrix.h>
#include <blaze/math/SymmetricMatrix.h>
#include <blaze/math/Traits.h>
#include <blaze/math/TransposeFlag.h>
#include <blaze/math/TypeTraits.h>
#include <blaze/math/UniLowerMatrix.h>
#include <blaze/math/UniUpperMatrix.h>
#include <blaze/math/UpperMatrix.h>
#include <blaze/math/Views.h>
#endif

10694
src/cpu/blaze/Tutorial.h Normal file

File diff suppressed because it is too large Load Diff

90
src/cpu/blaze/Util.h Normal file
View File

@ -0,0 +1,90 @@
//=================================================================================================
/*!
// \file blaze/Util.h
// \brief Header file for the inclusion of the utility module of the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_UTIL_MODULE_H_
#define _BLAZE_UTIL_MODULE_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/util/AlignedAllocator.h>
#include <blaze/util/AlignedArray.h>
#include <blaze/util/AlignmentCheck.h>
#include <blaze/util/Algorithm.h>
#include <blaze/util/Assert.h>
#include <blaze/util/ColorMacros.h>
#include <blaze/util/Complex.h>
#include <blaze/util/Constraints.h>
#include <blaze/util/Convert.h>
#include <blaze/util/DimensionOf.h>
#include <blaze/util/DisableIf.h>
#include <blaze/util/EmptyType.h>
#include <blaze/util/EnableIf.h>
#include <blaze/util/Exception.h>
#include <blaze/util/Indices.h>
#include <blaze/util/IntegralConstant.h>
#include <blaze/util/InputString.h>
#include <blaze/util/InvalidType.h>
#include <blaze/util/Limits.h>
#include <blaze/util/Logging.h>
#include <blaze/util/Memory.h>
#include <blaze/util/MemoryPool.h>
#include <blaze/util/MPL.h>
#include <blaze/util/NonCopyable.h>
#include <blaze/util/NonCreatable.h>
#include <blaze/util/NullType.h>
#include <blaze/util/PointerCast.h>
#include <blaze/util/Policies.h>
#include <blaze/util/PtrIterator.h>
#include <blaze/util/PtrVector.h>
#include <blaze/util/Random.h>
#include <blaze/util/Serialization.h>
#include <blaze/util/Singleton.h>
#include <blaze/util/StaticAssert.h>
#include <blaze/util/Suffix.h>
#include <blaze/util/SystemClock.h>
#include <blaze/util/SystemClockID.h>
#include <blaze/util/Thread.h>
#include <blaze/util/ThreadPool.h>
#include <blaze/util/Time.h>
#include <blaze/util/Timing.h>
#include <blaze/util/TypeList.h>
#include <blaze/util/Types.h>
#include <blaze/util/TypeTraits.h>
#include <blaze/util/UnsignedValue.h>
#include <blaze/util/ValueTraits.h>
#endif

View File

@ -0,0 +1,65 @@
//=================================================================================================
/*!
// \file blaze/config/Assertion.h
// \brief Configuration of the run time assertion macros
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
/*!\brief Compilation switch for internal assertions.
// \ingroup config
//
// This compilation switch triggers internal assertions, which are used to verify the program
// itself. The internal assertions can also be deactivated by defining \a NDEBUG during the
// compilation.
//
// Possible settings for the internal assertion switch:
// - Deactivated: \b 0
// - Activated : \b 1
*/
#define BLAZE_INTERNAL_ASSERTION 0
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Compilation switch for user assertions.
// \ingroup config
//
// This compilation switch triggers user assertions, which are used to check user specified
// function parameters and values. The user assertions can also be deactivated by defining
// \a NDEBUG during the compilation.
//
// Possible settings for the user assertion switch:
// - Deactivated: \b 0
// - Activated : \b 1
*/
#define BLAZE_USER_ASSERTION 0
//*************************************************************************************************

View File

@ -0,0 +1,92 @@
//=================================================================================================
/*!
// \file blaze/config/BLAS.h
// \brief Configuration of the BLAS mode
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
/*!\brief Compilation switch for the BLAS mode.
// \ingroup config
//
// This compilation switch enables/disables the BLAS mode. In case the BLAS mode is enabled,
// several basic linear algebra functions (such as for instance matrix-matrix multiplications
// between two dense matrices) are handled by performance optimized BLAS functions. Note that
// in this case it is mandatory to provide the according BLAS header file for the compilation
// of the Blaze library. In case the BLAS mode is disabled, all linear algebra functions use
// the default implementations of the Blaze library and therefore BLAS is not a requirement
// for the compilation process.
//
// Possible settings for the BLAS switch:
// - Deactivated: \b 0
// - Activated : \b 1
//
// Note that changing the setting of the BLAS mode requires a recompilation of all code using
// the Blaze library.
*/
#define BLAZE_BLAS_MODE 0
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Compilation switch for the parallel BLAS mode.
// \ingroup config
//
// This compilation switch specifies whether the used BLAS library is itself parallelized or not.
// In case the given BLAS library is itself parallelized, the Blaze library does not perform any
// attempt to parallelize the execution of BLAS kernels. If, however, the given BLAS library is
// not parallelized Blaze will attempt to parallelize the execution of BLAS kernels.
//
// Possible settings for the switch:
// - BLAS library is not parallelized: \b 0
// - BLAS library is parallelized : \b 1
//
// Note that changing the setting of the BLAS mode requires a recompilation of all code using the
// Blaze library.
*/
#define BLAZE_BLAS_IS_PARALLEL 0
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Compilation switch for the of the BLAS include file.
// \ingroup config
//
// This compilation switch specifies the name of the BLAS include file. By default, the header
// \c <cblas.h> is included when the BLAS mode is activated. In case the name of the include file
// differs (as for instance in case of the MKL the file is called \c <mkl_cblas.h>) this switch
// needs to be adapted accordingly.
//
// Note that changing the name of the BLAS include file requires a recompilation of all code using
// the Blaze library.
*/
#define BLAZE_BLAS_INCLUDE_FILE <cblas.h>
//*************************************************************************************************

View File

@ -0,0 +1,51 @@
//=================================================================================================
/*!
// \file blaze/config/CacheSize.h
// \brief Configuration of the cache size of the target architecture
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
namespace blaze {
//*************************************************************************************************
/*!\brief Cache size of the target architecture.
// \ingroup config
//
// This setting specifies the available cache size in Byte of the used target architecture.
// Several algorithms use this setting for an optimized evaluation.
//
// The size of the cache is specified in Byte. For instance, a cache of 3 MiByte must therefore
// be specified as 3145728.
*/
constexpr size_t cacheSize = 3145728UL;
//*************************************************************************************************
} // namespace blaze

View File

@ -0,0 +1,53 @@
//=================================================================================================
/*!
// \file blaze/config/Config.h
// \brief Config module documentation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_CONFIG_CONFIG_H_
#define _BLAZE_CONFIG_CONFIG_H_
//=================================================================================================
//
// DOXYGEN DOCUMENTATION
//
//=================================================================================================
//*************************************************************************************************
/*!\defgroup config Configuration
//
// The configuration module offers the possibility to tune the Blaze library to the individual
// needs and requirements.
*/
//*************************************************************************************************
#endif

View File

@ -0,0 +1,55 @@
//=================================================================================================
/*!
// \file blaze/config/Debugging.h
// \brief Configuration of the debugging policy of the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
namespace blaze {
//*************************************************************************************************
/*!\brief Compilation switch for the (de-)activation of the debug mode.
// \ingroup config
//
// This compilation switch enables/disables the debug mode of the Blaze library. In case the
// switch is set to 1 (i.e. in case the debug mode is enabled), the Blaze library is allowed
// to perform additional runtime checks and to modify user-defined settings to guarantee a
// full and thorough debugging process. In case the switch is set to 0 (i.e. the debug mode
// is disabled), no additional checks are added and no settings are modified.
//
// Possible settings for the debug mode switch:
// - Deactivated: \b 0 (default)
// - Activated : \b 1
*/
#define BLAZE_USE_DEBUG_MODE 0
//*************************************************************************************************
} // namespace blaze

View File

@ -0,0 +1,75 @@
//=================================================================================================
/*!
// \file blaze/config/Inline.h
// \brief Configuration of the inline policy of the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
/*!\brief Compilation switch for a strengthened inline keyword.
// \ingroup config
//
// The regular C++ \c inline keyword merely represents a hint to the compiler to inline a function.
// Due to that, when using the \c inline keyword for performance critical functions, one is at the
// mercy of the compiler to properly inline the functions. In order to improve the likelihood of
// a function being properly inlined the BLAZE_STRONG_INLINE keyword can be used. In contrast to
// the regular \c inline keyword, BLAZE_STRONG_INLINE uses platform-specific keywords and modifiers
// to improve the likelihood of a function being properly inlined. Please note, however, that even
// in case the platform-specific inline is used, there is no guarantee that a function is inlined
// (see for instance the http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx).
//
// This compilation switch enables/disables the BLAZE_STRONG_INLINE keyword. When disabled, the
// keyword uses the regular \c inline keyword as fallback. Possible setting for the switch are:
// - Deactivated: \b 0
// - Activated : \b 1
*/
#define BLAZE_USE_STRONG_INLINE 1
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Compilation switch for an enforced inline keyword.
// \ingroup config
//
// Although the BLAZE_STRONG_INLINE keyword improves the likelihood of a function being inlined it
// does not provide a 100% guarantee. Depending on the availability of an according keyword and/or
// modifier on a specific platform, this guarantee is provided by the BLAZE_ALWAYS_INLINE keyword,
// which uses platform-specific functionality to enforce the inlining of a function.
//
// This compilation switch enables/disables the BLAZE_ALWAYS_INLINE keyword. When disabled or in
// case the platform does not provide a keyword and/or modifier for a 100% inline guarantee, the
// BLAZE_ALWAYS_INLINE keyword uses the BLAZE_STRONG_INLINE keyword as fallback. Possible settings
// for the switch are:
// - Deactivated: \b 0
// - Activated : \b 1
*/
#define BLAZE_USE_ALWAYS_INLINE 1
//*************************************************************************************************

View File

@ -0,0 +1,93 @@
//=================================================================================================
/*!
// \file blaze/config/Logging.h
// \brief Configuration of the logging functionality
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
namespace blaze {
namespace logging {
//*************************************************************************************************
/*!\brief Setting of the logging level.
// \ingroup config
//
// This value specifies the logging level of the Blaze logging functionality. Depending on
// this setting, more or less informations will be written to the log file(s). The following
// logging levels can be selected:
//
// - \a inactive: Completely deactives the logging functionality, i.e., no log file(s) will be
// written. Since this setting can immensely complicate error correction, it is
// not recommended to use this setting!
// - \a error : Only (severe) errors are written to the log file(s).
// - \a warning : Extends the \a error setting by warning messages.
// - \a info : Extends the \a warning setting by additional informative messages (default).
// - \a progress: Extends the \a info setting by progress informations.
// - \a debug : Extends the \a progress setting by debug information.
// - \a detail : Extends the \a debug setting by very fine grained detail information.
*/
constexpr LogLevel loglevel = info;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Adding an additional spacing line between two log messages.
// \ingroup config
//
// This setting gives the opportunity to add an additional spacing line between two log messages
// to improve readability of log files. If set to \a true, each log message will be appended with
// an additional empty line. If set to \a false, no line will be appended.
*/
constexpr bool spacing = false;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Compilation switch for function traces.
// \ingroup config
//
// This compilation switch triggers the use of function traces. In case the switch is set to
// 1, function traces via the BLAZE_FUNCTION_TRACE are enabled. Note however, that enabling
// function traces creates a dependency to the compiled Blaze library, i.e. it will be
// necessary to link the Blaze library to the executable. This is also true in case only
// template functionality is used!
//
// Possible settings for the function trace switch:
// - Deactivated: \b 0 (default)
// - Activated : \b 1
*/
#define BLAZE_USE_FUNCTION_TRACES 0
//*************************************************************************************************
} // namespace logging
} // namespace blaze

View File

@ -0,0 +1,51 @@
//=================================================================================================
/*!
// \file blaze/config/MPI.h
// \brief Configuration of the MPI parallelization
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
/*!\brief Compilation switch for the MPI parallelization.
// \ingroup mpi
//
// This compilation switch enables/disables the MPI parallelization.
//
// Possible settings for the MPI switch:
// - Deactivated: \b 0
// - Activated : \b 1
//
// Note that changing the setting of the MPI parallel mode requires a recompilation of the
// Blaze library. Also note that this switch is automatically set by the configuration script
// of the Blaze library.
*/
#define BLAZE_MPI_PARALLEL_MODE 0
//*************************************************************************************************

View File

@ -0,0 +1,87 @@
//=================================================================================================
/*!
// \file blaze/config/Optimizations.h
// \brief Configuration of performance optimizations
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
namespace blaze {
//*************************************************************************************************
/*!\brief Configuration of the padding of dense vectors and matrices.
// \ingroup config
//
// This configuration switch enables/disables the padding of dense vectors and matrices. Padding
// is used by the Blaze library in order to achieve maximum performance for both dense vector
// and matrix operations. Due to padding, the proper alignment of data elements can be guaranteed
// and the need for remainder loops is minimized. In case the switch is set to \a true, padding
// is enabled for all native dense vectors and matrices. If the switch is set to \a false, padding
// is generally disabled.
//
// \warning Note that disabling padding can considerably reduce the performance of all dense
// vector and matrix operations!
*/
constexpr bool usePadding = true;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Configuration of the streaming behavior.
// \ingroup config
//
// For large vectors and matrices non-temporal stores can provide a significant performance
// advantage of about 20%. However, this advantage is only in effect in case the memory bandwidth
// of the target architecture is maxed out. If the target architecture's memory bandwidth cannot
// be exhausted the use of non-temporal stores can decrease performance instead of increasing it.
//
// Via this compilation switch streaming (i.e. non-temporal stores) can be (de-)activated. If
// set to \a true streaming is enabled, if set to \a false streaming is disabled.
*/
constexpr bool useStreaming = true;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Configuration switch for optimized kernels.
// \ingroup config
//
// This configuration switch enables/disables all optimized compute kernels of the Blaze library,
// including all vectorized and data type depending kernels. In case the switch is set to \a true
// the optimized kernels are used whenever possible. In case the switch is set to \a false all
// optimized kernels are not used, even if it would be possible.
//
// \warning Note that disabling the optimized kernels causes a severe performance limitiation
// to nearly all operations!
*/
constexpr bool useOptimizedKernels = true;
//*************************************************************************************************
} // namespace blaze

View File

@ -0,0 +1,50 @@
//=================================================================================================
/*!
// \file blaze/config/Precision.h
// \brief Configuration of the floating point precision of the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
namespace blaze {
//*************************************************************************************************
/*!\brief Floating point data type of the Blaze library.
// \ingroup config
//
// This type definition offers the possibility to switch the floating point precision of
// the Blaze library between float, double and long double.
//
// Valid types for the \a real_t floating point type: <a>float, double, long double</a>
*/
typedef float real_t;
//*************************************************************************************************
} // namespace blaze

View File

@ -0,0 +1,51 @@
//=================================================================================================
/*!
// \file blaze/config/Random.h
// \brief Configuration of the random number generator used in the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
namespace blaze {
//*************************************************************************************************
/*!\brief Type of the random number generator of the Blaze library.
// \ingroup config
//
// This type definition represents the type of the random number generated used in the Blaze
// library. The default random number generator is the std::mt19937 mersenne-twister pseudo
// random number generator. For more information see the following reference documentation:
//
// http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine
*/
typedef std::mt19937 RNG;
//*************************************************************************************************
} // namespace blaze

View File

@ -0,0 +1,47 @@
//=================================================================================================
/*!
// \file blaze/config/Restrict.h
// \brief Configuration of the restrict policy of the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
/*!\brief Compilation switch for C99 restrict keyword.
// \ingroup config
//
// This compilation switch enables/disables the C99 restrict keyword.
//
// Possible settings for the C99 restrict switch:
// - Deactivated: \b 0
// - Activated : \b 1
*/
#define BLAZE_USE_RESTRICT 1
//*************************************************************************************************

View File

@ -0,0 +1,54 @@
//=================================================================================================
/*!
// \file blaze/config/SMP.h
// \brief Configuration of the shared-memory parallelization
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
namespace blaze {
//*************************************************************************************************
/*!\brief Compilation switch for the (de-)activation of the shared-memory parallelization
// \ingroup config
//
// This compilation switch enables/disables the shared-memory parallelization. In case the switch
// is set to 1 (i.e. in case the shared-memory parallelization is enabled), the Blaze library is
// allowed to execute operations in parallel. In case the switch is set to 0 (i.e. parallelization
// is disabled), the Blaze library is restricted from executing operations in parallel.
//
// Possible settings for the shared-memory parallelization switch:
// - Deactivated: \b 0
// - Activated : \b 1 (default)
*/
#define BLAZE_USE_SHARED_MEMORY_PARALLELIZATION 1
//*************************************************************************************************
} // namespace blaze

View File

@ -0,0 +1,59 @@
//=================================================================================================
/*!
// \file blaze/config/StorageOrder.h
// \brief Configuration of the default storage order for all matrices of the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
namespace blaze {
//*************************************************************************************************
/*!\brief The default storage order for all matrices of the Blaze library.
// \ingroup config
//
// This value specifies the default storage order for all matrices of the Blaze library.
// In case no explicit storage order is specified with the according matrix type, this
// setting is used.
\code
// Explicit specification of the storage order => row-major matrix
StaticMatrix<double,3UL,3UL,rowMajor> A;
// No explicit specification of the storage order => use of the defaultStorageOrder
StaticMatrix<double,3UL,3UL> B;
\endcode
// Valid settings for the defaultStorageOrder are blaze::rowMajor and blaze::columnMajor.
*/
constexpr bool defaultStorageOrder = rowMajor;
//*************************************************************************************************
} // namespace blaze

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,59 @@
//=================================================================================================
/*!
// \file blaze/config/TransposeFlag.h
// \brief Configuration of the default transpose flag for all vectors of the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
namespace blaze {
//*************************************************************************************************
/*!\brief The default transpose flag for all vectors of the Blaze library.
// \ingroup config
//
// This value specifies the default transpose flag for all vector of the Blaze library.
// In case no explicit transpose flag is specified with the according vector type, this
// setting is used.
\code
// Explicit specification of the transpose flag => column vector
StaticVector<double,3UL,columnMajor> a;
// No explicit specification of the transpose flag => use of the defaultTransposeFlag
StaticVector<double,3UL> b;
\endcode
// Valid settings for the defaultTransposeFlag are blaze::rowVector and blaze::columnVector.
*/
constexpr bool defaultTransposeFlag = columnVector;
//*************************************************************************************************
} // namespace blaze

View File

@ -0,0 +1,54 @@
//=================================================================================================
/*!
// \file blaze/config/Vectorization.h
// \brief Configuration of the vectorization policy of the Blaze library
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
/*!\brief Compilation switch for (de-)activation of the Blaze vectorization.
// \ingroup config
//
// This compilation switch enables/disables vectorization of mathematical expressions via
// the SSE, AVX, and/or MIC instruction sets. In case the switch is set to 1 (i.e. in case
// vectorization is enabled), the Blaze library attempts to vectorize the linear algebra
// operations by SSE, AVX, and/or MIC intrinsics (depending on which instruction set is
// available on the target platform). In case the switch is set to 0 (i.e. vectorization
// is disabled), the Blaze library chooses default, non-vectorized functionality for the
// operations. Note that deactivating the vectorization may pose a severe performance
// limitation for a large number of operations!
//
// Possible settings for the vectorization switch:
// - Deactivated: \b 0
// - Activated : \b 1 (default)
*/
#define BLAZE_USE_VECTORIZATION 1
//*************************************************************************************************

View File

@ -0,0 +1,906 @@
//=================================================================================================
/*!
// \file blaze/math/Accuracy.h
// \brief Computation accuracy for floating point data types
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ACCURACY_H_
#define _BLAZE_MATH_ACCURACY_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/util/constraints/FloatingPoint.h>
#include <blaze/util/Limits.h>
namespace blaze {
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Negative computation accuracy for floating point data types.
// \ingroup math
//
// The NegativeAccuracy class is a wrapper class around the functionality of the blaze::Limits
// class. It represents the negative computation accuracy of the Blaze library for any floating
// point data type. In order to assign a negative accuracy value, the NegativeAccuracy class can
// be implicitly converted to the three built-in floating point data types float, double and long
// double.
//
// \note The NegativeAccuracy class is a helper class for the Accuracy class. It cannot be
// instantiated on its own, but can only be used by the Accuracy class.
*/
template< typename A > // Positive accuracy type
class NegativeAccuracy
{
public:
//**Type definitions****************************************************************************
typedef A PositiveType; //!< The positive accuracy type.
//**********************************************************************************************
private:
//**Constructor*********************************************************************************
/*!\name Constructor */
//@{
explicit inline NegativeAccuracy();
// No explicitly declared copy constructor.
//@}
//**********************************************************************************************
public:
//**Destructor**********************************************************************************
// No explicitly declared destructor.
//**********************************************************************************************
//**Unary plus/minus operators******************************************************************
/*!\name Unary plus/minus operators */
//@{
inline const NegativeAccuracy& operator+() const;
inline const PositiveType operator-() const;
//@}
//**********************************************************************************************
//**Conversion operator*************************************************************************
/*!\name Conversion operator */
//@{
template< typename T >
inline operator const T() const;
//@}
//**********************************************************************************************
private:
//**Forbidden operations************************************************************************
/*!\name Forbidden operations */
//@{
NegativeAccuracy& operator=( const NegativeAccuracy& ); //!< Copy assignment operator (private & undefined)
void* operator&() const; //!< Address operator (private & undefined)
//@}
//**********************************************************************************************
//**Friend declarations*************************************************************************
/*! \cond BLAZE_INTERNAL */
friend class Accuracy;
/*! \endcond */
//**********************************************************************************************
};
//*************************************************************************************************
//=================================================================================================
//
// CONSTRUCTOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief The default constructor of the NegativeAccuracy class.
*/
template< typename A > // Positive accuracy type
inline NegativeAccuracy<A>::NegativeAccuracy()
{}
//*************************************************************************************************
//=================================================================================================
//
// UNARY PLUS/MINUS OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Returns the negative computation accuracy for all floating point data types.
//
// \return The negative computation accuracy.
*/
template< typename A > // Positive accuracy type
inline const NegativeAccuracy<A>& NegativeAccuracy<A>::operator+() const
{
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns the positive computation accuracy for all floating point data types.
//
// \return The positive computation accuracy.
*/
template< typename A > // Positive accuracy type
inline const typename NegativeAccuracy<A>::PositiveType NegativeAccuracy<A>::operator-() const
{
return PositiveType();
}
//*************************************************************************************************
//=================================================================================================
//
// CONVERSION OPERATOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Conversion operator to the required floating point data type.
//
// The conversion operator returns the negative computation accuracy for the floating point
// data type \a T.
*/
template< typename A > // Positive accuracy type
template< typename T > // Floating point data type
inline NegativeAccuracy<A>::operator const T() const
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::accuracy();
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\name Accuracy operators */
//@{
template< typename A, typename T >
inline bool operator==( const NegativeAccuracy<A>& lhs, const T& rhs );
template< typename A, typename T >
inline bool operator==( const T& lhs, const NegativeAccuracy<A>& rhs );
template< typename A, typename T >
inline bool operator!=( const NegativeAccuracy<A>& lhs, const T& rhs );
template< typename A, typename T >
inline bool operator!=( const T& lhs, const NegativeAccuracy<A>& rhs );
template< typename A, typename T >
inline bool operator<( const NegativeAccuracy<A>& lhs, const T& rhs );
template< typename A, typename T >
inline bool operator<( const T& lhs, const NegativeAccuracy<A>& rhs );
template< typename A, typename T >
inline bool operator>( const NegativeAccuracy<A>& lhs, const T& rhs );
template< typename A, typename T >
inline bool operator>( const T& lhs, const NegativeAccuracy<A>& rhs );
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Equality comparison between a NegativeAccuracy object and a floating point value.
// \ingroup math
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is equal to the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator==( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::accuracy() == rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Equality comparison between a floating point value and a NegativeAccuracy object.
// \ingroup math
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is equal to the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator==( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs == -Limits<T>::accuracy();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Inequality comparison between a NegativeAccuracy object and a floating point value.
// \ingroup math
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is unequal to the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator!=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::accuracy() != rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Inequality comparison between a floating point value and a NegativeAccuracy object.
// \ingroup math
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is unequal to the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator!=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs != -Limits<T>::accuracy();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-than comparison between a NegativeAccuracy object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is greater than the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator<( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::accuracy() < rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-than comparison between a floating point value and a NegativeAccuracy object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is smaller than the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator<( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs < -Limits<T>::accuracy();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-than comparison between a NegativeAccuracy object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is smaller than the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator>( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::accuracy() > rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-than comparison between a floating point value and a NegativeAccuracy object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is greater than the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator>( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs > -Limits<T>::accuracy();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between a NegativeAccuracy object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is greater than or equal to the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator<=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::accuracy() <= rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between a floating point value and a NegativeAccuracy object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is smaller than or equal to the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator<=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs <= -Limits<T>::accuracy();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is smaller than or equal to the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator>=( const NegativeAccuracy<A>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::accuracy() >= rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between a floating point value and a NegativeAccuracy object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is greater than or equal to the negative accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename A // Positive accuracy type
, typename T > // Floating point data type
inline bool operator>=( const T& lhs, const NegativeAccuracy<A>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs >= -Limits<T>::accuracy();
}
//*************************************************************************************************
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Computation accuracy for floating point data types.
// \ingroup math
//
// The Accuracy class is a wrapper class around the functionality of the blaze::Limits class.
// It represents the computation accuracy of the Blaze library for any floating point data
// type. In order to assign an accuracy value, the Accuracy class can be implicitly converted
// to the three built-in floating point data types float, double and long double.\n
// In order to handle accuracy values conveniently, the global Accuracy instance blaze::accuracy
// is provided, which can be used wherever a floating point data value is required.
\code
float f = accuracy; // Assigns the positive computation accuracy for single precision values
double d = -accuracy; // Assigns the negative computation accuracy for double precision values
\endcode
*/
class Accuracy
{
public:
//**Type definitions****************************************************************************
typedef NegativeAccuracy<Accuracy> NegativeType; //!< The negated accuracy type.
//**********************************************************************************************
//**Constructor*********************************************************************************
/*!\name Constructor */
//@{
explicit inline Accuracy();
// No explicitly declared copy constructor.
//@}
//**********************************************************************************************
//**Destructor**********************************************************************************
// No explicitly declared destructor.
//**********************************************************************************************
//**Unary plus/minus operators******************************************************************
/*!\name Unary plus/minus operators */
//@{
inline const Accuracy& operator+() const;
inline const NegativeType operator-() const;
//@}
//**********************************************************************************************
//**Conversion operator*************************************************************************
/*!\name Conversion operator */
//@{
template< typename T >
inline operator const T() const;
//@}
//**********************************************************************************************
private:
//**Forbidden operations************************************************************************
/*!\name Forbidden operations */
//@{
Accuracy& operator=( const Accuracy& ); //!< Copy assignment operator (private & undefined)
void* operator&() const; //!< Address operator (private & undefined)
//@}
//**********************************************************************************************
};
//*************************************************************************************************
//=================================================================================================
//
// CONSTRUCTOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief The default constructor of the Accuracy class.
*/
inline Accuracy::Accuracy()
{}
//*************************************************************************************************
//=================================================================================================
//
// UNARY PLUS/MINUS OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Returns the positive computation accuracy for all floating point data types.
//
// \return The positive computation accuracy.
*/
inline const Accuracy& Accuracy::operator+() const
{
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns the negative computation accuracy for all floating point data types.
//
// \return The negative computation accuracy.
*/
inline const Accuracy::NegativeType Accuracy::operator-() const
{
return NegativeType();
}
//*************************************************************************************************
//=================================================================================================
//
// CONVERSION OPERATOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Conversion operator to the required floating point data type.
//
// The conversion operator returns the computation accuracy for the floating point data
// type \a T.
*/
template< typename T > // Floating point data type
inline Accuracy::operator const T() const
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::accuracy();
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\name Accuracy operators */
//@{
template< typename T >
inline bool operator==( const Accuracy& lhs, const T& rhs );
template< typename T >
inline bool operator==( const T& lhs, const Accuracy& rhs );
template< typename T >
inline bool operator!=( const Accuracy& lhs, const T& rhs );
template< typename T >
inline bool operator!=( const T& lhs, const Accuracy& rhs );
template< typename T >
inline bool operator<( const Accuracy& lhs, const T& rhs );
template< typename T >
inline bool operator<( const T& lhs, const Accuracy& rhs );
template< typename T >
inline bool operator>( const Accuracy& lhs, const T& rhs );
template< typename T >
inline bool operator>( const T& lhs, const Accuracy& rhs );
template< typename T >
inline bool operator<=( const Accuracy& lhs, const T& rhs );
template< typename T >
inline bool operator<=( const T& lhs, const Accuracy& rhs );
template< typename T >
inline bool operator>=( const Accuracy& lhs, const T& rhs );
template< typename T >
inline bool operator>=( const T& lhs, const Accuracy& rhs );
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Equality comparison between an Accuracy object and a floating point value.
// \ingroup math
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floating point value is equal to the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator==( const Accuracy& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::accuracy() == rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Equality comparison between a floating point value and an Accuracy object.
// \ingroup math
//
// \param lhs The left-hand side floating point value.
// \return \a true if the floating point value is equal to the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator==( const T& lhs, const Accuracy& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs == Limits<T>::accuracy();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Inequality comparison between an Accuracy object and a floating point value.
// \ingroup math
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floating point value is unequal to the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator!=( const Accuracy& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::accuracy() != rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Inequality comparison between a floating point value and an Accuracy object.
// \ingroup math
//
// \param lhs The left-hand side floating point value.
// \return \a true if the floating point value is unequal to the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator!=( const T& lhs, const Accuracy& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs != Limits<T>::accuracy();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-than comparison between an Accuracy object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floatin point value is greater than the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator<( const Accuracy& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::accuracy() < rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-than comparison between a floating point value and an Accuracy object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the floating point value is smaller than the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator<( const T& lhs, const Accuracy& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs < Limits<T>::accuracy();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-than comparison between an Accuracy object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floating point value is smaller than the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator>( const Accuracy& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::accuracy() > rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-than comparison between a floating point value and an Accuracy object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the floating point value is greater than the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator>( const T& lhs, const Accuracy& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs > Limits<T>::accuracy();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between an Accuracy object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floating point value is greater than or equal to the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator<=( const Accuracy& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::accuracy() <= rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between a floating point value and an Accuracy object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is smaller than or equal to the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator<=( const T& lhs, const Accuracy& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs <= Limits<T>::accuracy();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-or-equal-than comparison between an Accuracy object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is smaller than or equal to the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator>=( const Accuracy& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::accuracy() >= rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between a floating point value and an Accuracy object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is greater than or equal to the accuracy, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T > // Floating point data type
inline bool operator>=( const T& lhs, const Accuracy& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs >= Limits<T>::accuracy();
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL ACCURACY VALUE
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Global Accuracy instance.
// \ingroup math
//
// The blaze::accuracy instance can be used wherever a floating point data type is expected.
// It is implicitly converted to the corresponding floating point data type and represents
// the computation accuracy of the Blaze library for the according data type.
*/
const Accuracy accuracy;
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,428 @@
//=================================================================================================
/*!
// \file blaze/math/Aliases.h
// \brief Header file for auxiliary alias declarations
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ALIASES_H_
#define _BLAZE_MATH_ALIASES_H_
namespace blaze {
//=================================================================================================
//
// ALIAS DECLARATION
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Alias declaration for nested \c BaseType type definitions.
// \ingroup aliases
//
// The BaseType_ alias declaration provides a convenient shortcut to access the nested
// \a BaseType type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::BaseType;
using Type2 = BaseType_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using BaseType_ = typename T::BaseType;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c CompositeType type definitions.
// \ingroup aliases
//
// The CompositeType_ alias declaration provides a convenient shortcut to access the nested
// \a CompositeType type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::CompositeType;
using Type2 = CompositeType_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using CompositeType_ = typename T::CompositeType;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c ConstIterator type definitions.
// \ingroup aliases
//
// The ConstIterator_ alias declaration provides a convenient shortcut to access the nested
// \a ConstIterator type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::ConstIterator;
using Type2 = ConstIterator_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using ConstIterator_ = typename T::ConstIterator;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c ConstPointer type definitions.
// \ingroup aliases
//
// The ConstPointer_ alias declaration provides a convenient shortcut to access the nested
// \a ConstPointer type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::ConstPointer;
using Type2 = ConstPointer_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using ConstPointer_ = typename T::ConstPointer;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c ConstReference type definitions.
// \ingroup aliases
//
// The ConstReference_ alias declaration provides a convenient shortcut to access the nested
// \a ConstReference type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::ConstReference;
using Type2 = ConstReference_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using ConstReference_ = typename T::ConstReference;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c ElementType type definitions.
// \ingroup aliases
//
// The ElementType_ alias declaration provides a convenient shortcut to access the nested
// \a ElementType type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::ElementType;
using Type2 = ElementType_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using ElementType_ = typename T::ElementType;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c Iterator type definitions.
// \ingroup aliases
//
// The Iterator_ alias declaration provides a convenient shortcut to access the nested
// \a Iterator type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::Iterator;
using Type2 = Iterator_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using Iterator_ = typename T::Iterator;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c LeftOperand type definitions.
// \ingroup aliases
//
// The LeftOperand_ alias declaration provides a convenient shortcut to access the nested
// \a LeftOperand type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::LeftOperand;
using Type2 = LeftOperand_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using LeftOperand_ = typename T::LeftOperand;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c Operand type definitions.
// \ingroup aliases
//
// The Operand_ alias declaration provides a convenient shortcut to access the nested \a Operand
// type definition of the given type \a T. The following code example shows both ways to access
// the nested type definition:
\code
using Type1 = typename T::Operand;
using Type2 = Operand_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using Operand_ = typename T::Operand;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c OppositeType type definitions.
// \ingroup aliases
//
// The OppositeType_ alias declaration provides a convenient shortcut to access the nested
// \a OppositeType type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::OppositeType;
using Type2 = OppositeType_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using OppositeType_ = typename T::OppositeType;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c Pointer type definitions.
// \ingroup aliases
//
// The Pointer_ alias declaration provides a convenient shortcut to access the nested
// \a Pointer type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::Pointer;
using Type2 = Pointer_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using Pointer_ = typename T::Pointer;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c Reference type definitions.
// \ingroup aliases
//
// The Reference_ alias declaration provides a convenient shortcut to access the nested
// \a Reference type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::Reference;
using Type2 = Reference_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using Reference_ = typename T::Reference;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c RepresentedType type definitions.
// \ingroup aliases
//
// The RepresentedType_ alias declaration provides a convenient shortcut to access the nested
// \a RepresentedType type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::RepresentedType;
using Type2 = RepresentedType_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using RepresentedType_ = typename T::RepresentedType;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c ResultType type definitions.
// \ingroup aliases
//
// The ResultType_ alias declaration provides a convenient shortcut to access the nested
// \a ResultType type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::ResultType;
using Type2 = ResultType_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using ResultType_ = typename T::ResultType;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c ReturnType type definitions.
// \ingroup aliases
//
// The ReturnType_ alias declaration provides a convenient shortcut to access the nested
// \a ReturnType type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::ReturnType;
using Type2 = ReturnType_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using ReturnType_ = typename T::ReturnType;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c RightOperand type definitions.
// \ingroup aliases
//
// The RightOperand_ alias declaration provides a convenient shortcut to access the nested
// \a RightOperand type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::RightOperand;
using Type2 = RightOperand_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using RightOperand_ = typename T::RightOperand;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c SIMDType type definitions.
// \ingroup aliases
//
// The SIMDType_ alias declaration provides a convenient shortcut to access the nested
// \a SIMDType type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::SIMDType;
using Type2 = SIMDType_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using SIMDType_ = typename T::SIMDType;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c TransposeType type definitions.
// \ingroup aliases
//
// The TransposeType_ alias declaration provides a convenient shortcut to access the nested
// \a TransposeType type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::TransposeType;
using Type2 = TransposeType_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using TransposeType_ = typename T::TransposeType;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alias declaration for nested \c ValueType type definitions.
// \ingroup aliases
//
// The ValueType_ alias declaration provides a convenient shortcut to access the nested
// \a ValueType type definition of the given type \a T. The following code example shows
// both ways to access the nested type definition:
\code
using Type1 = typename T::ValueType;
using Type2 = ValueType_<T>;
BLAZE_CONSTRAINT_MUST_BE_STRICTLY_SAME_TYPE( Type1, Type2 );
\endcode
*/
template< typename T >
using ValueType_ = typename T::ValueType;
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,90 @@
//=================================================================================================
/*!
// \file blaze/math/AlignmentFlag.h
// \brief Header file for the alignment flag values
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ALIGNMENTFLAG_H_
#define _BLAZE_MATH_ALIGNMENTFLAG_H_
namespace blaze {
//=================================================================================================
//
// ALIGNMENT FLAG VALUES
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Alignment flag for unaligned vectors and matrices.
// \ingroup math
//
// Via this flag it is possible to specify subvectors, submatrices, custom vectors and matrices
// as unaligned. The following example demonstrates the setup of an unaligned subvector:
\code
using blaze::columnVector;
using blaze::unaligned;
typedef blaze::DynamicVector<int,columnVector> VectorType;
VectorType v( 100UL );
Subvector<VectorType,unaligned> sv = subvector<unaligned>( v, 10UL, 20UL );
\endcode
*/
const bool unaligned = false;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Alignment flag for aligned vectors and matrices.
// \ingroup math
//
// Via this flag it is possible to specify subvectors, submatrices, custom vectors and matrices
// as aligned. The following example demonstrates the setup of an aligned subvector:
\code
using blaze::columnVector;
using blaze::aligned;
typedef blaze::DynamicVector<int,columnVector> VectorType;
VectorType v( 100UL );
Subvector<VectorType,aligned> sv = subvector<aligned>( v, 8UL, 32UL );
\endcode
*/
const bool aligned = true;
//*************************************************************************************************
} // namespace blaze
#endif

50
src/cpu/blaze/math/BLAS.h Normal file
View File

@ -0,0 +1,50 @@
//=================================================================================================
/*!
// \file blaze/math/BLAS.h
// \brief Header file for BLAS functionality
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_BLAS_H_
#define _BLAZE_MATH_BLAS_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/blas/dot.h>
#include <blaze/math/blas/gemm.h>
#include <blaze/math/blas/gemv.h>
#include <blaze/math/blas/trmm.h>
#include <blaze/math/blas/trmv.h>
#include <blaze/math/blas/trsm.h>
#endif

315
src/cpu/blaze/math/Column.h Normal file
View File

@ -0,0 +1,315 @@
//=================================================================================================
/*!
// \file blaze/math/Column.h
// \brief Header file for the complete Column implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_COLUMN_H_
#define _BLAZE_MATH_COLUMN_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/Aliases.h>
#include <blaze/math/Exception.h>
#include <blaze/math/smp/DenseVector.h>
#include <blaze/math/smp/SparseVector.h>
#include <blaze/math/views/Column.h>
#include <blaze/math/views/Row.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION FOR DENSE COLUMNS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for dense columns.
// \ingroup random
//
// This specialization of the Rand class randomizes dense columns.
*/
template< typename MT // Type of the dense matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
class Rand< Column<MT,SO,true,SF> >
{
public:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( Column<MT,SO,true,SF>& column ) const;
template< typename Arg >
inline void randomize( Column<MT,SO,true,SF>& column, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense column.
//
// \param column The column to be randomized.
// \return void
*/
template< typename MT // Type of the dense matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
inline void Rand< Column<MT,SO,true,SF> >::randomize( Column<MT,SO,true,SF>& column ) const
{
using blaze::randomize;
for( size_t i=0UL; i<column.size(); ++i ) {
randomize( column[i] );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense column.
//
// \param column The column to be randomized.
// \param min The smallest possible value for a column element.
// \param max The largest possible value for a column element.
// \return void
*/
template< typename MT // Type of the dense matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
template< typename Arg > // Min/max argument type
inline void Rand< Column<MT,SO,true,SF> >::randomize( Column<MT,SO,true,SF>& column,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
for( size_t i=0UL; i<column.size(); ++i ) {
randomize( column[i], min, max );
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// RAND SPECIALIZATION FOR SPARSE COLUMNS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for sparse columns.
// \ingroup random
//
// This specialization of the Rand class randomizes sparse columns.
*/
template< typename MT // Type of the sparse matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
class Rand< Column<MT,SO,false,SF> >
{
public:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( Column<MT,SO,false,SF>& column ) const;
inline void randomize( Column<MT,SO,false,SF>& column, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( Column<MT,SO,false,SF>& column, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( Column<MT,SO,false,SF>& column, size_t nonzeros, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse column.
//
// \param column The column to be randomized.
// \return void
*/
template< typename MT // Type of the sparse matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
inline void Rand< Column<MT,SO,false,SF> >::randomize( Column<MT,SO,false,SF>& column ) const
{
typedef ElementType_< Column<MT,SO,false,SF> > ElementType;
const size_t size( column.size() );
if( size == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*size ) ) );
column.reset();
column.reserve( nonzeros );
while( column.nonZeros() < nonzeros ) {
column[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse column.
//
// \param column The column to be randomized.
// \param nonzeros The number of non-zero elements of the random column.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the sparse matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
inline void Rand< Column<MT,SO,false,SF> >::randomize( Column<MT,SO,false,SF>& column, size_t nonzeros ) const
{
typedef ElementType_< Column<MT,SO,false,SF> > ElementType;
const size_t size( column.size() );
if( nonzeros > size ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( size == 0UL ) return;
column.reset();
column.reserve( nonzeros );
while( column.nonZeros() < nonzeros ) {
column[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse column.
//
// \param column The column to be randomized.
// \param min The smallest possible value for a column element.
// \param max The largest possible value for a column element.
// \return void
*/
template< typename MT // Type of the sparse matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
template< typename Arg > // Min/max argument type
inline void Rand< Column<MT,SO,false,SF> >::randomize( Column<MT,SO,false,SF>& column,
const Arg& min, const Arg& max ) const
{
typedef ElementType_< Column<MT,SO,false,SF> > ElementType;
const size_t size( column.size() );
if( size == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*size ) ) );
column.reset();
column.reserve( nonzeros );
while( column.nonZeros() < nonzeros ) {
column[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse column.
//
// \param column The column to be randomized.
// \param nonzeros The number of non-zero elements of the random column.
// \param min The smallest possible value for a column element.
// \param max The largest possible value for a column element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the sparse matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
template< typename Arg > // Min/max argument type
inline void Rand< Column<MT,SO,false,SF> >::randomize( Column<MT,SO,false,SF>& column, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
typedef ElementType_< Column<MT,SO,false,SF> > ElementType;
const size_t size( column.size() );
if( nonzeros > size ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( size == 0UL ) return;
column.reset();
column.reserve( nonzeros );
while( column.nonZeros() < nonzeros ) {
column[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,465 @@
//=================================================================================================
/*!
// \file blaze/math/CompressedMatrix.h
// \brief Header file for the complete CompressedMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_COMPRESSEDMATRIX_H_
#define _BLAZE_MATH_COMPRESSEDMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <vector>
#include <blaze/math/sparse/CompressedMatrix.h>
#include <blaze/math/CompressedVector.h>
#include <blaze/math/Exception.h>
#include <blaze/math/SparseMatrix.h>
#include <blaze/system/Precision.h>
#include <blaze/util/Assert.h>
#include <blaze/util/Indices.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for CompressedMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of CompressedMatrix.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
class Rand< CompressedMatrix<Type,SO> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const CompressedMatrix<Type,SO> generate( size_t m, size_t n ) const;
inline const CompressedMatrix<Type,SO> generate( size_t m, size_t n, size_t nonzeros ) const;
template< typename Arg >
inline const CompressedMatrix<Type,SO> generate( size_t m, size_t n, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const CompressedMatrix<Type,SO> generate( size_t m, size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( CompressedMatrix<Type,SO>& matrix ) const;
inline void randomize( CompressedMatrix<Type,false>& matrix, size_t nonzeros ) const;
inline void randomize( CompressedMatrix<Type,true>& matrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( CompressedMatrix<Type,SO>& matrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( CompressedMatrix<Type,false>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( CompressedMatrix<Type,true>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random CompressedMatrix.
//
// \param m The number of rows of the random matrix.
// \param n The number of columns of the random matrix.
// \return The generated random matrix.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
inline const CompressedMatrix<Type,SO>
Rand< CompressedMatrix<Type,SO> >::generate( size_t m, size_t n ) const
{
CompressedMatrix<Type,SO> matrix( m, n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random CompressedMatrix.
//
// \param m The number of rows of the random matrix.
// \param n The number of columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
inline const CompressedMatrix<Type,SO>
Rand< CompressedMatrix<Type,SO> >::generate( size_t m, size_t n, size_t nonzeros ) const
{
if( nonzeros > m*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
CompressedMatrix<Type,SO> matrix( m, n );
randomize( matrix, nonzeros );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random CompressedMatrix.
//
// \param m The number of rows of the random matrix.
// \param n The number of columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \return The generated random matrix.
// \param max The largest possible value for a matrix element.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline const CompressedMatrix<Type,SO>
Rand< CompressedMatrix<Type,SO> >::generate( size_t m, size_t n, const Arg& min, const Arg& max ) const
{
CompressedMatrix<Type,SO> matrix( m, n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random CompressedMatrix.
//
// \param m The number of rows of the random matrix.
// \param n The number of columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline const CompressedMatrix<Type,SO>
Rand< CompressedMatrix<Type,SO> >::generate( size_t m, size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
if( nonzeros > m*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
CompressedMatrix<Type,SO> matrix( m, n );
randomize( matrix, nonzeros, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a CompressedMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
inline void Rand< CompressedMatrix<Type,SO> >::randomize( CompressedMatrix<Type,SO>& matrix ) const
{
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
if( m == 0UL || n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
randomize( matrix, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major CompressedMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
inline void Rand< CompressedMatrix<Type,SO> >::randomize( CompressedMatrix<Type,false>& matrix, size_t nonzeros ) const
{
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
if( nonzeros > m*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( m == 0UL || n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( m );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, m-1UL );
if( dist[index] == n ) continue;
++dist[index];
++nz;
}
for( size_t i=0UL; i<m; ++i ) {
const Indices indices( 0UL, n-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<Type>() );
}
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major CompressedMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
inline void Rand< CompressedMatrix<Type,SO> >::randomize( CompressedMatrix<Type,true>& matrix, size_t nonzeros ) const
{
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
if( nonzeros > m*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( m == 0UL || n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-1UL );
if( dist[index] == m ) continue;
++dist[index];
++nz;
}
for( size_t j=0UL; j<n; ++j ) {
const Indices indices( 0UL, m-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<Type>() );
}
matrix.finalize( j );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a CompressedMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline void Rand< CompressedMatrix<Type,SO> >::randomize( CompressedMatrix<Type,SO>& matrix,
const Arg& min, const Arg& max ) const
{
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
if( m == 0UL || n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
randomize( matrix, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major CompressedMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline void Rand< CompressedMatrix<Type,SO> >::randomize( CompressedMatrix<Type,false>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
if( nonzeros > m*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( m == 0UL || n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( m );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, m-1UL );
if( dist[index] == n ) continue;
++dist[index];
++nz;
}
for( size_t i=0UL; i<m; ++i ) {
const Indices indices( 0UL, n-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<Type>( min, max ) );
}
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major CompressedMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline void Rand< CompressedMatrix<Type,SO> >::randomize( CompressedMatrix<Type,true>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
if( nonzeros > m*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( m == 0UL || n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-1UL );
if( dist[index] == m ) continue;
++dist[index];
++nz;
}
for( size_t j=0UL; j<n; ++j ) {
const Indices indices( 0UL, m-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<Type>( min, max ) );
}
matrix.finalize( j );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,330 @@
//=================================================================================================
/*!
// \file blaze/math/CompressedVector.h
// \brief Header file for the complete CompressedVector implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_COMPRESSEDVECTOR_H_
#define _BLAZE_MATH_COMPRESSEDVECTOR_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/StaticVector.h>
#include <blaze/math/CompressedMatrix.h>
#include <blaze/math/Exception.h>
#include <blaze/math/sparse/CompressedVector.h>
#include <blaze/math/SparseVector.h>
#include <blaze/system/Precision.h>
#include <blaze/util/Indices.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for CompressedVector.
// \ingroup random
//
// This specialization of the Rand class creates random instances of CompressedVector.
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
class Rand< CompressedVector<Type,TF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const CompressedVector<Type,TF> generate( size_t size ) const;
inline const CompressedVector<Type,TF> generate( size_t size, size_t nonzeros ) const;
template< typename Arg >
inline const CompressedVector<Type,TF> generate( size_t size, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const CompressedVector<Type,TF> generate( size_t size, size_t nonzeros, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( CompressedVector<Type,TF>& vector ) const;
inline void randomize( CompressedVector<Type,TF>& vector, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( CompressedVector<Type,TF>& vector, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( CompressedVector<Type,TF>& vector, size_t nonzeros, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random CompressedVector.
//
// \param size The size of the random vector.
// \return The generated random vector.
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
inline const CompressedVector<Type,TF>
Rand< CompressedVector<Type,TF> >::generate( size_t size ) const
{
CompressedVector<Type,TF> vector( size );
randomize( vector );
return vector;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random CompressedVector.
//
// \param size The size of the random vector.
// \param nonzeros The number of non-zero elements of the random vector.
// \return The generated random vector.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
inline const CompressedVector<Type,TF>
Rand< CompressedVector<Type,TF> >::generate( size_t size, size_t nonzeros ) const
{
if( nonzeros > size ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
CompressedVector<Type,TF> vector( size, nonzeros );
randomize( vector, nonzeros );
return vector;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random CompressedVector.
//
// \param size The size of the random vector.
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return The generated random vector.
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline const CompressedVector<Type,TF>
Rand< CompressedVector<Type,TF> >::generate( size_t size, const Arg& min, const Arg& max ) const
{
CompressedVector<Type,TF> vector( size );
randomize( vector, min, max );
return vector;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random CompressedVector.
//
// \param size The size of the random vector.
// \param nonzeros The number of non-zero elements of the random vector.
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return The generated random vector.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline const CompressedVector<Type,TF>
Rand< CompressedVector<Type,TF> >::generate( size_t size, size_t nonzeros, const Arg& min, const Arg& max ) const
{
if( nonzeros > size ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
CompressedVector<Type,TF> vector( size, nonzeros );
randomize( vector, nonzeros, min, max );
return vector;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a CompressedVector.
//
// \param vector The vector to be randomized.
// \return void
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
inline void Rand< CompressedVector<Type,TF> >::randomize( CompressedVector<Type,TF>& vector ) const
{
const size_t size( vector.size() );
if( size == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*size ) ) );
randomize( vector, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a CompressedVector.
//
// \param vector The vector to be randomized.
// \param nonzeros The number of non-zero elements of the random vector.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
inline void Rand< CompressedVector<Type,TF> >::randomize( CompressedVector<Type,TF>& vector, size_t nonzeros ) const
{
const size_t size( vector.size() );
if( nonzeros > size ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( size == 0UL ) return;
vector.reset();
vector.reserve( nonzeros );
const Indices indices( 0UL, vector.size()-1UL, nonzeros );
for( size_t index : indices ) {
vector.append( index, rand<Type>() );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a CompressedVector.
//
// \param vector The vector to be randomized.
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return void
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline void Rand< CompressedVector<Type,TF> >::randomize( CompressedVector<Type,TF>& vector,
const Arg& min, const Arg& max ) const
{
const size_t size( vector.size() );
if( size == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*size ) ) );
randomize( vector, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a CompressedVector.
//
// \param vector The vector to be randomized.
// \param nonzeros The number of non-zero elements of the random vector.
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline void Rand< CompressedVector<Type,TF> >::randomize( CompressedVector<Type,TF>& vector,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
const size_t size( vector.size() );
if( nonzeros > size ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( size == 0UL ) return;
vector.reset();
vector.reserve( nonzeros );
const Indices indices( 0UL, vector.size()-1UL, nonzeros );
for( size_t index : indices ) {
vector.append( index, rand<Type>( min, max ) );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,208 @@
//=================================================================================================
/*!
// \file blaze/math/Constants.h
// \brief Header file for mathematical constants
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_CONSTANTS_H_
#define _BLAZE_MATH_CONSTANTS_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <blaze/system/Precision.h>
namespace blaze {
//=================================================================================================
//
// MATHEMATICAL CONSTANT E
//
//=================================================================================================
#ifdef M_E
# undef M_E
#endif
//*************************************************************************************************
/*!\brief Definition of the mathematical constant \f$ e \f$.
// \ingroup math
*/
const real_t M_E = 2.7182818284590452353602874713526625;
//*************************************************************************************************
//=================================================================================================
//
// MATHEMATICAL CONSTANT LOG2E
//
//=================================================================================================
#ifdef M_LOG2E
# undef M_LOG2E
#endif
//*************************************************************************************************
/*!\brief Definition of the mathematical constant \f$ \log_2 e \f$.
// \ingroup math
*/
const real_t M_LOG2E = 1.4426950408889634073599246810018921;
//*************************************************************************************************
//=================================================================================================
//
// MATHEMATICAL CONSTANT LOG10E
//
//=================================================================================================
#ifdef M_LOG10E
# undef M_LOG10E
#endif
//*************************************************************************************************
/*!\brief Definition of the mathematical constant \f$ \log_{10} e \f$.
// \ingroup math
*/
const real_t M_LOG10E = 0.4342944819032518276511289189166051;
//*************************************************************************************************
//=================================================================================================
//
// MATHEMATICAL CONSTANT LN2
//
//=================================================================================================
#ifdef M_LN2
# undef M_LN2
#endif
//*************************************************************************************************
/*!\brief Definition of the mathematical constant \f$ \ln 2 \f$.
// \ingroup math
*/
const real_t M_LN2 = 0.6931471805599453094172321214581766;
//*************************************************************************************************
//=================================================================================================
//
// MATHEMATICAL CONSTANT LN10
//
//=================================================================================================
#ifdef M_LN10
# undef M_LN10
#endif
//*************************************************************************************************
/*!\brief Definition of the mathematical constant \f$ \ln 10 \f$.
// \ingroup math
*/
const real_t M_LN10 = 2.3025850929940456840179914546843642;
//*************************************************************************************************
//=================================================================================================
//
// MATHEMATICAL CONSTANT PI
//
//=================================================================================================
#ifdef M_PI
# undef M_PI
#endif
//*************************************************************************************************
/*!\brief Definition of the mathematical constant \f$ \pi \f$.
// \ingroup math
*/
const real_t M_PI = 3.1415926535897932384626433832795029;
//*************************************************************************************************
//=================================================================================================
//
// MATHEMATICAL CONSTANT SQRT2
//
//=================================================================================================
#ifdef M_SQRT2
# undef M_SQRT2
#endif
//*************************************************************************************************
/*!\brief Definition of the mathematical constant \f$ \sqrt{2} \f$.
// \ingroup math
*/
const real_t M_SQRT2 = 1.4142135623730950488016887242096981;
//*************************************************************************************************
//=================================================================================================
//
// MATHEMATICAL CONSTANT SQRT3
//
//=================================================================================================
#ifdef M_SQRT3
# undef M_SQRT3
#endif
//*************************************************************************************************
/*!\brief Definition of the mathematical constant \f$ \sqrt{3} \f$.
// \ingroup math
*/
const real_t M_SQRT3 = 1.7320508075688772935274463415058724;
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,132 @@
//=================================================================================================
/*!
// \file blaze/math/Constraints.h
// \brief Header file for all mathematical constraints
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_CONSTRAINTS_H_
#define _BLAZE_MATH_CONSTRAINTS_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/constraints/Adaptor.h>
#include <blaze/math/constraints/AddExpr.h>
#include <blaze/math/constraints/Aligned.h>
#include <blaze/math/constraints/BLASCompatible.h>
#include <blaze/math/constraints/Column.h>
#include <blaze/math/constraints/ColumnMajorMatrix.h>
#include <blaze/math/constraints/Columns.h>
#include <blaze/math/constraints/ColumnVector.h>
#include <blaze/math/constraints/Computation.h>
#include <blaze/math/constraints/ConstDataAccess.h>
#include <blaze/math/constraints/CrossExpr.h>
#include <blaze/math/constraints/Custom.h>
#include <blaze/math/constraints/DenseMatrix.h>
#include <blaze/math/constraints/DenseVector.h>
#include <blaze/math/constraints/Diagonal.h>
#include <blaze/math/constraints/DivExpr.h>
#include <blaze/math/constraints/EvalExpr.h>
#include <blaze/math/constraints/Expression.h>
#include <blaze/math/constraints/ForEachExpr.h>
#include <blaze/math/constraints/General.h>
#include <blaze/math/constraints/Hermitian.h>
#include <blaze/math/constraints/Identity.h>
#include <blaze/math/constraints/Invertible.h>
#include <blaze/math/constraints/Lower.h>
#include <blaze/math/constraints/MatEvalExpr.h>
#include <blaze/math/constraints/MatForEachExpr.h>
#include <blaze/math/constraints/MatInvExpr.h>
#include <blaze/math/constraints/MatMatAddExpr.h>
#include <blaze/math/constraints/MatMatMultExpr.h>
#include <blaze/math/constraints/MatMatSubExpr.h>
#include <blaze/math/constraints/Matrix.h>
#include <blaze/math/constraints/MatScalarDivExpr.h>
#include <blaze/math/constraints/MatScalarMultExpr.h>
#include <blaze/math/constraints/MatSerialExpr.h>
#include <blaze/math/constraints/MatTransExpr.h>
#include <blaze/math/constraints/MatVecMultExpr.h>
#include <blaze/math/constraints/MultExpr.h>
#include <blaze/math/constraints/MutableDataAccess.h>
#include <blaze/math/constraints/NumericMatrix.h>
#include <blaze/math/constraints/NumericVector.h>
#include <blaze/math/constraints/OpposedView.h>
#include <blaze/math/constraints/Padded.h>
#include <blaze/math/constraints/Proxy.h>
#include <blaze/math/constraints/RequiresEvaluation.h>
#include <blaze/math/constraints/Resizable.h>
#include <blaze/math/constraints/Restricted.h>
#include <blaze/math/constraints/Row.h>
#include <blaze/math/constraints/RowMajorMatrix.h>
#include <blaze/math/constraints/Rows.h>
#include <blaze/math/constraints/RowVector.h>
#include <blaze/math/constraints/SerialExpr.h>
#include <blaze/math/constraints/SIMDEnabled.h>
#include <blaze/math/constraints/SIMDPack.h>
#include <blaze/math/constraints/Size.h>
#include <blaze/math/constraints/SMPAssignable.h>
#include <blaze/math/constraints/SparseElement.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/constraints/SparseVector.h>
#include <blaze/math/constraints/Square.h>
#include <blaze/math/constraints/StorageOrder.h>
#include <blaze/math/constraints/StrictlyLower.h>
#include <blaze/math/constraints/StrictlyTriangular.h>
#include <blaze/math/constraints/StrictlyUpper.h>
#include <blaze/math/constraints/SubExpr.h>
#include <blaze/math/constraints/Submatrix.h>
#include <blaze/math/constraints/Subvector.h>
#include <blaze/math/constraints/Symmetric.h>
#include <blaze/math/constraints/TransExpr.h>
#include <blaze/math/constraints/TransposeFlag.h>
#include <blaze/math/constraints/Triangular.h>
#include <blaze/math/constraints/TVecMatMultExpr.h>
#include <blaze/math/constraints/UniLower.h>
#include <blaze/math/constraints/UniTriangular.h>
#include <blaze/math/constraints/UniUpper.h>
#include <blaze/math/constraints/Upper.h>
#include <blaze/math/constraints/VecEvalExpr.h>
#include <blaze/math/constraints/VecForEachExpr.h>
#include <blaze/math/constraints/VecScalarDivExpr.h>
#include <blaze/math/constraints/VecScalarMultExpr.h>
#include <blaze/math/constraints/VecSerialExpr.h>
#include <blaze/math/constraints/Vector.h>
#include <blaze/math/constraints/VecTransExpr.h>
#include <blaze/math/constraints/VecTVecMultExpr.h>
#include <blaze/math/constraints/VecVecAddExpr.h>
#include <blaze/math/constraints/VecVecDivExpr.h>
#include <blaze/math/constraints/VecVecMultExpr.h>
#include <blaze/math/constraints/VecVecSubExpr.h>
#include <blaze/math/constraints/View.h>
#endif

View File

@ -0,0 +1,356 @@
//=================================================================================================
/*!
// \file blaze/math/CustomMatrix.h
// \brief Header file for the complete CustomMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_CUSTOMMATRIX_H_
#define _BLAZE_MATH_CUSTOMMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/CustomMatrix.h>
#include <blaze/math/dense/DynamicMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/DynamicVector.h>
#include <blaze/math/Exception.h>
#include <blaze/math/shims/Conjugate.h>
#include <blaze/math/shims/Real.h>
#include <blaze/math/typetraits/UnderlyingBuiltin.h>
#include <blaze/util/Assert.h>
#include <blaze/util/constraints/Numeric.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for CustomMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of CustomMatrix.
*/
template< typename Type // Data type of the matrix
, bool AF // Alignment flag
, bool PF // Padding flag
, bool SO > // Storage order
class Rand< CustomMatrix<Type,AF,PF,SO> >
{
public:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( CustomMatrix<Type,AF,PF,SO>& matrix ) const;
template< typename Arg >
inline void randomize( CustomMatrix<Type,AF,PF,SO>& matrix, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a CustomMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename Type // Data type of the matrix
, bool AF // Alignment flag
, bool PF // Padding flag
, bool SO > // Storage order
inline void Rand< CustomMatrix<Type,AF,PF,SO> >::randomize( CustomMatrix<Type,AF,PF,SO>& matrix ) const
{
using blaze::randomize;
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
for( size_t i=0UL; i<m; ++i ) {
for( size_t j=0UL; j<n; ++j ) {
randomize( matrix(i,j) );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a CustomMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename Type // Data type of the matrix
, bool AF // Alignment flag
, bool PF // Padding flag
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline void Rand< CustomMatrix<Type,AF,PF,SO> >::randomize( CustomMatrix<Type,AF,PF,SO>& matrix,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
for( size_t i=0UL; i<m; ++i ) {
for( size_t j=0UL; j<n; ++j ) {
randomize( matrix(i,j), min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric CustomMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, bool AF // Alignment flag
, bool PF // Padding flag
, bool SO > // Storage order
void makeSymmetric( CustomMatrix<Type,AF,PF,SO>& matrix )
{
using blaze::randomize;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j) );
matrix(j,i) = matrix(i,j);
}
randomize( matrix(i,i) );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric CustomMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, bool AF // Alignment flag
, bool PF // Padding flag
, bool SO // Storage order
, typename Arg > // Min/max argument type
void makeSymmetric( CustomMatrix<Type,AF,PF,SO>& matrix, const Arg& min, const Arg& max )
{
using blaze::randomize;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j), min, max );
matrix(j,i) = matrix(i,j);
}
randomize( matrix(i,i), min, max );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian CustomMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, bool AF // Alignment flag
, bool PF // Padding flag
, bool SO > // Storage order
void makeHermitian( CustomMatrix<Type,AF,PF,SO>& matrix )
{
using blaze::randomize;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
typedef UnderlyingBuiltin_<Type> BT;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j) );
matrix(j,i) = conj( matrix(i,j) );
}
matrix(i,i) = rand<BT>();
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian CustomMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, bool AF // Alignment flag
, bool PF // Padding flag
, bool SO // Storage order
, typename Arg > // Min/max argument type
void makeHermitian( CustomMatrix<Type,AF,PF,SO>& matrix, const Arg& min, const Arg& max )
{
using blaze::randomize;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
typedef UnderlyingBuiltin_<Type> BT;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j), min, max );
matrix(j,i) = conj( matrix(i,j) );
}
matrix(i,i) = rand<BT>( real( min ), real( max ) );
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite CustomMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, bool AF // Alignment flag
, bool PF // Padding flag
, bool SO > // Storage order
void makePositiveDefinite( CustomMatrix<Type,AF,PF,SO>& matrix )
{
using blaze::randomize;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
randomize( matrix );
matrix *= ctrans( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) += Type(n);
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,140 @@
//=================================================================================================
/*!
// \file blaze/math/CustomVector.h
// \brief Header file for the complete CustomVector implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_CUSTOMVECTOR_H_
#define _BLAZE_MATH_CUSTOMVECTOR_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/CustomVector.h>
#include <blaze/math/dense/DynamicVector.h>
#include <blaze/math/dense/StaticVector.h>
#include <blaze/math/DenseVector.h>
#include <blaze/math/DynamicMatrix.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for CustomVector.
// \ingroup random
//
// This specialization of the Rand class randomizes instances of CustomVector.
*/
template< typename Type // Data type of the vector
, bool AF // Alignment flag
, bool PF // Padding flag
, bool TF > // Transpose flag
class Rand< CustomVector<Type,AF,PF,TF> >
{
public:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( CustomVector<Type,AF,PF,TF>& vector ) const;
template< typename Arg >
inline void randomize( CustomVector<Type,AF,PF,TF>& vector, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a CustomVector.
//
// \param vector The vector to be randomized.
// \return void
*/
template< typename Type // Data type of the vector
, bool AF // Alignment flag
, bool PF // Padding flag
, bool TF > // Transpose flag
inline void Rand< CustomVector<Type,AF,PF,TF> >::randomize( CustomVector<Type,AF,PF,TF>& vector ) const
{
using blaze::randomize;
const size_t size( vector.size() );
for( size_t i=0UL; i<size; ++i ) {
randomize( vector[i] );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a CustomVector.
//
// \param vector The vector to be randomized.
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return void
*/
template< typename Type // Data type of the vector
, bool AF // Alignment flag
, bool PF // Padding flag
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline void Rand< CustomVector<Type,AF,PF,TF> >::randomize( CustomVector<Type,AF,PF,TF>& vector,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
const size_t size( vector.size() );
for( size_t i=0UL; i<size; ++i ) {
randomize( vector[i], min, max );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,103 @@
//=================================================================================================
/*!
// \file blaze/math/DenseMatrix.h
// \brief Header file for all basic DenseMatrix functionality
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_DENSEMATRIX_H_
#define _BLAZE_MATH_DENSEMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/DenseMatrix.h>
#include <blaze/math/dense/Inversion.h>
#include <blaze/math/dense/LLH.h>
#include <blaze/math/dense/LQ.h>
#include <blaze/math/dense/LU.h>
#include <blaze/math/dense/QL.h>
#include <blaze/math/dense/QR.h>
#include <blaze/math/dense/RQ.h>
#include <blaze/math/expressions/DenseMatrix.h>
#include <blaze/math/expressions/DMatDetExpr.h>
#include <blaze/math/expressions/DMatDMatAddExpr.h>
#include <blaze/math/expressions/DMatDMatMultExpr.h>
#include <blaze/math/expressions/DMatDMatSubExpr.h>
#include <blaze/math/expressions/DMatDVecMultExpr.h>
#include <blaze/math/expressions/DMatEvalExpr.h>
#include <blaze/math/expressions/DMatForEachExpr.h>
#include <blaze/math/expressions/DMatInvExpr.h>
#include <blaze/math/expressions/DMatScalarDivExpr.h>
#include <blaze/math/expressions/DMatScalarMultExpr.h>
#include <blaze/math/expressions/DMatSerialExpr.h>
#include <blaze/math/expressions/DMatSMatAddExpr.h>
#include <blaze/math/expressions/DMatSMatMultExpr.h>
#include <blaze/math/expressions/DMatSMatSubExpr.h>
#include <blaze/math/expressions/DMatSVecMultExpr.h>
#include <blaze/math/expressions/DMatTDMatAddExpr.h>
#include <blaze/math/expressions/DMatTDMatMultExpr.h>
#include <blaze/math/expressions/DMatTDMatSubExpr.h>
#include <blaze/math/expressions/DMatTransExpr.h>
#include <blaze/math/expressions/DMatTransposer.h>
#include <blaze/math/expressions/DMatTSMatAddExpr.h>
#include <blaze/math/expressions/DMatTSMatMultExpr.h>
#include <blaze/math/expressions/DMatTSMatSubExpr.h>
#include <blaze/math/expressions/DVecTDVecMultExpr.h>
#include <blaze/math/expressions/SMatDMatMultExpr.h>
#include <blaze/math/expressions/SMatDMatSubExpr.h>
#include <blaze/math/expressions/SMatTDMatMultExpr.h>
#include <blaze/math/expressions/SMatTDMatSubExpr.h>
#include <blaze/math/expressions/SparseMatrix.h>
#include <blaze/math/expressions/TDMatDMatMultExpr.h>
#include <blaze/math/expressions/TDMatDVecMultExpr.h>
#include <blaze/math/expressions/TDMatSMatAddExpr.h>
#include <blaze/math/expressions/TDMatSMatMultExpr.h>
#include <blaze/math/expressions/TDMatSMatSubExpr.h>
#include <blaze/math/expressions/TDMatSVecMultExpr.h>
#include <blaze/math/expressions/TDMatTDMatMultExpr.h>
#include <blaze/math/expressions/TDMatTSMatMultExpr.h>
#include <blaze/math/expressions/TDVecDMatMultExpr.h>
#include <blaze/math/expressions/TDVecTDMatMultExpr.h>
#include <blaze/math/expressions/TSMatDMatMultExpr.h>
#include <blaze/math/expressions/TSMatDMatSubExpr.h>
#include <blaze/math/expressions/TSMatTDMatMultExpr.h>
#include <blaze/math/expressions/TSVecDMatMultExpr.h>
#include <blaze/math/expressions/TSVecTDMatMultExpr.h>
#include <blaze/math/Matrix.h>
#include <blaze/math/smp/DenseMatrix.h>
#include <blaze/math/smp/SparseMatrix.h>
#include <blaze/math/views/Column.h>
#include <blaze/math/views/Row.h>
#include <blaze/math/views/Submatrix.h>
#endif

View File

@ -0,0 +1,69 @@
//=================================================================================================
/*!
// \file blaze/math/DenseVector.h
// \brief Header file for all basic DenseVector functionality
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_DENSEVECTOR_H_
#define _BLAZE_MATH_DENSEVECTOR_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/DenseVector.h>
#include <blaze/math/expressions/DenseVector.h>
#include <blaze/math/expressions/DVecDVecAddExpr.h>
#include <blaze/math/expressions/DVecDVecDivExpr.h>
#include <blaze/math/expressions/DVecDVecCrossExpr.h>
#include <blaze/math/expressions/DVecDVecMultExpr.h>
#include <blaze/math/expressions/DVecDVecSubExpr.h>
#include <blaze/math/expressions/DVecEvalExpr.h>
#include <blaze/math/expressions/DVecForEachExpr.h>
#include <blaze/math/expressions/DVecScalarDivExpr.h>
#include <blaze/math/expressions/DVecScalarMultExpr.h>
#include <blaze/math/expressions/DVecSerialExpr.h>
#include <blaze/math/expressions/DVecSVecAddExpr.h>
#include <blaze/math/expressions/DVecSVecCrossExpr.h>
#include <blaze/math/expressions/DVecSVecSubExpr.h>
#include <blaze/math/expressions/DVecTransExpr.h>
#include <blaze/math/expressions/SparseVector.h>
#include <blaze/math/expressions/SVecDVecCrossExpr.h>
#include <blaze/math/expressions/SVecDVecSubExpr.h>
#include <blaze/math/expressions/SVecSVecCrossExpr.h>
#include <blaze/math/expressions/TDVecDVecMultExpr.h>
#include <blaze/math/smp/DenseVector.h>
#include <blaze/math/smp/SparseVector.h>
#include <blaze/math/Vector.h>
#include <blaze/math/views/Subvector.h>
#endif

View File

@ -0,0 +1,685 @@
//=================================================================================================
/*!
// \file blaze/math/DiagonalMatrix.h
// \brief Header file for the complete DiagonalMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_DIAGONALMATRIX_H_
#define _BLAZE_MATH_DIAGONALMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/adaptors/DiagonalMatrix.h>
#include <blaze/math/constraints/DenseMatrix.h>
#include <blaze/math/constraints/Resizable.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/Exception.h>
#include <blaze/math/SparseMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/math/typetraits/UnderlyingBuiltin.h>
#include <blaze/util/FalseType.h>
#include <blaze/util/Indices.h>
#include <blaze/util/Random.h>
#include <blaze/util/TrueType.h>
#include <blaze/util/Types.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for DiagonalMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of DiagonalMatrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
class Rand< DiagonalMatrix<MT,SO,DF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const DiagonalMatrix<MT,SO,DF> generate() const;
inline const DiagonalMatrix<MT,SO,DF> generate( size_t n ) const;
inline const DiagonalMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros ) const;
template< typename Arg >
inline const DiagonalMatrix<MT,SO,DF> generate( const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const DiagonalMatrix<MT,SO,DF> generate( size_t n, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const DiagonalMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix ) const;
inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
private:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix, TrueType ) const;
inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix, FalseType ) const;
template< typename Arg >
inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, TrueType ) const;
template< typename Arg >
inline void randomize( DiagonalMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, FalseType ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random DiagonalMatrix.
//
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const DiagonalMatrix<MT,SO,DF> Rand< DiagonalMatrix<MT,SO,DF> >::generate() const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
DiagonalMatrix<MT,SO,DF> matrix;
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random DiagonalMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const DiagonalMatrix<MT,SO,DF>
Rand< DiagonalMatrix<MT,SO,DF> >::generate( size_t n ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
DiagonalMatrix<MT,SO,DF> matrix( n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random DiagonalMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const DiagonalMatrix<MT,SO,DF>
Rand< DiagonalMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
DiagonalMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random DiagonalMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const DiagonalMatrix<MT,SO,DF>
Rand< DiagonalMatrix<MT,SO,DF> >::generate( const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
DiagonalMatrix<MT,SO,DF> matrix;
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random DiagonalMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const DiagonalMatrix<MT,SO,DF>
Rand< DiagonalMatrix<MT,SO,DF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
DiagonalMatrix<MT,SO,DF> matrix( n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random DiagonalMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const DiagonalMatrix<MT,SO,DF>
Rand< DiagonalMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > DiagonalMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
DiagonalMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< DiagonalMatrix<MT,SO,DF> >::randomize( DiagonalMatrix<MT,SO,DF>& matrix ) const
{
randomize( matrix, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< DiagonalMatrix<MT,SO,DF> >::randomize( DiagonalMatrix<MT,SO,DF>& matrix, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<ET>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< DiagonalMatrix<MT,SO,DF> >::randomize( DiagonalMatrix<MT,SO,DF>& matrix, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, n ) );
randomize( matrix, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< DiagonalMatrix<MT,SO,DF> >::randomize( DiagonalMatrix<MT,SO,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
Indices indices( 0UL, n-1UL, nonzeros );
size_t i( 0UL );
for( size_t index : indices ) {
for( ; i<index; ++i )
matrix.finalize( i );
matrix.append( i, i, rand<ET>() );
}
for( ; i<n; ++i ) {
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< DiagonalMatrix<MT,SO,DF> >::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max ) const
{
randomize( matrix, min, max, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< DiagonalMatrix<MT,SO,DF> >::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<ET>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< DiagonalMatrix<MT,SO,DF> >::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, n ) );
randomize( matrix, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< DiagonalMatrix<MT,SO,DF> >::randomize( DiagonalMatrix<MT,SO,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
Indices indices( 0UL, n-1UL, nonzeros );
size_t i( 0UL );
for( size_t index : indices ) {
for( ; i<index; ++i )
matrix.finalize( i );
matrix.append( i, i, rand<ET>( min, max ) );
}
for( ; i<n; ++i ) {
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeSymmetric( DiagonalMatrix<MT,SO,DF>& matrix )
{
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand< ElementType_<MT> >();
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeSymmetric( DiagonalMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
typedef ElementType_<MT> Type;
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<Type>( min, max );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeHermitian( DiagonalMatrix<MT,SO,DF>& matrix )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > Type;
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<Type>();
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeHermitian( DiagonalMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > Type;
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<Type>( min, max );
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite DiagonalMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makePositiveDefinite( DiagonalMatrix<MT,SO,DF>& matrix )
{
makeHermitian( matrix );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,395 @@
//=================================================================================================
/*!
// \file blaze/math/DynamicMatrix.h
// \brief Header file for the complete DynamicMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_DYNAMICMATRIX_H_
#define _BLAZE_MATH_DYNAMICMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/DynamicMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/DynamicVector.h>
#include <blaze/math/Exception.h>
#include <blaze/math/shims/Conjugate.h>
#include <blaze/math/shims/Real.h>
#include <blaze/math/typetraits/UnderlyingBuiltin.h>
#include <blaze/system/Precision.h>
#include <blaze/util/Assert.h>
#include <blaze/util/constraints/Numeric.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for DynamicMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of DynamicMatrix.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
class Rand< DynamicMatrix<Type,SO> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const DynamicMatrix<Type,SO> generate( size_t m, size_t n ) const;
template< typename Arg >
inline const DynamicMatrix<Type,SO> generate( size_t m, size_t n, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( DynamicMatrix<Type,SO>& matrix ) const;
template< typename Arg >
inline void randomize( DynamicMatrix<Type,SO>& matrix, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random DynamicMatrix.
//
// \param m The number of rows of the random matrix.
// \param n The number of columns of the random matrix.
// \return The generated random matrix.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
inline const DynamicMatrix<Type,SO>
Rand< DynamicMatrix<Type,SO> >::generate( size_t m, size_t n ) const
{
DynamicMatrix<Type,SO> matrix( m, n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random DynamicMatrix.
//
// \param m The number of rows of the random matrix.
// \param n The number of columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline const DynamicMatrix<Type,SO>
Rand< DynamicMatrix<Type,SO> >::generate( size_t m, size_t n, const Arg& min, const Arg& max ) const
{
DynamicMatrix<Type,SO> matrix( m, n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a DynamicMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
inline void Rand< DynamicMatrix<Type,SO> >::randomize( DynamicMatrix<Type,SO>& matrix ) const
{
using blaze::randomize;
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
for( size_t i=0UL; i<m; ++i ) {
for( size_t j=0UL; j<n; ++j ) {
randomize( matrix(i,j) );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a DynamicMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline void Rand< DynamicMatrix<Type,SO> >::randomize( DynamicMatrix<Type,SO>& matrix,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
for( size_t i=0UL; i<m; ++i ) {
for( size_t j=0UL; j<n; ++j ) {
randomize( matrix(i,j), min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric DynamicMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
void makeSymmetric( DynamicMatrix<Type,SO>& matrix )
{
using blaze::randomize;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j) );
matrix(j,i) = matrix(i,j);
}
randomize( matrix(i,i) );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric DynamicMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, bool SO // Storage order
, typename Arg > // Min/max argument type
void makeSymmetric( DynamicMatrix<Type,SO>& matrix, const Arg& min, const Arg& max )
{
using blaze::randomize;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j), min, max );
matrix(j,i) = matrix(i,j);
}
randomize( matrix(i,i), min, max );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian DynamicMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
void makeHermitian( DynamicMatrix<Type,SO>& matrix )
{
using blaze::randomize;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
typedef UnderlyingBuiltin_<Type> BT;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j) );
matrix(j,i) = conj( matrix(i,j) );
}
matrix(i,i) = rand<BT>();
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian DynamicMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, bool SO // Storage order
, typename Arg > // Min/max argument type
void makeHermitian( DynamicMatrix<Type,SO>& matrix, const Arg& min, const Arg& max )
{
using blaze::randomize;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
typedef UnderlyingBuiltin_<Type> BT;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j), min, max );
matrix(j,i) = conj( matrix(i,j) );
}
matrix(i,i) = rand<BT>( real( min ), real( max ) );
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite DynamicMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, bool SO > // Storage order
void makePositiveDefinite( DynamicMatrix<Type,SO>& matrix )
{
using blaze::randomize;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
randomize( matrix );
matrix *= ctrans( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) += Type(n);
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,186 @@
//=================================================================================================
/*!
// \file blaze/math/DynamicVector.h
// \brief Header file for the complete DynamicVector implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_DYNAMICVECTOR_H_
#define _BLAZE_MATH_DYNAMICVECTOR_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/DynamicVector.h>
#include <blaze/math/dense/StaticVector.h>
#include <blaze/math/DenseVector.h>
#include <blaze/math/DynamicMatrix.h>
#include <blaze/system/Precision.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for DynamicVector.
// \ingroup random
//
// This specialization of the Rand class creates random instances of DynamicVector.
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
class Rand< DynamicVector<Type,TF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const DynamicVector<Type,TF> generate( size_t n ) const;
template< typename Arg >
inline const DynamicVector<Type,TF> generate( size_t n, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( DynamicVector<Type,TF>& vector ) const;
template< typename Arg >
inline void randomize( DynamicVector<Type,TF>& vector, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random DynamicVector.
//
// \param n The size of the random vector.
// \return The generated random vector.
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
inline const DynamicVector<Type,TF> Rand< DynamicVector<Type,TF> >::generate( size_t n ) const
{
DynamicVector<Type,TF> vector( n );
randomize( vector );
return vector;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random DynamicVector.
//
// \param n The size of the random vector.
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return The generated random vector.
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline const DynamicVector<Type,TF>
Rand< DynamicVector<Type,TF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
DynamicVector<Type,TF> vector( n );
randomize( vector, min, max );
return vector;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a DynamicVector.
//
// \param vector The vector to be randomized.
// \return void
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
inline void Rand< DynamicVector<Type,TF> >::randomize( DynamicVector<Type,TF>& vector ) const
{
using blaze::randomize;
const size_t size( vector.size() );
for( size_t i=0UL; i<size; ++i ) {
randomize( vector[i] );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a DynamicVector.
//
// \param vector The vector to be randomized.
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return void
*/
template< typename Type // Data type of the vector
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline void Rand< DynamicVector<Type,TF> >::randomize( DynamicVector<Type,TF>& vector,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
const size_t size( vector.size() );
for( size_t i=0UL; i<size; ++i ) {
randomize( vector[i], min, max );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,906 @@
//=================================================================================================
/*!
// \file blaze/math/Epsilon.h
// \brief Numerical epsilon value for floating point data types
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_EPSILON_H_
#define _BLAZE_MATH_EPSILON_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/util/constraints/FloatingPoint.h>
#include <blaze/util/Limits.h>
namespace blaze {
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Negative epsilon value for floating point data types.
// \ingroup math
//
// The NegativeEpsilon class is a wrapper class around the functionality of the blaze::Limits
// class. It represents the negative smallest difference between two values of any floating
// point data type. In order to assign a negative epsilon value, the Epsilon class can be
// implicitly converted to the three built-in floating point data types float, double and
// long double.
//
// \note The NegativeEpsilon class is a helper class for the Epsilon class. It cannot be
// instantiated on its own, but can only be used by the Epsilon class.
*/
template< typename E > // Positive epsilon type
class NegativeEpsilon
{
public:
//**Type definitions****************************************************************************
typedef E PositiveType; //!< The positive epsilon type.
//**********************************************************************************************
private:
//**Constructor*********************************************************************************
/*!\name Constructor */
//@{
explicit inline NegativeEpsilon();
// No explicitly declared copy constructor.
//@}
//**********************************************************************************************
public:
//**Destructor**********************************************************************************
// No explicitly declared destructor.
//**********************************************************************************************
//**Unary plus/minus operators******************************************************************
/*!\name Unary plus/minus operators */
//@{
inline const NegativeEpsilon& operator+() const;
inline const PositiveType operator-() const;
//@}
//**********************************************************************************************
//**Conversion operator*************************************************************************
/*!\name Conversion operator */
//@{
template< typename T >
inline operator const T() const;
//@}
//**********************************************************************************************
private:
//**Forbidden operations************************************************************************
/*!\name Forbidden operations */
//@{
NegativeEpsilon& operator=( const NegativeEpsilon& ); //!< Copy assignment operator (private & undefined)
void* operator&() const; //!< Address operator (private & undefined)
//@}
//**********************************************************************************************
//**Friend declarations*************************************************************************
/*! \cond BLAZE_INTERNAL */
friend class Epsilon;
/*! \endcond */
//**********************************************************************************************
};
//*************************************************************************************************
//=================================================================================================
//
// CONSTRUCTOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief The default constructor of the NegativeEpsilon class.
*/
template< typename E > // Positive epsilon type
inline NegativeEpsilon<E>::NegativeEpsilon()
{}
//*************************************************************************************************
//=================================================================================================
//
// UNARY PLUS/MINUS OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Returns the negative epsilon value for all floating point data types.
//
// \return The negative epsilon value.
*/
template< typename E > // Positive epsilon type
inline const NegativeEpsilon<E>& NegativeEpsilon<E>::operator+() const
{
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns the positive epsilon value for all floating point data types.
//
// \return The positive epsilon value.
*/
template< typename E > // Positive epsilon type
inline const typename NegativeEpsilon<E>::PositiveType NegativeEpsilon<E>::operator-() const
{
return PositiveType();
}
//*************************************************************************************************
//=================================================================================================
//
// CONVERSION OPERATOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Conversion operator to the required floating point data type.
//
// The conversion operator returns the negative epsilon value for the floating point
// data type \a T.
*/
template< typename E > // Positive epsilon type
template< typename T > // Floating point data type
inline NegativeEpsilon<E>::operator const T() const
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::epsilon();
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\name NegativeEpsilon operators */
//@{
template< typename E, typename T >
inline bool operator==( const NegativeEpsilon<E>& lhs, const T& rhs );
template< typename E, typename T >
inline bool operator==( const T& lhs, const NegativeEpsilon<E>& rhs );
template< typename E, typename T >
inline bool operator!=( const NegativeEpsilon<E>& lhs, const T& rhs );
template< typename E, typename T >
inline bool operator!=( const T& lhs, const NegativeEpsilon<E>& rhs );
template< typename E, typename T >
inline bool operator<( const NegativeEpsilon<E>& lhs, const T& rhs );
template< typename E, typename T >
inline bool operator<( const T& lhs, const NegativeEpsilon<E>& rhs );
template< typename E, typename T >
inline bool operator>( const NegativeEpsilon<E>& lhs, const T& rhs );
template< typename E, typename T >
inline bool operator>( const T& lhs, const NegativeEpsilon<E>& rhs );
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Equality comparison between a NegativeEpsilon object and a floating point value.
// \ingroup math
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is equal to the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator==( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::epsilon() == rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Equality comparison between a floating point value and a NegativeEpsilon object.
// \ingroup math
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is equal to the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator==( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs == -Limits<T>::epsilon();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Inequality comparison between a NegativeEpsilon object and a floating point value.
// \ingroup math
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is unequal to the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator!=( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::epsilon() != rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Inequality comparison between a floating point value and a NegativeEpsilon object.
// \ingroup math
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is unequal to the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator!=( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs != -Limits<T>::epsilon();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-than comparison between a NegativeEpsilon object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is greater than the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator<( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::epsilon() < rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-than comparison between a floating point value and a NegativeEpsilon object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is smaller than the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator<( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs < -Limits<T>::epsilon();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-than comparison between a NegativeEpsilon object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is smaller than the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator>( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::epsilon() > rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-than comparison between a floating point value and a NegativeEpsilon object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is greater than the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator>( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs > -Limits<T>::epsilon();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between a NegativeEpsilon object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is greater than or equal to the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator<=( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::epsilon() <= rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between a floating point value and a NegativeEpsilon object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is smaller than or equal to the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator<=( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs <= -Limits<T>::epsilon();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-or-equal-than comparison between a NegativeEpsilon object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the value is smaller than or equal to the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator>=( const NegativeEpsilon<E>& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return -Limits<T>::epsilon() >= rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between a floating point value and a NegativeEpsilon object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the value is greater than or equal to the negative epsilon, \a false if not.
//
// This operator exclusively works for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename E // Positive epsilon type
, typename T > // Floating point data type
inline bool operator>=( const T& lhs, const NegativeEpsilon<E>& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs >= -Limits<T>::epsilon();
}
//*************************************************************************************************
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Numerical epsilon value for floating point data types.
// \ingroup math
//
// The Epsilon class is a wrapper class around the functionality of the blaze::Limits class.
// It represents the smallest difference between two values of any floating point data type.
// In order to assign an epsilon value, the Epsilon class can be implicitly converted to the
// three built-in floating point data types float, double and long double.\n
// In order to handle epsilon values conveniently, the global Epsilon instance blaze::epsilon
// is provided, which can be used wherever a floating point data type is required.
\code
float f = epsilon; // Assigns the positive epsilon for single precision values
double d = -epsilon; // Assigns the negative epsilon for double precision values
\endcode
*/
class Epsilon
{
public:
//**Type definitions****************************************************************************
typedef NegativeEpsilon<Epsilon> NegativeType; //!< The negative epsilon type.
//**********************************************************************************************
//**Constructor*********************************************************************************
/*!\name Constructor */
//@{
explicit inline Epsilon();
// No explicitly declared copy constructor.
//@}
//**********************************************************************************************
//**Destructor**********************************************************************************
// No explicitly declared destructor.
//**********************************************************************************************
//**Unary plus/minus operators******************************************************************
/*!\name Unary plus/minus operators */
//@{
inline const Epsilon& operator+() const;
inline const NegativeType operator-() const;
//@}
//**********************************************************************************************
//**Conversion operators************************************************************************
/*!\name Conversion operators */
//@{
template< typename T >
inline operator const T() const;
//@}
//**********************************************************************************************
private:
//**Forbidden operations************************************************************************
/*!\name Forbidden operations */
//@{
Epsilon& operator=( const Epsilon& ); //!< Copy assignment operator (private & undefined)
void* operator&() const; //!< Address operator (private & undefined)
//@}
//**********************************************************************************************
};
//*************************************************************************************************
//=================================================================================================
//
// CONSTRUCTOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief The default constructor of the Epsilon class.
*/
inline Epsilon::Epsilon()
{}
//*************************************************************************************************
//=================================================================================================
//
// UNARY PLUS/MINUS OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Returns the positive epsilon value for all floating point data types.
//
// \return The positive epsilon value.
*/
inline const Epsilon& Epsilon::operator+() const
{
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns the negative epsilon value for all floating point data types.
//
// \return The negative epsilon value.
*/
inline const Epsilon::NegativeType Epsilon::operator-() const
{
return NegativeType();
}
//*************************************************************************************************
//=================================================================================================
//
// CONVERSION OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Conversion operator to the required floating point data type.
//
// The conversion operator returns the smallest possible difference between values of the
// floating point data type \a T.
*/
template< typename T >
inline Epsilon::operator const T() const
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::epsilon();
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\name Epsilon operators */
//@{
template< typename T >
inline bool operator==( const Epsilon& lhs, const T& rhs );
template< typename T >
inline bool operator==( const T& lhs, const Epsilon& rhs );
template< typename T >
inline bool operator!=( const Epsilon& lhs, const T& rhs );
template< typename T >
inline bool operator!=( const T& lhs, const Epsilon& rhs );
template< typename T >
inline bool operator<( const Epsilon& lhs, const T& rhs );
template< typename T >
inline bool operator<( const T& lhs, const Epsilon& rhs );
template< typename T >
inline bool operator>( const Epsilon& lhs, const T& rhs );
template< typename T >
inline bool operator>( const T& lhs, const Epsilon& rhs );
template< typename T >
inline bool operator<=( const Epsilon& lhs, const T& rhs );
template< typename T >
inline bool operator<=( const T& lhs, const Epsilon& rhs );
template< typename T >
inline bool operator>=( const Epsilon& lhs, const T& rhs );
template< typename T >
inline bool operator>=( const T& lhs, const Epsilon& rhs );
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Equality comparison between an Epsilon object and a floating point value.
// \ingroup math
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floating point value is equal to epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator==( const Epsilon& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::epsilon() == rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Equality comparison between a floating point value and an Epsilon object.
// \ingroup math
//
// \param lhs The left-hand side floating point value.
// \return \a true if the floating point value is equal to epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator==( const T& lhs, const Epsilon& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs == Limits<T>::epsilon();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Inequality comparison between an Epsilon object and a floating point value.
// \ingroup math
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floating point value is unequal to epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator!=( const Epsilon& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::epsilon() != rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Inequality comparison between a floating point value and an Epsilon object.
// \ingroup math
//
// \param lhs The left-hand side floating point value.
// \return \a true if the floating point value is unequal to epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator!=( const T& lhs, const Epsilon& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs != Limits<T>::epsilon();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-than comparison between an Epsilon object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floating point value is greater than epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator<( const Epsilon& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::epsilon() < rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-than comparison between a floating point value and an Epsilon object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the floating point value is smaller than epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator<( const T& lhs, const Epsilon& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs < Limits<T>::epsilon();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-than comparison between an Epsilon object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floating point value is smaller than epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator>( const Epsilon& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::epsilon() > rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-than comparison between a floating point value and an Epsilon object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the floating point value is greater than epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator>( const T& lhs, const Epsilon& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs > Limits<T>::epsilon();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between an Epsilon object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floating point value is greater than or equal to epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator<=( const Epsilon& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::epsilon() <= rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between a floating point value and an Epsilon object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the floating point value is smaller than or equal to epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator<=( const T& lhs, const Epsilon& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs <= Limits<T>::epsilon();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Greater-or-equal-than comparison between an Epsilon object and a floating point value.
//
// \param rhs The right-hand side floating point value.
// \return \a true if the floating point value is smaller than or equal to epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator>=( const Epsilon& /*lhs*/, const T& rhs )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return Limits<T>::epsilon() >= rhs;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Less-or-equal-than comparison between a floating point value and an Epsilon object.
//
// \param lhs The left-hand side floating point value.
// \return \a true if the floating point value is greater than or equal to epsilon, \a false if not.
//
// This operator works only for floating point data types. The attempt to compare any
// integral data type or user-defined class types will result in a compile time error.
*/
template< typename T >
inline bool operator>=( const T& lhs, const Epsilon& /*rhs*/ )
{
BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE( T );
return lhs >= Limits<T>::epsilon();
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL EPSILON VALUE
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Global Epsilon instance.
// \ingroup math
//
// The blaze::epsilon instance can be used wherever a floating point data type is expected.
// It is implicitly converted to the corresponding floating point data type and represents
// the smallest possible difference between two values of the according data type.
*/
const Epsilon epsilon;
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,150 @@
//=================================================================================================
/*!
// \file blaze/math/Exception.h
// \brief Header file for the exception macros of the math module
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_EXCEPTION_H_
#define _BLAZE_MATH_EXCEPTION_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/util/Exception.h>
//=================================================================================================
//
// EXCEPTION MACROS
//
//=================================================================================================
//*************************************************************************************************
/*!\def BLAZE_THROW_DIVISION_BY_ZERO
// \brief Macro for the emission of an exception on detection of a division by zero.
// \ingroup math
//
// This macro encapsulates the default way of \b Blaze to throw an exception on detection of
// a division by zero. Also, since it may be desirable to replace the type of exception by a
// custom exception type this macro provides an opportunity to customize the behavior.
//
// The macro excepts a single argument, which specifies the message of the exception:
\code
#define BLAZE_THROW_DIVISION_BY_ZERO( MESSAGE ) \
BLAZE_THROW_RUNTIME_ERROR( MESSAGE )
\endcode
// In order to customize the type of exception all that needs to be done is to define the macro
// prior to including any \a Blaze header file. This will override the \b Blaze default behavior.
// The following example demonstrates this by replacing \a std::runtime_error by a custom
// exception type:
\code
class DivisionByZero
{
public:
DivisionByZero();
explicit DivisionByZero( const std::string& message );
// ...
};
#define BLAZE_THROW_DIVISION_BY_ZERO( MESSAGE ) \
throw DivisionByZero( MESSAGE )
#include <blaze/Blaze.h>
\endcode
// \note It is recommended to define the macro such that a subsequent semicolon is required!
//
// \warning This macro is provided with the intention to assist in adapting \b Blaze to special
// conditions and environments. However, the customization of the type of exception via this
// macro may have an effect on the library. Thus be advised to use the macro with due care!
*/
#ifndef BLAZE_THROW_DIVISION_BY_ZERO
# define BLAZE_THROW_DIVISION_BY_ZERO( MESSAGE ) BLAZE_THROW_RUNTIME_ERROR( MESSAGE )
#endif
//*************************************************************************************************
//*************************************************************************************************
/*!\def BLAZE_THROW_LAPACK_ERROR
// \brief Macro for the emission of an exception on detection of a LAPACK error.
// \ingroup math
//
// This macro encapsulates the default way of \b Blaze to throw an exception when encountering
// a LAPACK error (for instance when trying to invert a singular matrix). Also, since it may be
// desirable to replace the type of exception by a custom exception type this macro provides an
// opportunity to customize the behavior.
//
// The macro excepts a single argument, which specifies the message of the exception:
\code
#define BLAZE_THROW_LAPACK_ERROR( MESSAGE ) \
BLAZE_THROW_RUNTIME_ERROR( MESSAGE )
\endcode
// In order to customize the type of exception all that needs to be done is to define the macro
// prior to including any \a Blaze header file. This will override the \b Blaze default behavior.
// The following example demonstrates this by replacing \a std::runtime_error by a custom
// exception type:
\code
class LapackError
{
public:
LapackError();
explicit LapackError( const std::string& message );
// ...
};
#define BLAZE_THROW_LAPACK_ERROR( MESSAGE ) \
throw LapackError( MESSAGE )
#include <blaze/Blaze.h>
\endcode
// \note It is recommended to define the macro such that a subsequent semicolon is required!
//
// \warning This macro is provided with the intention to assist in adapting \b Blaze to special
// conditions and environments. However, the customization of the type of exception via this
// macro may have an effect on the library. Thus be advised to use the macro with due care!
*/
#ifndef BLAZE_THROW_LAPACK_ERROR
# define BLAZE_THROW_LAPACK_ERROR( MESSAGE ) BLAZE_THROW_RUNTIME_ERROR( MESSAGE )
#endif
//*************************************************************************************************
#endif

View File

@ -0,0 +1,49 @@
//=================================================================================================
/*!
// \file blaze/math/Forward.h
// \brief Header file for all forward declarations of the math module
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_FORWARD_H_
#define _BLAZE_MATH_FORWARD_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/adaptors/Forward.h>
#include <blaze/math/dense/Forward.h>
#include <blaze/math/functors/Forward.h>
#include <blaze/math/sparse/Forward.h>
#include <blaze/math/views/Forward.h>
#endif

View File

@ -0,0 +1,462 @@
//=================================================================================================
/*!
// \file blaze/math/Functions.h
// \brief Header file for mathematical functions
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_FUNCTIONS_H_
#define _BLAZE_MATH_FUNCTIONS_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <blaze/system/Inline.h>
#include <blaze/util/constraints/Builtin.h>
#include <blaze/util/constraints/Integral.h>
#include <blaze/util/mpl/And.h>
#include <blaze/util/Types.h>
#include <blaze/util/typetraits/All.h>
#include <blaze/util/typetraits/CommonType.h>
#include <blaze/util/typetraits/IsBuiltin.h>
#include <blaze/util/typetraits/IsFloatingPoint.h>
#include <blaze/util/typetraits/IsNumeric.h>
#include <blaze/util/typetraits/IsSigned.h>
namespace blaze {
//=================================================================================================
//
// MATHEMATICAL UTILITY FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\name Mathematical utility functions */
//@{
template< typename T >
inline constexpr int sign( T a ) noexcept;
template< typename T >
inline size_t digits( T a ) noexcept;
template< typename T1, typename T2 >
BLAZE_ALWAYS_INLINE constexpr CommonType_<T1,T2>
min( const T1& a, const T2& b ) noexcept( All<IsNumeric,T1,T2>::value );
template< typename T1, typename T2, typename... Ts >
BLAZE_ALWAYS_INLINE constexpr CommonType_<T1,T2,Ts...>
min( const T1& a, const T2& b, const Ts&... args ) noexcept( All<IsNumeric,T1,T2,Ts...>::value );
template< typename T1, typename T2 >
BLAZE_ALWAYS_INLINE constexpr CommonType_<T1,T2>
max( const T1& a, const T2& b ) noexcept( All<IsNumeric,T1,T2>::value );
template< typename T1, typename T2, typename... Ts >
BLAZE_ALWAYS_INLINE constexpr CommonType_<T1,T2,Ts...>
max( const T1& a, const T2& b, const Ts&... args ) noexcept( All<IsNumeric,T1,T2,Ts...>::value );
template< typename T >
BLAZE_ALWAYS_INLINE T round( T a ) noexcept;
template< typename T >
BLAZE_ALWAYS_INLINE constexpr T nextMultiple( T value, T factor ) noexcept;
template< typename T1, typename T2 >
BLAZE_ALWAYS_INLINE constexpr bool lessThan( T1 a, T2 b )
noexcept( IsBuiltin< CommonType_<T1,T2> >::value );
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Sign function.
// \ingroup math
//
// \param a The given value.
// \return 1 if the value is greater than zero, 0 if it is zero, and -1 if it is smaller than zero.
//
// The sign function only works for built-in data types. The attempt to use any user-defined class
// type will result in a compile time error.
*/
template< typename T >
inline constexpr int sign( T a ) noexcept
{
BLAZE_CONSTRAINT_MUST_BE_BUILTIN_TYPE( T );
return ( IsSigned<T>::value || IsFloatingPoint<T>::value )
?( T(0) < a ) - ( a < T(0) )
:( T(0) < a );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns the number of valid digits of an integral value.
// \ingroup math
//
// \param a The integral value.
// \return The number of valid digits.
//
// This function counts the number of valid digits in the given integral value.
\code
digits( 100 ); // Returns 3
digits( 12345 ); // Returns 5
digits( 0 ); // Returns 0
\endcode
// The digits function only works for integral built-in data types. The attempt to use any
// other type will result in a compile time error.
*/
template< typename T >
inline size_t digits( T a ) noexcept
{
BLAZE_CONSTRAINT_MUST_BE_INTEGRAL_TYPE( T );
size_t count( 0 );
while( a != 0 ) {
a /= 10;
++count;
}
return count;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Minimum function for two data values.
// \ingroup math
//
// \param a The first value.
// \param b The second value.
// \return The minimum of the two values.
//
// This function returns the minimum of the two given data values. The return type of the function
// is determined by the data types of the given arguments (for further detail see the CommonType
// class description).
*/
template< typename T1, typename T2 >
BLAZE_ALWAYS_INLINE constexpr CommonType_<T1,T2>
min( const T1& a, const T2& b ) noexcept( All<IsNumeric,T1,T2>::value )
{
return ( a < b )?( a ):( b );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Minimum function for at least three data values.
// \ingroup math
//
// \param a The first value.
// \param b The second value.
// \param args The pack of additional values.
// \return The minimum of the given values.
//
// This function returns the minimum of the given data values. The return type of the function
// is determined by the data types of the given arguments (for further detail see the CommonType
// class description).
*/
template< typename T1, typename T2, typename... Ts >
BLAZE_ALWAYS_INLINE constexpr CommonType_<T1,T2,Ts...>
min( const T1& a, const T2& b, const Ts&... args ) noexcept( All<IsNumeric,T1,T2,Ts...>::value )
{
return min( a, min( b, args... ) );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Maximum function for two data values.
// \ingroup math
//
// \param a The first value.
// \param b The second value.
// \return The maximum of the two values.
//
// This function returns the maximum of the two given data values. The return type of the function
// is determined by the data types of the given arguments (for further detail see the CommonType
// class description).
*/
template< typename T1, typename T2 >
BLAZE_ALWAYS_INLINE constexpr CommonType_<T1,T2>
max( const T1& a, const T2& b ) noexcept( All<IsNumeric,T1,T2>::value )
{
return ( a < b )?( b ):( a );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Maximum function for at least three data values.
// \ingroup math
//
// \param a The first value.
// \param b The second value.
// \param args The pack of additional values.
// \return The maximum of the given values.
//
// This function returns the maximum of the given data values. The return type of the function
// is determined by the data types of the given arguments (for further detail see the CommonType
// class description).
*/
template< typename T1, typename T2, typename... Ts >
BLAZE_ALWAYS_INLINE constexpr CommonType_<T1,T2,Ts...>
max( const T1& a, const T2& b, const Ts&... args ) noexcept( All<IsNumeric,T1,T2,Ts...>::value )
{
return max( a, max( b, args... ) );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Rounds the given input value.
// \ingroup math
//
// \param a Value to be rounded.
// \return The rounded value.
//
// This function rounds the given input value. In case the first digit after the comma
// is smaller than five the value is rounded down. Otherwise it is rounded up. Note that
// this function only works for integral and floating point types. The attempt to use the
// function for any other type will result in a compile time error.
*/
template< typename T >
BLAZE_ALWAYS_INLINE T round( T a ) noexcept
{
BLAZE_CONSTRAINT_MUST_BE_INTEGRAL_TYPE( T );
return a;
}
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Rounds the given single precision floating point value.
// \ingroup math
//
// \param a Value to be rounded.
// \return The rounded value.
//
// This function rounds the given single precision floating point value. In case the first
// digit after the comma is smaller than five the value is rounded down. Otherwise it is
// rounded up.
*/
BLAZE_ALWAYS_INLINE float round( float a ) noexcept
{
return std::floor( a + 0.5F );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Rounds the given double precision floating point value.
// \ingroup math
//
// \param a Value to be rounded.
// \return The rounded value.
//
// This function rounds the given double precision floating point value. In case the first
// digit after the comma is smaller than five the value is rounded down. Otherwise it is
// rounded up.
*/
BLAZE_ALWAYS_INLINE double round( double a ) noexcept
{
return std::floor( a + 0.5 );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Rounds the given long double precision floating point value.
// \ingroup math
//
// \param a Value to be rounded.
// \return The rounded value.
//
// This function rounds the given long double precision floating point value. In case the
// first digit after the comma is smaller than five the value is rounded down. Otherwise
// it is rounded up.
*/
BLAZE_ALWAYS_INLINE long double round( long double a ) noexcept
{
return std::floor( a + 0.5L );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Rounds up an integral value to the next multiple of a given factor.
// \ingroup math
//
// \param value The integral value to be rounded up \f$[1..\infty)\f$.
// \param factor The factor of the multiple \f$[1..\infty)\f$.
// \return The multiple of the given factor.
//
// This function rounds up the given integral value to the next multiple of the given factor.
// In case the integral value is already a multiple of the given factor, the value itself is
// returned. Note that both \a value and \a factor are expected to be positive integrals. In
// case any of them is negative, the function returns 0. Note that the attempt to use the
// function with non-integral types results in a compilation error!
*/
template< typename T >
BLAZE_ALWAYS_INLINE constexpr T nextMultiple( T value, T factor ) noexcept
{
BLAZE_CONSTRAINT_MUST_BE_INTEGRAL_TYPE( T );
return ( value > T(0) && factor > T(0) )
?( value + ( factor - ( value % factor ) ) % factor )
:( T(0) );
}
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Default less-than comparison for any data type.
// \ingroup math
//
// \param a First value.
// \param b Second value.
// \return \a true if the first value is smaller than the second, \a false if not.
//
// Default implementation of a less-than comparison of two data values.
*/
template< typename T >
BLAZE_ALWAYS_INLINE constexpr bool lessThan_backend( const T& a, const T& b )
noexcept( IsBuiltin<T>::value )
{
return a < b;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Less-than comparison for single precision floating point values.
// \ingroup math
//
// \param a First value.
// \param b Second value.
// \return \a true if the first value is smaller than the second, \a false if not.
//
// Less-than function for the comparison of two single precision floating point numbers. Due
// to the limited machine accuracy, a direct comparison of two floating point numbers should
// be avoided. This functions offers the possibility to compare two floating-point values with
// a certain accuracy margin.
*/
BLAZE_ALWAYS_INLINE constexpr bool lessThan_backend( float a, float b ) noexcept
{
return ( b - a ) > 1E-8F;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Less-than comparison for double precision floating point values.
// \ingroup math
//
// \param a First value.
// \param b Second value.
// \return \a true if the first value is smaller than the second, \a false if not.
//
// Less-than function for the comparison of two double precision floating point numbers. Due
// to the limited machine accuracy, a direct comparison of two floating point numbers should
// be avoided. This functions offers the possibility to compare two floating-point values with
// a certain accuracy margin.
*/
BLAZE_ALWAYS_INLINE constexpr bool lessThan_backend( double a, double b ) noexcept
{
return ( b - a ) > 1E-8;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Less-than comparison for long double precision floating point values.
// \ingroup math
//
// \param a First value.
// \param b Second value.
// \return \a true if the first value is smaller than the second, \a false if not.
//
// Less-than function for the comparison of two long double precision floating point numbers. Due
// to the limited machine accuracy, a direct comparison of two floating point numbers should be
// avoided. This functions offers the possibility to compare two floating-point values with a
// certain accuracy margin.
*/
BLAZE_ALWAYS_INLINE constexpr bool lessThan_backend( long double a, long double b ) noexcept
{
return ( b - a ) > 1E-10;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Generic less-than comparison.
// \ingroup math
//
// \param a First value.
// \param b Second value.
// \return \a true if the first value is smaller than the second, \a false if not.
//
// Generic less-than comparison between to numeric values. Depending on the types of the
// two arguments, a special comparison for floating point values is selected that takes
// the limited machine accuracy into account.
*/
template< typename T1, typename T2 >
BLAZE_ALWAYS_INLINE constexpr bool lessThan( const T1& a, const T2& b )
noexcept( IsBuiltin< CommonType_<T1,T2> >::value )
{
return lessThan_backend< CommonType_<T1,T2> >( a, b );
}
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,77 @@
//=================================================================================================
/*!
// \file blaze/math/Functors.h
// \brief Header file for all functors
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_FUNCTORS_H_
#define _BLAZE_MATH_FUNCTORS_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/functors/Abs.h>
#include <blaze/math/functors/Acos.h>
#include <blaze/math/functors/Acosh.h>
#include <blaze/math/functors/Asin.h>
#include <blaze/math/functors/Asinh.h>
#include <blaze/math/functors/Atan.h>
#include <blaze/math/functors/Atanh.h>
#include <blaze/math/functors/Cbrt.h>
#include <blaze/math/functors/Ceil.h>
#include <blaze/math/functors/Conj.h>
#include <blaze/math/functors/Cos.h>
#include <blaze/math/functors/Cosh.h>
#include <blaze/math/functors/CTrans.h>
#include <blaze/math/functors/Erf.h>
#include <blaze/math/functors/Erfc.h>
#include <blaze/math/functors/Eval.h>
#include <blaze/math/functors/Exp.h>
#include <blaze/math/functors/Floor.h>
#include <blaze/math/functors/Imag.h>
#include <blaze/math/functors/Inv.h>
#include <blaze/math/functors/InvCbrt.h>
#include <blaze/math/functors/InvSqrt.h>
#include <blaze/math/functors/Log.h>
#include <blaze/math/functors/Log10.h>
#include <blaze/math/functors/Pow.h>
#include <blaze/math/functors/Real.h>
#include <blaze/math/functors/Serial.h>
#include <blaze/math/functors/Sin.h>
#include <blaze/math/functors/Sinh.h>
#include <blaze/math/functors/Sqrt.h>
#include <blaze/math/functors/Tan.h>
#include <blaze/math/functors/Tanh.h>
#include <blaze/math/functors/Trans.h>
#endif

View File

@ -0,0 +1,687 @@
//=================================================================================================
/*!
// \file blaze/math/HermitianMatrix.h
// \brief Header file for the complete HermitianMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_HERMITIANMATRIX_H_
#define _BLAZE_MATH_HERMITIANMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <stdexcept>
#include <blaze/math/Aliases.h>
#include <blaze/math/adaptors/HermitianMatrix.h>
#include <blaze/math/constraints/DenseMatrix.h>
#include <blaze/math/constraints/Resizable.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/shims/Real.h>
#include <blaze/math/SparseMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/math/typetraits/UnderlyingBuiltin.h>
#include <blaze/util/Assert.h>
#include <blaze/util/FalseType.h>
#include <blaze/util/Random.h>
#include <blaze/util/TrueType.h>
#include <blaze/util/Types.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for HermitianMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of HermitianMatrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
class Rand< HermitianMatrix<MT,SO,DF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const HermitianMatrix<MT,SO,DF> generate() const;
inline const HermitianMatrix<MT,SO,DF> generate( size_t n ) const;
inline const HermitianMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros ) const;
template< typename Arg >
inline const HermitianMatrix<MT,SO,DF> generate( const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const HermitianMatrix<MT,SO,DF> generate( size_t n, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const HermitianMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( HermitianMatrix<MT,SO,DF>& matrix ) const;
inline void randomize( HermitianMatrix<MT,SO,DF>& matrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( HermitianMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( HermitianMatrix<MT,SO,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
private:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( HermitianMatrix<MT,SO,DF>& matrix, TrueType ) const;
inline void randomize( HermitianMatrix<MT,SO,DF>& matrix, FalseType ) const;
template< typename Arg >
inline void randomize( HermitianMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, TrueType ) const;
template< typename Arg >
inline void randomize( HermitianMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, FalseType ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random HermitianMatrix.
//
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline const HermitianMatrix<MT,SO,DF> Rand< HermitianMatrix<MT,SO,DF> >::generate() const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
HermitianMatrix<MT,SO,DF> matrix;
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random HermitianMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline const HermitianMatrix<MT,SO,DF>
Rand< HermitianMatrix<MT,SO,DF> >::generate( size_t n ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
HermitianMatrix<MT,SO,DF> matrix( n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random HermitianMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline const HermitianMatrix<MT,SO,DF>
Rand< HermitianMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > n*n )
throw std::invalid_argument( "Invalid number of non-zero elements" );
HermitianMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random HermitianMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
template< typename Arg > // Min/max argument type
inline const HermitianMatrix<MT,SO,DF>
Rand< HermitianMatrix<MT,SO,DF> >::generate( const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
HermitianMatrix<MT,SO,DF> matrix;
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random HermitianMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
template< typename Arg > // Min/max argument type
inline const HermitianMatrix<MT,SO,DF>
Rand< HermitianMatrix<MT,SO,DF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
HermitianMatrix<MT,SO,DF> matrix( n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random HermitianMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
template< typename Arg > // Min/max argument type
inline const HermitianMatrix<MT,SO,DF>
Rand< HermitianMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > n*n )
throw std::invalid_argument( "Invalid number of non-zero elements" );
HermitianMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline void Rand< HermitianMatrix<MT,SO,DF> >::randomize( HermitianMatrix<MT,SO,DF>& matrix ) const
{
randomize( matrix, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline void Rand< HermitianMatrix<MT,SO,DF> >::randomize( HermitianMatrix<MT,SO,DF>& matrix, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
typedef UnderlyingBuiltin_<ET> BT;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
matrix(i,j) = rand<ET>();
}
matrix(i,i) = rand<BT>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline void Rand< HermitianMatrix<MT,SO,DF> >::randomize( HermitianMatrix<MT,SO,DF>& matrix, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*n*n ) ) );
randomize( matrix, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
inline void Rand< HermitianMatrix<MT,SO,DF> >::randomize( HermitianMatrix<MT,SO,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
typedef UnderlyingBuiltin_<ET> BT;
const size_t n( matrix.rows() );
if( nonzeros > n*n )
throw std::invalid_argument( "Invalid number of non-zero elements" );
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
while( matrix.nonZeros() < nonzeros )
{
const size_t row ( rand<size_t>( 0UL, n-1UL ) );
const size_t column( rand<size_t>( 0UL, n-1UL ) );
if( row == column )
matrix(row,column) = rand<BT>();
else
matrix(row,column) = rand<ET>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
template< typename Arg > // Min/max argument type
inline void Rand< HermitianMatrix<MT,SO,DF> >::randomize( HermitianMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max ) const
{
randomize( matrix, min, max, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
template< typename Arg > // Min/max argument type
inline void Rand< HermitianMatrix<MT,SO,DF> >::randomize( HermitianMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
typedef UnderlyingBuiltin_<ET> BT;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
matrix(i,j) = rand<ET>( min, max );
}
matrix(i,i) = rand<BT>( real( min ), real( max ) );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
template< typename Arg > // Min/max argument type
inline void Rand< HermitianMatrix<MT,SO,DF> >::randomize( HermitianMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*n*n ) ) );
randomize( matrix, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
template< typename Arg > // Min/max argument type
inline void Rand< HermitianMatrix<MT,SO,DF> >::randomize( HermitianMatrix<MT,SO,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
typedef UnderlyingBuiltin_<ET> BT;
const size_t n( matrix.rows() );
if( nonzeros > n*n )
throw std::invalid_argument( "Invalid number of non-zero elements" );
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
while( matrix.nonZeros() < nonzeros )
{
const size_t row ( rand<size_t>( 0UL, n-1UL ) );
const size_t column( rand<size_t>( 0UL, n-1UL ) );
if( row == column )
matrix(row,column) = rand<BT>( real( min ), real( max ) );
else
matrix(row,column) = rand<ET>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeSymmetric( HermitianMatrix<MT,SO,DF>& matrix )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<=i; ++j ) {
matrix(i,j) = rand<BT>();
}
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeSymmetric( HermitianMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<=i; ++j ) {
matrix(i,j) = rand<BT>( real( min ), real( max ) );
}
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeHermitian( HermitianMatrix<MT,SO,DF>& matrix )
{
using blaze::randomize;
randomize( matrix );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeHermitian( HermitianMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
using blaze::randomize;
randomize( matrix, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite HermitianMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makePositiveDefinite( HermitianMatrix<MT,SO,DF>& matrix )
{
using blaze::randomize;
typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
const size_t n( matrix.rows() );
randomize( matrix );
matrix *= matrix;
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) += BT(n);
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,412 @@
//=================================================================================================
/*!
// \file blaze/math/HybridMatrix.h
// \brief Header file for the complete HybridMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_HYBRIDMATRIX_H_
#define _BLAZE_MATH_HYBRIDMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/HybridMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/Exception.h>
#include <blaze/math/HybridVector.h>
#include <blaze/math/shims/Conjugate.h>
#include <blaze/math/shims/Real.h>
#include <blaze/math/StaticMatrix.h>
#include <blaze/math/typetraits/UnderlyingBuiltin.h>
#include <blaze/system/Precision.h>
#include <blaze/util/Assert.h>
#include <blaze/util/constraints/Numeric.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for HybridMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of HybridMatrix.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
class Rand< HybridMatrix<Type,M,N,SO> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const HybridMatrix<Type,M,N,SO> generate( size_t m, size_t n ) const;
template< typename Arg >
inline const HybridMatrix<Type,M,N,SO> generate( size_t m, size_t n, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( HybridMatrix<Type,M,N,SO>& matrix ) const;
template< typename Arg >
inline void randomize( HybridMatrix<Type,M,N,SO>& matrix, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random HybridMatrix.
//
// \return The generated random matrix.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
inline const HybridMatrix<Type,M,N,SO>
Rand< HybridMatrix<Type,M,N,SO> >::generate( size_t m, size_t n ) const
{
HybridMatrix<Type,M,N,SO> matrix( m, n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random HybridMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline const HybridMatrix<Type,M,N,SO>
Rand< HybridMatrix<Type,M,N,SO> >::generate( size_t m, size_t n, const Arg& min, const Arg& max ) const
{
HybridMatrix<Type,M,N,SO> matrix( m, n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a HybridMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
inline void Rand< HybridMatrix<Type,M,N,SO> >::randomize( HybridMatrix<Type,M,N,SO>& matrix ) const
{
using blaze::randomize;
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
for( size_t i=0UL; i<m; ++i ) {
for( size_t j=0UL; j<n; ++j ) {
randomize( matrix(i,j) );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a HybridMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline void Rand< HybridMatrix<Type,M,N,SO> >::randomize( HybridMatrix<Type,M,N,SO>& matrix,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
const size_t m( matrix.rows() );
const size_t n( matrix.columns() );
for( size_t i=0UL; i<m; ++i ) {
for( size_t j=0UL; j<n; ++j ) {
randomize( matrix(i,j), min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric HybridMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
void makeSymmetric( HybridMatrix<Type,M,N,SO>& matrix )
{
using blaze::randomize;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j) );
matrix(j,i) = matrix(i,j);
}
randomize( matrix(i,i) );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric HybridMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO // Storage order
, typename Arg > // Min/max argument type
void makeSymmetric( HybridMatrix<Type,M,N,SO>& matrix, const Arg& min, const Arg& max )
{
using blaze::randomize;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j), min, max );
matrix(j,i) = matrix(i,j);
}
randomize( matrix(i,i), min, max );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian HybridMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
void makeHermitian( HybridMatrix<Type,M,N,SO>& matrix )
{
using blaze::randomize;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
typedef UnderlyingBuiltin_<Type> BT;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j) );
matrix(j,i) = conj( matrix(i,j) );
}
matrix(i,i) = rand<BT>();
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian HybridMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO // Storage order
, typename Arg > // Min/max argument type
void makeHermitian( HybridMatrix<Type,M,N,SO>& matrix, const Arg& min, const Arg& max )
{
using blaze::randomize;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
typedef UnderlyingBuiltin_<Type> BT;
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j), min, max );
matrix(j,i) = conj( matrix(i,j) );
}
matrix(i,i) = rand<BT>( real( min ), real( max ) );
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite HybridMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
void makePositiveDefinite( HybridMatrix<Type,M,N,SO>& matrix )
{
using blaze::randomize;
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
if( !isSquare( ~matrix ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid non-square matrix provided" );
}
const size_t n( matrix.rows() );
randomize( matrix );
matrix *= ctrans( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) += Type(n);
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,188 @@
//=================================================================================================
/*!
// \file blaze/math/HybridVector.h
// \brief Header file for the complete HybridVector implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_HYBRIDVECTOR_H_
#define _BLAZE_MATH_HYBRIDVECTOR_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/HybridVector.h>
#include <blaze/math/dense/StaticVector.h>
#include <blaze/math/DenseVector.h>
#include <blaze/math/DynamicMatrix.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for HybridVector.
// \ingroup random
//
// This specialization of the Rand class creates random instances of HybridVector.
*/
template< typename Type // Data type of the vector
, size_t N // Number of elements
, bool TF > // Transpose flag
class Rand< HybridVector<Type,N,TF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const HybridVector<Type,N,TF> generate( size_t n ) const;
template< typename Arg >
inline const HybridVector<Type,N,TF> generate( size_t n, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( HybridVector<Type,N,TF>& vector ) const;
template< typename Arg >
inline void randomize( HybridVector<Type,N,TF>& vector, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random HybridVector.
//
// \param n The size of the random vector.
// \return The generated random vector.
*/
template< typename Type // Data type of the vector
, size_t N // Number of elements
, bool TF > // Transpose flag
inline const HybridVector<Type,N,TF> Rand< HybridVector<Type,N,TF> >::generate( size_t n ) const
{
HybridVector<Type,N,TF> vector( n );
randomize( vector );
return vector;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random HybridVector.
//
// \param n The size of the random vector.
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return The generated random vector.
*/
template< typename Type // Data type of the vector
, size_t N // Number of elements
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline const HybridVector<Type,N,TF>
Rand< HybridVector<Type,N,TF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
HybridVector<Type,N,TF> vector( n );
randomize( vector, min, max );
return vector;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a HybridVector.
//
// \param vector The vector to be randomized.
// \return void
*/
template< typename Type // Data type of the vector
, size_t N // Number of elements
, bool TF > // Transpose flag
inline void Rand< HybridVector<Type,N,TF> >::randomize( HybridVector<Type,N,TF>& vector ) const
{
using blaze::randomize;
for( size_t i=0UL; i<vector.size(); ++i ) {
randomize( vector[i] );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a HybridVector.
//
// \param vector The vector to be randomized.
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return void
*/
template< typename Type // Data type of the vector
, size_t N // Number of elements
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline void Rand< HybridVector<Type,N,TF> >::randomize( HybridVector<Type,N,TF>& vector,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
for( size_t i=0UL; i<vector.size(); ++i ) {
randomize( vector[i], min, max );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
//=================================================================================================
/*!
// \file blaze/math/InitializerList.h
// \brief Header file for the std::initializer_list aliases
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_INITIALIZERLIST_H_
#define _BLAZE_MATH_INITIALIZERLIST_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <initializer_list>
#include <blaze/math/Functions.h>
namespace blaze {
//=================================================================================================
//
// TYPE DEFINITIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\class blaze::initializer_list
// \brief Initializer list type of the Blaze library.
// \ingroup math
*/
using std::initializer_list;
//*************************************************************************************************
//=================================================================================================
//
// UTILITY FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Determine the maximum number of columns specified by the given initializer list.
// \ingroup math
//
// \param list The given initializer list
// \return The maximum number of columns.
*/
template< typename Type >
inline size_t determineColumns( initializer_list< initializer_list<Type> > list ) noexcept
{
size_t cols( 0UL );
for( const auto& rowList : list )
cols = max( cols, rowList.size() );
return cols;
}
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,88 @@
//=================================================================================================
/*!
// \file blaze/math/InversionFlag.h
// \brief Header file for the dense matrix inversion flags
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_INVERSIONFLAG_H_
#define _BLAZE_MATH_INVERSIONFLAG_H_
namespace blaze {
//=================================================================================================
//
// DECOMPOSITION FLAG VALUES
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Inversion flag.
// \ingroup dense_matrix
//
// The InversionFlag type enumeration represents the different types of matrix inversion algorithms
// that are available within the Blaze library. The following flags are available:
//
// - \a byDefault: The default algorithm for each type of matrix. In case of general square
// matrices an LU decomposition is used, in case of symmetric and Hermitian matrices
// the Bunch-Kaufman diagonal pivoting method is applied, and in case of triangular
// matrices a direct inversion via backward substitution is performed.
// - \a byLU: The default inversion algorithm for general square matrices. It uses the LU
// algorithm to decompose a matrix into a lower unitriangular matrix \c L, an upper
// triangular matrix \c U, and a permutation matrix \c P (\f$ A = P L U \f$). If no
// permutations are required, \c P is the identity matrix.
// - \a byLDLT: The Bunch-Kaufman inversion algorithm for symmetric indefinite matrices. It
// decomposes the given matrix into either \f$ A = U D U^{T} \f$ or \f$ A = L D L^{T} \f$,
// where \c U (or \c L) is a product of permutation and unit upper (lower) triangular
// matrices, and \c D is symmetric and block diagonal with 1-by-1 and 2-by-2 diagonal
// blocks.
// - \a byLDLH: The Bunch-Kaufman inversion algorithm for Hermitian indefinite matrices. It
// decomposes the given matrix into either \f$ A = U D U^{H} \f$ or \f$ A = L D L^{H} \f$,
// where \c U (or \c L) is a product of permutation and unit upper (lower) triangular
// matrices, and \c D is Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal
// blocks.
// - \a byLLH: The Cholesky inversion algorithm for Hermitian positive definite matrices. It
// decomposes a given matrix into either \f$ A = L L^H \f$, where \c L is a lower
// triangular matrix, or \f$ A = U^H U \f$, where \c U is an upper triangular matrix.
*/
enum InversionFlag
{
byDefault = 0, //!< Flag for the default, optimal inversion algorithm.
byLU = 1, //!< Flag for the LU-based matrix inversion.
byLDLT = 2, //!< Flag for the Bunch-Kaufman-based inversion for symmetric matrices.
byLDLH = 3, //!< Flag for the Bunch-Kaufman-based inversion for Hermitian matrices.
byLLH = 4 //!< Flag for the Cholesky-based inversion for positive-definite matrices.
};
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,84 @@
//=================================================================================================
/*!
// \file blaze/math/LAPACK.h
// \brief Header file for the LAPACK functionality
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_LAPACK_H_
#define _BLAZE_MATH_LAPACK_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/lapack/gelqf.h>
#include <blaze/math/lapack/geqlf.h>
#include <blaze/math/lapack/geqp3.h>
#include <blaze/math/lapack/geqrf.h>
#include <blaze/math/lapack/gerqf.h>
#include <blaze/math/lapack/gesv.h>
#include <blaze/math/lapack/getrf.h>
#include <blaze/math/lapack/getri.h>
#include <blaze/math/lapack/getrs.h>
#include <blaze/math/lapack/hesv.h>
#include <blaze/math/lapack/hetrf.h>
#include <blaze/math/lapack/hetri.h>
#include <blaze/math/lapack/hetrs.h>
#include <blaze/math/lapack/orglq.h>
#include <blaze/math/lapack/orgql.h>
#include <blaze/math/lapack/orgqr.h>
#include <blaze/math/lapack/orgrq.h>
#include <blaze/math/lapack/ormlq.h>
#include <blaze/math/lapack/ormql.h>
#include <blaze/math/lapack/ormqr.h>
#include <blaze/math/lapack/ormrq.h>
#include <blaze/math/lapack/posv.h>
#include <blaze/math/lapack/potrf.h>
#include <blaze/math/lapack/potri.h>
#include <blaze/math/lapack/potrs.h>
#include <blaze/math/lapack/sysv.h>
#include <blaze/math/lapack/sytrf.h>
#include <blaze/math/lapack/sytri.h>
#include <blaze/math/lapack/sytrs.h>
#include <blaze/math/lapack/trsv.h>
#include <blaze/math/lapack/trtri.h>
#include <blaze/math/lapack/trtrs.h>
#include <blaze/math/lapack/unglq.h>
#include <blaze/math/lapack/ungql.h>
#include <blaze/math/lapack/ungqr.h>
#include <blaze/math/lapack/ungrq.h>
#include <blaze/math/lapack/unmlq.h>
#include <blaze/math/lapack/unmql.h>
#include <blaze/math/lapack/unmqr.h>
#include <blaze/math/lapack/unmrq.h>
#endif

View File

@ -0,0 +1,810 @@
//=================================================================================================
/*!
// \file blaze/math/LowerMatrix.h
// \brief Header file for the complete LowerMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_LOWERMATRIX_H_
#define _BLAZE_MATH_LOWERMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <vector>
#include <blaze/math/Aliases.h>
#include <blaze/math/adaptors/LowerMatrix.h>
#include <blaze/math/constraints/DenseMatrix.h>
#include <blaze/math/constraints/Resizable.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/Exception.h>
#include <blaze/math/SparseMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/math/typetraits/UnderlyingBuiltin.h>
#include <blaze/math/UpperMatrix.h>
#include <blaze/util/FalseType.h>
#include <blaze/util/Indices.h>
#include <blaze/util/Random.h>
#include <blaze/util/TrueType.h>
#include <blaze/util/Types.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for LowerMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of LowerMatrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
class Rand< LowerMatrix<MT,SO,DF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const LowerMatrix<MT,SO,DF> generate() const;
inline const LowerMatrix<MT,SO,DF> generate( size_t n ) const;
inline const LowerMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros ) const;
template< typename Arg >
inline const LowerMatrix<MT,SO,DF> generate( const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const LowerMatrix<MT,SO,DF> generate( size_t n, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const LowerMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( LowerMatrix<MT,SO,DF>& matrix ) const;
inline void randomize( LowerMatrix<MT,false,DF>& matrix, size_t nonzeros ) const;
inline void randomize( LowerMatrix<MT,true,DF>& matrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( LowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( LowerMatrix<MT,false,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( LowerMatrix<MT,true,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
private:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( LowerMatrix<MT,SO,DF>& matrix, TrueType ) const;
inline void randomize( LowerMatrix<MT,SO,DF>& matrix, FalseType ) const;
template< typename Arg >
inline void randomize( LowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, TrueType ) const;
template< typename Arg >
inline void randomize( LowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, FalseType ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random LowerMatrix.
//
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const LowerMatrix<MT,SO,DF> Rand< LowerMatrix<MT,SO,DF> >::generate() const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
LowerMatrix<MT,SO,DF> matrix;
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random LowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const LowerMatrix<MT,SO,DF>
Rand< LowerMatrix<MT,SO,DF> >::generate( size_t n ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
LowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random LowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const LowerMatrix<MT,SO,DF>
Rand< LowerMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > LowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
LowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random LowerMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const LowerMatrix<MT,SO,DF>
Rand< LowerMatrix<MT,SO,DF> >::generate( const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
LowerMatrix<MT,SO,DF> matrix;
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random LowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const LowerMatrix<MT,SO,DF>
Rand< LowerMatrix<MT,SO,DF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
LowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random LowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const LowerMatrix<MT,SO,DF>
Rand< LowerMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > LowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
LowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< LowerMatrix<MT,SO,DF> >::randomize( LowerMatrix<MT,SO,DF>& matrix ) const
{
randomize( matrix, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< LowerMatrix<MT,SO,DF> >::randomize( LowerMatrix<MT,SO,DF>& matrix, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<=i; ++j ) {
matrix(i,j) = rand<ET>();
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< LowerMatrix<MT,SO,DF> >::randomize( LowerMatrix<MT,SO,DF>& matrix, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.3*n*n ) ) );
randomize( matrix, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< LowerMatrix<MT,SO,DF> >::randomize( LowerMatrix<MT,false,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > LowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-1UL );
if( dist[index] == index+1UL ) continue;
++dist[index];
++nz;
}
for( size_t i=0UL; i<n; ++i ) {
const Indices indices( 0UL, i, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< LowerMatrix<MT,SO,DF> >::randomize( LowerMatrix<MT,true,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > LowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-1UL );
if( dist[index] == n - index ) continue;
++dist[index];
++nz;
}
for( size_t j=0UL; j<n; ++j ) {
const Indices indices( j, n-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( j );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< LowerMatrix<MT,SO,DF> >::randomize( LowerMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max ) const
{
randomize( matrix, min, max, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< LowerMatrix<MT,SO,DF> >::randomize( LowerMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<=i; ++j ) {
matrix(i,j) = rand<ET>( min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< LowerMatrix<MT,SO,DF> >::randomize( LowerMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.3*n*n ) ) );
randomize( matrix, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< LowerMatrix<MT,SO,DF> >::randomize( LowerMatrix<MT,false,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > LowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-1UL );
if( dist[index] == index+1UL ) continue;
++dist[index];
++nz;
}
for( size_t i=0UL; i<n; ++i ) {
const Indices indices( 0UL, i, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< LowerMatrix<MT,SO,DF> >::randomize( LowerMatrix<MT,true,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > LowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-1UL );
if( dist[index] == n - index ) continue;
++dist[index];
++nz;
}
for( size_t j=0UL; j<n; ++j ) {
const Indices indices( j, n-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( j );
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeSymmetric( LowerMatrix<MT,SO,DF>& matrix )
{
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand< ElementType_<MT> >();
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeSymmetric( LowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
typedef ElementType_<MT> Type;
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<Type>( min, max );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeHermitian( LowerMatrix<MT,SO,DF>& matrix )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > Type;
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<Type>();
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeHermitian( LowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > Type;
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<Type>( min, max );
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite LowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makePositiveDefinite( LowerMatrix<MT,SO,DF>& matrix )
{
makeHermitian( matrix );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

49
src/cpu/blaze/math/Math.h Normal file
View File

@ -0,0 +1,49 @@
//=================================================================================================
/*!
// \file blaze/math/Math.h
// \brief Math module documentation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_MATH_H_
#define _BLAZE_MATH_MATH_H_
//=================================================================================================
//
// DOXYGEN DOCUMENTATION
//
//=================================================================================================
//*************************************************************************************************
/*!\defgroup math Math module */
//*************************************************************************************************
#endif

View File

@ -0,0 +1,94 @@
//=================================================================================================
/*!
// \file blaze/math/Matrix.h
// \brief Header file for all basic Matrix functionality
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_MATRIX_H_
#define _BLAZE_MATH_MATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <iomanip>
#include <ostream>
#include <blaze/math/Aliases.h>
#include <blaze/math/expressions/Matrix.h>
namespace blaze {
//=================================================================================================
//
// GLOBAL OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\name Matrix operators */
//@{
template< typename MT, bool SO >
inline std::ostream& operator<<( std::ostream& os, const Matrix<MT,SO>& m );
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Global output operator for dense and sparse matrices.
// \ingroup matrix
//
// \param os Reference to the output stream.
// \param m Reference to a constant matrix object.
// \return Reference to the output stream.
*/
template< typename MT // Type of the matrix
, bool SO > // Storage order
inline std::ostream& operator<<( std::ostream& os, const Matrix<MT,SO>& m )
{
CompositeType_<MT> tmp( ~m );
for( size_t i=0UL; i<tmp.rows(); ++i ) {
os << "( ";
for( size_t j=0UL; j<tmp.columns(); ++j ) {
os << std::setw(12) << tmp(i,j) << " ";
}
os << ")\n";
}
return os;
}
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,91 @@
//=================================================================================================
/*!
// \file blaze/math/PaddingFlag.h
// \brief Header file for the padding flag values
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_PADDINGFLAG_H_
#define _BLAZE_MATH_PADDINGFLAG_H_
namespace blaze {
//=================================================================================================
//
// PADDING FLAG VALUES
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Padding flag for unpadded vectors and matrices.
// \ingroup math
//
// Via this flag it is possible to specify custom vectors and matrices as unpadded. The following
// example demonstrates the setup of an unaligned, unpadded custom row vector of size 7:
\code
using blaze::CustomVector;
using blaze::unaligned;
using blaze::unpadded;
using blaze::columnVector;
std::vector<int> vec( 7UL );
CustomVector<int,unaligned,unpadded,columnVector> a( &vec[0], 7UL );
\endcode
*/
const bool unpadded = false;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Padding flag for padded vectors and matrices.
// \ingroup math
//
// Via this flag it is possible to specify custom vectors and matrices as aligned. The following
// example demonstrates the setup of an aligned, padded custom row vector of size 7:
\code
using blaze::CustomVector;
using blaze::ArrayDelete;
using blaze::aligned;
using blaze::padded;
using blaze::columnVector;
std::vector<int> vec( 16UL );
CustomVector<int,unaligned,padded,columnVector> a( &vec[0], 7UL, 16UL );
\endcode
*/
const bool padded = true;
//*************************************************************************************************
} // namespace blaze
#endif

315
src/cpu/blaze/math/Row.h Normal file
View File

@ -0,0 +1,315 @@
//=================================================================================================
/*!
// \file blaze/math/Row.h
// \brief Header file for the complete Row implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ROW_H_
#define _BLAZE_MATH_ROW_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/Aliases.h>
#include <blaze/math/Exception.h>
#include <blaze/math/smp/DenseVector.h>
#include <blaze/math/smp/SparseVector.h>
#include <blaze/math/views/Column.h>
#include <blaze/math/views/Row.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION FOR DENSE ROWS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for dense rows.
// \ingroup random
//
// This specialization of the Rand class randomizes dense rows.
*/
template< typename MT // Type of the dense matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
class Rand< Row<MT,SO,true,SF> >
{
public:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( Row<MT,SO,true,SF>& row ) const;
template< typename Arg >
inline void randomize( Row<MT,SO,true,SF>& row, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense row.
//
// \param row The row to be randomized.
// \return void
*/
template< typename MT // Type of the dense matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
inline void Rand< Row<MT,SO,true,SF> >::randomize( Row<MT,SO,true,SF>& row ) const
{
using blaze::randomize;
for( size_t i=0UL; i<row.size(); ++i ) {
randomize( row[i] );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense row.
//
// \param row The row to be randomized.
// \param min The smallest possible value for a row element.
// \param max The largest possible value for a row element.
// \return void
*/
template< typename MT // Type of the dense matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
template< typename Arg > // Min/max argument type
inline void Rand< Row<MT,SO,true,SF> >::randomize( Row<MT,SO,true,SF>& row,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
for( size_t i=0UL; i<row.size(); ++i ) {
randomize( row[i], min, max );
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for sparse rows.
// \ingroup random
//
// This specialization of the Rand class randomizes sparse rows.
*/
template< typename MT // Type of the sparse matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
class Rand< Row<MT,SO,false,SF> >
{
public:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( Row<MT,SO,false,SF>& row ) const;
inline void randomize( Row<MT,SO,false,SF>& row, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( Row<MT,SO,false,SF>& row, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( Row<MT,SO,false,SF>& row, size_t nonzeros, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse row.
//
// \param row The row to be randomized.
// \return void
*/
template< typename MT // Type of the sparse matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
inline void Rand< Row<MT,SO,false,SF> >::randomize( Row<MT,SO,false,SF>& row ) const
{
typedef ElementType_< Row<MT,SO,false,SF> > ElementType;
const size_t size( row.size() );
if( size == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*size ) ) );
row.reset();
row.reserve( nonzeros );
while( row.nonZeros() < nonzeros ) {
row[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse row.
//
// \param row The row to be randomized.
// \param nonzeros The number of non-zero elements of the random row.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the sparse matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
inline void Rand< Row<MT,SO,false,SF> >::randomize( Row<MT,SO,false,SF>& row, size_t nonzeros ) const
{
typedef ElementType_< Row<MT,SO,false,SF> > ElementType;
const size_t size( row.size() );
if( nonzeros > size ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( size == 0UL ) return;
row.reset();
row.reserve( nonzeros );
while( row.nonZeros() < nonzeros ) {
row[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse row.
//
// \param row The row to be randomized.
// \param min The smallest possible value for a row element.
// \param max The largest possible value for a row element.
// \return void
*/
template< typename MT // Type of the sparse matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
template< typename Arg > // Min/max argument type
inline void Rand< Row<MT,SO,false,SF> >::randomize( Row<MT,SO,false,SF>& row,
const Arg& min, const Arg& max ) const
{
typedef ElementType_< Row<MT,SO,false,SF> > ElementType;
const size_t size( row.size() );
if( size == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*size ) ) );
row.reset();
row.reserve( nonzeros );
while( row.nonZeros() < nonzeros ) {
row[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse row.
//
// \param row The row to be randomized.
// \param nonzeros The number of non-zero elements of the random row.
// \param min The smallest possible value for a row element.
// \param max The largest possible value for a row element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the sparse matrix
, bool SO // Storage order
, bool SF > // Symmetry flag
template< typename Arg > // Min/max argument type
inline void Rand< Row<MT,SO,false,SF> >::randomize( Row<MT,SO,false,SF>& row, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
typedef ElementType_< Row<MT,SO,false,SF> > ElementType;
const size_t size( row.size() );
if( nonzeros > size ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( size == 0UL ) return;
row.reset();
row.reserve( nonzeros );
while( row.nonZeros() < nonzeros ) {
row[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

48
src/cpu/blaze/math/SIMD.h Normal file
View File

@ -0,0 +1,48 @@
//=================================================================================================
/*!
// \file blaze/math/SIMD.h
// \brief Header file for all SIMD functionality
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_SIMD_H_
#define _BLAZE_MATH_SIMD_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/simd/BasicTypes.h>
#include <blaze/math/simd/DerivedTypes.h>
#include <blaze/math/simd/Functions.h>
#include <blaze/math/simd/SIMDTrait.h>
#endif

50
src/cpu/blaze/math/SMP.h Normal file
View File

@ -0,0 +1,50 @@
//=================================================================================================
/*!
// \file blaze/math/SMP.h
// \brief Header file for the shared memory parallelization
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_SMP_H_
#define _BLAZE_MATH_SMP_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/smp/DenseMatrix.h>
#include <blaze/math/smp/DenseVector.h>
#include <blaze/math/smp/Functions.h>
#include <blaze/math/smp/SerialSection.h>
#include <blaze/math/smp/SparseMatrix.h>
#include <blaze/math/smp/SparseVector.h>
#endif

View File

@ -0,0 +1,47 @@
//=================================================================================================
/*!
// \file blaze/math/Serialization.h
// \brief Header file for the serialization functionality for vectors and matrices
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_SERIALIZATION_H_
#define _BLAZE_MATH_SERIALIZATION_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/serialization/MatrixSerializer.h>
#include <blaze/math/serialization/TypeValueMapping.h>
#include <blaze/math/serialization/VectorSerializer.h>
#endif

View File

@ -0,0 +1,84 @@
//=================================================================================================
/*!
// \file blaze/math/Shims.h
// \brief Header file for the mathematical shims
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_SHIMS_H_
#define _BLAZE_MATH_SHIMS_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/shims/Abs.h>
#include <blaze/math/shims/Acos.h>
#include <blaze/math/shims/Acosh.h>
#include <blaze/math/shims/Asin.h>
#include <blaze/math/shims/Asinh.h>
#include <blaze/math/shims/Atan.h>
#include <blaze/math/shims/Atanh.h>
#include <blaze/math/shims/Cbrt.h>
#include <blaze/math/shims/Ceil.h>
#include <blaze/math/shims/Clear.h>
#include <blaze/math/shims/Conjugate.h>
#include <blaze/math/shims/Cos.h>
#include <blaze/math/shims/Cosh.h>
#include <blaze/math/shims/Equal.h>
#include <blaze/math/shims/Erf.h>
#include <blaze/math/shims/Erfc.h>
#include <blaze/math/shims/Exp.h>
#include <blaze/math/shims/Floor.h>
#include <blaze/math/shims/Imaginary.h>
#include <blaze/math/shims/InvCbrt.h>
#include <blaze/math/shims/Invert.h>
#include <blaze/math/shims/InvSqrt.h>
#include <blaze/math/shims/IsDefault.h>
#include <blaze/math/shims/IsDivisor.h>
#include <blaze/math/shims/IsNaN.h>
#include <blaze/math/shims/IsOne.h>
#include <blaze/math/shims/IsReal.h>
#include <blaze/math/shims/IsZero.h>
#include <blaze/math/shims/Log.h>
#include <blaze/math/shims/Log10.h>
#include <blaze/math/shims/Pow.h>
#include <blaze/math/shims/Real.h>
#include <blaze/math/shims/Reset.h>
#include <blaze/math/shims/Serial.h>
#include <blaze/math/shims/Sin.h>
#include <blaze/math/shims/Sinh.h>
#include <blaze/math/shims/Sqrt.h>
#include <blaze/math/shims/Square.h>
#include <blaze/math/shims/Tan.h>
#include <blaze/math/shims/Tanh.h>
#endif

View File

@ -0,0 +1,81 @@
//=================================================================================================
/*!
// \file blaze/math/SparseMatrix.h
// \brief Header file for all basic SparseMatrix functionality
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_SPARSEMATRIX_H_
#define _BLAZE_MATH_SPARSEMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/expressions/DenseMatrix.h>
#include <blaze/math/expressions/DVecTSVecMultExpr.h>
#include <blaze/math/expressions/SMatDVecMultExpr.h>
#include <blaze/math/expressions/SMatEvalExpr.h>
#include <blaze/math/expressions/SMatForEachExpr.h>
#include <blaze/math/expressions/SMatScalarDivExpr.h>
#include <blaze/math/expressions/SMatScalarMultExpr.h>
#include <blaze/math/expressions/SMatSerialExpr.h>
#include <blaze/math/expressions/SMatSMatAddExpr.h>
#include <blaze/math/expressions/SMatSMatMultExpr.h>
#include <blaze/math/expressions/SMatSMatSubExpr.h>
#include <blaze/math/expressions/SMatSVecMultExpr.h>
#include <blaze/math/expressions/SMatTransExpr.h>
#include <blaze/math/expressions/SMatTSMatAddExpr.h>
#include <blaze/math/expressions/SMatTSMatMultExpr.h>
#include <blaze/math/expressions/SMatTSMatSubExpr.h>
#include <blaze/math/expressions/SparseMatrix.h>
#include <blaze/math/expressions/SVecTDVecMultExpr.h>
#include <blaze/math/expressions/SVecTSVecMultExpr.h>
#include <blaze/math/expressions/TDVecSMatMultExpr.h>
#include <blaze/math/expressions/TDVecTSMatMultExpr.h>
#include <blaze/math/expressions/TSMatDVecMultExpr.h>
#include <blaze/math/expressions/TSMatSMatMultExpr.h>
#include <blaze/math/expressions/TSMatSMatSubExpr.h>
#include <blaze/math/expressions/TSMatSVecMultExpr.h>
#include <blaze/math/expressions/TSMatTSMatAddExpr.h>
#include <blaze/math/expressions/TSMatTSMatMultExpr.h>
#include <blaze/math/expressions/TSMatTSMatSubExpr.h>
#include <blaze/math/expressions/TSVecSMatMultExpr.h>
#include <blaze/math/expressions/TSVecTSMatMultExpr.h>
#include <blaze/math/Matrix.h>
#include <blaze/math/smp/DenseMatrix.h>
#include <blaze/math/smp/SparseMatrix.h>
#include <blaze/math/sparse/SparseMatrix.h>
#include <blaze/math/views/Column.h>
#include <blaze/math/views/Row.h>
#include <blaze/math/views/Submatrix.h>
#endif

View File

@ -0,0 +1,66 @@
//=================================================================================================
/*!
// \file blaze/math/SparseVector.h
// \brief Header file for all basic SparseVector functionality
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_SPARSEVECTOR_H_
#define _BLAZE_MATH_SPARSEVECTOR_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/expressions/DenseVector.h>
#include <blaze/math/expressions/DVecSVecMultExpr.h>
#include <blaze/math/expressions/SparseVector.h>
#include <blaze/math/expressions/SVecDVecDivExpr.h>
#include <blaze/math/expressions/SVecDVecMultExpr.h>
#include <blaze/math/expressions/SVecEvalExpr.h>
#include <blaze/math/expressions/SVecForEachExpr.h>
#include <blaze/math/expressions/SVecScalarDivExpr.h>
#include <blaze/math/expressions/SVecScalarMultExpr.h>
#include <blaze/math/expressions/SVecSerialExpr.h>
#include <blaze/math/expressions/SVecSVecAddExpr.h>
#include <blaze/math/expressions/SVecSVecMultExpr.h>
#include <blaze/math/expressions/SVecSVecSubExpr.h>
#include <blaze/math/expressions/SVecTransExpr.h>
#include <blaze/math/expressions/TDVecSVecMultExpr.h>
#include <blaze/math/expressions/TSVecSVecMultExpr.h>
#include <blaze/math/expressions/TSVecDVecMultExpr.h>
#include <blaze/math/smp/DenseVector.h>
#include <blaze/math/smp/SparseVector.h>
#include <blaze/math/sparse/SparseVector.h>
#include <blaze/math/Vector.h>
#include <blaze/math/views/Subvector.h>
#endif

View File

@ -0,0 +1,382 @@
//=================================================================================================
/*!
// \file blaze/math/StaticMatrix.h
// \brief Header file for the complete StaticMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_STATICMATRIX_H_
#define _BLAZE_MATH_STATICMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/StaticMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/HybridMatrix.h>
#include <blaze/math/shims/Conjugate.h>
#include <blaze/math/shims/Real.h>
#include <blaze/math/StaticVector.h>
#include <blaze/math/typetraits/UnderlyingBuiltin.h>
#include <blaze/system/Precision.h>
#include <blaze/util/Assert.h>
#include <blaze/util/constraints/Numeric.h>
#include <blaze/util/Random.h>
#include <blaze/util/StaticAssert.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for StaticMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of StaticMatrix.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
class Rand< StaticMatrix<Type,M,N,SO> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const StaticMatrix<Type,M,N,SO> generate() const;
template< typename Arg >
inline const StaticMatrix<Type,M,N,SO> generate( const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( StaticMatrix<Type,M,N,SO>& matrix ) const;
template< typename Arg >
inline void randomize( StaticMatrix<Type,M,N,SO>& matrix, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StaticMatrix.
//
// \return The generated random matrix.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
inline const StaticMatrix<Type,M,N,SO> Rand< StaticMatrix<Type,M,N,SO> >::generate() const
{
StaticMatrix<Type,M,N,SO> matrix;
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StaticMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline const StaticMatrix<Type,M,N,SO>
Rand< StaticMatrix<Type,M,N,SO> >::generate( const Arg& min, const Arg& max ) const
{
StaticMatrix<Type,M,N,SO> matrix;
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a StaticMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
inline void Rand< StaticMatrix<Type,M,N,SO> >::randomize( StaticMatrix<Type,M,N,SO>& matrix ) const
{
using blaze::randomize;
for( size_t i=0UL; i<M; ++i ) {
for( size_t j=0UL; j<N; ++j ) {
randomize( matrix(i,j) );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a StaticMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline void Rand< StaticMatrix<Type,M,N,SO> >::randomize( StaticMatrix<Type,M,N,SO>& matrix,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
for( size_t i=0UL; i<M; ++i ) {
for( size_t j=0UL; j<N; ++j ) {
randomize( matrix(i,j), min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric StaticMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
void makeSymmetric( StaticMatrix<Type,M,N,SO>& matrix )
{
using blaze::randomize;
BLAZE_STATIC_ASSERT( M == N );
for( size_t i=0UL; i<N; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j) );
matrix(j,i) = matrix(i,j);
}
randomize( matrix(i,i) );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric StaticMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO // Storage order
, typename Arg > // Min/max argument type
void makeSymmetric( StaticMatrix<Type,M,N,SO>& matrix, const Arg& min, const Arg& max )
{
using blaze::randomize;
BLAZE_STATIC_ASSERT( M == N );
for( size_t i=0UL; i<N; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j), min, max );
matrix(j,i) = matrix(i,j);
}
randomize( matrix(i,i), min, max );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian StaticMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
void makeHermitian( StaticMatrix<Type,M,N,SO>& matrix )
{
using blaze::randomize;
BLAZE_STATIC_ASSERT( M == N );
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
typedef UnderlyingBuiltin_<Type> BT;
for( size_t i=0UL; i<N; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j) );
matrix(j,i) = conj( matrix(i,j) );
}
matrix(i,i) = rand<BT>();
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian StaticMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO // Storage order
, typename Arg > // Min/max argument type
void makeHermitian( StaticMatrix<Type,M,N,SO>& matrix, const Arg& min, const Arg& max )
{
using blaze::randomize;
BLAZE_STATIC_ASSERT( M == N );
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
typedef UnderlyingBuiltin_<Type> BT;
for( size_t i=0UL; i<N; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
randomize( matrix(i,j), min, max );
matrix(j,i) = conj( matrix(i,j) );
}
matrix(i,i) = rand<BT>( real( min ), real( max ) );
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite StaticMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
// \exception std::invalid_argument Invalid non-square matrix provided.
*/
template< typename Type // Data type of the matrix
, size_t M // Number of rows
, size_t N // Number of columns
, bool SO > // Storage order
void makePositiveDefinite( StaticMatrix<Type,M,N,SO>& matrix )
{
using blaze::randomize;
BLAZE_STATIC_ASSERT( M == N );
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( Type );
randomize( matrix );
matrix *= ctrans( matrix );
for( size_t i=0UL; i<N; ++i ) {
matrix(i,i) += Type(N);
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,187 @@
//=================================================================================================
/*!
// \file blaze/math/StaticVector.h
// \brief Header file for the complete StaticVector implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_STATICVECTOR_H_
#define _BLAZE_MATH_STATICVECTOR_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/dense/StaticVector.h>
#include <blaze/math/DenseVector.h>
#include <blaze/math/DynamicVector.h>
#include <blaze/math/StaticMatrix.h>
#include <blaze/system/Precision.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for StaticVector.
// \ingroup random
//
// This specialization of the Rand class creates random instances of StaticVector.
*/
template< typename Type // Data type of the vector
, size_t N // Number of elements
, bool TF > // Transpose flag
class Rand< StaticVector<Type,N,TF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const StaticVector<Type,N,TF> generate() const;
template< typename Arg >
inline const StaticVector<Type,N,TF> generate( const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( StaticVector<Type,N,TF>& vector ) const;
template< typename Arg >
inline void randomize( StaticVector<Type,N,TF>& vector, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StaticVector.
//
// \return The generated random vector.
*/
template< typename Type // Data type of the vector
, size_t N // Number of elements
, bool TF > // Transpose flag
inline const StaticVector<Type,N,TF> Rand< StaticVector<Type,N,TF> >::generate() const
{
StaticVector<Type,N,TF> vector;
randomize( vector );
return vector;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StaticVector.
//
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return The generated random vector.
*/
template< typename Type // Data type of the vector
, size_t N // Number of elements
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline const StaticVector<Type,N,TF>
Rand< StaticVector<Type,N,TF> >::generate( const Arg& min, const Arg& max ) const
{
StaticVector<Type,N,TF> vector;
randomize( vector, min, max );
return vector;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a StaticVector.
//
// \param vector The vector to be randomized.
// \return void
*/
template< typename Type // Data type of the vector
, size_t N // Number of elements
, bool TF > // Transpose flag
inline void Rand< StaticVector<Type,N,TF> >::randomize( StaticVector<Type,N,TF>& vector ) const
{
using blaze::randomize;
for( size_t i=0UL; i<N; ++i ) {
randomize( vector[i] );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a StaticVector.
//
// \param vector The vector to be randomized.
// \param min The smallest possible value for a vector element.
// \param max The largest possible value for a vector element.
// \return void
*/
template< typename Type // Data type of the vector
, size_t N // Number of elements
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline void Rand< StaticVector<Type,N,TF> >::randomize( StaticVector<Type,N,TF>& vector,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
for( size_t i=0UL; i<N; ++i ) {
randomize( vector[i], min, max );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,104 @@
//=================================================================================================
/*!
// \file blaze/math/StorageOrder.h
// \brief Header file for the matrix storage order types
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_STORAGEORDER_H_
#define _BLAZE_MATH_STORAGEORDER_H_
namespace blaze {
//=================================================================================================
//
// MATRIX STORAGE ORDER TYPES
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Storage order flag for row-major matrices.
//
// Via this flag it is possible to specify the storage order of matrices as row-major. For
// instance, given the following matrix
\f[\left(\begin{array}{*{3}{c}}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{array}\right)\f]\n
// in case of row-major order the elements are stored in the order
\f[\left(\begin{array}{*{6}{c}}
1 & 2 & 3 & 4 & 5 & 6. \\
\end{array}\right)\f]
// The following example demonstrates the setup of this \f$ 2 \times 3 \f$ matrix:
\code
using blaze::rowMajor;
blaze::StaticMatrix<int,2UL,3UL,rowMajor> A( { { 1, 2, 3 }, { 4, 5, 6 } } );
\endcode
*/
const bool rowMajor = false;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Storage order flag for column-major matrices.
//
// Via this flag it is possible to specify the storage order of matrices as column-major. For
// instance, given the following matrix
\f[\left(\begin{array}{*{3}{c}}
1 & 2 & 3 \\
4 & 5 & 6 \\
\end{array}\right)\f]\n
// in case of column-major order the elements are stored in the order
\f[\left(\begin{array}{*{6}{c}}
1 & 4 & 2 & 5 & 3 & 6. \\
\end{array}\right)\f]
// The following example demonstrates the setup of this \f$ 2 \times 3 \f$ matrix:
\code
using blaze::columnMajor;
blaze::StaticMatrix<int,2UL,3UL,columnMajor> A( { { 1, 2, 3 }, { 4, 5, 6 } } );
\endcode
*/
const bool columnMajor = true;
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,673 @@
//=================================================================================================
/*!
// \file blaze/math/StrictlyLowerMatrix.h
// \brief Header file for the complete StrictlyLowerMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_STRICTLYLOWERMATRIX_H_
#define _BLAZE_MATH_STRICTLYLOWERMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <vector>
#include <blaze/math/Aliases.h>
#include <blaze/math/adaptors/StrictlyLowerMatrix.h>
#include <blaze/math/constraints/DenseMatrix.h>
#include <blaze/math/constraints/Resizable.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/Exception.h>
#include <blaze/math/SparseMatrix.h>
#include <blaze/math/StrictlyUpperMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/util/FalseType.h>
#include <blaze/util/Indices.h>
#include <blaze/util/Random.h>
#include <blaze/util/TrueType.h>
#include <blaze/util/Types.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for StrictlyLowerMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of StrictlyLowerMatrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
class Rand< StrictlyLowerMatrix<MT,SO,DF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const StrictlyLowerMatrix<MT,SO,DF> generate() const;
inline const StrictlyLowerMatrix<MT,SO,DF> generate( size_t n ) const;
inline const StrictlyLowerMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros ) const;
template< typename Arg >
inline const StrictlyLowerMatrix<MT,SO,DF> generate( const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const StrictlyLowerMatrix<MT,SO,DF> generate( size_t n, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const StrictlyLowerMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix ) const;
inline void randomize( StrictlyLowerMatrix<MT,false,DF>& matrix, size_t nonzeros ) const;
inline void randomize( StrictlyLowerMatrix<MT,true,DF>& matrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( StrictlyLowerMatrix<MT,false,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( StrictlyLowerMatrix<MT,true,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
private:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix, TrueType ) const;
inline void randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix, FalseType ) const;
template< typename Arg >
inline void randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, TrueType ) const;
template< typename Arg >
inline void randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, FalseType ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyLowerMatrix.
//
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const StrictlyLowerMatrix<MT,SO,DF> Rand< StrictlyLowerMatrix<MT,SO,DF> >::generate() const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
StrictlyLowerMatrix<MT,SO,DF> matrix;
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyLowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const StrictlyLowerMatrix<MT,SO,DF>
Rand< StrictlyLowerMatrix<MT,SO,DF> >::generate( size_t n ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
StrictlyLowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyLowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const StrictlyLowerMatrix<MT,SO,DF>
Rand< StrictlyLowerMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > StrictlyLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
StrictlyLowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyLowerMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const StrictlyLowerMatrix<MT,SO,DF>
Rand< StrictlyLowerMatrix<MT,SO,DF> >::generate( const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
StrictlyLowerMatrix<MT,SO,DF> matrix;
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyLowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const StrictlyLowerMatrix<MT,SO,DF>
Rand< StrictlyLowerMatrix<MT,SO,DF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
StrictlyLowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyLowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const StrictlyLowerMatrix<MT,SO,DF>
Rand< StrictlyLowerMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > StrictlyLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
StrictlyLowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a StrictlyLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< StrictlyLowerMatrix<MT,SO,DF> >::randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix ) const
{
randomize( matrix, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense StrictlyLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< StrictlyLowerMatrix<MT,SO,DF> >::randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=1UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
matrix(i,j) = rand<ET>();
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse StrictlyLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< StrictlyLowerMatrix<MT,SO,DF> >::randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL || n == 1UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.2*n*n ) ) );
randomize( matrix, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse StrictlyLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< StrictlyLowerMatrix<MT,SO,DF> >::randomize( StrictlyLowerMatrix<MT,false,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > StrictlyLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
matrix.finalize( 0UL );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 1UL, n-1UL );
if( dist[index] == index ) continue;
++dist[index];
++nz;
}
for( size_t i=1UL; i<n; ++i ) {
const Indices indices( 0UL, i-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse StrictlyLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< StrictlyLowerMatrix<MT,SO,DF> >::randomize( StrictlyLowerMatrix<MT,true,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > StrictlyLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n-1UL );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-2UL );
if( dist[index] == n - index - 1UL ) continue;
++dist[index];
++nz;
}
for( size_t j=0UL; j<n-1UL; ++j ) {
const Indices indices( j+1UL, n-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( j );
}
matrix.finalize( n-1UL );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a StrictlyLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< StrictlyLowerMatrix<MT,SO,DF> >::randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max ) const
{
randomize( matrix, min, max, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense StrictlyLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< StrictlyLowerMatrix<MT,SO,DF> >::randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=1UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
matrix(i,j) = rand<ET>( min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse StrictlyLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< StrictlyLowerMatrix<MT,SO,DF> >::randomize( StrictlyLowerMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL || n == 1UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.2*n*n ) ) );
randomize( matrix, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse StrictlyLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< StrictlyLowerMatrix<MT,SO,DF> >::randomize( StrictlyLowerMatrix<MT,false,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > StrictlyLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
matrix.finalize( 0UL );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 1UL, n-1UL );
if( dist[index] == index ) continue;
++dist[index];
++nz;
}
for( size_t i=1UL; i<n; ++i ) {
const Indices indices( 0UL, i-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse StrictlyLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< StrictlyLowerMatrix<MT,SO,DF> >::randomize( StrictlyLowerMatrix<MT,true,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > StrictlyLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n-1UL );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-2UL );
if( dist[index] == n - index - 1UL ) continue;
++dist[index];
++nz;
}
for( size_t j=0UL; j<n-1UL; ++j ) {
const Indices indices( j+1UL, n-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( j );
}
matrix.finalize( n-1UL );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,673 @@
//=================================================================================================
/*!
// \file blaze/math/StrictlyUpperMatrix.h
// \brief Header file for the complete StrictlyUpperMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_STRICTLYUPPERMATRIX_H_
#define _BLAZE_MATH_STRICTLYUPPERMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <vector>
#include <blaze/math/Aliases.h>
#include <blaze/math/adaptors/StrictlyUpperMatrix.h>
#include <blaze/math/constraints/DenseMatrix.h>
#include <blaze/math/constraints/Resizable.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/Exception.h>
#include <blaze/math/SparseMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/math/StrictlyLowerMatrix.h>
#include <blaze/util/FalseType.h>
#include <blaze/util/Indices.h>
#include <blaze/util/Random.h>
#include <blaze/util/TrueType.h>
#include <blaze/util/Types.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for StrictlyUpperMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of StrictlyUpperMatrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
class Rand< StrictlyUpperMatrix<MT,SO,DF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const StrictlyUpperMatrix<MT,SO,DF> generate() const;
inline const StrictlyUpperMatrix<MT,SO,DF> generate( size_t n ) const;
inline const StrictlyUpperMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros ) const;
template< typename Arg >
inline const StrictlyUpperMatrix<MT,SO,DF> generate( const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const StrictlyUpperMatrix<MT,SO,DF> generate( size_t n, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const StrictlyUpperMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix ) const;
inline void randomize( StrictlyUpperMatrix<MT,false,DF>& matrix, size_t nonzeros ) const;
inline void randomize( StrictlyUpperMatrix<MT,true,DF>& matrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( StrictlyUpperMatrix<MT,false,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( StrictlyUpperMatrix<MT,true,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
private:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix, TrueType ) const;
inline void randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix, FalseType ) const;
template< typename Arg >
inline void randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, TrueType ) const;
template< typename Arg >
inline void randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, FalseType ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyUpperMatrix.
//
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const StrictlyUpperMatrix<MT,SO,DF> Rand< StrictlyUpperMatrix<MT,SO,DF> >::generate() const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
StrictlyUpperMatrix<MT,SO,DF> matrix;
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyUpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const StrictlyUpperMatrix<MT,SO,DF>
Rand< StrictlyUpperMatrix<MT,SO,DF> >::generate( size_t n ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
StrictlyUpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyUpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const StrictlyUpperMatrix<MT,SO,DF>
Rand< StrictlyUpperMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > StrictlyUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
StrictlyUpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyUpperMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const StrictlyUpperMatrix<MT,SO,DF>
Rand< StrictlyUpperMatrix<MT,SO,DF> >::generate( const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
StrictlyUpperMatrix<MT,SO,DF> matrix;
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyUpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const StrictlyUpperMatrix<MT,SO,DF>
Rand< StrictlyUpperMatrix<MT,SO,DF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
StrictlyUpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random StrictlyUpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const StrictlyUpperMatrix<MT,SO,DF>
Rand< StrictlyUpperMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > StrictlyUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
StrictlyUpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a StrictlyUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< StrictlyUpperMatrix<MT,SO,DF> >::randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix ) const
{
randomize( matrix, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense StrictlyUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< StrictlyUpperMatrix<MT,SO,DF> >::randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=i+1UL; j<n; ++j ) {
matrix(i,j) = rand<ET>();
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse StrictlyUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< StrictlyUpperMatrix<MT,SO,DF> >::randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL || n == 1UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.2*n*n ) ) );
randomize( matrix, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse StrictlyUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< StrictlyUpperMatrix<MT,SO,DF> >::randomize( StrictlyUpperMatrix<MT,false,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > StrictlyUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n-1UL );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-2UL );
if( dist[index] == n - index - 1UL ) continue;
++dist[index];
++nz;
}
for( size_t i=0UL; i<n-1UL; ++i ) {
const Indices indices( i+1UL, n-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( i );
}
matrix.finalize( n-1UL );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse StrictlyUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< StrictlyUpperMatrix<MT,SO,DF> >::randomize( StrictlyUpperMatrix<MT,true,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > StrictlyUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
matrix.finalize( 0UL );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 1UL, n-1UL );
if( dist[index] == index ) continue;
++dist[index];
++nz;
}
for( size_t j=1UL; j<n; ++j ) {
const Indices indices( 0UL, j-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( j );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a StrictlyUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< StrictlyUpperMatrix<MT,SO,DF> >::randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max ) const
{
randomize( matrix, min, max, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense StrictlyUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< StrictlyUpperMatrix<MT,SO,DF> >::randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=i+1UL; j<n; ++j ) {
matrix(i,j) = rand<ET>( min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse StrictlyUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< StrictlyUpperMatrix<MT,SO,DF> >::randomize( StrictlyUpperMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL || n == 1UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.2*n*n ) ) );
randomize( matrix, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse StrictlyUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< StrictlyUpperMatrix<MT,SO,DF> >::randomize( StrictlyUpperMatrix<MT,false,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > StrictlyUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n-1UL );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-2UL );
if( dist[index] == n - index - 1UL ) continue;
++dist[index];
++nz;
}
for( size_t i=0UL; i<n-1UL; ++i ) {
const Indices indices( i+1UL, n-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( i );
}
matrix.finalize( n-1UL );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse StrictlyUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< StrictlyUpperMatrix<MT,SO,DF> >::randomize( StrictlyUpperMatrix<MT,true,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > StrictlyUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
matrix.finalize( 0UL );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 1UL, n-1UL );
if( dist[index] == index ) continue;
++dist[index];
++nz;
}
for( size_t j=1UL; j<n; ++j ) {
const Indices indices( 0UL, j-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( j );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,342 @@
//=================================================================================================
/*!
// \file blaze/math/Submatrix.h
// \brief Header file for the complete Submatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_SUBMATRIX_H_
#define _BLAZE_MATH_SUBMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/Aliases.h>
#include <blaze/math/Exception.h>
#include <blaze/math/smp/DenseMatrix.h>
#include <blaze/math/smp/SparseMatrix.h>
#include <blaze/math/views/Submatrix.h>
#include <blaze/math/views/Subvector.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION FOR DENSE SUBMATRICES
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for dense submatrices.
// \ingroup random
//
// This specialization of the Rand class randomizes dense submatrices.
*/
template< typename MT // Type of the dense matrix
, bool AF // Alignment flag
, bool SO > // Storage order
class Rand< Submatrix<MT,AF,SO,true> >
{
public:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( Submatrix<MT,AF,SO,true>& submatrix ) const;
template< typename Arg >
inline void randomize( Submatrix<MT,AF,SO,true>& submatrix, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense submatrix.
//
// \param submatrix The submatrix to be randomized.
// \return void
*/
template< typename MT // Type of the dense matrix
, bool AF // Alignment flag
, bool SO > // Storage order
inline void Rand< Submatrix<MT,AF,SO,true> >::randomize( Submatrix<MT,AF,SO,true>& submatrix ) const
{
using blaze::randomize;
if( SO == rowMajor ) {
for( size_t i=0UL; i<submatrix.rows(); ++i ) {
for( size_t j=0UL; j<submatrix.columns(); ++j ) {
randomize( submatrix(i,j) );
}
}
}
else {
for( size_t j=0UL; j<submatrix.columns(); ++j ) {
for( size_t i=0UL; i<submatrix.rows(); ++i ) {
randomize( submatrix(i,j) );
}
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense submatrix.
//
// \param submatrix The submatrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the dense matrix
, bool AF // Alignment flag
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline void Rand< Submatrix<MT,AF,SO,true> >::randomize( Submatrix<MT,AF,SO,true>& submatrix,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
if( SO == rowMajor ) {
for( size_t i=0UL; i<submatrix.rows(); ++i ) {
for( size_t j=0UL; j<submatrix.columns(); ++j ) {
randomize( submatrix(i,j), min, max );
}
}
}
else {
for( size_t j=0UL; j<submatrix.columns(); ++j ) {
for( size_t i=0UL; i<submatrix.rows(); ++i ) {
randomize( submatrix(i,j), min, max );
}
}
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// RAND SPECIALIZATION FOR SPARSE SUBMATRICES
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for sparse submatrices.
// \ingroup random
//
// This specialization of the Rand class randomizes sparse submatrices.
*/
template< typename MT // Type of the sparse matrix
, bool AF // Alignment flag
, bool SO > // Storage order
class Rand< Submatrix<MT,AF,SO,false> >
{
public:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( Submatrix<MT,AF,SO,false>& submatrix ) const;
inline void randomize( Submatrix<MT,AF,SO,false>& submatrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( Submatrix<MT,AF,SO,false>& submatrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( Submatrix<MT,AF,SO,false>& submatrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse submatrix.
//
// \param submatrix The submatrix to be randomized.
// \return void
*/
template< typename MT // Type of the sparse matrix
, bool AF // Alignment flag
, bool SO > // Storage order
inline void Rand< Submatrix<MT,AF,SO,false> >::randomize( Submatrix<MT,AF,SO,false>& submatrix ) const
{
typedef ElementType_< Submatrix<MT,AF,SO,false> > ElementType;
const size_t m( submatrix.rows() );
const size_t n( submatrix.columns() );
if( m == 0UL || n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
submatrix.reset();
submatrix.reserve( nonzeros );
while( submatrix.nonZeros() < nonzeros ) {
submatrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ElementType>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse submatrix.
//
// \param submatrix The submatrix to be randomized.
// \param nonzeros The number of non-zero elements of the random submatrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the sparse matrix
, bool AF // Alignment flag
, bool SO > // Storage order
inline void Rand< Submatrix<MT,AF,SO,false> >::randomize( Submatrix<MT,AF,SO,false>& submatrix, size_t nonzeros ) const
{
typedef ElementType_< Submatrix<MT,AF,SO,false> > ElementType;
const size_t m( submatrix.rows() );
const size_t n( submatrix.columns() );
if( nonzeros > m*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( m == 0UL || n == 0UL ) return;
submatrix.reset();
submatrix.reserve( nonzeros );
while( submatrix.nonZeros() < nonzeros ) {
submatrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ElementType>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse submatrix.
//
// \param submatrix The submatrix to be randomized.
// \param min The smallest possible value for a submatrix element.
// \param max The largest possible value for a submatrix element.
// \return void
*/
template< typename MT // Type of the sparse matrix
, bool AF // Alignment flag
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline void Rand< Submatrix<MT,AF,SO,false> >::randomize( Submatrix<MT,AF,SO,false>& submatrix,
const Arg& min, const Arg& max ) const
{
typedef ElementType_< Submatrix<MT,AF,SO,false> > ElementType;
const size_t m( submatrix.rows() );
const size_t n( submatrix.columns() );
if( m == 0UL || n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*m*n ) ) );
submatrix.reset();
submatrix.reserve( nonzeros );
while( submatrix.nonZeros() < nonzeros ) {
submatrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ElementType>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse submatrix.
//
// \param submatrix The submatrix to be randomized.
// \param nonzeros The number of non-zero elements of the random submatrix.
// \param min The smallest possible value for a submatrix element.
// \param max The largest possible value for a submatrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the sparse matrix
, bool AF // Alignment flag
, bool SO > // Storage order
template< typename Arg > // Min/max argument type
inline void Rand< Submatrix<MT,AF,SO,false> >::randomize( Submatrix<MT,AF,SO,false>& submatrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
typedef ElementType_< Submatrix<MT,AF,SO,false> > ElementType;
const size_t m( submatrix.rows() );
const size_t n( submatrix.columns() );
if( nonzeros > m*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( m == 0UL || n == 0UL ) return;
submatrix.reset();
submatrix.reserve( nonzeros );
while( submatrix.nonZeros() < nonzeros ) {
submatrix( rand<size_t>( 0UL, m-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ElementType>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,315 @@
//=================================================================================================
/*!
// \file blaze/math/Subvector.h
// \brief Header file for the complete Subvector implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_DENSESUBVECTOR_H_
#define _BLAZE_MATH_DENSESUBVECTOR_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/Aliases.h>
#include <blaze/math/Exception.h>
#include <blaze/math/smp/DenseVector.h>
#include <blaze/math/smp/SparseVector.h>
#include <blaze/math/views/Submatrix.h>
#include <blaze/math/views/Subvector.h>
#include <blaze/util/Random.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION FOR DENSE SUBVECTORS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for dense subvectors.
// \ingroup random
//
// This specialization of the Rand class randomizes dense subvectors.
*/
template< typename VT // Type of the dense vector
, bool AF // Alignment flag
, bool TF > // Transpose flag
class Rand< Subvector<VT,AF,TF,true> >
{
public:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( Subvector<VT,AF,TF,true>& subvector ) const;
template< typename Arg >
inline void randomize( Subvector<VT,AF,TF,true>& subvector, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense subvector.
//
// \param subvector The subvector to be randomized.
// \return void
*/
template< typename VT // Type of the dense vector
, bool AF // Alignment flag
, bool TF > // Transpose flag
inline void Rand< Subvector<VT,AF,TF,true> >::randomize( Subvector<VT,AF,TF,true>& subvector ) const
{
using blaze::randomize;
for( size_t i=0UL; i<subvector.size(); ++i ) {
randomize( subvector[i] );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense subvector.
//
// \param subvector The subvector to be randomized.
// \param min The smallest possible value for a subvector element.
// \param max The largest possible value for a subvector element.
// \return void
*/
template< typename VT // Type of the dense vector
, bool AF // Alignment flag
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline void Rand< Subvector<VT,AF,TF,true> >::randomize( Subvector<VT,AF,TF,true>& subvector,
const Arg& min, const Arg& max ) const
{
using blaze::randomize;
for( size_t i=0UL; i<subvector.size(); ++i ) {
randomize( subvector[i], min, max );
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// RAND SPECIALIZATION FOR SPARSE SUBVECTORS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for sparse subvectors.
// \ingroup random
//
// This specialization of the Rand class randomizes sparse subvectors.
*/
template< typename VT // Type of the sparse vector
, bool AF // Alignment flag
, bool TF > // Transpose flag
class Rand< Subvector<VT,AF,TF,false> >
{
public:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( Subvector<VT,AF,TF,false>& subvector ) const;
inline void randomize( Subvector<VT,AF,TF,false>& subvector, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( Subvector<VT,AF,TF,false>& subvector, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( Subvector<VT,AF,TF,false>& subvector, size_t nonzeros, const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse subvector.
//
// \param subvector The subvector to be randomized.
// \return void
*/
template< typename VT // Type of the sparse vector
, bool AF // Alignment flag
, bool TF > // Transpose flag
inline void Rand< Subvector<VT,AF,TF,false> >::randomize( Subvector<VT,AF,TF,false>& subvector ) const
{
typedef ElementType_< Subvector<VT,AF,TF,false> > ElementType;
const size_t size( subvector.size() );
if( size == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*size ) ) );
subvector.reset();
subvector.reserve( nonzeros );
while( subvector.nonZeros() < nonzeros ) {
subvector[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse subvector.
//
// \param subvector The subvector to be randomized.
// \param nonzeros The number of non-zero elements of the random subvector.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename VT // Type of the sparse vector
, bool AF // Alignment flag
, bool TF > // Transpose flag
inline void Rand< Subvector<VT,AF,TF,false> >::randomize( Subvector<VT,AF,TF,false>& subvector, size_t nonzeros ) const
{
typedef ElementType_< Subvector<VT,AF,TF,false> > ElementType;
const size_t size( subvector.size() );
if( nonzeros > size ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( size == 0UL ) return;
subvector.reset();
subvector.reserve( nonzeros );
while( subvector.nonZeros() < nonzeros ) {
subvector[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse subvector.
//
// \param subvector The subvector to be randomized.
// \param min The smallest possible value for a subvector element.
// \param max The largest possible value for a subvector element.
// \return void
*/
template< typename VT // Type of the sparse vector
, bool AF // Alignment flag
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline void Rand< Subvector<VT,AF,TF,false> >::randomize( Subvector<VT,AF,TF,false>& subvector,
const Arg& min, const Arg& max ) const
{
typedef ElementType_< Subvector<VT,AF,TF,false> > ElementType;
const size_t size( subvector.size() );
if( size == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*size ) ) );
subvector.reset();
subvector.reserve( nonzeros );
while( subvector.nonZeros() < nonzeros ) {
subvector[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse subvector.
//
// \param subvector The subvector to be randomized.
// \param nonzeros The number of non-zero elements of the random subvector.
// \param min The smallest possible value for a subvector element.
// \param max The largest possible value for a subvector element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename VT // Type of the sparse vector
, bool AF // Alignment flag
, bool TF > // Transpose flag
template< typename Arg > // Min/max argument type
inline void Rand< Subvector<VT,AF,TF,false> >::randomize( Subvector<VT,AF,TF,false>& subvector,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
typedef ElementType_< Subvector<VT,AF,TF,false> > ElementType;
const size_t size( subvector.size() );
if( nonzeros > size ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( size == 0UL ) return;
subvector.reset();
subvector.reserve( nonzeros );
while( subvector.nonZeros() < nonzeros ) {
subvector[ rand<size_t>( 0UL, size-1UL ) ] = rand<ElementType>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,686 @@
//=================================================================================================
/*!
// \file blaze/math/SymmetricMatrix.h
// \brief Header file for the complete SymmetricMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_SYMMETRICMATRIX_H_
#define _BLAZE_MATH_SYMMETRICMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <blaze/math/Aliases.h>
#include <blaze/math/adaptors/SymmetricMatrix.h>
#include <blaze/math/constraints/DenseMatrix.h>
#include <blaze/math/constraints/Resizable.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/Exception.h>
#include <blaze/math/shims/Real.h>
#include <blaze/math/SparseMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/math/typetraits/UnderlyingBuiltin.h>
#include <blaze/util/Assert.h>
#include <blaze/util/FalseType.h>
#include <blaze/util/Random.h>
#include <blaze/util/TrueType.h>
#include <blaze/util/Types.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for SymmetricMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of SymmetricMatrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
class Rand< SymmetricMatrix<MT,SO,DF,NF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const SymmetricMatrix<MT,SO,DF,NF> generate() const;
inline const SymmetricMatrix<MT,SO,DF,NF> generate( size_t n ) const;
inline const SymmetricMatrix<MT,SO,DF,NF> generate( size_t n, size_t nonzeros ) const;
template< typename Arg >
inline const SymmetricMatrix<MT,SO,DF,NF> generate( const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const SymmetricMatrix<MT,SO,DF,NF> generate( size_t n, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const SymmetricMatrix<MT,SO,DF,NF> generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix ) const;
inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
private:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix, TrueType ) const;
inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix, FalseType ) const;
template< typename Arg >
inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix, const Arg& min, const Arg& max, TrueType ) const;
template< typename Arg >
inline void randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix, const Arg& min, const Arg& max, FalseType ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random SymmetricMatrix.
//
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
inline const SymmetricMatrix<MT,SO,DF,NF> Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate() const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
SymmetricMatrix<MT,SO,DF,NF> matrix;
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random SymmetricMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
inline const SymmetricMatrix<MT,SO,DF,NF>
Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate( size_t n ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
SymmetricMatrix<MT,SO,DF,NF> matrix( n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random SymmetricMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
inline const SymmetricMatrix<MT,SO,DF,NF>
Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate( size_t n, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > n*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
SymmetricMatrix<MT,SO,DF,NF> matrix( n );
randomize( matrix, nonzeros );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random SymmetricMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const SymmetricMatrix<MT,SO,DF,NF>
Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate( const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
SymmetricMatrix<MT,SO,DF,NF> matrix;
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random SymmetricMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const SymmetricMatrix<MT,SO,DF,NF>
Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
SymmetricMatrix<MT,SO,DF,NF> matrix( n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random SymmetricMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const SymmetricMatrix<MT,SO,DF,NF>
Rand< SymmetricMatrix<MT,SO,DF,NF> >::generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > n*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
SymmetricMatrix<MT,SO,DF,NF> matrix( n );
randomize( matrix, nonzeros, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix ) const
{
randomize( matrix, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<=i; ++j ) {
matrix(i,j) = rand<ET>();
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*n*n ) ) );
randomize( matrix, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > n*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros+1UL );
while( matrix.nonZeros() < nonzeros ) {
matrix( rand<size_t>( 0UL, n-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ET>();
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
const Arg& min, const Arg& max ) const
{
randomize( matrix, min, max, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
const Arg& min, const Arg& max, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<=i; ++j ) {
matrix(i,j) = rand<ET>( min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
const Arg& min, const Arg& max, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.5*n*n ) ) );
randomize( matrix, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, bool NF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< SymmetricMatrix<MT,SO,DF,NF> >::randomize( SymmetricMatrix<MT,SO,DF,NF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > n*n ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros+1UL );
while( matrix.nonZeros() < nonzeros ) {
matrix( rand<size_t>( 0UL, n-1UL ), rand<size_t>( 0UL, n-1UL ) ) = rand<ET>( min, max );
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool NF > // Numeric flag
void makeSymmetric( SymmetricMatrix<MT,SO,true,NF>& matrix )
{
using blaze::randomize;
randomize( matrix );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool NF // Numeric flag
, typename Arg > // Min/max argument type
void makeSymmetric( SymmetricMatrix<MT,SO,true,NF>& matrix, const Arg& min, const Arg& max )
{
using blaze::randomize;
randomize( matrix, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool NF > // Numeric flag
void makeHermitian( SymmetricMatrix<MT,SO,true,NF>& matrix )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<=i; ++j ) {
matrix(i,j) = rand<BT>();
}
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool NF // Numeric flag
, typename Arg > // Min/max argument type
void makeHermitian( SymmetricMatrix<MT,SO,true,NF>& matrix, const Arg& min, const Arg& max )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=0UL; j<=i; ++j ) {
matrix(i,j) = rand<BT>( real( min ), real( max ) );
}
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite SymmetricMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool NF > // Numeric flag
void makePositiveDefinite( SymmetricMatrix<MT,SO,true,NF>& matrix )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > BT;
const size_t n( matrix.rows() );
makeHermitian( matrix );
matrix *= matrix;
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) += BT(n);
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

235
src/cpu/blaze/math/Traits.h Normal file
View File

@ -0,0 +1,235 @@
//=================================================================================================
/*!
// \file blaze/math/Traits.h
// \brief Header file for all expression traits
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_TRAITS_H_
#define _BLAZE_MATH_TRAITS_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/traits/AddExprTrait.h>
#include <blaze/math/traits/AddTrait.h>
#include <blaze/math/traits/ColumnTrait.h>
#include <blaze/math/traits/CrossExprTrait.h>
#include <blaze/math/traits/CrossTrait.h>
#include <blaze/math/traits/CTransExprTrait.h>
#include <blaze/math/traits/DerestrictTrait.h>
#include <blaze/math/traits/DivExprTrait.h>
#include <blaze/math/traits/DivTrait.h>
#include <blaze/math/traits/DMatCTransExprTrait.h>
#include <blaze/math/traits/DMatDMatAddExprTrait.h>
#include <blaze/math/traits/DMatDMatMultExprTrait.h>
#include <blaze/math/traits/DMatDMatSubExprTrait.h>
#include <blaze/math/traits/DMatDVecMultExprTrait.h>
#include <blaze/math/traits/DMatEvalExprTrait.h>
#include <blaze/math/traits/DMatForEachExprTrait.h>
#include <blaze/math/traits/DMatInvExprTrait.h>
#include <blaze/math/traits/DMatScalarDivExprTrait.h>
#include <blaze/math/traits/DMatScalarMultExprTrait.h>
#include <blaze/math/traits/DMatSerialExprTrait.h>
#include <blaze/math/traits/DMatSMatAddExprTrait.h>
#include <blaze/math/traits/DMatSMatMultExprTrait.h>
#include <blaze/math/traits/DMatSMatSubExprTrait.h>
#include <blaze/math/traits/DMatSVecMultExprTrait.h>
#include <blaze/math/traits/DMatTDMatAddExprTrait.h>
#include <blaze/math/traits/DMatTDMatMultExprTrait.h>
#include <blaze/math/traits/DMatTDMatSubExprTrait.h>
#include <blaze/math/traits/DMatTransExprTrait.h>
#include <blaze/math/traits/DMatTSMatAddExprTrait.h>
#include <blaze/math/traits/DMatTSMatMultExprTrait.h>
#include <blaze/math/traits/DMatTSMatSubExprTrait.h>
#include <blaze/math/traits/DVecCTransExprTrait.h>
#include <blaze/math/traits/DVecDVecAddExprTrait.h>
#include <blaze/math/traits/DVecDVecCrossExprTrait.h>
#include <blaze/math/traits/DVecDVecDivExprTrait.h>
#include <blaze/math/traits/DVecDVecMultExprTrait.h>
#include <blaze/math/traits/DVecDVecSubExprTrait.h>
#include <blaze/math/traits/DVecEvalExprTrait.h>
#include <blaze/math/traits/DVecForEachExprTrait.h>
#include <blaze/math/traits/DVecScalarDivExprTrait.h>
#include <blaze/math/traits/DVecScalarMultExprTrait.h>
#include <blaze/math/traits/DVecSerialExprTrait.h>
#include <blaze/math/traits/DVecSVecAddExprTrait.h>
#include <blaze/math/traits/DVecSVecCrossExprTrait.h>
#include <blaze/math/traits/DVecSVecMultExprTrait.h>
#include <blaze/math/traits/DVecSVecSubExprTrait.h>
#include <blaze/math/traits/DVecTDVecMultExprTrait.h>
#include <blaze/math/traits/DVecTransExprTrait.h>
#include <blaze/math/traits/DVecTSVecMultExprTrait.h>
#include <blaze/math/traits/EvalExprTrait.h>
#include <blaze/math/traits/ForEachExprTrait.h>
#include <blaze/math/traits/ForEachTrait.h>
#include <blaze/math/traits/ImagTrait.h>
#include <blaze/math/traits/InvExprTrait.h>
#include <blaze/math/traits/MathTrait.h>
#include <blaze/math/traits/MultExprTrait.h>
#include <blaze/math/traits/MultTrait.h>
#include <blaze/math/traits/RealTrait.h>
#include <blaze/math/traits/RowTrait.h>
#include <blaze/math/traits/SerialExprTrait.h>
#include <blaze/math/traits/SMatCTransExprTrait.h>
#include <blaze/math/traits/SMatDMatAddExprTrait.h>
#include <blaze/math/traits/SMatDMatMultExprTrait.h>
#include <blaze/math/traits/SMatDMatSubExprTrait.h>
#include <blaze/math/traits/SMatDVecMultExprTrait.h>
#include <blaze/math/traits/SMatEvalExprTrait.h>
#include <blaze/math/traits/SMatForEachExprTrait.h>
#include <blaze/math/traits/SMatScalarDivExprTrait.h>
#include <blaze/math/traits/SMatScalarMultExprTrait.h>
#include <blaze/math/traits/SMatSerialExprTrait.h>
#include <blaze/math/traits/SMatSMatAddExprTrait.h>
#include <blaze/math/traits/SMatSMatMultExprTrait.h>
#include <blaze/math/traits/SMatSMatSubExprTrait.h>
#include <blaze/math/traits/SMatSVecMultExprTrait.h>
#include <blaze/math/traits/SMatTDMatAddExprTrait.h>
#include <blaze/math/traits/SMatTDMatMultExprTrait.h>
#include <blaze/math/traits/SMatTDMatSubExprTrait.h>
#include <blaze/math/traits/SMatTransExprTrait.h>
#include <blaze/math/traits/SMatTSMatAddExprTrait.h>
#include <blaze/math/traits/SMatTSMatMultExprTrait.h>
#include <blaze/math/traits/SMatTSMatSubExprTrait.h>
#include <blaze/math/traits/SubExprTrait.h>
#include <blaze/math/traits/SubTrait.h>
#include <blaze/math/traits/SubvectorExprTrait.h>
#include <blaze/math/traits/SubvectorTrait.h>
#include <blaze/math/traits/SVecCTransExprTrait.h>
#include <blaze/math/traits/SVecDVecAddExprTrait.h>
#include <blaze/math/traits/SVecDVecCrossExprTrait.h>
#include <blaze/math/traits/SVecDVecDivExprTrait.h>
#include <blaze/math/traits/SVecDVecMultExprTrait.h>
#include <blaze/math/traits/SVecDVecSubExprTrait.h>
#include <blaze/math/traits/SVecEvalExprTrait.h>
#include <blaze/math/traits/SVecForEachExprTrait.h>
#include <blaze/math/traits/SVecScalarDivExprTrait.h>
#include <blaze/math/traits/SVecScalarMultExprTrait.h>
#include <blaze/math/traits/SVecSerialExprTrait.h>
#include <blaze/math/traits/SVecSVecAddExprTrait.h>
#include <blaze/math/traits/SVecSVecCrossExprTrait.h>
#include <blaze/math/traits/SVecSVecMultExprTrait.h>
#include <blaze/math/traits/SVecSVecSubExprTrait.h>
#include <blaze/math/traits/SVecTDVecMultExprTrait.h>
#include <blaze/math/traits/SVecTransExprTrait.h>
#include <blaze/math/traits/SVecTSVecMultExprTrait.h>
#include <blaze/math/traits/TDMatCTransExprTrait.h>
#include <blaze/math/traits/TDMatDMatAddExprTrait.h>
#include <blaze/math/traits/TDMatDMatMultExprTrait.h>
#include <blaze/math/traits/TDMatDMatSubExprTrait.h>
#include <blaze/math/traits/TDMatEvalExprTrait.h>
#include <blaze/math/traits/TDMatForEachExprTrait.h>
#include <blaze/math/traits/TDMatInvExprTrait.h>
#include <blaze/math/traits/TDMatScalarDivExprTrait.h>
#include <blaze/math/traits/TDMatScalarMultExprTrait.h>
#include <blaze/math/traits/TDMatSerialExprTrait.h>
#include <blaze/math/traits/TDMatSMatAddExprTrait.h>
#include <blaze/math/traits/TDMatSMatMultExprTrait.h>
#include <blaze/math/traits/TDMatSMatSubExprTrait.h>
#include <blaze/math/traits/TDMatDVecMultExprTrait.h>
#include <blaze/math/traits/TDMatSVecMultExprTrait.h>
#include <blaze/math/traits/TDMatTDMatAddExprTrait.h>
#include <blaze/math/traits/TDMatTDMatMultExprTrait.h>
#include <blaze/math/traits/TDMatTDMatSubExprTrait.h>
#include <blaze/math/traits/TDMatTransExprTrait.h>
#include <blaze/math/traits/TDMatTSMatAddExprTrait.h>
#include <blaze/math/traits/TDMatTSMatMultExprTrait.h>
#include <blaze/math/traits/TDMatTSMatSubExprTrait.h>
#include <blaze/math/traits/TDVecCTransExprTrait.h>
#include <blaze/math/traits/TDVecDMatMultExprTrait.h>
#include <blaze/math/traits/TDVecDVecMultExprTrait.h>
#include <blaze/math/traits/TDVecEvalExprTrait.h>
#include <blaze/math/traits/TDVecForEachExprTrait.h>
#include <blaze/math/traits/TDVecScalarDivExprTrait.h>
#include <blaze/math/traits/TDVecScalarMultExprTrait.h>
#include <blaze/math/traits/TDVecSerialExprTrait.h>
#include <blaze/math/traits/TDVecSMatMultExprTrait.h>
#include <blaze/math/traits/TDVecSVecMultExprTrait.h>
#include <blaze/math/traits/TDVecTDMatMultExprTrait.h>
#include <blaze/math/traits/TDVecTDVecAddExprTrait.h>
#include <blaze/math/traits/TDVecTDVecCrossExprTrait.h>
#include <blaze/math/traits/TDVecTDVecDivExprTrait.h>
#include <blaze/math/traits/TDVecTDVecMultExprTrait.h>
#include <blaze/math/traits/TDVecTDVecSubExprTrait.h>
#include <blaze/math/traits/TDVecTransExprTrait.h>
#include <blaze/math/traits/TDVecTSMatMultExprTrait.h>
#include <blaze/math/traits/TDVecTSVecAddExprTrait.h>
#include <blaze/math/traits/TDVecTSVecCrossExprTrait.h>
#include <blaze/math/traits/TDVecTSVecMultExprTrait.h>
#include <blaze/math/traits/TDVecTSVecSubExprTrait.h>
#include <blaze/math/traits/TransExprTrait.h>
#include <blaze/math/traits/TSMatCTransExprTrait.h>
#include <blaze/math/traits/TSMatDMatAddExprTrait.h>
#include <blaze/math/traits/TSMatDMatMultExprTrait.h>
#include <blaze/math/traits/TSMatDMatSubExprTrait.h>
#include <blaze/math/traits/TSMatEvalExprTrait.h>
#include <blaze/math/traits/TSMatForEachExprTrait.h>
#include <blaze/math/traits/TSMatScalarDivExprTrait.h>
#include <blaze/math/traits/TSMatScalarMultExprTrait.h>
#include <blaze/math/traits/TSMatSerialExprTrait.h>
#include <blaze/math/traits/TSMatSMatAddExprTrait.h>
#include <blaze/math/traits/TSMatSMatMultExprTrait.h>
#include <blaze/math/traits/TSMatSMatSubExprTrait.h>
#include <blaze/math/traits/TSMatDVecMultExprTrait.h>
#include <blaze/math/traits/TSMatSVecMultExprTrait.h>
#include <blaze/math/traits/TSMatTDMatAddExprTrait.h>
#include <blaze/math/traits/TSMatTDMatMultExprTrait.h>
#include <blaze/math/traits/TSMatTDMatSubExprTrait.h>
#include <blaze/math/traits/TSMatTransExprTrait.h>
#include <blaze/math/traits/TSMatTSMatAddExprTrait.h>
#include <blaze/math/traits/TSMatTSMatMultExprTrait.h>
#include <blaze/math/traits/TSMatTSMatSubExprTrait.h>
#include <blaze/math/traits/TSVecCTransExprTrait.h>
#include <blaze/math/traits/TSVecDMatMultExprTrait.h>
#include <blaze/math/traits/TSVecDVecMultExprTrait.h>
#include <blaze/math/traits/TSVecEvalExprTrait.h>
#include <blaze/math/traits/TSVecForEachExprTrait.h>
#include <blaze/math/traits/TSVecScalarDivExprTrait.h>
#include <blaze/math/traits/TSVecScalarMultExprTrait.h>
#include <blaze/math/traits/TSVecSerialExprTrait.h>
#include <blaze/math/traits/TSVecSMatMultExprTrait.h>
#include <blaze/math/traits/TSVecSVecMultExprTrait.h>
#include <blaze/math/traits/TSVecTDMatMultExprTrait.h>
#include <blaze/math/traits/TSVecTDVecAddExprTrait.h>
#include <blaze/math/traits/TSVecTDVecCrossExprTrait.h>
#include <blaze/math/traits/TSVecTDVecDivExprTrait.h>
#include <blaze/math/traits/TSVecTDVecMultExprTrait.h>
#include <blaze/math/traits/TSVecTDVecSubExprTrait.h>
#include <blaze/math/traits/TSVecTransExprTrait.h>
#include <blaze/math/traits/TSVecTSMatMultExprTrait.h>
#include <blaze/math/traits/TSVecTSVecAddExprTrait.h>
#include <blaze/math/traits/TSVecTSVecCrossExprTrait.h>
#include <blaze/math/traits/TSVecTSVecMultExprTrait.h>
#include <blaze/math/traits/TSVecTSVecSubExprTrait.h>
#endif

View File

@ -0,0 +1,78 @@
//=================================================================================================
/*!
// \file blaze/math/TransposeFlag.h
// \brief Header file for the vector transpose flag types
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_TRANSPOSEFLAG_H_
#define _BLAZE_MATH_TRANSPOSEFLAG_H_
namespace blaze {
//=================================================================================================
//
// VECTOR TRANSPOSE FLAG TYPES
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Transpose flag for column vectors.
//
// Via this flag it is possible to specify vectors as column vectors. The following example
// demonstrates the setup of a 3-dimensional column vector:
\code
using blaze::columnVector;
blaze::StaticVector<int,3UL,columnVector> v( 1, 2, 3 );
\endcode
*/
const bool columnVector = false;
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Transpose flag for row vectors.
//
// Via this flag it is possible to specify vectors as row vectors. The following example
// demonstrates the setup of a 3-dimensional row vector:
\code
using blaze::rowVector;
blaze::StaticVector<int,3UL,rowVector> v( 1, 2, 3 );
\endcode
*/
const bool rowVector = true;
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,168 @@
//=================================================================================================
/*!
// \file blaze/math/TypeTraits.h
// \brief Header file for all type traits
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_TYPETRAITS_H_
#define _BLAZE_MATH_TYPETRAITS_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/typetraits/AreSIMDCombinable.h>
#include <blaze/math/typetraits/Columns.h>
#include <blaze/math/typetraits/HasConstDataAccess.h>
#include <blaze/math/typetraits/HasMutableDataAccess.h>
#include <blaze/math/typetraits/HasSIMDAbs.h>
#include <blaze/math/typetraits/HasSIMDAcos.h>
#include <blaze/math/typetraits/HasSIMDAcosh.h>
#include <blaze/math/typetraits/HasSIMDAdd.h>
#include <blaze/math/typetraits/HasSIMDAsin.h>
#include <blaze/math/typetraits/HasSIMDAsinh.h>
#include <blaze/math/typetraits/HasSIMDAtan.h>
#include <blaze/math/typetraits/HasSIMDAtanh.h>
#include <blaze/math/typetraits/HasSIMDCbrt.h>
#include <blaze/math/typetraits/HasSIMDCeil.h>
#include <blaze/math/typetraits/HasSIMDConj.h>
#include <blaze/math/typetraits/HasSIMDCos.h>
#include <blaze/math/typetraits/HasSIMDCosh.h>
#include <blaze/math/typetraits/HasSIMDDiv.h>
#include <blaze/math/typetraits/HasSIMDErf.h>
#include <blaze/math/typetraits/HasSIMDErfc.h>
#include <blaze/math/typetraits/HasSIMDExp.h>
#include <blaze/math/typetraits/HasSIMDFloor.h>
#include <blaze/math/typetraits/HasSIMDInvCbrt.h>
#include <blaze/math/typetraits/HasSIMDInvSqrt.h>
#include <blaze/math/typetraits/HasSIMDLog.h>
#include <blaze/math/typetraits/HasSIMDLog10.h>
#include <blaze/math/typetraits/HasSIMDMult.h>
#include <blaze/math/typetraits/HasSIMDPow.h>
#include <blaze/math/typetraits/HasSIMDSin.h>
#include <blaze/math/typetraits/HasSIMDSinh.h>
#include <blaze/math/typetraits/HasSIMDSqrt.h>
#include <blaze/math/typetraits/HasSIMDSub.h>
#include <blaze/math/typetraits/HasSIMDTan.h>
#include <blaze/math/typetraits/HasSIMDTanh.h>
#include <blaze/math/typetraits/IsAdaptor.h>
#include <blaze/math/typetraits/IsAddExpr.h>
#include <blaze/math/typetraits/IsAligned.h>
#include <blaze/math/typetraits/IsBLASCompatible.h>
#include <blaze/math/typetraits/IsColumn.h>
#include <blaze/math/typetraits/IsColumnMajorMatrix.h>
#include <blaze/math/typetraits/IsColumnVector.h>
#include <blaze/math/typetraits/IsComputation.h>
#include <blaze/math/typetraits/IsCrossExpr.h>
#include <blaze/math/typetraits/IsCustom.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/math/typetraits/IsDenseVector.h>
#include <blaze/math/typetraits/IsDiagonal.h>
#include <blaze/math/typetraits/IsDivExpr.h>
#include <blaze/math/typetraits/IsEvalExpr.h>
#include <blaze/math/typetraits/IsExpression.h>
#include <blaze/math/typetraits/IsForEachExpr.h>
#include <blaze/math/typetraits/IsGeneral.h>
#include <blaze/math/typetraits/IsHermitian.h>
#include <blaze/math/typetraits/IsIdentity.h>
#include <blaze/math/typetraits/IsInvertible.h>
#include <blaze/math/typetraits/IsLower.h>
#include <blaze/math/typetraits/IsMatEvalExpr.h>
#include <blaze/math/typetraits/IsMatForEachExpr.h>
#include <blaze/math/typetraits/IsMatInvExpr.h>
#include <blaze/math/typetraits/IsMatMatAddExpr.h>
#include <blaze/math/typetraits/IsMatMatMultExpr.h>
#include <blaze/math/typetraits/IsMatMatSubExpr.h>
#include <blaze/math/typetraits/IsMatrix.h>
#include <blaze/math/typetraits/IsMatScalarDivExpr.h>
#include <blaze/math/typetraits/IsMatScalarMultExpr.h>
#include <blaze/math/typetraits/IsMatSerialExpr.h>
#include <blaze/math/typetraits/IsMatTransExpr.h>
#include <blaze/math/typetraits/IsMatVecMultExpr.h>
#include <blaze/math/typetraits/IsMultExpr.h>
#include <blaze/math/typetraits/IsNumericMatrix.h>
#include <blaze/math/typetraits/IsNumericVector.h>
#include <blaze/math/typetraits/IsOpposedView.h>
#include <blaze/math/typetraits/IsPadded.h>
#include <blaze/math/typetraits/IsProxy.h>
#include <blaze/math/typetraits/IsResizable.h>
#include <blaze/math/typetraits/IsRestricted.h>
#include <blaze/math/typetraits/IsRow.h>
#include <blaze/math/typetraits/IsRowMajorMatrix.h>
#include <blaze/math/typetraits/IsRowVector.h>
#include <blaze/math/typetraits/IsSerialExpr.h>
#include <blaze/math/typetraits/IsSIMDEnabled.h>
#include <blaze/math/typetraits/IsSIMDPack.h>
#include <blaze/math/typetraits/IsSMPAssignable.h>
#include <blaze/math/typetraits/IsSparseElement.h>
#include <blaze/math/typetraits/IsSparseMatrix.h>
#include <blaze/math/typetraits/IsSparseVector.h>
#include <blaze/math/typetraits/IsSquare.h>
#include <blaze/math/typetraits/IsStrictlyLower.h>
#include <blaze/math/typetraits/IsStrictlyTriangular.h>
#include <blaze/math/typetraits/IsStrictlyUpper.h>
#include <blaze/math/typetraits/IsSubExpr.h>
#include <blaze/math/typetraits/IsSubmatrix.h>
#include <blaze/math/typetraits/IsSubvector.h>
#include <blaze/math/typetraits/IsSymmetric.h>
#include <blaze/math/typetraits/IsTemporary.h>
#include <blaze/math/typetraits/IsTransExpr.h>
#include <blaze/math/typetraits/IsTriangular.h>
#include <blaze/math/typetraits/IsTVecMatMultExpr.h>
#include <blaze/math/typetraits/IsUniLower.h>
#include <blaze/math/typetraits/IsUniTriangular.h>
#include <blaze/math/typetraits/IsUniUpper.h>
#include <blaze/math/typetraits/IsUpper.h>
#include <blaze/math/typetraits/IsVecEvalExpr.h>
#include <blaze/math/typetraits/IsVecForEachExpr.h>
#include <blaze/math/typetraits/IsVecScalarDivExpr.h>
#include <blaze/math/typetraits/IsVecScalarMultExpr.h>
#include <blaze/math/typetraits/IsVecSerialExpr.h>
#include <blaze/math/typetraits/IsVector.h>
#include <blaze/math/typetraits/IsVecTransExpr.h>
#include <blaze/math/typetraits/IsVecTVecMultExpr.h>
#include <blaze/math/typetraits/IsVecVecAddExpr.h>
#include <blaze/math/typetraits/IsVecVecDivExpr.h>
#include <blaze/math/typetraits/IsVecVecMultExpr.h>
#include <blaze/math/typetraits/IsVecVecSubExpr.h>
#include <blaze/math/typetraits/IsView.h>
#include <blaze/math/typetraits/RemoveAdaptor.h>
#include <blaze/math/typetraits/RequiresEvaluation.h>
#include <blaze/math/typetraits/Rows.h>
#include <blaze/math/typetraits/Size.h>
#include <blaze/math/typetraits/StorageOrder.h>
#include <blaze/math/typetraits/TransposeFlag.h>
#include <blaze/math/typetraits/UnderlyingBuiltin.h>
#include <blaze/math/typetraits/UnderlyingElement.h>
#include <blaze/math/typetraits/UnderlyingNumeric.h>
#endif

View File

@ -0,0 +1,786 @@
//=================================================================================================
/*!
// \file blaze/math/UniLowerMatrix.h
// \brief Header file for the complete UniLowerMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_UNILOWERMATRIX_H_
#define _BLAZE_MATH_UNILOWERMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <vector>
#include <blaze/math/Aliases.h>
#include <blaze/math/adaptors/UniLowerMatrix.h>
#include <blaze/math/constraints/DenseMatrix.h>
#include <blaze/math/constraints/Resizable.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/Exception.h>
#include <blaze/math/SparseMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/math/UniUpperMatrix.h>
#include <blaze/util/FalseType.h>
#include <blaze/util/Indices.h>
#include <blaze/util/Random.h>
#include <blaze/util/TrueType.h>
#include <blaze/util/Types.h>
#include <blaze/util/Unused.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for UniLowerMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of UniLowerMatrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
class Rand< UniLowerMatrix<MT,SO,DF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const UniLowerMatrix<MT,SO,DF> generate() const;
inline const UniLowerMatrix<MT,SO,DF> generate( size_t n ) const;
inline const UniLowerMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros ) const;
template< typename Arg >
inline const UniLowerMatrix<MT,SO,DF> generate( const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const UniLowerMatrix<MT,SO,DF> generate( size_t n, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const UniLowerMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( UniLowerMatrix<MT,SO,DF>& matrix ) const;
inline void randomize( UniLowerMatrix<MT,false,DF>& matrix, size_t nonzeros ) const;
inline void randomize( UniLowerMatrix<MT,true,DF>& matrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( UniLowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( UniLowerMatrix<MT,false,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( UniLowerMatrix<MT,true,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
private:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( UniLowerMatrix<MT,SO,DF>& matrix, TrueType ) const;
inline void randomize( UniLowerMatrix<MT,SO,DF>& matrix, FalseType ) const;
template< typename Arg >
inline void randomize( UniLowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, TrueType ) const;
template< typename Arg >
inline void randomize( UniLowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, FalseType ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniLowerMatrix.
//
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const UniLowerMatrix<MT,SO,DF> Rand< UniLowerMatrix<MT,SO,DF> >::generate() const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
UniLowerMatrix<MT,SO,DF> matrix;
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniLowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const UniLowerMatrix<MT,SO,DF>
Rand< UniLowerMatrix<MT,SO,DF> >::generate( size_t n ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
UniLowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniLowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const UniLowerMatrix<MT,SO,DF>
Rand< UniLowerMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > UniLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
UniLowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniLowerMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const UniLowerMatrix<MT,SO,DF>
Rand< UniLowerMatrix<MT,SO,DF> >::generate( const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
UniLowerMatrix<MT,SO,DF> matrix;
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniLowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const UniLowerMatrix<MT,SO,DF>
Rand< UniLowerMatrix<MT,SO,DF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
UniLowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniLowerMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const UniLowerMatrix<MT,SO,DF>
Rand< UniLowerMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > UniLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
UniLowerMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UniLowerMatrix<MT,SO,DF> >::randomize( UniLowerMatrix<MT,SO,DF>& matrix ) const
{
randomize( matrix, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UniLowerMatrix<MT,SO,DF> >::randomize( UniLowerMatrix<MT,SO,DF>& matrix, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=1UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
matrix(i,j) = rand<ET>();
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UniLowerMatrix<MT,SO,DF> >::randomize( UniLowerMatrix<MT,SO,DF>& matrix, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL || n == 1UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.2*n*n ) ) );
randomize( matrix, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UniLowerMatrix<MT,SO,DF> >::randomize( UniLowerMatrix<MT,false,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UniLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
matrix.finalize( 0UL );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 1UL, n-1UL );
if( dist[index] == index ) continue;
++dist[index];
++nz;
}
for( size_t i=1UL; i<n; ++i ) {
const Indices indices( 0UL, i-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UniLowerMatrix<MT,SO,DF> >::randomize( UniLowerMatrix<MT,true,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UniLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n-1UL );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-2UL );
if( dist[index] == n - index - 1UL ) continue;
++dist[index];
++nz;
}
for( size_t j=0UL; j<n-1UL; ++j ) {
const Indices indices( j+1UL, n-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( j );
}
matrix.finalize( n-1UL );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UniLowerMatrix<MT,SO,DF> >::randomize( UniLowerMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max ) const
{
randomize( matrix, min, max, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UniLowerMatrix<MT,SO,DF> >::randomize( UniLowerMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=1UL; i<n; ++i ) {
for( size_t j=0UL; j<i; ++j ) {
matrix(i,j) = rand<ET>( min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UniLowerMatrix<MT,SO,DF> >::randomize( UniLowerMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL || n == 1UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.2*n*n ) ) );
randomize( matrix, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UniLowerMatrix<MT,SO,DF> >::randomize( UniLowerMatrix<MT,false,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UniLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
matrix.finalize( 0UL );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 1UL, n-1UL );
if( dist[index] == index ) continue;
++dist[index];
++nz;
}
for( size_t i=1UL; i<n; ++i ) {
const Indices indices( 0UL, i-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UniLowerMatrix<MT,SO,DF> >::randomize( UniLowerMatrix<MT,true,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UniLowerMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n-1UL );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-2UL );
if( dist[index] == n - index - 1UL ) continue;
++dist[index];
++nz;
}
for( size_t j=0UL; j<n-1UL; ++j ) {
const Indices indices( j+1UL, n-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( j );
}
matrix.finalize( n-1UL );
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeSymmetric( UniLowerMatrix<MT,SO,DF>& matrix )
{
reset( matrix );
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeSymmetric( UniLowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
UNUSED_PARAMETER( min, max );
makeSymmetric( matrix );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeHermitian( UniLowerMatrix<MT,SO,DF>& matrix )
{
reset( matrix );
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeHermitian( UniLowerMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
UNUSED_PARAMETER( min, max );
makeHermitian( matrix );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite UniLowerMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makePositiveDefinite( UniLowerMatrix<MT,SO,DF>& matrix )
{
makeHermitian( matrix );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,785 @@
//=================================================================================================
/*!
// \file blaze/math/UniUpperMatrix.h
// \brief Header file for the complete UniUpperMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_UNIUPPERMATRIX_H_
#define _BLAZE_MATH_UNIUPPERMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <vector>
#include <blaze/math/Aliases.h>
#include <blaze/math/adaptors/UniUpperMatrix.h>
#include <blaze/math/constraints/DenseMatrix.h>
#include <blaze/math/constraints/Resizable.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/Exception.h>
#include <blaze/math/SparseMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/math/UniLowerMatrix.h>
#include <blaze/util/FalseType.h>
#include <blaze/util/Indices.h>
#include <blaze/util/Random.h>
#include <blaze/util/TrueType.h>
#include <blaze/util/Types.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for UniUpperMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of UniUpperMatrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
class Rand< UniUpperMatrix<MT,SO,DF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const UniUpperMatrix<MT,SO,DF> generate() const;
inline const UniUpperMatrix<MT,SO,DF> generate( size_t n ) const;
inline const UniUpperMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros ) const;
template< typename Arg >
inline const UniUpperMatrix<MT,SO,DF> generate( const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const UniUpperMatrix<MT,SO,DF> generate( size_t n, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const UniUpperMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( UniUpperMatrix<MT,SO,DF>& matrix ) const;
inline void randomize( UniUpperMatrix<MT,false,DF>& matrix, size_t nonzeros ) const;
inline void randomize( UniUpperMatrix<MT,true,DF>& matrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( UniUpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( UniUpperMatrix<MT,false,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( UniUpperMatrix<MT,true,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
private:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( UniUpperMatrix<MT,SO,DF>& matrix, TrueType ) const;
inline void randomize( UniUpperMatrix<MT,SO,DF>& matrix, FalseType ) const;
template< typename Arg >
inline void randomize( UniUpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, TrueType ) const;
template< typename Arg >
inline void randomize( UniUpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, FalseType ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniUpperMatrix.
//
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const UniUpperMatrix<MT,SO,DF> Rand< UniUpperMatrix<MT,SO,DF> >::generate() const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
UniUpperMatrix<MT,SO,DF> matrix;
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniUpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const UniUpperMatrix<MT,SO,DF>
Rand< UniUpperMatrix<MT,SO,DF> >::generate( size_t n ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
UniUpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniUpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const UniUpperMatrix<MT,SO,DF>
Rand< UniUpperMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
UniUpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniUpperMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const UniUpperMatrix<MT,SO,DF>
Rand< UniUpperMatrix<MT,SO,DF> >::generate( const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
UniUpperMatrix<MT,SO,DF> matrix;
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniUpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const UniUpperMatrix<MT,SO,DF>
Rand< UniUpperMatrix<MT,SO,DF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
UniUpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UniUpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const UniUpperMatrix<MT,SO,DF>
Rand< UniUpperMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
UniUpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UniUpperMatrix<MT,SO,DF> >::randomize( UniUpperMatrix<MT,SO,DF>& matrix ) const
{
randomize( matrix, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UniUpperMatrix<MT,SO,DF> >::randomize( UniUpperMatrix<MT,SO,DF>& matrix, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=i+1UL; j<n; ++j ) {
matrix(i,j) = rand<ET>();
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UniUpperMatrix<MT,SO,DF> >::randomize( UniUpperMatrix<MT,SO,DF>& matrix, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL || n == 1UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.2*n*n ) ) );
randomize( matrix, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UniUpperMatrix<MT,SO,DF> >::randomize( UniUpperMatrix<MT,false,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n-1UL );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-2UL );
if( dist[index] == n - index - 1UL ) continue;
++dist[index];
++nz;
}
for( size_t i=0UL; i<n-1UL; ++i ) {
const Indices indices( i+1UL, n-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( i );
}
matrix.finalize( n-1UL );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UniUpperMatrix<MT,SO,DF> >::randomize( UniUpperMatrix<MT,true,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
matrix.finalize( 0UL );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 1UL, n-1UL );
if( dist[index] == index ) continue;
++dist[index];
++nz;
}
for( size_t j=1UL; j<n; ++j ) {
const Indices indices( 0UL, j-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( j );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UniUpperMatrix<MT,SO,DF> >::randomize( UniUpperMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max ) const
{
randomize( matrix, min, max, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UniUpperMatrix<MT,SO,DF> >::randomize( UniUpperMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=i+1UL; j<n; ++j ) {
matrix(i,j) = rand<ET>( min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UniUpperMatrix<MT,SO,DF> >::randomize( UniUpperMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL || n == 1UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.2*n*n ) ) );
randomize( matrix, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UniUpperMatrix<MT,SO,DF> >::randomize( UniUpperMatrix<MT,false,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n-1UL );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-2UL );
if( dist[index] == n - index - 1UL ) continue;
++dist[index];
++nz;
}
for( size_t i=0UL; i<n-1UL; ++i ) {
const Indices indices( i+1UL, n-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( i );
}
matrix.finalize( n-1UL );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UniUpperMatrix<MT,SO,DF> >::randomize( UniUpperMatrix<MT,true,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UniUpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL || n == 1UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
matrix.finalize( 0UL );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 1UL, n-1UL );
if( dist[index] == index ) continue;
++dist[index];
++nz;
}
for( size_t j=1UL; j<n; ++j ) {
const Indices indices( 0UL, j-1UL, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( j );
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeSymmetric( UniUpperMatrix<MT,SO,DF>& matrix )
{
reset( matrix );
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeSymmetric( UniUpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
UNUSED_PARAMETER( min, max );
makeSymmetric( matrix );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeHermitian( UniUpperMatrix<MT,SO,DF>& matrix )
{
reset( matrix );
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeHermitian( UniUpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
UNUSED_PARAMETER( min, max );
makeHermitian( matrix );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite UniUpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makePositiveDefinite( UniUpperMatrix<MT,SO,DF>& matrix )
{
makeHermitian( matrix );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,810 @@
//=================================================================================================
/*!
// \file blaze/math/UpperMatrix.h
// \brief Header file for the complete UpperMatrix implementation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_UPPERMATRIX_H_
#define _BLAZE_MATH_UPPERMATRIX_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cmath>
#include <vector>
#include <blaze/math/Aliases.h>
#include <blaze/math/adaptors/UpperMatrix.h>
#include <blaze/math/constraints/DenseMatrix.h>
#include <blaze/math/constraints/Resizable.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/DenseMatrix.h>
#include <blaze/math/Exception.h>
#include <blaze/math/LowerMatrix.h>
#include <blaze/math/SparseMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/math/typetraits/UnderlyingBuiltin.h>
#include <blaze/util/FalseType.h>
#include <blaze/util/Indices.h>
#include <blaze/util/Random.h>
#include <blaze/util/TrueType.h>
#include <blaze/util/Types.h>
namespace blaze {
//=================================================================================================
//
// RAND SPECIALIZATION
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Specialization of the Rand class template for UpperMatrix.
// \ingroup random
//
// This specialization of the Rand class creates random instances of UpperMatrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
class Rand< UpperMatrix<MT,SO,DF> >
{
public:
//**Generate functions**************************************************************************
/*!\name Generate functions */
//@{
inline const UpperMatrix<MT,SO,DF> generate() const;
inline const UpperMatrix<MT,SO,DF> generate( size_t n ) const;
inline const UpperMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros ) const;
template< typename Arg >
inline const UpperMatrix<MT,SO,DF> generate( const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const UpperMatrix<MT,SO,DF> generate( size_t n, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline const UpperMatrix<MT,SO,DF> generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( UpperMatrix<MT,SO,DF>& matrix ) const;
inline void randomize( UpperMatrix<MT,false,DF>& matrix, size_t nonzeros ) const;
inline void randomize( UpperMatrix<MT,true,DF>& matrix, size_t nonzeros ) const;
template< typename Arg >
inline void randomize( UpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( UpperMatrix<MT,false,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
template< typename Arg >
inline void randomize( UpperMatrix<MT,true,DF>& matrix, size_t nonzeros,
const Arg& min, const Arg& max ) const;
//@}
//**********************************************************************************************
private:
//**Randomize functions*************************************************************************
/*!\name Randomize functions */
//@{
inline void randomize( UpperMatrix<MT,SO,DF>& matrix, TrueType ) const;
inline void randomize( UpperMatrix<MT,SO,DF>& matrix, FalseType ) const;
template< typename Arg >
inline void randomize( UpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, TrueType ) const;
template< typename Arg >
inline void randomize( UpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max, FalseType ) const;
//@}
//**********************************************************************************************
};
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UpperMatrix.
//
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const UpperMatrix<MT,SO,DF> Rand< UpperMatrix<MT,SO,DF> >::generate() const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
UpperMatrix<MT,SO,DF> matrix;
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const UpperMatrix<MT,SO,DF>
Rand< UpperMatrix<MT,SO,DF> >::generate( size_t n ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
UpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline const UpperMatrix<MT,SO,DF>
Rand< UpperMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
UpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UpperMatrix.
//
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const UpperMatrix<MT,SO,DF>
Rand< UpperMatrix<MT,SO,DF> >::generate( const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_NOT_BE_RESIZABLE( MT );
UpperMatrix<MT,SO,DF> matrix;
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const UpperMatrix<MT,SO,DF>
Rand< UpperMatrix<MT,SO,DF> >::generate( size_t n, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE( MT );
UpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Generation of a random UpperMatrix.
//
// \param n The number of rows and columns of the random matrix.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return The generated random matrix.
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline const UpperMatrix<MT,SO,DF>
Rand< UpperMatrix<MT,SO,DF> >::generate( size_t n, size_t nonzeros,
const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_RESIZABLE ( MT );
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
UpperMatrix<MT,SO,DF> matrix( n );
randomize( matrix, nonzeros, min, max );
return matrix;
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UpperMatrix<MT,SO,DF> >::randomize( UpperMatrix<MT,SO,DF>& matrix ) const
{
randomize( matrix, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UpperMatrix<MT,SO,DF> >::randomize( UpperMatrix<MT,SO,DF>& matrix, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=i; j<n; ++j ) {
matrix(i,j) = rand<ET>();
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UpperMatrix<MT,SO,DF> >::randomize( UpperMatrix<MT,SO,DF>& matrix, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.3*n*n ) ) );
randomize( matrix, nonzeros );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UpperMatrix<MT,SO,DF> >::randomize( UpperMatrix<MT,false,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-1UL );
if( dist[index] == n - index ) continue;
++dist[index];
++nz;
}
for( size_t i=0UL; i<n; ++i ) {
const Indices indices( i, n-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
inline void Rand< UpperMatrix<MT,SO,DF> >::randomize( UpperMatrix<MT,true,DF>& matrix, size_t nonzeros ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-1UL );
if( dist[index] == index+1UL ) continue;
++dist[index];
++nz;
}
for( size_t j=0UL; j<n; ++j ) {
const Indices indices( 0UL, j, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>() );
}
matrix.finalize( j );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UpperMatrix<MT,SO,DF> >::randomize( UpperMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max ) const
{
randomize( matrix, min, max, typename IsDenseMatrix<MT>::Type() );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a dense UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UpperMatrix<MT,SO,DF> >::randomize( UpperMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, TrueType ) const
{
BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
for( size_t i=0UL; i<n; ++i ) {
for( size_t j=i; j<n; ++j ) {
matrix(i,j) = rand<ET>( min, max );
}
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a sparse UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UpperMatrix<MT,SO,DF> >::randomize( UpperMatrix<MT,SO,DF>& matrix,
const Arg& min, const Arg& max, FalseType ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
const size_t n( matrix.rows() );
if( n == 0UL ) return;
const size_t nonzeros( rand<size_t>( 1UL, std::ceil( 0.3*n*n ) ) );
randomize( matrix, nonzeros, min, max );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a row-major sparse UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UpperMatrix<MT,SO,DF> >::randomize( UpperMatrix<MT,false,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-1UL );
if( dist[index] == n - index ) continue;
++dist[index];
++nz;
}
for( size_t i=0UL; i<n; ++i ) {
const Indices indices( i, n-1UL, dist[i] );
for( size_t j : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( i );
}
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Randomization of a column-major sparse UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param nonzeros The number of non-zero elements of the random matrix.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
// \exception std::invalid_argument Invalid number of non-zero elements.
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Numeric flag
template< typename Arg > // Min/max argument type
inline void Rand< UpperMatrix<MT,SO,DF> >::randomize( UpperMatrix<MT,true,DF>& matrix,
size_t nonzeros, const Arg& min, const Arg& max ) const
{
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE( MT );
typedef ElementType_<MT> ET;
const size_t n( matrix.rows() );
if( nonzeros > UpperMatrix<MT,SO,DF>::maxNonZeros( n ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid number of non-zero elements" );
}
if( n == 0UL ) return;
matrix.reset();
matrix.reserve( nonzeros );
std::vector<size_t> dist( n );
for( size_t nz=0UL; nz<nonzeros; ) {
const size_t index = rand<size_t>( 0UL, n-1UL );
if( dist[index] == index+1UL ) continue;
++dist[index];
++nz;
}
for( size_t j=0UL; j<n; ++j ) {
const Indices indices( 0UL, j, dist[j] );
for( size_t i : indices ) {
matrix.append( i, j, rand<ET>( min, max ) );
}
matrix.finalize( j );
}
}
/*! \endcond */
//*************************************************************************************************
//=================================================================================================
//
// MAKE FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeSymmetric( UpperMatrix<MT,SO,DF>& matrix )
{
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand< ElementType_<MT> >();
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random symmetric UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeSymmetric( UpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
typedef ElementType_<MT> Type;
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<Type>( min, max );
}
BLAZE_INTERNAL_ASSERT( isSymmetric( matrix ), "Non-symmetric matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makeHermitian( UpperMatrix<MT,SO,DF>& matrix )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > Type;
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<Type>();
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random Hermitian UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \param min The smallest possible value for a matrix element.
// \param max The largest possible value for a matrix element.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF // Density flag
, typename Arg > // Min/max argument type
void makeHermitian( UpperMatrix<MT,SO,DF>& matrix, const Arg& min, const Arg& max )
{
typedef UnderlyingBuiltin_< ElementType_<MT> > Type;
const size_t n( matrix.rows() );
reset( matrix );
for( size_t i=0UL; i<n; ++i ) {
matrix(i,i) = rand<Type>( min, max );
}
BLAZE_INTERNAL_ASSERT( isHermitian( matrix ), "Non-Hermitian matrix detected" );
}
/*! \endcond */
//*************************************************************************************************
//*************************************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Setup of a random (Hermitian) positive definite UpperMatrix.
//
// \param matrix The matrix to be randomized.
// \return void
*/
template< typename MT // Type of the adapted matrix
, bool SO // Storage order of the adapted matrix
, bool DF > // Density flag
void makePositiveDefinite( UpperMatrix<MT,SO,DF>& matrix )
{
makeHermitian( matrix );
}
/*! \endcond */
//*************************************************************************************************
} // namespace blaze
#endif

378
src/cpu/blaze/math/Vector.h Normal file
View File

@ -0,0 +1,378 @@
//=================================================================================================
/*!
// \file blaze/math/Vector.h
// \brief Header file for all basic Vector functionality
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_VECTOR_H_
#define _BLAZE_MATH_VECTOR_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <iomanip>
#include <ostream>
#include <blaze/math/Aliases.h>
#include <blaze/math/expressions/Vector.h>
#include <blaze/math/traits/MultTrait.h>
#include <blaze/math/TransposeFlag.h>
namespace blaze {
//=================================================================================================
//
// GLOBAL OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\name Vector operators */
//@{
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
operator,( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
operator,( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
operator,( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
operator,( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
dot( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
dot( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
dot( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
dot( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
outer( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
outer( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
outer( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs );
template< typename T1, typename T2 >
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
outer( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs );
template< typename VT, bool TF >
inline std::ostream& operator<<( std::ostream& os, const Vector<VT,TF>& v );
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the scalar product (dot product) of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the scalar product.
// \param rhs The right-hand side vector for the scalar product.
// \return The scalar product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
operator,( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs )
{
return trans(~lhs) * (~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the scalar product (dot product) of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the scalar product.
// \param rhs The right-hand side vector for the scalar product.
// \return The scalar product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
operator,( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs )
{
return trans(~lhs) * trans(~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the scalar product (dot product) of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the scalar product.
// \param rhs The right-hand side vector for the scalar product.
// \return The scalar product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
operator,( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs )
{
return (~lhs) * (~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the scalar product (dot product) of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the scalar product.
// \param rhs The right-hand side vector for the scalar product.
// \return The scalar product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
operator,( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs )
{
return (~lhs) * trans(~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the scalar product (dot product) of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the scalar product.
// \param rhs The right-hand side vector for the scalar product.
// \return The scalar product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
dot( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs )
{
return trans(~lhs) * (~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the scalar product (dot product) of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the scalar product.
// \param rhs The right-hand side vector for the scalar product.
// \return The scalar product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
dot( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs )
{
return trans(~lhs) * trans(~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the scalar product (dot product) of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the scalar product.
// \param rhs The right-hand side vector for the scalar product.
// \return The scalar product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
dot( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs )
{
return (~lhs) * (~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the scalar product (dot product) of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the scalar product.
// \param rhs The right-hand side vector for the scalar product.
// \return The scalar product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
dot( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs )
{
return (~lhs) * trans(~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the outer product of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the outer product.
// \param rhs The right-hand side vector for the outer product.
// \return The outer product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
outer( const Vector<T1,false>& lhs, const Vector<T2,false>& rhs )
{
return (~lhs) * trans(~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the outer product of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the outer product.
// \param rhs The right-hand side vector for the outer product.
// \return The outer product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
outer( const Vector<T1,false>& lhs, const Vector<T2,true>& rhs )
{
return (~lhs) * (~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the outer product of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the outer product.
// \param rhs The right-hand side vector for the outer product.
// \return The outer product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
outer( const Vector<T1,true>& lhs, const Vector<T2,false>& rhs )
{
return trans(~lhs) * trans(~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication operator for the outer product of two vectors
// (\f$ s=(\vec{a},\vec{b}) \f$).
// \ingroup vector
//
// \param lhs The left-hand side vector for the outer product.
// \param rhs The right-hand side vector for the outer product.
// \return The outer product.
*/
template< typename T1 // Type of the left-hand side vector
, typename T2 > // Type of the right-hand side vector
inline const MultTrait_< ElementType_<T1>, ElementType_<T2> >
outer( const Vector<T1,true>& lhs, const Vector<T2,true>& rhs )
{
return trans(~lhs) * (~rhs);
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Global output operator for dense and sparse vectors.
// \ingroup vector
//
// \param os Reference to the output stream.
// \param v Reference to a constant vector object.
// \return Reference to the output stream.
*/
template< typename VT // Type of the vector
, bool TF > // Transpose flag
inline std::ostream& operator<<( std::ostream& os, const Vector<VT,TF>& v )
{
CompositeType_<VT> tmp( ~v );
if( tmp.size() == 0UL ) {
os << "( )\n";
}
else if( TF == rowVector ) {
os << "(";
for( size_t i=0UL; i<tmp.size(); ++i )
os << " " << tmp[i];
os << " )\n";
}
else {
for( size_t i=0UL; i<tmp.size(); ++i )
os << "( " << std::setw( 11UL ) << tmp[i] << " )\n";
}
return os;
}
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,48 @@
//=================================================================================================
/*!
// \file blaze/math/Views.h
// \brief Header file for the vector and matrix views
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_VIEWS_H_
#define _BLAZE_MATH_VIEWS_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/Column.h>
#include <blaze/math/Row.h>
#include <blaze/math/Submatrix.h>
#include <blaze/math/Subvector.h>
#endif

View File

@ -0,0 +1,51 @@
//=================================================================================================
/*!
// \file blaze/math/adaptors/Adaptors.h
// \brief Adaptors module documentation
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ADAPTORS_ADAPTORS_H_
#define _BLAZE_MATH_ADAPTORS_ADAPTORS_H_
//=================================================================================================
//
// DOXYGEN DOCUMENTATION
//
//=================================================================================================
//*************************************************************************************************
/*!\defgroup adaptors Adaptors
// \ingroup math
*/
//*************************************************************************************************
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,59 @@
//=================================================================================================
/*!
// \file blaze/math/adaptors/Forward.h
// \brief Header file for all adaptor forward declarations
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ADAPTORS_FORWARD_H_
#define _BLAZE_MATH_ADAPTORS_FORWARD_H_
namespace blaze {
//=================================================================================================
//
// ::blaze NAMESPACE FORWARD DECLARATIONS
//
//=================================================================================================
template< typename, bool, bool > class DiagonalMatrix;
template< typename, bool, bool > class LowerMatrix;
template< typename, bool, bool > class HermitianMatrix;
template< typename, bool, bool > class StrictlyLowerMatrix;
template< typename, bool, bool > class StrictlyUpperMatrix;
template< typename, bool, bool, bool > class SymmetricMatrix;
template< typename, bool, bool > class UniLowerMatrix;
template< typename, bool, bool > class UniUpperMatrix;
template< typename, bool, bool > class UpperMatrix;
} // namespace blaze
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,562 @@
//=================================================================================================
/*!
// \file blaze/math/adaptors/diagonalmatrix/BaseTemplate.h
// \brief Header file for the implementation of the base template of the DiagonalMatrix
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_BASETEMPLATE_H_
#define _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_BASETEMPLATE_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/typetraits/IsColumnMajorMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
namespace blaze {
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/*!\defgroup diagonal_matrix DiagonalMatrix
// \ingroup adaptors
*/
/*!\brief Matrix adapter for diagonal \f$ N \times N \f$ matrices.
// \ingroup diagonal_matrix
//
// \section diagonalmatrix_general General
//
// The DiagonalMatrix class template is an adapter for existing dense and sparse matrix types.
// It inherits the properties and the interface of the given matrix type \a MT and extends it by
// enforcing the additional invariant that all matrix elements above and below the diagonal are
// 0 (diagonal matrix). The type of the adapted matrix can be specified via the first template
// parameter:
\code
template< typename MT, bool SO, bool DF >
class DiagonalMatrix;
\endcode
// - MT: specifies the type of the matrix to be adapted. DiagonalMatrix can be used with any
// non-cv-qualified, non-reference, non-pointer, non-expression dense or sparse matrix
// type. Note that the given matrix type must be either resizable (as for instance
// HybridMatrix or DynamicMatrix) or must be square at compile time (as for instance
// StaticMatrix).
// - SO: specifies the storage order (blaze::rowMajor, blaze::columnMajor) of the matrix. This
// template parameter doesn't have to be explicitly defined, but is automatically derived
// from the first template parameter.
// - DF: specifies whether the given matrix type is a dense or sparse matrix type. This template
// parameter doesn't have to be defined explicitly, it is automatically derived from the
// first template parameter. Defining the parameter explicitly may result in a compilation
// error!
//
// The following examples give an impression of several possible diagonal matrices:
\code
using blaze::unaligned;
using blaze::unpadded;
using blaze::rowMajor;
using blaze::columnMajor;
// Definition of a 3x3 row-major dense diagonal matrix with static memory
blaze::DiagonalMatrix< blaze::StaticMatrix<int,3UL,3UL,rowMajor> > A;
// Definition of a resizable column-major dense diagonal matrix based on HybridMatrix
blaze::DiagonalMatrix< blaze::HybridMatrix<float,4UL,4UL,columnMajor> B;
// Definition of a resizable row-major dense diagonal matrix based on DynamicMatrix
blaze::DiagonalMatrix< blaze::DynamicMatrix<double,rowMajor> > C;
// Definition of a fixed-size row-major dense diagonal matrix based on CustomMatrix
blaze::DiagonalMatrix< blaze::CustomMatrix<double,unaligned,unpadded,rowMajor> > D;
// Definition of a compressed row-major single precision diagonal matrix
blaze::DiagonalMatrix< blaze::CompressedMatrix<float,rowMajor> > E;
\endcode
// The storage order of a diagonal matrix is depending on the storage order of the adapted matrix
// type \a MT. In case the adapted matrix is stored in a row-wise fashion (i.e. is specified
// as blaze::rowMajor), the diagonal matrix will also be a row-major matrix. Otherwise, if the
// adapted matrix is column-major (i.e. is specified as blaze::columnMajor), the diagonal matrix
// will also be a column-major matrix.
//
//
// \n \section diagonalmatrix_special_properties Special Properties of Diagonal Matrices
//
// A diagonal matrix is used exactly like a matrix of the underlying, adapted matrix type \a MT.
// It also provides (nearly) the same interface as the underlying matrix type. However, there
// are some important exceptions resulting from the diagonal matrix constraint:
//
// -# <b>\ref diagonalmatrix_square</b>
// -# <b>\ref diagonalmatrix_diagonal</b>
// -# <b>\ref diagonalmatrix_initialization</b>
// -# <b>\ref diagonalmatrix_storage</b>
//
// \n \subsection diagonalmatrix_square Diagonal Matrices Must Always be Square!
//
// In case a resizable matrix is used (as for instance blaze::HybridMatrix, blaze::DynamicMatrix,
// or blaze::CompressedMatrix), this means that the according constructors, the \c resize() and
// the \c extend() functions only expect a single parameter, which specifies both the number of
// rows and columns, instead of two (one for the number of rows and one for the number of columns):
\code
using blaze::DynamicMatrix;
using blaze::DiagonalMatrix;
using blaze::rowMajor;
// Default constructed, default initialized, row-major 3x3 diagonal dynamic matrix
DiagonalMatrix< DynamicMatrix<double,rowMajor> > A( 3 );
// Resizing the matrix to 5x5
A.resize( 5 );
// Extending the number of rows and columns by 2, resulting in a 7x7 matrix
A.extend( 2 );
\endcode
// In case a matrix with a fixed size is used (as for instance blaze::StaticMatrix), the number
// of rows and number of columns must be specified equally:
\code
using blaze::StaticMatrix;
using blaze::DiagonalMatrix;
using blaze::columnMajor;
// Correct setup of a fixed size column-major 3x3 diagonal static matrix
DiagonalMatrix< StaticMatrix<int,3UL,3UL,columnMajor> > A;
// Compilation error: the provided matrix type is not a square matrix type
DiagonalMatrix< StaticMatrix<int,3UL,4UL,columnMajor> > B;
\endcode
// \n \subsection diagonalmatrix_diagonal The Diagonal Matrix Property is Always Enforced!
//
// This means that it is only allowed to modify elements on the the diagonal of the matrix, but
// not the elements in the lower or upper part of the matrix. Also, it is only possible to assign
// matrices that are diagonal matrices themselves:
\code
using blaze::CompressedMatrix;
using blaze::DynamicMatrix;
using blaze::StaticMatrix;
using blaze::DiagonalMatrix;
using blaze::rowMajor;
typedef DiagonalMatrix< CompressedMatrix<double,rowMajor> > CompressedDiagonal;
// Default constructed, row-major 3x3 diagonal compressed matrix
CompressedDiagonal A( 3 );
// Initializing elements via the function call operator
A(0,0) = 1.0; // Initialization of the diagonal element (0,0)
A(1,0) = 9.0; // Throws an exception; invalid modification of lower element
// Inserting more elements via the insert() function
A.insert( 1, 1, 3.0 ); // Inserting the diagonal element (1,1)
A.insert( 0, 2, 9.0 ); // Throws an exception; invalid insertion of upper element
// Appending an element via the append() function
A.reserve( 2, 1 ); // Reserving enough capacity in row 2
A.append( 2, 2, 5.0 ); // Appending the diagonal element (2,2)
A.append( 1, 2, 9.0 ); // Throws an exception; appending an element in the upper part
// Access via a non-const iterator
CompressedDiagonal::Iterator it = A.begin(1);
*it = 6.0; // Modifies the element (1,1)
// Erasing elements via the erase() function
A.erase( 0, 0 ); // Erasing the diagonal element (0,0)
A.erase( 2, 2 ); // Erasing the diagonal element (2,2)
// Construction from a diagonal dense matrix
StaticMatrix<double,3UL,3UL> B( 3.0, 0.0, 0.0,
0.0, -2.0, 0.0,
0.0, 0.0, 4.0 );
DiagonalMatrix< DynamicMatrix<double,rowMajor> > C( B ); // OK
// Assignment of a non-diagonal dense matrix
StaticMatrix<double,3UL,3UL> D( 3.0, 0.0, 9.0,
0.0, -2.0, 0.0,
0.0, 0.0, 4.0 );
C = D; // Throws an exception; diagonal matrix invariant would be violated!
\endcode
// The diagonal matrix property is also enforced for diagonal custom matrices: In case the given
// array of elements does not represent a diagonal matrix, a \a std::invalid_argument exception is
// thrown:
\code
using blaze::CustomMatrix;
using blaze::DiagonalMatrix;
using blaze::unaligned;
using blaze::unpadded;
using blaze::rowMajor;
typedef DiagonalMatrix< CustomMatrix<double,unaligned,unpadded,rowMajor> > CustomDiagonal;
// Creating a 3x3 diagonal custom matrix from a properly initialized array
double array[9] = { 1.0, 0.0, 0.0,
0.0, 2.0, 0.0,
0.0, 0.0, 3.0 };
CustomDiagonal A( array, 3UL ); // OK
// Attempt to create a second 3x3 diagonal custom matrix from an uninitialized array
CustomDiagonal B( new double[9UL], 3UL, blaze::ArrayDelete() ); // Throws an exception
\endcode
// Finally, the diagonal matrix property is enforced for views (rows, columns, submatrices, ...)
// on the diagonal matrix. The following example demonstrates that modifying the elements of an
// entire row and submatrix of a diagonal matrix only affects the diagonal matrix elements:
\code
using blaze::DynamicMatrix;
using blaze::DiagonalMatrix;
// Setup of the diagonal matrix
//
// ( 0 0 0 0 )
// A = ( 0 1 0 0 )
// ( 0 0 2 0 )
// ( 0 0 0 3 )
//
DiagonalMatrix< DynamicMatrix<int> > A( 4 );
A(1,1) = 1;
A(2,2) = 2;
A(3,3) = 3;
// Setting the diagonal element in the 2nd row to 9 results in the matrix
//
// ( 0 0 0 0 )
// A = ( 0 1 0 0 )
// ( 0 0 9 0 )
// ( 0 0 0 3 )
//
row( A, 2 ) = 9;
// Setting the diagonal element in the 1st and 2nd column to 7 results in
//
// ( 0 0 0 0 )
// A = ( 0 7 0 0 )
// ( 0 0 7 0 )
// ( 0 0 0 3 )
//
submatrix( A, 0, 1, 4, 2 ) = 7;
\endcode
// The next example demonstrates the (compound) assignment to rows/columns and submatrices of
// diagonal matrices. Since only diagonal elements may be modified the matrix to be assigned
// must be structured such that the diagonal matrix invariant of the diagonal matrix is
// preserved. Otherwise a \a std::invalid_argument exception is thrown:
\code
using blaze::DynamicMatrix;
using blaze::DynamicVector;
using blaze::DiagonalMatrix;
using blaze::rowVector;
// Setup of two default 4x4 diagonal matrices
DiagonalMatrix< DynamicMatrix<int> > A1( 4 ), A2( 4 );
// Setup of a 4-dimensional vector
//
// v = ( 0 0 3 0 )
//
DynamicVector<int,rowVector> v( 4, 0 );
v[2] = 3;
// OK: Assigning v to the 2nd row of A1 preserves the diagonal matrix invariant
//
// ( 0 0 0 0 )
// A1 = ( 0 0 0 0 )
// ( 0 0 3 0 )
// ( 0 0 0 0 )
//
row( A1, 2 ) = v; // OK
// Error: Assigning v to the 1st row of A1 violates the diagonal matrix invariant! The element
// marked with X cannot be assigned and triggers an exception.
//
// ( 0 0 0 0 )
// A1 = ( 0 0 X 0 )
// ( 0 0 3 0 )
// ( 0 0 0 0 )
//
row( A1, 1 ) = v; // Assignment throws an exception!
// Setup of the 3x2 dynamic matrix
//
// ( 0 0 )
// B = ( 2 0 )
// ( 0 3 )
//
DynamicMatrix<int> B( 3UL, 2UL, 0 );
B(1,0) = 2;
B(2,1) = 3;
// OK: Assigning B to a submatrix of A2 such that the diagonal matrix invariant can be preserved
//
// ( 0 0 0 0 )
// A2 = ( 0 2 0 0 )
// ( 0 0 3 0 )
// ( 0 0 0 0 )
//
submatrix( A2, 0UL, 1UL, 3UL, 2UL ) = B; // OK
// Error: Assigning B to a submatrix of A2 such that the diagonal matrix invariant cannot be
// preserved! The elements marked with X cannot be assigned without violating the invariant!
//
// ( 0 0 0 0 )
// A2 = ( 0 2 X 0 )
// ( 0 0 3 X )
// ( 0 0 0 0 )
//
submatrix( A2, 0UL, 2UL, 3UL, 2UL ) = B; // Assignment throws an exception!
\endcode
// \n \subsection diagonalmatrix_initialization The Lower and Upper Elements of a Dense Diagonal Matrix are Always Default Initialized!
//
// Although this results in a small loss of efficiency during the creation of a dense diagonal
// matrix this initialization is important since otherwise the diagonal matrix property of dense
// diagonal matrices would not be guaranteed:
\code
using blaze::DynamicMatrix;
using blaze::DiagonalMatrix;
// Uninitialized, 5x5 row-major diagonal matrix
DynamicMatrix<int,rowMajor> A( 5, 5 );
// 5x5 row-major diagonal dynamic matrix with default initialized lower and upper matrix
DiagonalMatrix< DynamicMatrix<int,rowMajor> > B( 5 );
\endcode
// \n \subsection diagonalmatrix_storage Dense Diagonal Matrices Also Store the Non-diagonal Elements!
//
// It is very important to note that dense diagonal matrices store all elements, including the
// non-diagonal elements, and therefore don't provide any kind of memory reduction! There are
// two main reasons for this: First, storing also the non-diagonal elements guarantees maximum
// performance for many algorithms that perform vectorized operations on the diagonal matrix,
// which is especially true for small dense matrices. Second, conceptually the DiagonalMatrix
// adaptor merely restricts the interface to the matrix type \a MT and does not change the data
// layout or the underlying matrix type. Thus, in order to achieve the perfect combination of
// performance and memory consumption it is recommended to use dense matrices for small diagonal
// matrices and sparse matrices for large diagonal matrices:
\code
// Recommendation 1: use dense matrices for small diagonal matrices
typedef blaze::DiagonalMatrix< blaze::StaticMatrix<float,3UL,3UL> > SmallDiagonalMatrix;
// Recommendation 2: use sparse matrices for large diagonal matrices
typedef blaze::DiagonalMatrix< blaze::CompressedMatrix<float> > LargeDiagonalMatrix;
\endcode
// \n \section diagonalmatrix_arithmetic_operations Arithmetic Operations
//
// A DiagonalMatrix matrix can participate in numerical operations in any way any other dense or
// sparse matrix can participate. It can also be combined with any other dense or sparse vector
// or matrix. The following code example gives an impression of the use of DiagonalMatrix within
// arithmetic operations:
\code
using blaze::DiagonalMatrix;
using blaze::DynamicMatrix;
using blaze::HybridMatrix;
using blaze::StaticMatrix;
using blaze::CompressedMatrix;
using blaze::rowMajor;
using blaze::columnMajor;
DynamicMatrix<double,rowMajor> A( 3, 3 );
CompressedMatrix<double,rowMajor> B( 3, 3 );
DiagonalMatrix< DynamicMatrix<double,rowMajor> > C( 3 );
DiagonalMatrix< CompressedMatrix<double,rowMajor> > D( 3 );
DiagonalMatrix< HybridMatrix<float,3UL,3UL,rowMajor> > E;
DiagonalMatrix< StaticMatrix<float,3UL,3UL,columnMajor> > F;
E = A + B; // Matrix addition and assignment to a row-major diagonal matrix
F = C - D; // Matrix subtraction and assignment to a column-major diagonal matrix
F = A * D; // Matrix multiplication between a dense and a sparse matrix
C *= 2.0; // In-place scaling of matrix C
E = 2.0 * B; // Scaling of matrix B
F = C * 2.0; // Scaling of matrix C
E += A - B; // Addition assignment
F -= C + D; // Subtraction assignment
F *= A * D; // Multiplication assignment
\endcode
// \n \section diagonalmatrix_block_structured Block-Structured Diagonal Matrices
//
// It is also possible to use block-structured diagonal matrices:
\code
using blaze::CompressedMatrix;
using blaze::StaticMatrix;
using blaze::DiagonalMatrix;
// Definition of a 5x5 block-structured diagonal matrix based on CompressedMatrix
DiagonalMatrix< CompressedMatrix< StaticMatrix<int,3UL,3UL> > > A( 5 );
\endcode
// Also in this case the diagonal matrix invariant is enforced, i.e. it is not possible to
// manipulate elements in the lower and upper part of the matrix:
\code
const StaticMatrix<int,3UL,3UL> B( { { 1, -4, 5 },
{ 6, 8, -3 },
{ 2, -1, 2 } } )
A.insert( 2, 2, B ); // Inserting the diagonal elements (2,2)
A(2,4)(1,1) = -5; // Invalid manipulation of upper matrix element; Results in an exception
\endcode
// \n \section diagonalmatrix_performance Performance Considerations
//
// The \b Blaze library tries to exploit the properties of diagonal matrices whenever and wherever
// possible. In fact, diagonal matrices come with several special kernels and additionally profit
// from all optimizations for symmetric and triangular matrices. Thus using a diagonal matrix
// instead of a general matrix can result in a considerable performance improvement. However,
// there are also situations when using a diagonal triangular matrix introduces some overhead. The
// following examples demonstrate several common situations where diagonal matrices can positively
// or negatively impact performance.
//
// \n \subsection diagonalmatrix_matrix_matrix_multiplication Positive Impact: Matrix/Matrix Multiplication
//
// When multiplying two matrices, at least one of which is diagonal, \b Blaze can exploit the fact
// that the lower and upper part of the matrix contains only default elements and restrict the
// algorithm to the diagonal elements. The following example demonstrates this by means of a dense
// matrix/dense matrix multiplication:
\code
using blaze::DynamicMatrix;
using blaze::DiagonalMatrix;
using blaze::rowMajor;
using blaze::columnMajor;
DiagonalMatrix< DynamicMatrix<double,rowMajor> > A;
DynamicMatrix<double,columnMajor> B, C;
// ... Resizing and initialization
C = A * B;
\endcode
// In comparison to a general matrix multiplication, the performance advantage is significant,
// especially for large matrices. In this particular case, the multiplication performs similarly
// to a matrix addition since the complexity is reduced from \f$ O(N^3) \f$ to \f$ O(N^2) \f$.
// Therefore is it highly recommended to use the DiagonalMatrix adaptor when a matrix is known
// to be diagonal. Note however that the performance advantage is most pronounced for dense
// matrices and much less so for sparse matrices.
//
// \n \subsection diagonalmatrix_matrix_vector_multiplication Positive Impact: Matrix/Vector Multiplication
//
// A similar performance improvement can be gained when using a diagonal matrix in a matrix/vector
// multiplication:
\code
using blaze::DynamicMatrix;
using blaze::DynamicVector;
using blaze::DiagonalMatrix;
using blaze::rowMajor;
using blaze::columnVector;
DiagonalMatrix< DynamicMatrix<double,rowMajor> > A;
DynamicVector<double,columnVector> x, y;
// ... Resizing and initialization
y = A * x;
\endcode
// In this example, \b Blaze also exploits the structure of the matrix and performs similarly to
// a vector addition. Also in case of matrix/vector multiplications the performance improvement
// is most pronounced for dense matrices and much less so for sparse matrices.
//
// \n \subsection diagonalmatrix_assignment Negative Impact: Assignment of a General Matrix
//
// In contrast to using a diagonal matrix on the right-hand side of an assignment (i.e. for read
// access), which introduces absolutely no performance penalty, using a diagonal matrix on the
// left-hand side of an assignment (i.e. for write access) may introduce additional overhead when
// it is assigned a general matrix, which is not diagonal at compile time:
\code
using blaze::DynamicMatrix;
using blaze::DiagonalMatrix;
DiagonalMatrix< DynamicMatrix<double> > A, C;
DynamicMatrix<double> B;
B = A; // Only read-access to the diagonal matrix; no performance penalty
C = A; // Assignment of a diagonal matrix to another diagonal matrix; no runtime overhead
C = B; // Assignment of a general matrix to a diagonal matrix; some runtime overhead
\endcode
// When assigning a general, potentially not diagonal matrix to a diagonal matrix it is necessary
// to check whether the matrix is diagonal at runtime in order to guarantee the diagonal property
// of the diagonal matrix. In case it turns out to be diagonal, it is assigned as efficiently as
// possible, if it is not, an exception is thrown. In order to prevent this runtime overhead it
// is therefore generally advisable to assign diagonal matrices to other diagonal matrices.\n
// In this context it is especially noteworthy that the addition, subtraction, and multiplication
// of two diagonal matrices always results in another diagonal matrix:
\code
using blaze::DynamicMatrix;
using blaze::DiagonalMatrix;
DiagonalMatrix< DynamicMatrix<double> > A, B, C;
C = A + B; // Results in a diagonal matrix; no runtime overhead
C = A - B; // Results in a diagonal matrix; no runtime overhead
C = A * B; // Results in a diagonal matrix; no runtime overhead
\endcode
*/
template< typename MT // Type of the adapted matrix
, bool SO = IsColumnMajorMatrix<MT>::value // Storage order of the adapted matrix
, bool DF = IsDenseMatrix<MT>::value > // Density flag
class DiagonalMatrix
{};
//*************************************************************************************************
} // namespace blaze
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,665 @@
//=================================================================================================
/*!
// \file blaze/math/adaptors/diagonalmatrix/DiagonalProxy.h
// \brief Header file for the DiagonalProxy class
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_DIAGONALPROXY_H_
#define _BLAZE_MATH_ADAPTORS_DIAGONALMATRIX_DIAGONALPROXY_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/Aliases.h>
#include <blaze/math/constraints/Expression.h>
#include <blaze/math/constraints/Hermitian.h>
#include <blaze/math/constraints/Lower.h>
#include <blaze/math/constraints/Matrix.h>
#include <blaze/math/constraints/Symmetric.h>
#include <blaze/math/constraints/Upper.h>
#include <blaze/math/Exception.h>
#include <blaze/math/InitializerList.h>
#include <blaze/math/proxy/Proxy.h>
#include <blaze/math/shims/Clear.h>
#include <blaze/math/shims/IsDefault.h>
#include <blaze/math/shims/IsNaN.h>
#include <blaze/math/shims/IsOne.h>
#include <blaze/math/shims/IsReal.h>
#include <blaze/math/shims/IsZero.h>
#include <blaze/math/shims/Reset.h>
#include <blaze/util/constraints/Const.h>
#include <blaze/util/constraints/Pointer.h>
#include <blaze/util/constraints/Reference.h>
#include <blaze/util/constraints/Volatile.h>
#include <blaze/util/typetraits/AddConst.h>
#include <blaze/util/typetraits/AddReference.h>
#include <blaze/util/Types.h>
namespace blaze {
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Access proxy for diagonal matrices.
// \ingroup diagonal_matrix
//
// The DiagonalProxy provides controlled access to the elements of a non-const diagonal matrix.
// It guarantees that the diagonal matrix invariant is not violated, i.e. that elements in the
// lower and upper part of the matrix remain default values. The following example illustrates
// this by means of a \f$ 3 \times 3 \f$ dense diagonal matrix:
\code
// Creating a 3x3 dense diagonal matrix
blaze::DiagonalMatrix< blaze::DynamicMatrix<int> > A( 3UL );
A(0,0) = -2; // ( -2 0 0 )
A(1,1) = 3; // => A = ( 0 3 0 )
A(2,2) = 5; // ( 0 0 5 )
A(0,2) = 7; // Invalid assignment to upper matrix element; results in an exception!
\endcode
*/
template< typename MT > // Type of the adapted matrix
class DiagonalProxy : public Proxy< DiagonalProxy<MT>, ElementType_<MT> >
{
private:
//**Type definitions****************************************************************************
//! Reference type of the underlying matrix type.
typedef AddConst_< typename MT::Reference > ReferenceType;
//**********************************************************************************************
public:
//**Type definitions****************************************************************************
typedef ElementType_<MT> RepresentedType; //!< Type of the represented matrix element.
typedef AddReference_<ReferenceType> RawReference; //!< Reference-to-non-const to the represented element.
typedef const RepresentedType& ConstReference; //!< Reference-to-const to the represented element.
//**********************************************************************************************
//**Constructors********************************************************************************
/*!\name Constructors */
//@{
explicit inline DiagonalProxy( MT& matrix, size_t row, size_t column );
inline DiagonalProxy( const DiagonalProxy& dp );
//@}
//**********************************************************************************************
//**Destructor**********************************************************************************
// No explicitly declared destructor.
//**********************************************************************************************
//**Assignment operators************************************************************************
/*!\name Assignment operators */
//@{
inline DiagonalProxy& operator=( const DiagonalProxy& dp );
template< typename T >
inline DiagonalProxy& operator=( initializer_list<T> list );
template< typename T >
inline DiagonalProxy& operator=( initializer_list< initializer_list<T> > list );
template< typename T > inline DiagonalProxy& operator= ( const T& value );
template< typename T > inline DiagonalProxy& operator+=( const T& value );
template< typename T > inline DiagonalProxy& operator-=( const T& value );
template< typename T > inline DiagonalProxy& operator*=( const T& value );
template< typename T > inline DiagonalProxy& operator/=( const T& value );
//@}
//**********************************************************************************************
//**Utility functions***************************************************************************
/*!\name Utility functions */
//@{
inline RawReference get() const noexcept;
inline bool isRestricted() const noexcept;
//@}
//**********************************************************************************************
//**Conversion operator*************************************************************************
/*!\name Conversion operator */
//@{
inline operator ConstReference() const noexcept;
//@}
//**********************************************************************************************
private:
//**Member variables****************************************************************************
/*!\name Member variables */
//@{
ReferenceType value_; //!< Reference to the accessed matrix element.
const bool restricted_; //!< Access flag for the accessed matrix element.
/*!< The flag indicates if access to the matrix element is
restricted. It is \a true in case the proxy represents
an element in the lower or upper part of the matrix. */
//@}
//**********************************************************************************************
//**Compile time checks*************************************************************************
/*! \cond BLAZE_INTERNAL */
BLAZE_CONSTRAINT_MUST_BE_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_CONST ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE ( MT );
/*! \endcond */
//**********************************************************************************************
};
//*************************************************************************************************
//=================================================================================================
//
// CONSTRUCTORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Initialization constructor for a DiagonalProxy.
//
// \param matrix Reference to the adapted matrix.
// \param row The row-index of the accessed matrix element.
// \param column The column-index of the accessed matrix element.
*/
template< typename MT > // Type of the adapted matrix
inline DiagonalProxy<MT>::DiagonalProxy( MT& matrix, size_t row, size_t column )
: value_ ( matrix( row, column ) ) // Reference to the accessed matrix element
, restricted_( row != column ) // Access flag for the accessed matrix element
{}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief The copy constructor for DiagonalProxy.
//
// \param dp Diagonal proxy to be copied.
*/
template< typename MT > // Type of the adapted matrix
inline DiagonalProxy<MT>::DiagonalProxy( const DiagonalProxy& dp )
: value_ ( dp.value_ ) // Reference to the accessed matrix element
, restricted_( dp.restricted_ ) // Access flag for the accessed matrix element
{}
//*************************************************************************************************
//=================================================================================================
//
// OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Copy assignment operator for DiagonalProxy.
//
// \param dp Diagonal proxy to be copied.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to non-diagonal matrix element.
//
// In case the proxy represents a non-diagonal matrix element, a \a std::invalid_argument
// exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
inline DiagonalProxy<MT>& DiagonalProxy<MT>::operator=( const DiagonalProxy& dp )
{
if( restricted_ ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
}
value_ = dp.value_;
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Initializer list assignment to the accessed matrix element.
//
// \param list The list to be assigned to the matrix element.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to non-diagonal matrix element.
//
// In case the proxy represents a non-diagonal matrix element, a \a std::invalid_argument
// exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline DiagonalProxy<MT>& DiagonalProxy<MT>::operator=( initializer_list<T> list )
{
if( restricted_ ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
}
value_ = list;
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Initializer list assignment to the accessed matrix element.
//
// \param list The list to be assigned to the matrix element.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to non-diagonal matrix element.
//
// In case the proxy represents a non-diagonal matrix element, a \a std::invalid_argument
// exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline DiagonalProxy<MT>& DiagonalProxy<MT>::operator=( initializer_list< initializer_list<T> > list )
{
if( restricted_ ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
}
value_ = list;
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Assignment to the accessed matrix element.
//
// \param value The new value of the matrix element.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to non-diagonal matrix element.
//
// In case the proxy represents a non-diagonal matrix element, a \a std::invalid_argument
// exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline DiagonalProxy<MT>& DiagonalProxy<MT>::operator=( const T& value )
{
if( restricted_ ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
}
value_ = value;
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Addition assignment to the accessed matrix element.
//
// \param value The right-hand side value to be added to the matrix element.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to non-diagonal matrix element.
//
// In case the proxy represents a non-diagonal matrix element, a \a std::invalid_argument
// exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline DiagonalProxy<MT>& DiagonalProxy<MT>::operator+=( const T& value )
{
if( restricted_ ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
}
value_ += value;
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Subtraction assignment to the accessed matrix element.
//
// \param value The right-hand side value to be subtracted from the matrix element.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to non-diagonal matrix element.
//
// In case the proxy represents a non-diagonal matrix element, a \a std::invalid_argument
// exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline DiagonalProxy<MT>& DiagonalProxy<MT>::operator-=( const T& value )
{
if( restricted_ ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
}
value_ -= value;
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication assignment to the accessed matrix element.
//
// \param value The right-hand side value for the multiplication.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to non-diagonal matrix element.
//
// In case the proxy represents a non-diagonal matrix element, a \a std::invalid_argument
// exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline DiagonalProxy<MT>& DiagonalProxy<MT>::operator*=( const T& value )
{
if( restricted_ ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
}
value_ *= value;
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Division assignment to the accessed matrix element.
//
// \param value The right-hand side value for the division.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to non-diagonal matrix element.
//
// In case the proxy represents a non-diagonal matrix element, a \a std::invalid_argument
// exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline DiagonalProxy<MT>& DiagonalProxy<MT>::operator/=( const T& value )
{
if( restricted_ ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to non-diagonal matrix element" );
}
value_ /= value;
return *this;
}
//*************************************************************************************************
//=================================================================================================
//
// UTILITY FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Returning the value of the accessed matrix element.
//
// \return Direct/raw reference to the accessed matrix element.
*/
template< typename MT > // Type of the adapted matrix
inline typename DiagonalProxy<MT>::RawReference DiagonalProxy<MT>::get() const noexcept
{
return value_;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the proxy represents a restricted matrix element..
//
// \return \a true in case access to the matrix element is restricted, \a false if not.
*/
template< typename MT > // Type of the adapted matrix
inline bool DiagonalProxy<MT>::isRestricted() const noexcept
{
return restricted_;
}
//*************************************************************************************************
//=================================================================================================
//
// CONVERSION OPERATOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Conversion to the accessed matrix element.
//
// \return Reference-to-const to the accessed matrix element.
*/
template< typename MT > // Type of the adapted matrix
inline DiagonalProxy<MT>::operator ConstReference() const noexcept
{
return static_cast<ConstReference>( value_ );
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\name DiagonalProxy global functions */
//@{
template< typename MT >
inline void reset( const DiagonalProxy<MT>& proxy );
template< typename MT >
inline void clear( const DiagonalProxy<MT>& proxy );
template< typename MT >
inline bool isDefault( const DiagonalProxy<MT>& proxy );
template< typename MT >
inline bool isReal( const DiagonalProxy<MT>& proxy );
template< typename MT >
inline bool isZero( const DiagonalProxy<MT>& proxy );
template< typename MT >
inline bool isOne( const DiagonalProxy<MT>& proxy );
template< typename MT >
inline bool isnan( const DiagonalProxy<MT>& proxy );
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Resetting the represented element to the default initial values.
// \ingroup diagonal_matrix
//
// \param proxy The given access proxy.
// \return void
//
// This function resets the element represented by the numeric proxy to its default initial
// value.
*/
template< typename MT >
inline void reset( const DiagonalProxy<MT>& proxy )
{
using blaze::reset;
reset( proxy.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Clearing the represented element.
// \ingroup diagonal_matrix
//
// \param proxy The given access proxy.
// \return void
//
// This function clears the element represented by the numeric proxy to its default initial
// state.
*/
template< typename MT >
inline void clear( const DiagonalProxy<MT>& proxy )
{
using blaze::clear;
clear( proxy.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the represented element is in default state.
// \ingroup diagonal_matrix
//
// \param proxy The given access proxy
// \return \a true in case the represented element is in default state, \a false otherwise.
//
// This function checks whether the element represented by the access proxy is in default state.
// In case it is in default state, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isDefault( const DiagonalProxy<MT>& proxy )
{
using blaze::isDefault;
return isDefault( proxy.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the matrix element represents a real number.
// \ingroup diagonal_matrix
//
// \param proxy The given access proxy.
// \return \a true in case the matrix element represents a real number, \a false otherwise.
//
// This function checks whether the element represented by the access proxy represents the a
// real number. In case the element is of built-in type, the function returns \a true. In case
// the element is of complex type, the function returns \a true if the imaginary part is equal
// to 0. Otherwise it returns \a false.
*/
template< typename MT >
inline bool isReal( const DiagonalProxy<MT>& proxy )
{
using blaze::isReal;
return isReal( proxy.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the represented element is 0.
// \ingroup diagonal_matrix
//
// \param proxy The given access proxy.
// \return \a true in case the represented element is 0, \a false otherwise.
//
// This function checks whether the element represented by the access proxy represents the numeric
// value 0. In case it is 0, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isZero( const DiagonalProxy<MT>& proxy )
{
using blaze::isZero;
return isZero( proxy.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the represented element is 1.
// \ingroup diagonal_matrix
//
// \param proxy The given access proxy.
// \return \a true in case the represented element is 1, \a false otherwise.
//
// This function checks whether the element represented by the access proxy represents the numeric
// value 1. In case it is 1, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isOne( const DiagonalProxy<MT>& proxy )
{
using blaze::isOne;
return isOne( proxy.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the represented element is not a number.
// \ingroup diagonal_matrix
//
// \param proxy The given access proxy.
// \return \a true in case the represented element is in not a number, \a false otherwise.
//
// This function checks whether the element represented by the access proxy is not a number (NaN).
// In case it is not a number, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isnan( const DiagonalProxy<MT>& proxy )
{
using blaze::isnan;
return isnan( proxy.get() );
}
//*************************************************************************************************
} // namespace blaze
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,617 @@
//=================================================================================================
/*!
// \file blaze/math/adaptors/hermitianmatrix/BaseTemplate.h
// \brief Header file for the implementation of the base template of the HeritianMatrix
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_BASETEMPLATE_H_
#define _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_BASETEMPLATE_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/typetraits/IsColumnMajorMatrix.h>
#include <blaze/math/typetraits/IsDenseMatrix.h>
#include <blaze/util/typetraits/IsNumeric.h>
namespace blaze {
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/*!\defgroup hermitian_matrix HermitianMatrix
// \ingroup adaptors
*/
/*!\brief Matrix adapter for Hermitian \f$ N \times N \f$ matrices.
// \ingroup hermitian_matrix
//
// \section hermitianmatrix_general General
//
// The HermitianMatrix class template is an adapter for existing dense and sparse matrix types.
// It inherits the properties and the interface of the given matrix type \a MT and extends it
// by enforcing the additional invariant of Hermitian symmetry (i.e. the matrix is always equal
// to its conjugate transpose \f$ A = \overline{A^T} \f$). The type of the adapted matrix can
// be specified via the first template parameter:
\code
template< typename MT, bool SO, bool DF >
class HermitianMatrix;
\endcode
// - MT: specifies the type of the matrix to be adapted. HermitianMatrix can be used with any
// non-cv-qualified, non-reference, non-pointer, non-expression dense or sparse matrix
// type. Also, the given matrix type must have numeric element types (i.e. all integral
// types except \a bool, floating point and complex types). Note that the given matrix
// type must be either resizable (as for instance HybridMatrix or DynamicMatrix) or must
// be square at compile time (as for instance StaticMatrix).
// - SO: specifies the storage order (blaze::rowMajor, blaze::columnMajor) of the matrix. This
// template parameter doesn't have to be explicitly defined, but is automatically derived
// from the first template parameter.
// - DF: specifies whether the given matrix type is a dense or sparse matrix type. This template
// parameter doesn't have to be defined explicitly, it is automatically derived from the
// first template parameter. Defining the parameter explicitly may result in a compilation
// error!
//
// The following examples give an impression of several possible Hermitian matrices:
\code
using blaze::unaligned;
using blaze::unpadded;
using blaze::rowMajor;
using blaze::columnMajor;
// Definition of a 3x3 row-major dense Hermitian matrix with static memory
blaze::HermitianMatrix< blaze::StaticMatrix<int,3UL,3UL,rowMajor> > A;
// Definition of a resizable column-major dense Hermitian matrix based on HybridMatrix
blaze::HermitianMatrix< blaze::HybridMatrix<float,4UL,4UL,columnMajor> B;
// Definition of a resizable row-major dense Hermitian matrix based on DynamicMatrix
blaze::HermitianMatrix< blaze::DynamicMatrix<std::complex<double>,rowMajor> > C;
// Definition of a fixed-size row-major dense diagonal matrix based on CustomMatrix
blaze::HermitianMatrix< blaze::CustomMatrix<double,unaligned,unpadded,rowMajor> > D;
// Definition of a compressed row-major single precision complex Hermitian matrix
blaze::HermitianMatrix< blaze::CompressedMatrix<std::complex<float>,rowMajor> > E;
\endcode
// The storage order of a Hermitian matrix is depending on the storage order of the adapted matrix
// type \a MT. In case the adapted matrix is stored in a row-wise fashion (i.e. is specified as
// blaze::rowMajor), the Hermitian matrix will also be a row-major matrix. Otherwise, if the
// adapted matrix is column-major (i.e. is specified as blaze::columnMajor), the Hermitian matrix
// will also be a column-major matrix.
//
//
// \n \section hermitianmatrix_vs_symmetricmatrix Hermitian Matrices vs. Symmetric Matrices
//
// The blaze::HermitianMatrix adaptor and the blaze::SymmetricMatrix adaptor share several traits.
// However, there are a couple of differences, both from a mathematical point of view as well as
// from an implementation point of view.
//
// From a mathematical point of view, a matrix is called symmetric when it is equal to its
// transpose (\f$ A = A^T \f$) and it is called Hermitian when it is equal to its conjugate
// transpose (\f$ A = \overline{A^T} \f$). For matrices of real values, however, these two
// conditions coincide, which means that symmetric matrices of real values are also Hermitian
// and Hermitian matrices of real values are also symmetric.
//
// From an implementation point of view, \b Blaze restricts Hermitian matrices to numeric data
// types (i.e. all integral types except \a bool, floating point and complex types), whereas
// symmetric matrices can also be block structured (i.e. can have vector or matrix elements).
// For built-in element types, the HermitianMatrix adaptor behaves exactly like the according
// SymmetricMatrix implementation. For complex element types, however, the Hermitian property
// is enforced (see also \ref hermitianmatrix_hermitian).
\code
using blaze::DynamicMatrix;
using blaze::DynamicVector;
using blaze::HermitianMatrix;
using blaze::SymmetricMatrix;
// The following two matrices provide an identical experience (including performance)
HermitianMatrix< DynamicMatrix<double> > A; // Both Hermitian and symmetric
SymmetricMatrix< DynamicMatrix<double> > B; // Both Hermitian and symmetric
// The following two matrices will behave differently
HermitianMatrix< DynamicMatrix< complex<double> > > C; // Only Hermitian
SymmetricMatrix< DynamicMatrix< complex<double> > > D; // Only symmetric
// Block-structured Hermitian matrices are not allowed
HermitianMatrix< DynamicMatrix< DynamicVector<double> > > E; // Compilation error!
SymmetricMatrix< DynamicMatrix< DynamicVector<double> > > F; // Block-structured symmetric matrix
\endcode
// \n \section hermitianmatrix_special_properties Special Properties of Hermitian Matrices
//
// A Hermitian matrix is used exactly like a matrix of the underlying, adapted matrix type \a MT.
// It also provides (nearly) the same interface as the underlying matrix type. However, there are
// some important exceptions resulting from the Hermitian symmetry constraint:
//
// -# <b>\ref hermitianmatrix_square</b>
// -# <b>\ref hermitianmatrix_hermitian</b>
// -# <b>\ref hermitianmatrix_initialization</b>
//
// \n \subsection hermitianmatrix_square Hermitian Matrices Must Always be Square!
//
// In case a resizable matrix is used (as for instance blaze::HybridMatrix, blaze::DynamicMatrix,
// or blaze::CompressedMatrix), this means that the according constructors, the \c resize() and
// the \c extend() functions only expect a single parameter, which specifies both the number of
// rows and columns, instead of two (one for the number of rows and one for the number of columns):
\code
using blaze::DynamicMatrix;
using blaze::HermitianMatrix;
using blaze::rowMajor;
// Default constructed, default initialized, row-major 3x3 Hermitian dynamic matrix
HermitianMatrix< DynamicMatrix<std::complex<double>,rowMajor> > A( 3 );
// Resizing the matrix to 5x5
A.resize( 5 );
// Extending the number of rows and columns by 2, resulting in a 7x7 matrix
A.extend( 2 );
\endcode
// In case a matrix with a fixed size is used (as for instance blaze::StaticMatrix), the number
// of rows and number of columns must be specified equally:
\code
using blaze::StaticMatrix;
using blaze::HermitianMatrix;
using blaze::columnMajor;
// Correct setup of a fixed size column-major 3x3 Hermitian static matrix
HermitianMatrix< StaticMatrix<std::complex<float>,3UL,3UL,columnMajor> > A;
// Compilation error: the provided matrix type is not a square matrix type
HermitianMatrix< StaticMatrix<std::complex<float>,3UL,4UL,columnMajor> > B;
\endcode
// \n \subsection hermitianmatrix_hermitian The Hermitian Property is Always Enforced!
//
// This means that the following properties of a Hermitian matrix are always guaranteed:
//
// - The diagonal elements are real numbers, i.e. the imaginary part is zero
// - Element \f$ a_{ij} \f$ is always the complex conjugate of element \f$ a_{ji} \f$
//
// Thus modifying the element \f$ a_{ij} \f$ of a Hermitian matrix also modifies its
// counterpart element \f$ a_{ji} \f$. Also, it is only possible to assign matrices that
// are Hermitian themselves:
\code
using blaze::CompressedMatrix;
using blaze::DynamicMatrix;
using blaze::StaticMatrix;
using blaze::HermitianMatrix;
using blaze::rowMajor;
typedef std::complex<double> cplx;
// Default constructed, row-major 3x3 Hermitian compressed matrix
HermitianMatrix< CompressedMatrix<cplx,rowMajor> > A( 3 );
// Initializing the matrix via the function call operator
//
// ( (1, 0) (0,0) (2,1) )
// ( (0, 0) (0,0) (0,0) )
// ( (2,-1) (0,0) (0,0) )
//
A(0,0) = cplx( 1.0, 0.0 ); // Initialization of the diagonal element (0,0)
A(0,2) = cplx( 2.0, 1.0 ); // Initialization of the elements (0,2) and (2,0)
// Inserting three more elements via the insert() function
//
// ( (1,-3) (0,0) (2, 1) )
// ( (0, 0) (2,0) (4,-2) )
// ( (2,-1) (4,2) (0, 0) )
//
A.insert( 1, 1, cplx( 2.0, 0.0 ) ); // Inserting the diagonal element (1,1)
A.insert( 1, 2, cplx( 4.0, -2.0 ) ); // Inserting the elements (1,2) and (2,1)
// Access via a non-const iterator
//
// ( (1,-3) (8,1) (2, 1) )
// ( (8,-1) (2,0) (4,-2) )
// ( (2,-1) (4,2) (0, 0) )
//
*A.begin(1UL) = cplx( 8.0, -1.0 ); // Modifies both elements (1,0) and (0,1)
// Erasing elements via the erase() function
//
// ( (0, 0) (8,1) (0, 0) )
// ( (8,-1) (2,0) (4,-2) )
// ( (0, 0) (4,2) (0, 0) )
//
A.erase( 0, 0 ); // Erasing the diagonal element (0,0)
A.erase( 0, 2 ); // Erasing the elements (0,2) and (2,0)
// Construction from a Hermitian dense matrix
StaticMatrix<cplx,3UL,3UL> B( { { cplx( 3.0, 0.0 ), cplx( 8.0, 2.0 ), cplx( -2.0, 2.0 ) },
{ cplx( 8.0, 1.0 ), cplx( 0.0, 0.0 ), cplx( -1.0, -1.0 ) },
{ cplx( -2.0, -2.0 ), cplx( -1.0, 1.0 ), cplx( 4.0, 0.0 ) } } );
HermitianMatrix< DynamicMatrix<double,rowMajor> > C( B ); // OK
// Assignment of a non-Hermitian dense matrix
StaticMatrix<cplx,3UL,3UL> D( { { cplx( 3.0, 0.0 ), cplx( 7.0, 2.0 ), cplx( 3.0, 2.0 ) },
{ cplx( 8.0, 1.0 ), cplx( 0.0, 0.0 ), cplx( 6.0, 4.0 ) },
{ cplx( -2.0, 2.0 ), cplx( -1.0, 1.0 ), cplx( 4.0, 0.0 ) } } );
C = D; // Throws an exception; Hermitian invariant would be violated!
\endcode
// The same restriction also applies to the \c append() function for sparse matrices: Appending
// the element \f$ a_{ij} \f$ additionally inserts the element \f$ a_{ji} \f$ into the matrix.
// Despite the additional insertion, the \c append() function still provides the most efficient
// way to set up a Hermitian sparse matrix. In order to achieve the maximum efficiency, the
// capacity of the individual rows/columns of the matrix should to be specifically prepared with
// \c reserve() calls:
\code
using blaze::CompressedMatrix;
using blaze::HermitianMatrix;
using blaze::rowMajor;
typedef std::complex<double> cplx;
// Setup of the Hermitian matrix
//
// ( (0, 0) (1,2) (3,-4) )
// A = ( (1,-2) (2,0) (0, 0) )
// ( (3, 4) (0,0) (0, 0) )
//
HermitianMatrix< CompressedMatrix<cplx,rowMajor> > A( 3 );
A.reserve( 5 ); // Reserving enough space for 5 non-zero elements
A.reserve( 0, 2 ); // Reserving two non-zero elements in the first row
A.reserve( 1, 2 ); // Reserving two non-zero elements in the second row
A.reserve( 2, 1 ); // Reserving a single non-zero element in the third row
A.append( 0, 1, cplx( 1.0, 2.0 ) ); // Appending an element at position (0,1) and (1,0)
A.append( 1, 1, cplx( 2.0, 0.0 ) ); // Appending an element at position (1,1)
A.append( 2, 0, cplx( 3.0, 4.0 ) ); // Appending an element at position (2,0) and (0,2)
\endcode
// The Hermitian property is also enforced for Hermitian custom matrices: In case the given array
// of elements does not represent a Hermitian matrix, a \a std::invalid_argument exception is
// thrown:
\code
using blaze::CustomMatrix;
using blaze::HermitianMatrix;
using blaze::unaligned;
using blaze::unpadded;
using blaze::rowMajor;
typedef HermitianMatrix< CustomMatrix<double,unaligned,unpadded,rowMajor> > CustomHermitian;
// Creating a 3x3 Hermitian custom matrix from a properly initialized array
double array[9] = { 1.0, 2.0, 4.0,
2.0, 3.0, 5.0,
4.0, 5.0, 6.0 };
CustomHermitian A( array, 3UL ); // OK
// Attempt to create a second 3x3 Hermitian custom matrix from an uninitialized array
CustomHermitian B( new double[9UL], 3UL, blaze::ArrayDelete() ); // Throws an exception
\endcode
// Finally, the Hermitian property is enforced for views (rows, columns, submatrices, ...) on the
// Hermitian matrix. The following example demonstrates that modifying the elements of an entire
// row of the Hermitian matrix also affects the counterpart elements in the according column of
// the matrix:
\code
using blaze::DynamicMatrix;
using blaze::HermtianMatrix;
typedef std::complex<double> cplx;
// Setup of the Hermitian matrix
//
// ( (0, 0) (1,-1) (0,0) (2, 1) )
// A = ( (1, 1) (3, 0) (4,2) (0, 0) )
// ( (0, 0) (4,-2) (0,0) (5,-3) )
// ( (2,-1) (0, 0) (5,3) (0, 0) )
//
HermitianMatrix< DynamicMatrix<int> > A( 4 );
A(0,1) = cplx( 1.0, -1.0 );
A(0,3) = cplx( 2.0, 1.0 );
A(1,1) = cplx( 3.0, 0.0 );
A(1,2) = cplx( 4.0, 2.0 );
A(2,3) = cplx( 5.0, 3.0 );
// Setting all elements in the 1st row to 0 results in the matrix
//
// ( (0, 0) (0,0) (0,0) (2, 1) )
// A = ( (0, 0) (0,0) (0,0) (0, 0) )
// ( (0, 0) (0,0) (0,0) (5,-3) )
// ( (2,-1) (0,0) (5,3) (0, 0) )
//
row( A, 1 ) = cplx( 0.0, 0.0 );
\endcode
// The next example demonstrates the (compound) assignment to submatrices of Hermitian matrices.
// Since the modification of element \f$ a_{ij} \f$ of a Hermitian matrix also modifies the
// element \f$ a_{ji} \f$, the matrix to be assigned must be structured such that the Hermitian
// symmetry of the matrix is preserved. Otherwise a \a std::invalid_argument exception is thrown:
\code
using blaze::DynamicMatrix;
using blaze::HermitianMatrix;
std::complex<double> cplx;
// Setup of two default 4x4 Hermitian matrices
HermitianMatrix< DynamicMatrix<cplx> > A1( 4 ), A2( 4 );
// Setup of the 3x2 dynamic matrix
//
// ( (1,-1) (2, 5) )
// B = ( (3, 0) (4,-6) )
// ( (5, 0) (6, 0) )
//
DynamicMatrix<int> B( 3UL, 2UL );
B(0,0) = cplx( 1.0, -1.0 );
B(0,1) = cplx( 2.0, 5.0 );
B(1,0) = cplx( 3.0, 0.0 );
B(1,1) = cplx( 4.0, -6.0 );
B(2,1) = cplx( 5.0, 0.0 );
B(2,2) = cplx( 6.0, 7.0 );
// OK: Assigning B to a submatrix of A1 such that the Hermitian property is preserved
//
// ( (0, 0) (0, 0) (1,-1) (2, 5) )
// A1 = ( (0, 0) (0, 0) (3, 0) (4,-6) )
// ( (1, 1) (3, 0) (5, 0) (6, 0) )
// ( (2,-5) (4, 6) (6, 0) (0, 0) )
//
submatrix( A1, 0UL, 2UL, 3UL, 2UL ) = B; // OK
// Error: Assigning B to a submatrix of A2 such that the Hermitian property isn't preserved!
// The elements marked with X cannot be assigned unambiguously!
//
// ( (0, 0) (1,-1) (2,5) (0,0) )
// A2 = ( (1, 1) (3, 0) (X,X) (0,0) )
// ( (2,-5) (X, X) (6,0) (0,0) )
// ( (0, 0) (0, 0) (0,0) (0,0) )
//
submatrix( A2, 0UL, 1UL, 3UL, 2UL ) = B; // Assignment throws an exception!
\endcode
// \n \subsection hermitianmatrix_initialization The Elements of a Dense Hermitian Matrix are Always Default Initialized!
//
// Although this results in a small loss of efficiency (especially in case all default values are
// overridden afterwards), this property is important since otherwise the Hermitian property of
// dense Hermitian matrices could not be guaranteed:
\code
using blaze::DynamicMatrix;
using blaze::HermitianMatrix;
// Uninitialized, 5x5 row-major dynamic matrix
DynamicMatrix<int,rowMajor> A( 5, 5 );
// Default initialized, 5x5 row-major Hermitian dynamic matrix
HermitianMatrix< DynamicMatrix<int,rowMajor> > B( 5 );
\endcode
// \n \section hermitianmatrix_arithmetic_operations Arithmetic Operations
//
// A HermitianMatrix can be used within all numerical operations in any way any other dense or
// sparse matrix can be used. It can also be combined with any other dense or sparse vector or
// matrix. The following code example gives an impression of the use of HermitianMatrix within
// arithmetic operations:
\code
using blaze::HermitianMatrix;
using blaze::DynamicMatrix;
using blaze::HybridMatrix;
using blaze::StaticMatrix;
using blaze::CompressedMatrix;
using blaze::rowMajor;
using blaze::columnMajor;
typedef complex<float> cplx;
DynamicMatrix<cplx,rowMajor> A( 3, 3 );
CompressedMatrix<cplx,rowMajor> B( 3, 3 );
HermitianMatrix< DynamicMatrix<cplx,rowMajor> > C( 3 );
HermitianMatrix< CompressedMatrix<cplx,rowMajor> > D( 3 );
HermitianMatrix< HybridMatrix<cplx,3UL,3UL,rowMajor> > E;
HermitianMatrix< StaticMatrix<cplx,3UL,3UL,columnMajor> > F;
E = A + B; // Matrix addition and assignment to a row-major Hermitian matrix
F = C - D; // Matrix subtraction and assignment to a column-major Hermitian matrix
F = A * D; // Matrix multiplication between a dense and a sparse matrix
C *= 2.0; // In-place scaling of matrix C
E = 2.0 * B; // Scaling of matrix B
F = C * 2.0; // Scaling of matrix C
E += A - B; // Addition assignment
F -= C + D; // Subtraction assignment
F *= A * D; // Multiplication assignment
\endcode
// \n \section hermitianmatrix_performance Performance Considerations
//
// When the Hermitian property of a matrix is known beforehands using the HermitianMatrix adaptor
// instead of a general matrix can be a considerable performance advantage. This is particularly
// true in case the Hermitian matrix is also symmetric (i.e. has built-in element types). The
// \b Blaze library tries to exploit the properties of Hermitian (symmetric) matrices whenever
// possible. However, there are also situations when using a Hermitian matrix introduces some
// overhead. The following examples demonstrate several situations where Hermitian matrices can
// positively or negatively impact performance.
//
// \n \subsection hermitianmatrix_matrix_matrix_multiplication Positive Impact: Matrix/Matrix Multiplication
//
// When multiplying two matrices, at least one of which is symmetric, \b Blaze can exploit the fact
// that \f$ A = A^T \f$ and choose the fastest and most suited combination of storage orders for the
// multiplication. The following example demonstrates this by means of a dense matrix/sparse matrix
// multiplication:
\code
using blaze::DynamicMatrix;
using blaze::HermitianMatrix;
using blaze::rowMajor;
using blaze::columnMajor;
HermitianMatrix< DynamicMatrix<double,rowMajor> > A; // Both Hermitian and symmetric
HermitianMatrix< CompressedMatrix<double,columnMajor> > B; // Both Hermitian and symmetric
DynamicMatrix<double,columnMajor> C;
// ... Resizing and initialization
C = A * B;
\endcode
// Intuitively, the chosen combination of a row-major and a column-major matrix is the most suited
// for maximum performance. However, \b Blaze evaluates the multiplication as
\code
C = A * trans( B );
\endcode
// which significantly increases the performance since in contrast to the original formulation the
// optimized form can be vectorized. Therefore, in the context of matrix multiplications, using a
// symmetric matrix is obviously an advantage.
//
// \n \subsection hermitianmatrix_matrix_vector_multiplication Positive Impact: Matrix/Vector Multiplication
//
// A similar optimization is possible in case of matrix/vector multiplications:
\code
using blaze::DynamicMatrix;
using blaze::DynamicVector;
using blaze::CompressedVector;
using blaze::HermitianMatrix;
using blaze::rowMajor;
using blaze::columnVector;
HermitianMatrix< DynamicMatrix<double,rowMajor> > A; // Hermitian and symmetric
CompressedVector<double,columnVector> x;
DynamicVector<double,columnVector> y;
// ... Resizing and initialization
y = A * x;
\endcode
// In this example it is not intuitively apparent that using a row-major matrix is not the best
// possible choice in terms of performance since the computation cannot be vectorized. Choosing
// a column-major matrix instead, however, would enable a vectorized computation. Therefore
// \b Blaze exploits the fact that \c A is symmetric, selects the best suited storage order and
// evaluates the multiplication as
\code
y = trans( A ) * x;
\endcode
// which also significantly increases the performance.
//
// \n \subsection hermitianmatrix_views Positive Impact: Row/Column Views on Column/Row-Major Matrices
//
// Another example is the optimization of a row view on a column-major symmetric matrix:
\code
using blaze::DynamicMatrix;
using blaze::HermitianMatrix;
using blaze::rowMajor;
using blaze::columnMajor;
typedef HermitianMatrix< DynamicMatrix<double,columnMajor> > DynamicHermitian;
DynamicHermitian A( 10UL ); // Both Hermitian and symmetric
Row<DynamicHermitian> row5 = row( A, 5UL );
\endcode
// Usually, a row view on a column-major matrix results in a considerable performance decrease in
// comparison to a row view on a row-major matrix due to the non-contiguous storage of the matrix
// elements. However, in case of symmetric matrices, \b Blaze instead uses the according column of
// the matrix, which provides the same performance as if the matrix would be row-major. Note that
// this also works for column views on row-major matrices, where \b Blaze can use the according
// row instead of a column in order to provide maximum performance.
//
// \n \subsection hermitianmatrix_assignment Negative Impact: Assignment of a General Matrix
//
// In contrast to using a Hermitian matrix on the right-hand side of an assignment (i.e. for read
// access), which introduces absolutely no performance penalty, using a Hermitian matrix on the
// left-hand side of an assignment (i.e. for write access) may introduce additional overhead when
// it is assigned a general matrix, which is not Hermitian at compile time:
\code
using blaze::DynamicMatrix;
using blaze::HermitianMatrix;
HermitianMatrix< DynamicMatrix< complex<double> > > A, C;
DynamicMatrix<double> B;
B = A; // Only read-access to the Hermitian matrix; no performance penalty
C = A; // Assignment of a Hermitian matrix to another Hermitian matrix; no runtime overhead
C = B; // Assignment of a general matrix to a Hermitian matrix; some runtime overhead
\endcode
// When assigning a general, potentially not Hermitian matrix to a Hermitian matrix it is necessary
// to check whether the matrix is Hermitian at runtime in order to guarantee the Hermitian property
// of the Hermitian matrix. In case it turns out to be Hermitian, it is assigned as efficiently as
// possible, if it is not, an exception is thrown. In order to prevent this runtime overhead it is
// therefore generally advisable to assign Hermitian matrices to other Hermitian matrices.\n
// In this context it is especially noteworthy that in contrast to additions and subtractions the
// multiplication of two Hermitian matrices does not necessarily result in another Hermitian matrix:
\code
HermitianMatrix< DynamicMatrix<double> > A, B, C;
C = A + B; // Results in a Hermitian matrix; no runtime overhead
C = A - B; // Results in a Hermitian matrix; no runtime overhead
C = A * B; // Is not guaranteed to result in a Hermitian matrix; some runtime overhead
\endcode
*/
template< typename MT // Type of the adapted matrix
, bool SO = IsColumnMajorMatrix<MT>::value // Storage order of the adapted matrix
, bool DF = IsDenseMatrix<MT>::value > // Density flag
class HermitianMatrix
{};
//*************************************************************************************************
} // namespace blaze
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,434 @@
//=================================================================================================
/*!
// \file blaze/math/adaptors/hermitianmatrix/HermitianElement.h
// \brief Header file for the HermitianElement class
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANELEMENT_H_
#define _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANELEMENT_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/Aliases.h>
#include <blaze/math/adaptors/hermitianmatrix/HermitianValue.h>
#include <blaze/math/constraints/Expression.h>
#include <blaze/math/constraints/Hermitian.h>
#include <blaze/math/constraints/Lower.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/constraints/Symmetric.h>
#include <blaze/math/constraints/Upper.h>
#include <blaze/math/Exception.h>
#include <blaze/math/shims/Conjugate.h>
#include <blaze/math/shims/IsDefault.h>
#include <blaze/math/shims/IsReal.h>
#include <blaze/math/sparse/SparseElement.h>
#include <blaze/math/typetraits/IsRowMajorMatrix.h>
#include <blaze/util/Assert.h>
#include <blaze/util/constraints/Const.h>
#include <blaze/util/constraints/Numeric.h>
#include <blaze/util/constraints/Pointer.h>
#include <blaze/util/constraints/Reference.h>
#include <blaze/util/constraints/Volatile.h>
#include <blaze/util/Types.h>
#include <blaze/util/typetraits/IsComplex.h>
namespace blaze {
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Representation of two synchronized elements within the sparse Hermitian matrix.
// \ingroup hermitian_matrix
//
// The HermitianElement class represents two synchronized elements (i.e. two value/index pairs)
// within a sparse Hermitian matrix. It guarantees that a modification of element \f$ a_{ij} \f$
// via iterator is also applied to element \f$ a_{ji} \f$. The following example illustrates this
// by means of a \f$ 3 \times 3 \f$ dense Hermitian matrix:
\code
typedef std::complex<double> cplx;
typedef blaze::HermitianMatrix< blaze::CompressedMatrix<cplx> > Hermitian;
// Creating a 3x3 Hermitian dense matrix
//
// ( ( 0, 0) (0, 0) (-2,1) )
// ( ( 0, 0) (3, 0) ( 5,2) )
// ( (-2,-1) (5,-2) ( 0,0) )
//
Hermitian A( 3UL );
A(0,2) = cplx(-2,1);
A(1,1) = cplx( 3,0);
A(1,2) = cplx( 5,2);
// Modification of the elements at position (2,0) and (0,2)
//
// ( (0,0) (0, 0) (4,-3) )
// ( (0,0) (3, 0) (5, 2) )
// ( (4,3) (5,-2) (0, 0) )
//
Hermitian::Iterator it = A.begin( 2UL );
*it = cplx(4,3);
\endcode
*/
template< typename MT > // Type of the adapted matrix
class HermitianElement : private SparseElement
{
private:
//**Type definitions****************************************************************************
typedef ElementType_<MT> ElementType; //!< Type of the represented matrix element.
typedef Iterator_<MT> IteratorType; //!< Type of the underlying sparse matrix iterators.
//**********************************************************************************************
public:
//**Type definitions****************************************************************************
typedef HermitianValue<MT> ValueType; //!< The value type of the value-index-pair.
typedef size_t IndexType; //!< The index type of the value-index-pair.
typedef HermitianValue<MT> Reference; //!< Reference return type.
typedef const HermitianValue<MT> ConstReference; //!< Reference-to-const return type.
typedef HermitianElement* Pointer; //!< Pointer return type.
//**********************************************************************************************
//**Constructor*********************************************************************************
/*!\name Constructors */
//@{
inline HermitianElement( IteratorType pos, MT* matrix, size_t idx );
//@}
//**********************************************************************************************
//**Assignment operators************************************************************************
/*!\name Assignment operators */
//@{
template< typename T > inline HermitianElement& operator= ( const T& v );
template< typename T > inline HermitianElement& operator+=( const T& v );
template< typename T > inline HermitianElement& operator-=( const T& v );
template< typename T > inline HermitianElement& operator*=( const T& v );
template< typename T > inline HermitianElement& operator/=( const T& v );
//@}
//**********************************************************************************************
//**Access operators****************************************************************************
/*!\name Access operators */
//@{
inline Pointer operator->() noexcept;
//@}
//**********************************************************************************************
//**Utility functions***************************************************************************
/*!\name Utility functions */
//@{
inline Reference value() const;
inline IndexType index() const;
//@}
//**********************************************************************************************
private:
//**Utility functions***************************************************************************
/*!\name Utility functions */
//@{
inline void sync();
inline bool isSynced() const;
//@}
//**********************************************************************************************
//**Member variables****************************************************************************
IteratorType pos_; //!< Iterator to the current sparse Hermitian matrix element.
MT* matrix_; //!< The sparse matrix containing the iterator.
size_t index_; //!< The row/column index of the iterator.
//**********************************************************************************************
//**Compile time checks*************************************************************************
/*! \cond BLAZE_INTERNAL */
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_CONST ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE ( ElementType );
/*! \endcond */
//**********************************************************************************************
};
//*************************************************************************************************
//=================================================================================================
//
// CONSTRUCTORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Constructor for the HermitianElement class.
//
// \param pos The initial position of the iterator.
// \param matrix The sparse matrix containing the iterator.
// \param idx The row/column index of the iterator.
*/
template< typename MT > // Type of the adapted matrix
inline HermitianElement<MT>::HermitianElement( IteratorType pos, MT* matrix, size_t idx )
: pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
, matrix_( matrix ) // The sparse matrix containing the iterator
, index_ ( idx ) // The row/column index of the iterator
{
BLAZE_INTERNAL_ASSERT( isSynced(), "Missing matrix element detected" );
}
//*************************************************************************************************
//=================================================================================================
//
// OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Assignment to the Hermitian element.
//
// \param v The new value of the Hermitian element.
// \return Reference to the assigned Hermitian element.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianElement<MT>& HermitianElement<MT>::operator=( const T& v )
{
if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
*pos_ = v;
sync();
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Addition assignment to the Hermitian element.
//
// \param v The right-hand side value for the addition.
// \return Reference to the assigned Hermitian element.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianElement<MT>& HermitianElement<MT>::operator+=( const T& v )
{
if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
*pos_ += v;
sync();
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Subtraction assignment to the Hermitian element.
//
// \param v The right-hand side value for the subtraction.
// \return Reference to the assigned Hermitian element.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianElement<MT>& HermitianElement<MT>::operator-=( const T& v )
{
if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
*pos_ -= v;
sync();
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication assignment to the Hermitian element.
//
// \param v The right-hand side value for the multiplication.
// \return Reference to the assigned Hermitian element.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianElement<MT>& HermitianElement<MT>::operator*=( const T& v )
{
if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
*pos_ *= v;
sync();
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Division assignment to the Hermitian element.
//
// \param v The right-hand side value for the division.
// \return Reference to the assigned Hermitian element.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianElement<MT>& HermitianElement<MT>::operator/=( const T& v )
{
if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
*pos_ /= v;
sync();
return *this;
}
//*************************************************************************************************
//=================================================================================================
//
// ACCESS OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Direct access to the Hermitian element.
//
// \return Reference to the value of the Hermitian element.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianElement<MT>::Pointer HermitianElement<MT>::operator->() noexcept
{
return this;
}
//*************************************************************************************************
//=================================================================================================
//
// UTILITY FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Access to the current value of the Hermitian element.
//
// \return The current value of the Hermitian element.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianElement<MT>::Reference HermitianElement<MT>::value() const
{
return Reference( pos_, matrix_, index_ );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Access to the current index of the Hermitian element.
//
// \return The current index of the Hermitian element.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianElement<MT>::IndexType HermitianElement<MT>::index() const
{
return pos_->index();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Synchronization of the current sparse element to the according paired element.
//
// \return void
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianElement<MT>::sync()
{
if( pos_->index() == index_ || isDefault( pos_->value() ) )
return;
const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
matrix_->set( row, column, conj( pos_->value() ) );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Checking if the current sparse element is in sync.
//
// \return \a true if the current sparse element is in sync, \a false if not.
*/
template< typename MT > // Type of the adapted matrix
inline bool HermitianElement<MT>::isSynced() const
{
const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
const IteratorType pos2( matrix_->find( row, column ) );
const IteratorType end( matrix_->end( pos_->index() ) );
return ( isDefault( pos_->value() ) && ( pos2 == end || isDefault( pos2->value() ) ) ) ||
( pos2 != end && pos_->value() == conj( pos2->value() ) );
}
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,851 @@
//=================================================================================================
/*!
// \file blaze/math/adaptors/hermitianmatrix/HermitianProxy.h
// \brief Header file for the HermitianProxy class
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANPROXY_H_
#define _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANPROXY_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/Aliases.h>
#include <blaze/math/constraints/Expression.h>
#include <blaze/math/constraints/Hermitian.h>
#include <blaze/math/constraints/Lower.h>
#include <blaze/math/constraints/Matrix.h>
#include <blaze/math/constraints/Symmetric.h>
#include <blaze/math/constraints/Upper.h>
#include <blaze/math/Exception.h>
#include <blaze/math/proxy/Proxy.h>
#include <blaze/math/shims/Clear.h>
#include <blaze/math/shims/Conjugate.h>
#include <blaze/math/shims/Invert.h>
#include <blaze/math/shims/IsDefault.h>
#include <blaze/math/shims/IsNaN.h>
#include <blaze/math/shims/IsOne.h>
#include <blaze/math/shims/IsReal.h>
#include <blaze/math/shims/IsZero.h>
#include <blaze/math/shims/Reset.h>
#include <blaze/util/constraints/Const.h>
#include <blaze/util/constraints/Numeric.h>
#include <blaze/util/constraints/Pointer.h>
#include <blaze/util/constraints/Reference.h>
#include <blaze/util/constraints/Volatile.h>
#include <blaze/util/InvalidType.h>
#include <blaze/util/mpl/If.h>
#include <blaze/util/Types.h>
#include <blaze/util/typetraits/IsComplex.h>
namespace blaze {
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Access proxy for Hermitian matrices.
// \ingroup hermitian_matrix
//
// The HermitianProxy provides controlled access to the elements of a non-const Hermitian matrix.
// It guarantees that a modification of element \f$ a_{ij} \f$ of the accessed matrix is also
// applied to element \f$ a_{ji} \f$. The following example illustrates this by means of a
// \f$ 3 \times 3 \f$ dense Hermitian matrix:
\code
// Creating a 3x3 Hermitian dense matrix
blaze::HermitianMatrix< blaze::DynamicMatrix<int> > A( 3UL );
A(0,2) = -2; // ( 0 0 -2 )
A(1,1) = 3; // => A = ( 0 3 5 )
A(1,2) = 5; // ( -2 5 0 )
\endcode
*/
template< typename MT > // Type of the adapted matrix
class HermitianProxy : public Proxy< HermitianProxy<MT> >
{
private:
//**struct BuiltinType**************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Auxiliary struct to determine the value type of the represented complex element.
*/
template< typename T >
struct BuiltinType { typedef INVALID_TYPE Type; };
/*! \endcond */
//**********************************************************************************************
//**struct ComplexType**************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Auxiliary struct to determine the value type of the represented complex element.
*/
template< typename T >
struct ComplexType { typedef typename T::value_type Type; };
/*! \endcond */
//**********************************************************************************************
public:
//**Type definitions****************************************************************************
typedef ElementType_<MT> RepresentedType; //!< Type of the represented matrix element.
typedef Reference_<MT> Reference; //!< Reference to the represented element.
typedef ConstReference_<MT> ConstReference; //!< Reference-to-const to the represented element.
typedef HermitianProxy* Pointer; //!< Pointer to the represented element.
typedef const HermitianProxy* ConstPointer; //!< Pointer-to-const to the represented element.
//! Value type of the represented complex element.
typedef typename If_< IsComplex<RepresentedType>
, ComplexType<RepresentedType>
, BuiltinType<RepresentedType> >::Type ValueType;
//**********************************************************************************************
//**Constructors********************************************************************************
/*!\name Constructors */
//@{
explicit inline HermitianProxy( MT& matrix, size_t row, size_t column );
inline HermitianProxy( const HermitianProxy& hp );
//@}
//**********************************************************************************************
//**Destructor**********************************************************************************
// No explicitly declared destructor.
//**********************************************************************************************
//**Assignment operators************************************************************************
/*!\name Assignment operators */
//@{
inline HermitianProxy& operator= ( const HermitianProxy& hp );
template< typename T > inline HermitianProxy& operator= ( const T& value );
template< typename T > inline HermitianProxy& operator+=( const T& value );
template< typename T > inline HermitianProxy& operator-=( const T& value );
template< typename T > inline HermitianProxy& operator*=( const T& value );
template< typename T > inline HermitianProxy& operator/=( const T& value );
//@}
//**********************************************************************************************
//**Access operators****************************************************************************
/*!\name Access operators */
//@{
inline Pointer operator->() noexcept;
inline ConstPointer operator->() const noexcept;
//@}
//**********************************************************************************************
//**Utility functions***************************************************************************
/*!\name Utility functions */
//@{
inline void reset () const;
inline void clear () const;
inline void invert() const;
inline ConstReference get() const noexcept;
//@}
//**********************************************************************************************
//**Conversion operator*************************************************************************
/*!\name Conversion operator */
//@{
inline operator ConstReference() const noexcept;
//@}
//**********************************************************************************************
//**Complex data access functions***************************************************************
/*!\name Complex data access functions */
//@{
inline ValueType real() const;
inline void real( ValueType value ) const;
inline ValueType imag() const;
inline void imag( ValueType value ) const;
//@}
//**********************************************************************************************
private:
//**Member variables****************************************************************************
/*!\name Member variables */
//@{
Reference value1_; //!< Reference to the first accessed matrix element.
Reference value2_; //!< Reference to the second accessed matrix element.
const bool diagonal_; //!< Flag for the accessed matrix element.
/*!< The flag indicates if the accessed element is a diagonal element.
It is \a true in case the proxy represents an element on the
diagonal. */
//@}
//**********************************************************************************************
//**Compile time checks*************************************************************************
/*! \cond BLAZE_INTERNAL */
BLAZE_CONSTRAINT_MUST_BE_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_CONST ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE ( RepresentedType );
/*! \endcond */
//**********************************************************************************************
};
//*************************************************************************************************
//=================================================================================================
//
// CONSTRUCTORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Initialization constructor for a HermitianProxy.
//
// \param matrix Reference to the adapted matrix.
// \param row The row-index of the accessed matrix element.
// \param column The column-index of the accessed matrix element.
*/
template< typename MT > // Type of the adapted matrix
inline HermitianProxy<MT>::HermitianProxy( MT& matrix, size_t row, size_t column )
: value1_ ( matrix(row,column) ) // Reference to the first accessed matrix element
, value2_ ( matrix(column,row) ) // Reference to the second accessed matrix element
, diagonal_( row == column ) // Flag for the accessed matrix element
{}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief The copy constructor for HermitianProxy.
//
// \param hp Numeric proxy to be copied.
*/
template< typename MT > // Type of the adapted matrix
inline HermitianProxy<MT>::HermitianProxy( const HermitianProxy& hp )
: value1_ ( hp.value1_ ) // Reference to the first accessed matrix element
, value2_ ( hp.value2_ ) // Reference to the second accessed matrix element
, diagonal_( hp.diagonal_ ) // Flag for the accessed matrix element
{}
//*************************************************************************************************
//=================================================================================================
//
// OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Copy assignment operator for HermitianProxy.
//
// \param hp Numeric proxy to be copied.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
//
// In case the proxy represents a diagonal element and the assigned value does not represent
// a real number, a \a std::invalid_argument exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
inline HermitianProxy<MT>& HermitianProxy<MT>::operator=( const HermitianProxy& hp )
{
typedef ElementType_<MT> ET;
if( IsComplex<ET>::value && diagonal_ && !isReal( hp.value1_ ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
value1_ = hp.value1_;
if( !diagonal_ )
value2_ = conj( value1_ );
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Assignment to the accessed matrix element.
//
// \param value The new value of the matrix element.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
//
// In case the proxy represents a diagonal element and the assigned value does not represent
// a real number, a \a std::invalid_argument exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianProxy<MT>& HermitianProxy<MT>::operator=( const T& value )
{
typedef ElementType_<MT> ET;
if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
value1_ = value;
if( !diagonal_ )
value2_ = conj( value1_ );
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Addition assignment to the accessed matrix element.
//
// \param value The right-hand side value to be added to the matrix element.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
//
// In case the proxy represents a diagonal element and the assigned value does not represent
// a real number, a \a std::invalid_argument exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianProxy<MT>& HermitianProxy<MT>::operator+=( const T& value )
{
typedef ElementType_<MT> ET;
if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
value1_ += value;
if( !diagonal_ )
value2_ = conj( value1_ );
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Subtraction assignment to the accessed matrix element.
//
// \param value The right-hand side value to be subtracted from the matrix element.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
//
// In case the proxy represents a diagonal element and the assigned value does not represent
// a real number, a \a std::invalid_argument exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianProxy<MT>& HermitianProxy<MT>::operator-=( const T& value )
{
typedef ElementType_<MT> ET;
if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
value1_ -= value;
if( !diagonal_ )
value2_ = conj( value1_ );
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication assignment to the accessed matrix element.
//
// \param value The right-hand side value for the multiplication.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
//
// In case the proxy represents a diagonal element and the assigned value does not represent
// a real number, a \a std::invalid_argument exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianProxy<MT>& HermitianProxy<MT>::operator*=( const T& value )
{
typedef ElementType_<MT> ET;
if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
value1_ *= value;
if( !diagonal_ )
value2_ = conj( value1_ );
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Division assignment to the accessed matrix element.
//
// \param value The right-hand side value for the division.
// \return Reference to the assigned proxy.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
//
// In case the proxy represents a diagonal element and the assigned value does not represent
// a real number, a \a std::invalid_argument exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianProxy<MT>& HermitianProxy<MT>::operator/=( const T& value )
{
typedef ElementType_<MT> ET;
if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
value1_ /= value;
if( !diagonal_ )
value2_ = conj( value1_ );
return *this;
}
//*************************************************************************************************
//=================================================================================================
//
// ACCESS OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Direct access to the represented matrix element.
//
// \return Pointer to the represented matrix element.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianProxy<MT>::Pointer HermitianProxy<MT>::operator->() noexcept
{
return this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Direct access to the represented matrix element.
//
// \return Pointer to the represented matrix element.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianProxy<MT>::ConstPointer HermitianProxy<MT>::operator->() const noexcept
{
return this;
}
//*************************************************************************************************
//=================================================================================================
//
// UTILITY FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Reset the represented element to its default initial value.
//
// \return void
//
// This function resets the element represented by the proxy to its default initial value.
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianProxy<MT>::reset() const
{
using blaze::reset;
reset( value1_ );
if( !diagonal_ )
reset( value2_ );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Clearing the represented element.
//
// \return void
//
// This function clears the element represented by the proxy to its default initial state.
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianProxy<MT>::clear() const
{
using blaze::clear;
clear( value1_ );
if( !diagonal_ )
clear( value2_ );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief In-place inversion of the represented element
//
// \return void
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianProxy<MT>::invert() const
{
using blaze::invert;
invert( value1_ );
if( !diagonal_ )
value2_ = conj( value1_ );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returning the value of the accessed matrix element.
//
// \return Direct/raw reference to the accessed matrix element.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianProxy<MT>::ConstReference HermitianProxy<MT>::get() const noexcept
{
return value1_;
}
//*************************************************************************************************
//=================================================================================================
//
// CONVERSION OPERATOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Conversion to the accessed matrix element.
//
// \return Direct/raw reference to the accessed matrix element.
*/
template< typename MT > // Type of the adapted matrix
inline HermitianProxy<MT>::operator ConstReference() const noexcept
{
return get();
}
//*************************************************************************************************
//=================================================================================================
//
// COMPLEX DATA ACCESS FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Returns the real part of the represented complex number.
//
// \return The current real part of the represented complex number.
//
// In case the proxy represents a complex number, this function returns the current value of its
// real part.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianProxy<MT>::ValueType HermitianProxy<MT>::real() const
{
return value1_.real();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Setting the real part of the represented complex number.
//
// \param value The new value for the real part.
// \return void
//
// In case the proxy represents a complex number, this function sets a new value to its real part.
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianProxy<MT>::real( ValueType value ) const
{
value1_.real( value );
if( !diagonal_ )
value2_.real( value );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns the imaginary part of the represented complex number.
//
// \return The current imaginary part of the represented complex number.
//
// In case the proxy represents a complex number, this function returns the current value of its
// imaginary part.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianProxy<MT>::ValueType HermitianProxy<MT>::imag() const
{
return value1_.imag();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Setting the imaginary part of the represented complex number.
//
// \param value The new value for the imaginary part.
// \return void
// \exception std::invalid_argument Invalid setting for diagonal matrix element.
//
// In case the proxy represents a complex number, this function sets a new value to its imaginary
// part. In case the proxy represents a diagonal element and the given value is not zero, a
// \a std::invalid_argument exception is thrown.
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianProxy<MT>::imag( ValueType value ) const
{
if( diagonal_ && !isZero( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid setting for diagonal matrix element" );
}
value1_.imag( value );
if( !diagonal_ )
value2_.imag( -value );
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\name HermitianProxy global functions */
//@{
template< typename MT >
inline void reset( const HermitianProxy<MT>& proxy );
template< typename MT >
inline void clear( const HermitianProxy<MT>& proxy );
template< typename MT >
inline void invert( const HermitianProxy<MT>& proxy );
template< typename MT >
inline bool isDefault( const HermitianProxy<MT>& proxy );
template< typename MT >
inline bool isReal( const HermitianProxy<MT>& proxy );
template< typename MT >
inline bool isZero( const HermitianProxy<MT>& proxy );
template< typename MT >
inline bool isOne( const HermitianProxy<MT>& proxy );
template< typename MT >
inline bool isnan( const HermitianProxy<MT>& proxy );
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Resetting the represented element to the default initial values.
// \ingroup hermitian_matrix
//
// \param proxy The given access proxy.
// \return void
//
// This function resets the element represented by the access proxy to its default initial
// value.
*/
template< typename MT >
inline void reset( const HermitianProxy<MT>& proxy )
{
proxy.reset();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Clearing the represented element.
// \ingroup hermitian_matrix
//
// \param proxy The given access proxy.
// \return void
//
// This function clears the element represented by the access proxy to its default initial
// state.
*/
template< typename MT >
inline void clear( const HermitianProxy<MT>& proxy )
{
proxy.clear();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief In-place inversion of the represented element.
// \ingroup hermitian_matrix
//
// \param proxy The given proxy instance.
// \return void
*/
template< typename MT >
inline void invert( const HermitianProxy<MT>& proxy )
{
proxy.invert();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the represented element is in default state.
// \ingroup hermitian_matrix
//
// \param proxy The given access proxy
// \return \a true in case the represented element is in default state, \a false otherwise.
//
// This function checks whether the element represented by the access proxy is in default state.
// In case it is in default state, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isDefault( const HermitianProxy<MT>& proxy )
{
using blaze::isDefault;
return isDefault( proxy.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the matrix element represents a real number.
// \ingroup hermitian_matrix
//
// \param proxy The given access proxy.
// \return \a true in case the matrix element represents a real number, \a false otherwise.
//
// This function checks whether the element represented by the access proxy represents the a
// real number. In case the element is of built-in type, the function returns \a true. In case
// the element is of complex type, the function returns \a true if the imaginary part is equal
// to 0. Otherwise it returns \a false.
*/
template< typename MT >
inline bool isReal( const HermitianProxy<MT>& proxy )
{
using blaze::isReal;
return isReal( proxy.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the represented element is 0.
// \ingroup hermitian_matrix
//
// \param proxy The given access proxy.
// \return \a true in case the represented element is 0, \a false otherwise.
//
// This function checks whether the element represented by the access proxy represents the numeric
// value 0. In case it is 0, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isZero( const HermitianProxy<MT>& proxy )
{
using blaze::isZero;
return isZero( proxy.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the represented element is 1.
// \ingroup hermitian_matrix
//
// \param proxy The given access proxy.
// \return \a true in case the represented element is 1, \a false otherwise.
//
// This function checks whether the element represented by the access proxy represents the numeric
// value 1. In case it is 1, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isOne( const HermitianProxy<MT>& proxy )
{
using blaze::isOne;
return isOne( proxy.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the represented element is not a number.
// \ingroup hermitian_matrix
//
// \param proxy The given access proxy.
// \return \a true in case the represented element is in not a number, \a false otherwise.
//
// This function checks whether the element represented by the access proxy is not a number (NaN).
// In case it is not a number, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isnan( const HermitianProxy<MT>& proxy )
{
using blaze::isnan;
return isnan( proxy.get() );
}
//*************************************************************************************************
} // namespace blaze
#endif

View File

@ -0,0 +1,811 @@
//=================================================================================================
/*!
// \file blaze/math/adaptors/hermitianmatrix/HermitianValue.h
// \brief Header file for the HermitianValue class
//
// Copyright (C) 2013 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
#ifndef _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANVALUE_H_
#define _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANVALUE_H_
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <blaze/math/Aliases.h>
#include <blaze/math/constraints/Expression.h>
#include <blaze/math/constraints/Hermitian.h>
#include <blaze/math/constraints/Lower.h>
#include <blaze/math/constraints/SparseMatrix.h>
#include <blaze/math/constraints/Symmetric.h>
#include <blaze/math/constraints/Upper.h>
#include <blaze/math/Exception.h>
#include <blaze/math/proxy/Proxy.h>
#include <blaze/math/shims/Clear.h>
#include <blaze/math/shims/Conjugate.h>
#include <blaze/math/shims/Invert.h>
#include <blaze/math/shims/IsDefault.h>
#include <blaze/math/shims/IsNaN.h>
#include <blaze/math/shims/IsOne.h>
#include <blaze/math/shims/IsReal.h>
#include <blaze/math/shims/IsZero.h>
#include <blaze/math/shims/Reset.h>
#include <blaze/math/typetraits/IsRowMajorMatrix.h>
#include <blaze/util/constraints/Const.h>
#include <blaze/util/constraints/Numeric.h>
#include <blaze/util/constraints/Pointer.h>
#include <blaze/util/constraints/Reference.h>
#include <blaze/util/constraints/Volatile.h>
#include <blaze/util/InvalidType.h>
#include <blaze/util/mpl/If.h>
#include <blaze/util/Types.h>
#include <blaze/util/typetraits/IsComplex.h>
namespace blaze {
//=================================================================================================
//
// CLASS DEFINITION
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Representation of two synchronized values within a sparse Hermitian matrix.
// \ingroup hermitian_matrix
//
// The HermitianValue class represents two synchronized values within a sparse Hermitian matrix.
// It guarantees that a modification of value \f$ a_{ij} \f$ via iterator is also applied to the
// value \f$ a_{ji} \f$. The following example illustrates this by means of a \f$ 3 \times 3 \f$
// sparse Hermitian matrix:
\code
typedef std::complex<double> cplx;
typedef blaze::HermitianMatrix< blaze::CompressedMatrix<cplx> > Hermitian;
// Creating a 3x3 Hermitian dense matrix
//
// ( ( 0, 0) (0, 0) (-2,1) )
// ( ( 0, 0) (3, 0) ( 5,2) )
// ( (-2,-1) (5,-2) ( 0,0) )
//
Hermitian A( 3UL );
A(0,2) = cplx(-2,1);
A(1,1) = cplx( 3,0);
A(1,2) = cplx( 5,2);
// Modification of the values at position (2,0) and (0,2)
//
// ( (0,0) (0, 0) (4,-3) )
// ( (0,0) (3, 0) (5, 2) )
// ( (4,3) (5,-2) (0, 0) )
//
Hermitian::Iterator it = A.begin( 2UL );
it->value() = cplx(4,3);
\endcode
*/
template< typename MT > // Type of the adapted matrix
class HermitianValue : public Proxy< HermitianValue<MT> >
{
private:
//**Type definitions****************************************************************************
typedef typename MT::Iterator IteratorType; //!< Type of the underlying sparse matrix iterators.
//**********************************************************************************************
//**struct BuiltinType**************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Auxiliary struct to determine the value type of the represented complex element.
*/
template< typename T >
struct BuiltinType { typedef INVALID_TYPE Type; };
/*! \endcond */
//**********************************************************************************************
//**struct ComplexType**************************************************************************
/*! \cond BLAZE_INTERNAL */
/*!\brief Auxiliary struct to determine the value type of the represented complex element.
*/
template< typename T >
struct ComplexType { typedef typename T::value_type Type; };
/*! \endcond */
//**********************************************************************************************
public:
//**Type definitions****************************************************************************
typedef ElementType_<MT> RepresentedType; //!< Type of the represented matrix element.
//! Value type of the represented complex element.
typedef typename If_< IsComplex<RepresentedType>
, ComplexType<RepresentedType>
, BuiltinType<RepresentedType> >::Type ValueType;
typedef ValueType value_type; //!< Value type of the represented complex element.
//**********************************************************************************************
//**Constructors********************************************************************************
/*!\name Constructors */
//@{
inline HermitianValue( IteratorType pos, MT* matrix, size_t index );
//@}
//**********************************************************************************************
//**Assignment operators************************************************************************
/*!\name Assignment operators */
//@{
inline HermitianValue& operator= ( const HermitianValue& hv );
template< typename T > inline HermitianValue& operator= ( const T& value );
template< typename T > inline HermitianValue& operator+=( const T& value );
template< typename T > inline HermitianValue& operator-=( const T& value );
template< typename T > inline HermitianValue& operator*=( const T& value );
template< typename T > inline HermitianValue& operator/=( const T& value );
//@}
//**********************************************************************************************
//**Utility functions***************************************************************************
/*!\name Utility functions */
//@{
inline void reset () const;
inline void clear () const;
inline void invert() const;
inline RepresentedType get() const noexcept;
//@}
//**********************************************************************************************
//**Conversion operator*************************************************************************
/*!\name Conversion operator */
//@{
inline operator RepresentedType() const noexcept;
//@}
//**********************************************************************************************
//**Complex data access functions***************************************************************
/*!\name Complex data access functions */
//@{
inline ValueType real() const;
inline void real( ValueType value ) const;
inline ValueType imag() const;
inline void imag( ValueType value ) const;
//@}
//**********************************************************************************************
private:
//**Utility functions***************************************************************************
/*!\name Utility functions */
//@{
inline void sync() const;
//@}
//**********************************************************************************************
//**Member variables****************************************************************************
IteratorType pos_; //!< Iterator to the current sparse Hermitian matrix element.
MT* matrix_; //!< The sparse matrix containing the iterator.
size_t index_; //!< The row/column index of the iterator.
//**********************************************************************************************
//**Compile time checks*************************************************************************
/*! \cond BLAZE_INTERNAL */
BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_CONST ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE ( MT );
BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( RepresentedType );
/*! \endcond */
//**********************************************************************************************
};
//*************************************************************************************************
//=================================================================================================
//
// CONSTRUCTORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Constructor for the HermitianValue class.
//
// \param pos The initial position of the iterator.
// \param matrix The sparse matrix containing the iterator.
// \param index The row/column index of the iterator.
*/
template< typename MT > // Type of the adapted matrix
inline HermitianValue<MT>::HermitianValue( IteratorType pos, MT* matrix, size_t index )
: pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
, matrix_( matrix ) // The sparse matrix containing the iterator
, index_ ( index ) // The row/column index of the iterator
{}
//*************************************************************************************************
//=================================================================================================
//
// OPERATORS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Copy assignment operator for HermitianValue.
//
// \param hv The Hermitian value to be copied.
// \return Reference to the assigned Hermitian value.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
inline HermitianValue<MT>& HermitianValue<MT>::operator=( const HermitianValue& hv )
{
const bool isDiagonal( pos_->index() == index_ );
if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( hv.pos_->value() ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
pos_->value() = hv.pos_->value();
sync();
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Assignment to the Hermitian value.
//
// \param value The new value of the Hermitian value.
// \return Reference to the assigned Hermitian value.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianValue<MT>& HermitianValue<MT>::operator=( const T& value )
{
const bool isDiagonal( pos_->index() == index_ );
if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
pos_->value() = value;
sync();
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Addition assignment to the Hermitian value.
//
// \param value The right-hand side value to be added to the Hermitian value.
// \return Reference to the assigned Hermitian value.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianValue<MT>& HermitianValue<MT>::operator+=( const T& value )
{
const bool isDiagonal( pos_->index() == index_ );
if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
pos_->value() += value;
sync();
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Subtraction assignment to the Hermitian value.
//
// \param value The right-hand side value to be subtracted from the Hermitian value.
// \return Reference to the assigned Hermitian value.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianValue<MT>& HermitianValue<MT>::operator-=( const T& value )
{
const bool isDiagonal( pos_->index() == index_ );
if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
pos_->value() -= value;
sync();
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Multiplication assignment to the Hermitian value.
//
// \param value The right-hand side value for the multiplication.
// \return Reference to the assigned Hermitian value.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianValue<MT>& HermitianValue<MT>::operator*=( const T& value )
{
const bool isDiagonal( pos_->index() == index_ );
if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
pos_->value() *= value;
sync();
return *this;
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Division assignment to the Hermitian value.
//
// \param value The right-hand side value for the division.
// \return Reference to the assigned Hermitian value.
// \exception std::invalid_argument Invalid assignment to diagonal matrix element.
*/
template< typename MT > // Type of the adapted matrix
template< typename T > // Type of the right-hand side value
inline HermitianValue<MT>& HermitianValue<MT>::operator/=( const T& value )
{
const bool isDiagonal( pos_->index() == index_ );
if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
}
pos_->value() /= value;
sync();
return *this;
}
//*************************************************************************************************
//=================================================================================================
//
// UTILITY FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Reset the Hermitian value to its default initial value.
//
// \return void
//
// This function resets the Hermitian value to its default initial value.
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianValue<MT>::reset() const
{
using blaze::reset;
reset( pos_->value() );
if( pos_->index() != index_ )
{
const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
const IteratorType pos2( matrix_->find( row, column ) );
reset( pos2->value() );
}
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Clearing the Hermitian value.
//
// \return void
//
// This function clears the Hermitian value to its default initial state.
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianValue<MT>::clear() const
{
using blaze::clear;
clear( pos_->value() );
if( pos_->index() != index_ )
{
const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
const IteratorType pos2( matrix_->find( row, column ) );
clear( pos2->value() );
}
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief In-place inversion of the Hermitian value
//
// \return void
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianValue<MT>::invert() const
{
using blaze::invert;
invert( pos_->value() );
if( pos_->index() != index_ )
{
const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
const IteratorType pos2( matrix_->find( row, column ) );
pos2->value() = conj( pos_->value() );
}
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Access to the represented value.
//
// \return Copy of the represented value.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianValue<MT>::RepresentedType HermitianValue<MT>::get() const noexcept
{
return pos_->value();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Synchronization of the current sparse element to the according paired element.
//
// \return void
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianValue<MT>::sync() const
{
if( pos_->index() == index_ || isDefault( pos_->value() ) )
return;
const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
matrix_->set( row, column, conj( pos_->value() ) );
}
//*************************************************************************************************
//=================================================================================================
//
// CONVERSION OPERATOR
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Conversion to the represented value.
//
// \return Copy of the represented value.
*/
template< typename MT > // Type of the adapted matrix
inline HermitianValue<MT>::operator RepresentedType() const noexcept
{
return pos_->value();
}
//*************************************************************************************************
//=================================================================================================
//
// COMPLEX DATA ACCESS FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\brief Returns the real part of the represented complex number.
//
// \return The current real part of the represented complex number.
//
// In case the value represents a complex number, this function returns the current value
// of its real part.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianValue<MT>::ValueType HermitianValue<MT>::real() const
{
return pos_->value().real();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Setting the real part of the represented complex number.
//
// \param value The new value for the real part.
// \return void
//
// In case the value represents a complex number, this function sets a new value to its
// real part.
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianValue<MT>::real( ValueType value ) const
{
pos_->value().real() = value;
sync();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns the imaginary part of the represented complex number.
//
// \return The current imaginary part of the represented complex number.
//
// In case the value represents a complex number, this function returns the current value of its
// imaginary part.
*/
template< typename MT > // Type of the adapted matrix
inline typename HermitianValue<MT>::ValueType HermitianValue<MT>::imag() const
{
return pos_->value.imag();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Setting the imaginary part of the represented complex number.
//
// \param value The new value for the imaginary part.
// \return void
//
// In case the proxy represents a complex number, this function sets a new value to its
// imaginary part.
*/
template< typename MT > // Type of the adapted matrix
inline void HermitianValue<MT>::imag( ValueType value ) const
{
pos_->value().imag( value );
sync();
}
//*************************************************************************************************
//=================================================================================================
//
// GLOBAL FUNCTIONS
//
//=================================================================================================
//*************************************************************************************************
/*!\name HermitianValue global functions */
//@{
template< typename MT >
inline void reset( const HermitianValue<MT>& value );
template< typename MT >
inline void clear( const HermitianValue<MT>& value );
template< typename MT >
inline void invert( const HermitianValue<MT>& value );
template< typename MT >
inline bool isDefault( const HermitianValue<MT>& value );
template< typename MT >
inline bool isReal( const HermitianValue<MT>& value );
template< typename MT >
inline bool isZero( const HermitianValue<MT>& value );
template< typename MT >
inline bool isOne( const HermitianValue<MT>& value );
template< typename MT >
inline bool isnan( const HermitianValue<MT>& value );
//@}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Resetting the Hermitian value to the default initial values.
// \ingroup hermitian_matrix
//
// \param value The given Hermitian value.
// \return void
//
// This function resets the Hermitian value to its default initial value.
*/
template< typename MT >
inline void reset( const HermitianValue<MT>& value )
{
value.reset();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Clearing the Hermitian value.
// \ingroup hermitian_matrix
//
// \param value The given Hermitian value.
// \return void
//
// This function clears the Hermitian value to its default initial state.
*/
template< typename MT >
inline void clear( const HermitianValue<MT>& value )
{
value.clear();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief In-place inversion of the Hermitian value.
// \ingroup hermitian_matrix
//
// \param value The given Hermitian value.
// \return void
*/
template< typename MT >
inline void invert( const HermitianValue<MT>& value )
{
value.invert();
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the Hermitian value is in default state.
// \ingroup hermitian_matrix
//
// \param value The given Hermitian value.
// \return \a true in case the Hermitian value is in default state, \a false otherwise.
//
// This function checks whether the Hermitian value is in default state. In case it is in
// default state, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isDefault( const HermitianValue<MT>& value )
{
using blaze::isDefault;
return isDefault( value.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the Hermitian value represents a real number.
// \ingroup hermitian_matrix
//
// \param value The given Hermitian value.
// \return \a true in case the Hermitian value represents a real number, \a false otherwise.
//
// This function checks whether the Hermitian value represents the a real number. In case the
// value is of built-in type, the function returns \a true. In case the element is of complex
// type, the function returns \a true if the imaginary part is equal to 0. Otherwise it returns
// \a false.
*/
template< typename MT >
inline bool isReal( const HermitianValue<MT>& value )
{
using blaze::isReal;
return isReal( value.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the Hermitian value is 0.
// \ingroup hermitian_matrix
//
// \param value The given Hermitian value.
// \return \a true in case the Hermitian value is 0, \a false otherwise.
//
// This function checks whether the Hermitian value represents the numeric value 0. In case it
// is 0, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isZero( const HermitianValue<MT>& value )
{
using blaze::isZero;
return isZero( value.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the Hermitian value is 1.
// \ingroup hermitian_matrix
//
// \param value The given Hermitian value.
// \return \a true in case the Hermitian value is 1, \a false otherwise.
//
// This function checks whether the Hermitian value represents the numeric value 1. In case it
// is 1, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isOne( const HermitianValue<MT>& value )
{
using blaze::isOne;
return isOne( value.get() );
}
//*************************************************************************************************
//*************************************************************************************************
/*!\brief Returns whether the Hermitian value is not a number.
// \ingroup hermitian_matrix
//
// \param value The given Hermitian value.
// \return \a true in case the Hermitian value is in not a number, \a false otherwise.
//
// This function checks whether the Hermitian value is not a number (NaN). In case it is not a
// number, the function returns \a true, otherwise it returns \a false.
*/
template< typename MT >
inline bool isnan( const HermitianValue<MT>& value )
{
using blaze::isnan;
return isnan( value.get() );
}
//*************************************************************************************************
} // namespace blaze
#endif

Some files were not shown because too many files have changed in this diff Show More