Update of /cvsroot/boost/boost/boost/numeric/ublas
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13019
Modified Files:
exception.hpp matrix.hpp storage.hpp traits.hpp vector.hpp
Log Message:
- add optimizations for trivial constructors to array types
- add initializing constructors to matix<> and vector<>
usage: matrix<double> m(3,3,5.0); vector<double> v(3,5.0);
- avoid constructor call for std::complex<T>, user can specialize
detail::has_trivial_constructor<T> to control this behavior
Index: exception.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/numeric/ublas/exception.hpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- exception.hpp 2 Feb 2006 19:27:23 -0000 1.19
+++ exception.hpp 16 Mar 2007 22:39:16 -0000 1.20
@@ -267,11 +267,19 @@
// return (std::min) (size1, size2);
// }
// #define BOOST_UBLAS_SAME(size1, size2) same_impl ((size1), (size2))
- template<class T>
+ // need two types here because different containers can have
+ // different size_types (especially sparse types)
+ template<class T1, class T2>
BOOST_UBLAS_INLINE
// Kresimir Fresl and Dan Muller reported problems with COMO.
// We better change the signature instead of libcomo ;-)
// const T &same_impl_ex (const T &size1, const T &size2, const char
*file, int line) {
+ T1 same_impl_ex (const T1 &size1, const T2 &size2, const char *file, int
line) {
+ BOOST_UBLAS_CHECK_EX (size1 == size2, file, line, bad_argument ());
+ return (size1 < size2)?(size1):(size2);
+ }
+ template<class T>
+ BOOST_UBLAS_INLINE
T same_impl_ex (const T &size1, const T &size2, const char *file, int
line) {
BOOST_UBLAS_CHECK_EX (size1 == size2, file, line, bad_argument ());
return (std::min) (size1, size2);
Index: matrix.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/numeric/ublas/matrix.hpp,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- matrix.hpp 16 Mar 2007 21:17:54 -0000 1.73
+++ matrix.hpp 16 Mar 2007 22:39:16 -0000 1.74
@@ -97,6 +97,10 @@
matrix_container<self_type> (),
size1_ (size1), size2_ (size2), data_ (layout_type::storage_size
(size1, size2)) {
}
+ matrix (size_type size1, size_type size2, const value_type &init):
+ matrix_container<self_type> (),
+ size1_ (size1), size2_ (size2), data_ (layout_type::storage_size
(size1, size2), init) {
+ }
BOOST_UBLAS_INLINE
matrix (size_type size1, size_type size2, const array_type &data):
matrix_container<self_type> (),
Index: storage.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/numeric/ublas/storage.hpp,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- storage.hpp 21 Jun 2006 18:17:53 -0000 1.75
+++ storage.hpp 16 Mar 2007 22:39:16 -0000 1.76
@@ -23,6 +23,7 @@
#endif
#include <boost/numeric/ublas/exception.hpp>
+#include <boost/numeric/ublas/traits.hpp>
#include <boost/numeric/ublas/detail/iterator.hpp>
@@ -63,19 +64,15 @@
explicit BOOST_UBLAS_INLINE
unbounded_array (size_type size, const ALLOC &a = ALLOC()):
alloc_(a), size_ (size) {
- if (size_) {
- data_ = alloc_.allocate (size_);
- // ISSUE some compilers may zero POD here
-#ifdef BOOST_UBLAS_USEFUL_ARRAY_PLACEMENT_NEW
- // array form fails on some compilers due to size cookie, is
it standard conforming?
- new (data_) value_type[size_];
-#else
- for (pointer d = data_; d != data_ + size_; ++d)
- new (d) value_type;
-#endif
- }
- else
- data_ = 0;
+ if (size_) {
+ data_ = alloc_.allocate (size_);
+ if (not detail::has_trivial_constructor<T>::value) {
+ for (pointer d = data_; d != data_ + size_; ++d)
+ alloc_.construct(d, value_type());
+ }
+ }
+ else
+ data_ = 0;
}
// No value initialised, but still be default constructed
BOOST_UBLAS_INLINE
@@ -101,9 +98,12 @@
BOOST_UBLAS_INLINE
~unbounded_array () {
if (size_) {
- const iterator i_end = end();
- for (iterator i = begin (); i != i_end; ++i) {
- iterator_destroy (i);
+ if (not detail::has_trivial_destructor<T>::value) {
+ // std::_Destroy (begin(), end(), alloc_);
+ const iterator i_end = end();
+ for (iterator i = begin (); i != i_end; ++i) {
+ iterator_destroy (i);
+ }
}
alloc_.deallocate (data_, size_);
}
@@ -137,20 +137,18 @@
}
}
else {
- // ISSUE some compilers may zero POD here
-#ifdef BOOST_UBLAS_USEFUL_ARRAY_PLACEMENT_NEW
- // array form fails on some compilers due to size
cookie, is it standard conforming?
- new (data_) value_type[size];
-#else
- for (pointer di = data_; di != data_ + size; ++di)
- new (di) value_type;
-#endif
+ if (not detail::has_trivial_constructor<T>::value) {
+ for (pointer di = data_; di != data_ + size; ++di)
+ alloc_.construct (di, value_type());
+ }
}
}
if (size_) {
- for (pointer si = p_data; si != p_data + size_; ++si)
- alloc_.destroy (si);
+ if (not detail::has_trivial_destructor<T>::value) {
+ for (pointer si = p_data; si != p_data + size_; ++si)
+ alloc_.destroy (si);
+ }
alloc_.deallocate (p_data, size_);
}
Index: traits.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/numeric/ublas/traits.hpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- traits.hpp 7 Oct 2006 18:18:01 -0000 1.41
+++ traits.hpp 16 Mar 2007 22:39:16 -0000 1.42
@@ -25,6 +25,8 @@
#include <boost/numeric/ublas/detail/iterator.hpp>
#include <boost/numeric/ublas/detail/returntype_deduction.hpp>
+#include <boost/type_traits.hpp>
+#include <complex>
namespace boost { namespace numeric { namespace ublas {
@@ -485,6 +487,24 @@
it = it_end;
}
+ namespace detail {
+
+ // specialisation which define whether a type has a trivial constructor
+ // or not. This is used by array types.
+ template<typename T>
+ struct has_trivial_constructor : public
boost::has_trivial_constructor<T> {};
+
+ template<typename T>
+ struct has_trivial_destructor : public
boost::has_trivial_destructor<T> {};
+
+ template<typename FLT>
+ struct has_trivial_constructor<std::complex<FLT> > : public
boost::true_type {};
+
+ template<typename FLT>
+ struct has_trivial_destructor<std::complex<FLT> > : public
boost::true_type {};
+
+ }
+
}}}
#endif
Index: vector.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/numeric/ublas/vector.hpp,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- vector.hpp 16 Mar 2007 21:26:39 -0000 1.75
+++ vector.hpp 16 Mar 2007 22:39:17 -0000 1.76
@@ -63,6 +63,10 @@
vector_container<self_type> (),
data_ (data) {}
BOOST_UBLAS_INLINE
+ vector (size_type size, const value_type &init):
+ vector_container<self_type> (),
+ data_ (size, init) {}
+ BOOST_UBLAS_INLINE
vector (const vector &v):
vector_container<self_type> (),
data_ (v.data_) {}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs