⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vector_concepts.hpp

📁 矩阵运算源码最新版本
💻 HPP
📖 第 1 页 / 共 2 页
字号:
// Copyright 2006. Peter Gottschling, Matthias Troyer, Rolf Bonderer// Software License for MTL// // Copyright (c) 2007 The Trustees of Indiana University. All rights reserved.// Authors: Peter Gottschling and Andrew Lumsdaine// // This file is part of the Matrix Template Library// // See also license.mtl.txt in the distribution.#ifndef LA_VECTOR_CONCEPTS_INCLUDE#define LA_VECTOR_CONCEPTS_INCLUDE#include <boost/numeric/linear_algebra/concepts.hpp>#include <boost/numeric/linear_algebra/ets_concepts.hpp>#ifdef __GXX_CONCEPTS__#  include <concepts>#else #  include <boost/numeric/linear_algebra/pseudo_concept.hpp>#endifnamespace math {    /** @addtogroup Concepts *  @{ */#ifdef __GXX_CONCEPTS__concept VectorSpace<typename Vector, typename Scalar = typename Vector::value_type>: AdditiveAbelianGroup<Vector>{    requires Field<Scalar>;    requires Multiplicable<Scalar, Vector>;    requires MultiplicableWithAssign<Vector, Scalar>;    requires DivisibleWithAssign<Vector, Scalar>;      requires std::Assignable<Vector, Multiplicable<Scalar, Vector>::result_type>;    requires std::Assignable<Vector, Multiplicable<Vector, Scalar>::result_type>;    requires std::Assignable<Vector, Divisible<Vector, Scalar>::result_type>;        // Associated types of Field<Scalar> and AdditiveAbelianGroup<Vector> collide    // typename result_type = AdditiveAbelianGroup<Vector>::result_type;    // typename assign_result_type = AdditiveAbelianGroup<Vector>::assign_result_type;    axiom Distributivity(Vector v, Vector w, Scalar a, Scalar b)    {	a * (v + w) == a * v + a * w;	(a + b) * v == a * v + b * v;	// The following properties are implied by the above, Field and Abelian group	// Can we be sure that compilers can deduce/interfere it?	(v + w) * a == v * a + w * a;	v * (a + b) == v * a + v * b;    }}#else    //! Concept VectorSpace    /*!	\param Vector   The the type of a vector or a collection         \param Scalar   The scalar over which the vector field is defined        	\par Requires:	- Field < Scalar >;	- Multiplicable <Scalar, Vector>;	- MultiplicableWithAssign <Vector, Scalar>;	- DivisibleWithAssign <Vector, Scalar>;	- std::Assignable <Vector, Multiplicable<Scalar, Vector>::result_type>;	- std::Assignable <Vector, Multiplicable<Vector, Scalar>::result_type>;	- std::Assignable <Vector, Divisible<Vector, Scalar>::result_type>;    */    template <typename Vector, typename Scalar = typename Vector::value_type>    struct VectorSpace      : AdditiveAbelianGroup<Vector>    {	/// Invariant: Distributivity of scalars and vectors from left and from right	axiom Distributivity(Vector v, Vector w, Scalar a, Scalar b)	{	    /// a * (v + w) == a * v + a * w;       // Scalar from left	    /// Vector from right: (a + b) * v == a * v + b * v; 	    /// Scalar from right: (v + w) * a == v * a + w * a; 	    /// Vector from left:  v * (a + b) == v * a + v * b;	}    };#endif#ifdef __GXX_CONCEPTS__concept Norm<typename N, typename Vector, 	     typename Scalar = typename Vector::value_type>  : std::Callable1<N, Vector>{    requires VectorSpace<Vector, Scalar>;    requires RealMagnitude<Scalar>;    typename magnitude_type = MagnitudeType<Scalar>::type;    requires std::Convertible<magnitude_type, Scalar>;    typename result_type_norm = std::Callable1<N, Vector>::result_type;    requires std::Convertible<result_type_norm, RealMagnitude<Scalar>::magnitude_type>;    requires std::Convertible<result_type_norm, Scalar>;    // Version with function instead functor, as used by Rolf and Matthias    // Axioms there defined without norm functor and concept has only 2 types#if 0           typename result_type_norm;     result_type_norm norm(const Vector&);    requires std::Convertible<result_type_norm, magnitude_type>;    requires std::Convertible<result_type_norm, Scalar>;#endif    axiom Positivity(N norm, Vector v, magnitude_type ref)    {	norm(v) >= zero(ref);    }    // The following is covered by RealMagnitude    // requires AbsApplicable<Scalar>;    // requires std::Convertible<AbsApplicable<Scalar>::result_type, magnitude_type>;    // requires Multiplicable<magnitude_type>;    axiom PositiveHomogeneity(N norm, Vector v, Scalar a)    {	norm(a * v) == abs(a) * norm(v);    }    axiom TriangleInequality(N norm, Vector u, Vector v)    {	norm(u + v) <= norm(u) + norm(v);    }}#else    //! Concept Norm    /*!        Semantic requirements of a norm	\param N        Norm functor	\param Vector   The the type of a vector or a collection         \param Scalar   The scalar over which the vector field is defined        	\par Refinement of:	- std::Callable1 <N, Vector>	\par Associated types:	- magnitude_type	- result_type_norm	\par Requires:	- VectorSpace <Vector, Scalar>;	- RealMagnitude < Scalar >;	- std::Convertible <magnitude_type, Scalar>;	- std::Convertible <result_type_norm, RealMagnitude<Scalar>::magnitude_type>;	- std::Convertible <result_type_norm, Scalar>;    */template <typename N, typename Vector, 	  typename Scalar = typename Vector::value_type>struct Norm  : std::Callable1<N, Vector>{    /// Associated type to represent real values in teh Field of scalar (with default)    /** By default MagnitudeType<Scalar>::type */    typedef associated_type magnitude_type;    /// Associated type for result of norm functor    /** Automatically detected */    typedef associated_type result_type_norm;    /// Invariant: norm of vector is larger than zero     axiom Positivity(N norm, Vector v, magnitude_type ref)    {	/// norm(v) >= zero(ref);    }    /// Invariant: positive homogeneity with scalar    axiom PositiveHomogeneity(N norm, Vector v, Scalar a)    {	/// norm(a * v) == abs(a) * norm(v);    }    /// Invariant: triangle inequality    axiom TriangleInequality(N norm, Vector u, Vector v)    {	/// norm(u + v) <= norm(u) + norm(v);    }};#endif#ifdef __GXX_CONCEPTS__concept SemiNorm<typename N, typename Vector, 		 typename Scalar = typename Vector::value_type>  : Norm<N, Vector, Scalar>{    axiom PositiveDefiniteness(N norm, Vector v, magnitude_type ref)    {	if (norm(v) == zero(ref))	    v == zero(v);	if (v == zero(v))	    norm(v) == zero(ref);    }}#else    //! Concept SemiNorm    /*!        Semantic requirements of a semi-norm	\param N        Norm functor	\param Vector   The the type of a vector or a collection         \param Scalar   The scalar over which the vector field is defined        	\par Refinement of:	- Norm <N, Vector, Scalar>    */template <typename N, typename Vector, 	  typename Scalar = typename Vector::value_type>struct SemiNorm  : Norm<N, Vector, Scalar>{    /// The norm of a vector is zero if and only if the vector is the zero vector    axiom PositiveDefiniteness(N norm, Vector v, magnitude_type ref)    {	/// if (norm(v) == zero(ref)) v == zero(v);	/// if (v == zero(v)) norm(v) == zero(ref);    }};#endif#ifdef __GXX_CONCEPTS__concept BanachSpace<typename N, typename Vector, 		    typename Scalar = typename Vector::value_type>  : Norm<N, Vector, Scalar>,    VectorSpace<Vector, Scalar>{};#else    //! Concept BanachSpace    /*!        A Banach space is a vector space with a norm	\param N        Norm functor	\param Vector   The the type of a vector or a collection         \param Scalar   The scalar over which the vector field is defined        	\par Refinement of:	- Norm <N, Vector, Scalar>	- VectorSpace <Vector, Scalar>	\note	- The (expressible) requirements of Banach Space are already given in Norm.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -