Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51213 - in sandbox/numeric_bindings/libs/numeric/bindings/tools: . templates templates/level1
From: rutger_at_[hidden]
Date: 2009-02-12 07:49:29


Author: rutger
Date: 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
New Revision: 51213
URL: http://svn.boost.org/trac/boost/changeset/51213

Log:
Added support for strided vectors (BLAS), added more level-1 BLAS templates

Added:
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/asum.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/copy.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/nrm2.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/scal.hpp (contents, props changed)
Text files modified:
   sandbox/numeric_bindings/libs/numeric/bindings/tools/blas_generator.py | 1
   sandbox/numeric_bindings/libs/numeric/bindings/tools/netlib.py | 68 ++++++++++++++++++++++-----------------
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/blas.hpp | 4 -
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/axpy.hpp | 4 +
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/dot.hpp | 4 +
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/swap.hpp | 7 ++-
   6 files changed, 51 insertions(+), 37 deletions(-)

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/blas_generator.py
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/blas_generator.py (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/blas_generator.py 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
@@ -688,6 +688,7 @@
       level2_template = level2_template.replace( "$TYPEOF_FIRST_TYPENAME", first_typename_datatype )
       level2_template = level2_template.replace( "$CALL_LEVEL1", ", ".join( call_level1_arg_list ) )
       level2_template = level2_template.replace( "$TYPES", ", ".join( level1_type_arg_list ) )
+ level2_template = level2_template.replace( '$RETURN_STATEMENT', info_map[ subroutine ][ 'return_statement' ] )
 
       level1_map[ value_type ] = bindings.proper_indent( level1_template )
       level2_map[ value_type ] = bindings.proper_indent( level2_template )

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/netlib.py
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/netlib.py (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/netlib.py 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
@@ -114,6 +114,9 @@
       result = "traits::vector_size(" + my_name + ")"
     if properties[ 'trait_type' ] == 'uplo':
       result = "traits::matrix_uplo_tag(" + properties[ 'trait_of' ].lower() + ")"
+ if properties[ 'trait_type' ] == 'stride':
+ result = "traits::vector_stride(" + properties[ 'trait_of' ].lower() + ")"
+
   else:
     result = name.lower()
   return result
@@ -618,7 +621,7 @@
 
   code_line_nr = 0
   while code_line_nr < len(code) and not subroutine_found:
- match_subroutine_name = re.compile( '(DOUBLE PRECISION FUNCTION|REAL FUNCTION|SUBROUTINE)[ ]+([A-Z]+)\(([^\)]+)' ).search( code[ code_line_nr ] )
+ match_subroutine_name = re.compile( '(DOUBLE PRECISION FUNCTION|REAL FUNCTION|SUBROUTINE)[ ]+([A-Z0-9]+)\(([^\)]+)' ).search( code[ code_line_nr ] )
     if match_subroutine_name != None:
       subroutine_found = True
       subroutine_name = match_subroutine_name.group( 2 )
@@ -630,6 +633,7 @@
 
   # If we could not find a subroutine, we quit at our earliest convenience
   if code_line_nr == len(code):
+ print "Could not find function/subroutine statement, bailing out."
     return None, None
 
   #
@@ -679,21 +683,6 @@
             argument_map[ argument_name ][ 'leading_dimension' ] = argument_description[1].split( "," )[0].strip()
     code_line_nr += 1
 
- # Create convenience lookups by value_type and types of arguments
- # e.g., grouped_arguments[ 'by_value_type' ][ 'INTEGER' ] will give an array of all integer types
- # grouped_arguments[ 'by_type' ][ 'matrix' ] will give an array of all matrices
- grouped_arguments = {}
- key_array = [ 'type', 'value_type' ]
- for s in key_array:
- grouped_arguments[ 'by_' + s ] = {}
- # make sure the order of argument names is the same as those in the subroutine argument order
- for argument_name in subroutine_arguments:
- argument_properties = argument_map[ argument_name ]
- for s in key_array:
- if not grouped_arguments[ 'by_' + s ].has_key( argument_properties[ s ] ):
- grouped_arguments[ 'by_' + s ][ argument_properties[ s ] ] = []
- grouped_arguments[ 'by_' + s ][ argument_properties[ s ] ] += [ argument_name ]
-
   # See if we are hard-forcing argument renaming aliases
   # This is needed for BLAS. It has argument names that are tied to the
   # value_type variant of the routine. E.g., daxpy has dx and dy, caxpy has
@@ -713,19 +702,36 @@
       else:
         prefixes = [ 'S', 'D' ]
       # determine the original name
- argument_with_value_type = ''
+ argument_with_value_type = None
       for prefix in prefixes:
         try_name = prefix + argument_new_name
         if try_name in subroutine_arguments:
           argument_with_value_type = try_name
- loc = subroutine_arguments.index( argument_with_value_type )
- # replace in the overall subroutine arguments list
- subroutine_arguments[ loc ] = argument_new_name
- # rename the key in the argument map
- # create a copy, delete the old
- argument_replace_map[ argument_with_value_type ] = argument_new_name
- argument_map[ argument_new_name ] = argument_map[ argument_with_value_type ]
- del argument_map[ argument_with_value_type ]
+ # only if we could find something, do something
+ if argument_with_value_type != None:
+ loc = subroutine_arguments.index( argument_with_value_type )
+ # replace in the overall subroutine arguments list
+ subroutine_arguments[ loc ] = argument_new_name
+ # rename the key in the argument map
+ # create a copy, delete the old
+ argument_replace_map[ argument_with_value_type ] = argument_new_name
+ argument_map[ argument_new_name ] = argument_map[ argument_with_value_type ]
+ del argument_map[ argument_with_value_type ]
+
+ # Create convenience lookups by value_type and types of arguments
+ # e.g., grouped_arguments[ 'by_value_type' ][ 'INTEGER' ] will give an array of all integer types
+ # grouped_arguments[ 'by_type' ][ 'matrix' ] will give an array of all matrices
+ grouped_arguments = {}
+ key_array = [ 'type', 'value_type' ]
+ for s in key_array:
+ grouped_arguments[ 'by_' + s ] = {}
+ # make sure the order of argument names is the same as those in the subroutine argument order
+ for argument_name in subroutine_arguments:
+ argument_properties = argument_map[ argument_name ]
+ for s in key_array:
+ if not grouped_arguments[ 'by_' + s ].has_key( argument_properties[ s ] ):
+ grouped_arguments[ 'by_' + s ][ argument_properties[ s ] ] = []
+ grouped_arguments[ 'by_' + s ][ argument_properties[ s ] ] += [ argument_name ]
 
   # The next bulk load of information can be acquired from the comment fields,
   # this is between "Purpose" and "Arguments". Locate those headers, and init with
@@ -756,11 +762,6 @@
     arguments_line_nr = len(comments)
     comments += template_map[ my_has_key( arguments_key, template_map ) ].splitlines()
     comments += [ '' ]
-
- pp.pprint( comments )
-
- pp.pprint( argument_map )
-
 
   # Break up the comments
   # Now, for each argument, locate its associated comment field
@@ -925,6 +926,13 @@
         argument_properties[ 'trait_type' ] = 'size'
         argument_properties[ 'trait_of' ] = match_array_traits[ 0 ][ 3 ]
 
+
+ match_stride_traits = re.compile( '([Tt]he increment)(\s|for|the|elements|of)+([A-Z]+)', re.M | re.S ).findall( comment_block )
+ print match_stride_traits
+ if len( match_stride_traits ) > 0 and match_stride_traits[ 0 ][ 2 ] in grouped_arguments[ 'by_type' ][ 'vector' ]:
+ argument_properties[ 'trait_type' ] = 'stride'
+ argument_properties[ 'trait_of' ] = match_stride_traits[ 0 ][ 2 ]
+
       # Fetch greater-than-or-equal-to integer asserts, such as
       # M >= 0.
       # N >= max(...)

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/blas.hpp
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/blas.hpp (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/blas.hpp 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
@@ -55,9 +55,7 @@
 template< $TYPES >
 inline integer_t $groupname( $LEVEL2 ) {
     typedef typename traits::$TYPEOF_FIRST_TYPENAME_traits< $FIRST_TYPENAME >::value_type value_type;
- integer_t info(0);
- $groupname_impl< value_type >::compute( $CALL_LEVEL1 );
- return info;
+ $RETURN_STATEMENT$groupname_impl< value_type >::compute( $CALL_LEVEL1 );
 }
 
 $TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/asum.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/asum.hpp 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,9 @@
+$TEMPLATE[asum.all.remove_argument_value_type_prepend]
+X
+$TEMPLATE[asum.all.arguments]
+ N (input) INTEGER
+ The length of array X
+ INCX (input) INTEGER
+ The increment of X
+ X (input) DATATYPE array of length (N)
+$TEMPLATE[end]

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/axpy.hpp
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/axpy.hpp (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/axpy.hpp 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
@@ -2,9 +2,11 @@
 A,X,Y
 $TEMPLATE[axpy.all.arguments]
  N (input) INTEGER
- Dimension of array A
+ The length of array X
  INCX (input) INTEGER
+ The increment of X
  INCY (input) INTEGER
+ The increment of Y
  A (input) DATATYPE variable alpha
  X (input) DATATYPE array of length (N)
  Y (output) DATATYPE array of length (N)

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/copy.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/copy.hpp 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,12 @@
+$TEMPLATE[copy.all.remove_argument_value_type_prepend]
+X,Y
+$TEMPLATE[copy.all.arguments]
+ N (input) INTEGER
+ The length of array X
+ INCX (input) INTEGER
+ The increment of X
+ INCY (input) INTEGER
+ The increment of Y
+ X (input) DATATYPE array of length (N)
+ Y (input) DATATYPE array of length (N)
+$TEMPLATE[end]

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/dot.hpp
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/dot.hpp (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/dot.hpp 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
@@ -2,9 +2,11 @@
 X,Y
 $TEMPLATE[dot.all.arguments]
  N (input) INTEGER
- Dimension of array A
+ The length of array X
  INCX (input) INTEGER
+ The increment of X
  INCY (input) INTEGER
+ The increment of Y
  X (input) DATATYPE array of length (N)
  Y (input) DATATYPE array of length (N)
 $TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/nrm2.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/nrm2.hpp 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,9 @@
+$TEMPLATE[nrm2.all.remove_argument_value_type_prepend]
+X
+$TEMPLATE[nrm2.all.arguments]
+ N (input) INTEGER
+ The length of array X
+ INCX (input) INTEGER
+ The increment of X
+ X (input) DATATYPE array of length (N)
+$TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/scal.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/scal.hpp 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,10 @@
+$TEMPLATE[scal.all.remove_argument_value_type_prepend]
+A,X
+$TEMPLATE[scal.all.arguments]
+ N (input) INTEGER
+ The length of array X
+ INCX (input) INTEGER
+ The increment of X
+ X (input) DATATYPE array of length (N)
+ A (input) DATATYPE
+$TEMPLATE[end]

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/swap.hpp
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/swap.hpp (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/swap.hpp 2009-02-12 07:49:27 EST (Thu, 12 Feb 2009)
@@ -2,8 +2,11 @@
 X,Y
 $TEMPLATE[swap.all.arguments]
  N (input) INTEGER
- INCX (input) INTEGER increment in X
- INCY (input) INTEGER increment in Y
+ The length of array X
+ INCX (input) INTEGER
+ The increment of X
+ INCY (input) INTEGER
+ The increment of Y
  X (output) DATATYPE
  Y (output) DATATYPE
 $TEMPLATE[end]


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