Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58541 - in sandbox/numeric_bindings/boost/numeric/bindings: . detail lapack/detail
From: rutger_at_[hidden]
Date: 2009-12-28 08:03:59


Author: rutger
Date: 2009-12-28 08:03:58 EST (Mon, 28 Dec 2009)
New Revision: 58541
URL: http://svn.boost.org/trac/boost/changeset/58541

Log:
updating lapack bindings and generator

Added:
   sandbox/numeric_bindings/boost/numeric/bindings/detail/array.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/detail/fortran.h (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/lapack/detail/lapack_option.hpp (contents, props changed)
Text files modified:
   sandbox/numeric_bindings/boost/numeric/bindings/size.hpp | 36 ++++++++++++++++++++++++++++++++++++
   sandbox/numeric_bindings/boost/numeric/bindings/trans_tag.hpp | 6 +++---
   2 files changed, 39 insertions(+), 3 deletions(-)

Added: sandbox/numeric_bindings/boost/numeric/bindings/detail/array.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/array.hpp 2009-12-28 08:03:58 EST (Mon, 28 Dec 2009)
@@ -0,0 +1,127 @@
+//
+// Copyright (c) 2003 Kresimir Fresl
+// Copyright (c) 2009 Rutger ter Borg
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef BOOST_NUMERIC_BINDINGS_DETAIL_ARRAY_HPP
+#define BOOST_NUMERIC_BINDINGS_DETAIL_ARRAY_HPP
+
+#include <new>
+#include <boost/noncopyable.hpp>
+#include <boost/numeric/bindings/detail/adaptor.hpp>
+
+
+/*
+ very simple dynamic array class which is used in `higher level'
+ bindings functions for pivot and work arrays
+
+ Namely, there are (at least) two versions of all bindings functions
+ where called LAPACK function expects work and/or pivot array, e.g.
+
+ `lower' level (user should provide work and pivot arrays):
+ int sysv (SymmA& a, IVec& i, MatrB& b, Work& w);
+
+ `higher' level (with `internal' work and pivot arrays):
+ int sysv (SymmA& a, MatrB& b);
+
+ Probably you ask why I didn't use std::vector. There are two reasons.
+ First is efficiency -- std::vector's constructor initialises vector
+ elements. Second is consistency. LAPACK functions use `info' parameter
+ as an error indicator. On the other hand, std::vector's allocator can
+ throw an exception if memory allocation fails. detail::array's
+ constructor uses `new (nothrow)' which returns 0 if allocation fails.
+ So I can check whether array::storage == 0 and return appropriate error
+ in `info'.*/
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template <typename T>
+class array : private noncopyable {
+public:
+ typedef std::ptrdiff_t size_type ;
+
+ array (size_type n) {
+ stg = new (std::nothrow) T[n];
+ sz = (stg != 0) ? n : 0;
+ }
+
+ ~array() {
+ delete[] stg;
+ }
+
+ size_type size() const {
+ return sz;
+ }
+
+ bool valid() const {
+ return stg != 0;
+ }
+
+ void resize (int n) {
+ delete[] stg;
+ stg = new (std::nothrow) T[n];
+ sz = (stg != 0) ? n : 0;
+ }
+
+ T* storage() {
+ return stg;
+ }
+
+ T const* storage() const {
+ return stg;
+ }
+
+ T& operator[] (int i) {
+ return stg[i];
+ }
+
+ T const& operator[] (int i) const {
+ return stg[i];
+ }
+
+private:
+ size_type sz;
+ T* stg;
+};
+
+
+template< typename T, typename Id, typename Enable >
+struct adaptor< array< T >, Id, Enable > {
+
+ typedef typename copy_const< Id, T >::type value_type;
+ typedef mpl::map<
+ mpl::pair< tag::value_type, value_type >,
+ mpl::pair< tag::entity, tag::vector >,
+ mpl::pair< tag::size_type<1>, std::ptrdiff_t >,
+ mpl::pair< tag::data_structure, tag::linear_array >,
+ mpl::pair< tag::stride_type<1>, tag::contiguous >
+ > property_map;
+
+ static std::ptrdiff_t size1( const Id& t ) {
+ return t.size();
+ }
+
+ static value_type* begin_value( Id& t ) {
+ return t.storage();
+ }
+
+ static value_type* end_value( Id& t ) {
+ return t.storage() + t.size();
+ }
+
+};
+
+
+} // namespace detail
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

Added: sandbox/numeric_bindings/boost/numeric/bindings/detail/fortran.h
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/fortran.h 2009-12-28 08:03:58 EST (Mon, 28 Dec 2009)
@@ -0,0 +1,51 @@
+//
+// Copyright (C) 2002, 2003 Si-Lab b.v.b.a., Toon Knapen and Kresimir Fresl
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef BOOST_NUMERIC_BINDINGS_TRAITS_FORTRAN_H
+#define BOOST_NUMERIC_BINDINGS_TRAITS_FORTRAN_H
+
+#if defined(BIND_FORTRAN_LOWERCASE_UNDERSCORE) || defined(BIND_FORTRAN_LOWERCASE)
+// Allow manual override of the defaults, e.g. if you want to use a fortran
+// lib compiled with gcc from MSVC
+#else
+
+// First we need to know what the conventions for linking
+// C with Fortran is on this platform/toolset
+#if defined(__GNUC__) || defined(__ICC) || defined(__sgi) || defined(__COMO__) || defined(__KCC)
+#define BIND_FORTRAN_LOWERCASE_UNDERSCORE
+#elif defined(__IBMCPP__) || defined(_MSC_VER)
+#define BIND_FORTRAN_LOWERCASE
+#else
+#error do not know how to link with fortran for the given platform
+#endif
+
+#endif
+
+// Next we define macro's to convert our symbols to
+// the current convention
+#if defined(BIND_FORTRAN_LOWERCASE_UNDERSCORE)
+#define FORTRAN_ID( id ) id##_
+#elif defined(BIND_FORTRAN_LOWERCASE)
+#define FORTRAN_ID( id ) id
+#else
+#error do not know how to bind to fortran calling convention
+#endif
+
+
+// "g77" or clapack or "gfortran -ff2c"
+//#define BIND_FORTRAN_F2C_RETURN_CONVENTIONS
+// "g77 -fno-f2c" or "gfortran"
+//#define BIND_FORTRAN_NO_F2C_RETURN_CONVENTIONS
+
+// As long as f2c return conventions are the common case,
+// we turn them on unless requested otherwise
+#ifndef BIND_FORTRAN_NO_F2C_RETURN_CONVENTIONS
+#define BIND_FORTRAN_F2C_RETURN_CONVENTIONS
+#endif
+
+#endif // BOOST_NUMERIC_BINDINGS_TRAITS_FORTRAN_H

