Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:59

0001 //
0002 //  Copyright (c) 2000-2002
0003 //  Joerg Walter, Mathias Koch
0004 //
0005 //  Distributed under the Boost Software License, Version 1.0. (See
0006 //  accompanying file LICENSE_1_0.txt or copy at
0007 //  http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 //  The authors gratefully acknowledge the support of
0010 //  GeNeSys mbH & Co. KG in producing this work.
0011 //
0012 
0013 #ifndef _BOOST_UBLAS_DEFINITIONS_
0014 #define _BOOST_UBLAS_DEFINITIONS_
0015 
0016 
0017 namespace boost { namespace numeric { namespace ublas {
0018 
0019     namespace detail {
0020         /* Borrowed from boost/concept_checks.hpp
0021            "inline" is used for ignore_unused_variable_warning()
0022            to make sure there is no overhead with g++.
0023          */
0024         template <class T> inline
0025         void ignore_unused_variable_warning(const T&) {}
0026     } // namespace detail
0027 
0028     // Borrowed from Dave Abraham's noncopyable.
0029     // I believe this should be part of utility.hpp one day...
0030     namespace nonassignable_  // protection from unintended ADL
0031     {
0032         class nonassignable {
0033         protected:
0034             nonassignable () {}
0035             ~nonassignable () {}
0036         private:  // emphasize the following members are private
0037             const nonassignable& operator= (const nonassignable &);
0038         }; // nonassignable
0039     }
0040     typedef nonassignable_::nonassignable nonassignable;
0041 
0042 
0043     // Assignment proxy.
0044     // Provides temporary free assigment when LHS has no alias on RHS
0045     template<class C>
0046     class noalias_proxy:
0047         private nonassignable {
0048     public:
0049         typedef typename C::closure_type closure_type;
0050 
0051         BOOST_UBLAS_INLINE
0052         noalias_proxy (C& lval):
0053             nonassignable (), lval_ (lval) {}
0054         BOOST_UBLAS_INLINE
0055         noalias_proxy (const noalias_proxy& p):
0056             nonassignable (), lval_ (p.lval_) {}
0057 
0058         template <class E>
0059         BOOST_UBLAS_INLINE
0060         closure_type &operator= (const E& e) {
0061             lval_.assign (e);
0062             return lval_;
0063         }
0064 
0065         template <class E>
0066         BOOST_UBLAS_INLINE
0067         closure_type &operator+= (const E& e) {
0068             lval_.plus_assign (e);
0069             return lval_;
0070         }
0071 
0072         template <class E>
0073         BOOST_UBLAS_INLINE
0074         closure_type &operator-= (const E& e) {
0075             lval_.minus_assign (e);
0076             return lval_;
0077         }
0078 
0079     private:
0080         closure_type lval_;
0081     };
0082 
0083     // Improve syntax of efficient assignment where no aliases of LHS appear on the RHS
0084     //  noalias(lhs) = rhs_expression
0085     template <class C>
0086     BOOST_UBLAS_INLINE
0087     noalias_proxy<C> noalias (C& lvalue) {
0088         return noalias_proxy<C> (lvalue);
0089     }
0090     template <class C>
0091     BOOST_UBLAS_INLINE
0092     noalias_proxy<const C> noalias (const C& lvalue) {
0093         return noalias_proxy<const C> (lvalue);
0094     }
0095 
0096     // Possible future compatible syntax where lvalue possible has an unsafe alias on the RHS
0097     //  safe(lhs) = rhs_expression
0098     template <class C>
0099     BOOST_UBLAS_INLINE
0100     C& safe (C& lvalue) {
0101         return lvalue;
0102     }
0103     template <class C>
0104     BOOST_UBLAS_INLINE
0105     const C& safe (const C& lvalue) {
0106         return lvalue;
0107     }
0108 
0109 
0110     // Dimension accessors
0111     namespace dimension {
0112 
0113         // Generic accessors
0114         template<unsigned dimension>
0115         struct dimension_properties {};
0116         
0117         template<>
0118         struct dimension_properties<1> {
0119             template <class E>
0120             BOOST_UBLAS_INLINE static
0121             typename E::size_type size (const vector_expression<E> &e) {
0122                 return e ().size ();
0123             }
0124             template <class E>
0125             BOOST_UBLAS_INLINE static
0126             typename E::size_type size (const matrix_expression<E> &e) {
0127                 return e ().size1 ();
0128             }
0129             // Note: Index functions cannot deduce dependant template parameter V or M from i
0130             template <class V>
0131             BOOST_UBLAS_INLINE static
0132             typename V::size_type index (const typename V::iterator &i) {
0133                 return i.index ();
0134             }
0135             template <class M>
0136             BOOST_UBLAS_INLINE static
0137             typename M::size_type index (const typename M::iterator1 &i) {
0138                 return i.index1 ();
0139             }
0140             template <class M>
0141             BOOST_UBLAS_INLINE static
0142             typename M::size_type index (const typename M::iterator2 &i) {
0143                 return i.index1 ();
0144             }
0145         };
0146         template<>
0147         struct dimension_properties<2> {
0148             template <class E>
0149             BOOST_UBLAS_INLINE static
0150             typename E::size_type size (const vector_expression<E> &) {
0151                 return 1;
0152             }
0153             template <class E>
0154             BOOST_UBLAS_INLINE static
0155             typename E::size_type size (const matrix_expression<E> &e) {
0156                 return e ().size2 ();
0157             }
0158             template <class V>
0159             BOOST_UBLAS_INLINE static
0160             typename V::size_type index (const typename V::iterator &) {
0161                 return 1;
0162             }
0163             template <class M>
0164             BOOST_UBLAS_INLINE static
0165             typename M::size_type index (const typename M::iterator1 &i) {
0166                 return i.index2 ();
0167             }
0168             template <class M>
0169             BOOST_UBLAS_INLINE static
0170             typename M::size_type index (const typename M::iterator2 &i) {
0171                 return i.index2 ();
0172             }
0173         };
0174 
0175         template<unsigned dimension, class E>
0176         BOOST_UBLAS_INLINE
0177         typename E::size_type size (const E& e) {
0178             return dimension_properties<dimension>::size (e);
0179         }
0180 
0181         template<unsigned dimension, class I>
0182         BOOST_UBLAS_INLINE
0183         typename I::container_type::size_type
0184         index (const I& i) {
0185             typedef typename I::container_type container_type;
0186             return dimension_properties<dimension>::template index<container_type> (i);
0187         }
0188 
0189 
0190         // Named accessors - just syntactic sugar
0191         template<class V>
0192         typename V::size_type num_elements (const V &v) {
0193             return v.size ();
0194         }
0195         template<class M>
0196         typename M::size_type num_rows (const M &m) {
0197             return m.size1 ();
0198         }
0199         template<class M>
0200         typename M::size_type num_columns (const M &m) {
0201             return m.size2 ();
0202         }
0203         template<class MV>
0204         typename MV::size_type num_non_zeros (const MV &mv) {
0205             return mv.non_zeros ();
0206         }
0207     }
0208 
0209 
0210 }}}
0211 
0212 #endif