2 // Copyright (c) 2000-2002
3 // Joerg Walter, Mathias Koch
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // The authors gratefully acknowledge the support of
10 // GeNeSys mbH & Co. KG in producing this work.
13 #ifndef _BOOST_UBLAS_DEFINITIONS_
14 #define _BOOST_UBLAS_DEFINITIONS_
17 namespace boost { namespace numeric { namespace ublas {
20 /* Borrowed from boost/concept_checks.hpp
21 "inline" is used for ignore_unused_variable_warning()
22 to make sure there is no overhead with g++.
24 template <class T> inline
25 void ignore_unused_variable_warning(const T&) {}
28 // Borrowed from Dave Abraham's noncopyable.
29 // I believe this should be part of utility.hpp one day...
30 namespace nonassignable_ // protection from unintended ADL
36 private: // emphasize the following members are private
37 const nonassignable& operator= (const nonassignable &);
40 typedef nonassignable_::nonassignable nonassignable;
44 // Provides temporary free assigment when LHS has no alias on RHS
47 private nonassignable {
49 typedef typename C::closure_type closure_type;
52 noalias_proxy (C& lval):
53 nonassignable (), lval_ (lval) {}
55 noalias_proxy (const noalias_proxy& p):
56 nonassignable (), lval_ (p.lval_) {}
60 closure_type &operator= (const E& e) {
67 closure_type &operator+= (const E& e) {
68 lval_.plus_assign (e);
74 closure_type &operator-= (const E& e) {
75 lval_.minus_assign (e);
83 // Improve syntax of efficient assignment where no aliases of LHS appear on the RHS
84 // noalias(lhs) = rhs_expression
87 noalias_proxy<C> noalias (C& lvalue) {
88 return noalias_proxy<C> (lvalue);
92 noalias_proxy<const C> noalias (const C& lvalue) {
93 return noalias_proxy<const C> (lvalue);
96 // Possible future compatible syntax where lvalue possible has an unsafe alias on the RHS
97 // safe(lhs) = rhs_expression
100 C& safe (C& lvalue) {
105 const C& safe (const C& lvalue) {
110 // Dimension accessors
111 namespace dimension {
114 template<unsigned dimension>
115 struct dimension_properties {};
118 struct dimension_properties<1> {
120 BOOST_UBLAS_INLINE static
121 typename E::size_type size (const vector_expression<E> &e) {
125 BOOST_UBLAS_INLINE static
126 typename E::size_type size (const matrix_expression<E> &e) {
127 return e ().size1 ();
129 // Note: Index functions cannot deduce dependant template parameter V or M from i
131 BOOST_UBLAS_INLINE static
132 typename V::size_type index (const typename V::iterator &i) {
136 BOOST_UBLAS_INLINE static
137 typename M::size_type index (const typename M::iterator1 &i) {
141 BOOST_UBLAS_INLINE static
142 typename M::size_type index (const typename M::iterator2 &i) {
147 struct dimension_properties<2> {
149 BOOST_UBLAS_INLINE static
150 typename E::size_type size (const vector_expression<E> &) {
154 BOOST_UBLAS_INLINE static
155 typename E::size_type size (const matrix_expression<E> &e) {
156 return e ().size2 ();
159 BOOST_UBLAS_INLINE static
160 typename V::size_type index (const typename V::iterator &) {
164 BOOST_UBLAS_INLINE static
165 typename M::size_type index (const typename M::iterator1 &i) {
169 BOOST_UBLAS_INLINE static
170 typename M::size_type index (const typename M::iterator2 &i) {
175 template<unsigned dimension, class E>
177 typename E::size_type size (const E& e) {
178 return dimension_properties<dimension>::size (e);
181 template<unsigned dimension, class I>
183 typename I::container_type::size_type
185 typedef typename I::container_type container_type;
186 return dimension_properties<dimension>::template index<container_type> (i);
190 // Named accessors - just syntactic sugar
192 typename V::size_type num_elements (const V &v) {
196 typename M::size_type num_rows (const M &m) {
200 typename M::size_type num_columns (const M &m) {
204 typename MV::size_type num_non_zeros (const MV &mv) {
205 return mv.non_zeros ();