Added: sandbox/numeric_bindings/boost/numeric/bindings/lapack/detail/lapack_option.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/lapack/detail/lapack_option.hpp 2009-12-28 08:03:58 EST (Mon, 28 Dec 2009)
@@ -0,0 +1,57 @@
+//
+// Copyright (c) 2009 Rutger ter Borg
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef BOOST_NUMERIC_BINDINGS_LAPACK_DETAIL_LAPACK_OPTION_HPP
+#define BOOST_NUMERIC_BINDINGS_LAPACK_DETAIL_LAPACK_OPTION_HPP
+
+#include <boost/mpl/char.hpp>
+#include <boost/numeric/bindings/tag.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace lapack {
+namespace detail {
+
+template< typename Tag >
+struct lapack_option {};
+
+template<>
+struct lapack_option< tag::transpose >: mpl::char_< 'T' > {};
+
+template<>
+struct lapack_option< tag::no_transpose >: mpl::char_< 'N' > {};
+
+template<>
+struct lapack_option< tag::conjugate >: mpl::char_< 'C' > {};
+
+template<>
+struct lapack_option< tag::upper >: mpl::char_< 'U' > {};
+
+template<>
+struct lapack_option< tag::lower >: mpl::char_< 'L' > {};
+
+template<>
+struct lapack_option< tag::unit >: mpl::char_< 'U' > {};
+
+template<>
+struct lapack_option< tag::non_unit >: mpl::char_< 'N' > {};
+
+template<>
+struct lapack_option< tag::left >: mpl::char_< 'L' > {};
+
+template<>
+struct lapack_option< tag::right >: mpl::char_< 'R' > {};
+
+} // namespace detail
+} // namespace lapack
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

Modified: sandbox/numeric_bindings/boost/numeric/bindings/size.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/size.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/size.hpp 2009-12-28 08:03:58 EST (Mon, 28 Dec 2009)
@@ -14,6 +14,7 @@
 #include <boost/numeric/bindings/rank.hpp>
 #include <boost/numeric/bindings/index_major.hpp>
 #include <boost/numeric/bindings/index_minor.hpp>
+#include <boost/numeric/bindings/index_trans.hpp>
 #include <boost/mpl/and.hpp>
 #include <boost/mpl/min.hpp>
 #include <boost/mpl/greater.hpp>
@@ -114,6 +115,41 @@
 GENERATE_FUNCTIONS( size, _major, typename index_major<T>::type )
 GENERATE_FUNCTIONS( size, _minor, typename index_minor<T>::type )
 
+//
+// Overloads for free template functions size_row( x, tag ),
+// Here, tag is assumed to be either one of
+// tag::transpose, tag::no_transpose, or tag::conjugate
+//
+namespace result_of {
+
+template< typename T, typename TransTag >
+struct size_row_op {
+ typedef typename size<
+ T,
+ typename index_trans< tag::index<1>, TransTag >::type
+ >::type type;
+};
+
+template< typename T, typename TransTag >
+struct size_column_op {
+ typedef typename size< T,
+ typename index_trans< tag::index<2>, TransTag >::type >::type type;
+};
+
+} // namespace result_of
+
+template< typename T, typename Tag >
+inline typename result_of::size_row_op< const T, Tag >::type
+size_row_op( const T& t, Tag ) {
+ return result_of::size_row_op< const T, Tag >::type( t );
+}
+
+template< typename T, typename Tag >
+inline typename result_of::size_row_op< const T, Tag >::type
+size_column_op( const T& t, Tag ) {
+ return result_of::size_column_op< const T, Tag >::type( t );
+}
+
 } // namespace bindings
 } // namespace numeric
 } // namespace boost

Modified: sandbox/numeric_bindings/boost/numeric/bindings/trans_tag.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/trans_tag.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/trans_tag.hpp 2009-12-28 08:03:58 EST (Mon, 28 Dec 2009)
@@ -60,7 +60,7 @@
 
 namespace result_of {
 
-template< typename Order, typename T >
+template< typename T, typename Order >
 struct trans_tag {
     typedef typename detail::trans_tag_impl< Order,
         typename detail::property_at< T, tag::data_order >::type,
@@ -77,8 +77,8 @@
 // tag is being generated in what kind of situation.
 //
 template< typename T, typename Order >
-typename result_of::trans_tag< Order, T >::type trans_tag( const T& t, Order ) {
- return result_of::trans_tag< Order, T >::type();
+typename result_of::trans_tag< T, Order >::type trans_tag( const T& t, Order ) {
+ return result_of::trans_tag< T, Order >::type();
 }
 
 } // namespace bindings


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk