Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51228 - in sandbox/numeric_bindings/libs/numeric/bindings/tools: . templates/level1 templates/level2
From: rutger_at_[hidden]
Date: 2009-02-12 15:10:08


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

Log:
Added more templates and corrections to the parser; 95% of BLAS bindings being generated now

Added:
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/dotc.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/dotu.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/rot.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/hpmv.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/hpr.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/hpr2.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/spmv.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/spr.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/spr2.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/tpmv.hpp (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/tpsv.hpp (contents, props changed)
Text files modified:
   sandbox/numeric_bindings/libs/numeric/bindings/tools/blas_generator.py | 2
   sandbox/numeric_bindings/libs/numeric/bindings/tools/netlib.py | 53 ++++++++++++++++++++++-----------------
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/rotmg.hpp | 2 +
   3 files changed, 33 insertions(+), 24 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 15:10:07 EST (Thu, 12 Feb 2009)
@@ -817,7 +817,7 @@
 routines[ 'level1' ][ 'endings' ] = [ 'ROTG', 'OTMG', 'ROT', 'ROTM', 'SWAP', 'SCAL', 'COPY', 'AXPY', 'DOT', 'DOTU', 'DOTC', 'NRM2', 'ASUM', 'AMAX' ]
 
 routines[ 'level2' ] = {}
-routines[ 'level2' ][ 'endings' ] = [ 'MV', 'SV', 'GER', 'GERU', 'GERC', 'HER', 'HPR', 'HER2', 'HPR2', 'SYR', 'SPR', 'SYR2' ]
+routines[ 'level2' ][ 'endings' ] = [ 'MV', 'SV', 'GER', 'GERU', 'GERC', 'HER', 'HPR', 'HER2', 'HPR2', 'SYR', 'SPR', 'SPR2', 'SYR2' ]
 
 routines[ 'level3' ] = {}
 routines[ 'level3' ][ 'endings' ] = [ 'MM', 'RK', 'R2K', 'SM' ]

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 15:10:07 EST (Thu, 12 Feb 2009)
@@ -164,6 +164,8 @@
 
 def nested_list_args( arg ):
   print "finding nested list arguments of", arg
+ if arg == None:
+ return None
   if type( arg ) == StringType:
     if re.compile( '^[A-Z]+$' ).match( arg ) == None:
       return [ None ]
@@ -177,7 +179,7 @@
   if re.compile( '^[A-Z]+$' ).match( arg[0] ) == None:
     for a in arg[1]:
       sub_result = nested_list_args( a )
- if sub_result != [ None ]:
+ if sub_result != [ None ] and sub_result != None:
         for r in sub_result:
           if r not in result:
             result.append( r )
@@ -194,6 +196,8 @@
 
 def expand_nested_list( arg, arg_map, use_arg_map = True ):
 
+ if arg == None:
+ return '?None'
   print "Expanding nested list: ", arg, len(arg)
   if type( arg ) == StringType:
     print "Type is string"
@@ -358,7 +362,6 @@
         code_result += [ call_level0_type( arg, arg_map[ arg ], arg_map ) ]
       else:
         code_result += [ '?' + arg.upper() ]
-
     result = ", ".join( code_result )
   return result
 
@@ -621,7 +624,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-Z0-9]+)\(([^\)]+)' ).search( code[ code_line_nr ] )
+ match_subroutine_name = re.compile( '(DOUBLE COMPLEX FUNCTION|COMPLEX FUNCTION|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 )
@@ -774,28 +777,29 @@
     detected_lapack_style = False
     detected_blas_style = False
     while comment_line_nr < len(comments) and not finished_the_last:
-
- print comments[ comment_line_nr ]
-
       # Example for LAPACK-style matching.
       # 45 M (input) INTEGER
       # 46 The number of rows of the matrix A. M >= 0.
       # 47
       # 48 N (input) INTEGER
- match_lapack_style = re.compile( '^[\s]*([A-Z]+[2]?)[\s]+\(([a-z/ ]+)\)' ).search( comments[ comment_line_nr ] )
+ match_lapack_style = re.compile( '^[\s]*([A-Z]+[12]?)[\s]+\(([a-z/ ]+)\)' ).search( comments[ comment_line_nr ] )
       if not detected_blas_style and match_lapack_style != None:
         detected_lapack_style = True
         argument_name = match_lapack_style.group(1)
- # If we're replacing arguments, we should do se here as well.
+ # If we're replacing arguments, we should do so here as well.
         if argument_replace_map.has_key( argument_name ):
           argument_name = argument_replace_map[ argument_name ]
- argument_map[ argument_name ][ 'comment_lines' ] = [ comment_line_nr ]
- split_regex = re.compile( '\/| or ' )
- argument_map[ argument_name ][ 'io' ] = split_regex.split( match_lapack_style.group(2) )
- if preceding_argument != '':
- argument_map[ preceding_argument ][ 'comment_lines' ] += [ comment_line_nr ]
- preceding_argument = argument_name
- no_commented_arguments += 1
+ # Check if the argument is in the argument_map, don't crash if it isn't
+ if argument_map.has_key( argument_name ):
+ argument_map[ argument_name ][ 'comment_lines' ] = [ comment_line_nr ]
+ split_regex = re.compile( '\/| or ' )
+ argument_map[ argument_name ][ 'io' ] = split_regex.split( match_lapack_style.group(2) )
+ if preceding_argument != '':
+ argument_map[ preceding_argument ][ 'comment_lines' ] += [ comment_line_nr ]
+ preceding_argument = argument_name
+ no_commented_arguments += 1
+ else:
+ print "WARNING: Skipping argument comment of", argument_name,", not in function argument list"
 
       # Example for BLAS, which doesn't mention input/output on the same line
       # 37 N - INTEGER.
@@ -861,7 +865,6 @@
   grouped_arguments[ 'by_io' ] = {}
   for argument_name in subroutine_arguments:
     argument_properties = argument_map[ argument_name ]
- print argument_name, argument_properties
     for io_type in argument_properties[ 'io' ]:
       if not grouped_arguments[ 'by_io' ].has_key( io_type ):
         grouped_arguments[ 'by_io' ][ io_type ] = []
@@ -870,6 +873,7 @@
   #
   # Parse the comment fields
   #
+ print "PARSING COMMENTS:"
   user_defined_arg_map = {}
   for argument_name, argument_properties in argument_map.iteritems():
 
@@ -891,25 +895,28 @@
         '([A-Z]+\s+and\s+[A-Z]+|[A-Z]+)', re.M | re.S ).findall( comment_block )
       if len( match_matrix_traits ) == 1:
         if match_matrix_traits[0][0] == 'order':
+ #
+ # see if the traits are overruled through the template system
+ # logically, these come first
+ traits_key = subroutine_group_name.lower() + '.' + subroutine_value_type + '.' + argument_name + '.trait_of'
+ if my_has_key( traits_key, template_map ):
+ argument_properties[ 'trait_type' ] = 'num_columns'
+ argument_properties[ 'trait_of' ] = template_map[ my_has_key( traits_key, template_map ) ].strip()
           # PANIC: return none
           # e.g., in tridiagonal case, there is no matrix, but a number of
           # vectors (the diagonals)
- if not grouped_arguments[ 'by_type' ].has_key( 'matrix' ):
+ elif not grouped_arguments[ 'by_type' ].has_key( 'matrix' ):
+ print "PANIC: returning none"
             # TODO
             # TODO
             return subroutine_name, None
             # TODO
             # TODO
- if match_matrix_traits[0][3] in grouped_arguments[ 'by_type' ][ 'matrix' ]:
+ elif match_matrix_traits[0][3] in grouped_arguments[ 'by_type' ][ 'matrix' ]:
             # because it is both #rows and #columns, we have to choose one
             argument_properties[ 'trait_type' ] = 'num_columns'
             argument_properties[ 'trait_of' ] = match_matrix_traits[0][3].strip()
 
- # see if the traits are overruled through the template system
- traits_key = subroutine_group_name.lower() + '.' + subroutine_value_type + '.' + argument_name + '.trait_of'
- if my_has_key( traits_key, template_map ):
- argument_properties[ 'trait_type' ] = 'num_columns'
- argument_properties[ 'trait_of' ] = template_map[ my_has_key( traits_key, template_map ) ].strip()
 
         else:
           references = match_matrix_traits[0][3].split( 'and' )

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/dotc.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/dotc.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,12 @@
+$TEMPLATE[dotc.all.remove_argument_value_type_prepend]
+X,Y
+$TEMPLATE[dotc.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
+ Y (input) DATATYPE
+$TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/dotu.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/dotu.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,12 @@
+$TEMPLATE[dotu.all.remove_argument_value_type_prepend]
+X,Y
+$TEMPLATE[dotu.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
+ Y (input) DATATYPE
+$TEMPLATE[end]

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

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/rotmg.hpp
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/rotmg.hpp (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level1/rotmg.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -1 +1,3 @@
+$TEMPLATE[rotmg.all.remove_argument_value_type_prepend]
+D1,D2,X1,Y1
 $TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/hpmv.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/hpmv.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,5 @@
+$TEMPLATE[hpmv.all.N.trait_of]
+AP
+$TEMPLATE[hpmv.all.UPLO.trait_of]
+AP
+$TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/hpr.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/hpr.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,5 @@
+$TEMPLATE[hpr.all.N.trait_of]
+AP
+$TEMPLATE[hpr.all.UPLO.trait_of]
+AP
+$TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/hpr2.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/hpr2.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,5 @@
+$TEMPLATE[hpr2.all.N.trait_of]
+AP
+$TEMPLATE[hpr2.all.UPLO.trait_of]
+AP
+$TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/spmv.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/spmv.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,5 @@
+$TEMPLATE[spmv.all.N.trait_of]
+AP
+$TEMPLATE[spmv.all.UPLO.trait_of]
+AP
+$TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/spr.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/spr.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,5 @@
+$TEMPLATE[spr.all.N.trait_of]
+AP
+$TEMPLATE[spr.all.UPLO.trait_of]
+AP
+$TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/spr2.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/spr2.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,5 @@
+$TEMPLATE[spr2.all.N.trait_of]
+AP
+$TEMPLATE[spr2.all.UPLO.trait_of]
+AP
+$TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/tpmv.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/tpmv.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,5 @@
+$TEMPLATE[tpmv.all.N.trait_of]
+AP
+$TEMPLATE[tpmv.all.UPLO.trait_of]
+AP
+$TEMPLATE[end]

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/tpsv.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/level2/tpsv.hpp 2009-02-12 15:10:07 EST (Thu, 12 Feb 2009)
@@ -0,0 +1,5 @@
+$TEMPLATE[tpsv.all.N.trait_of]
+AP
+$TEMPLATE[tpsv.all.UPLO.trait_of]
+AP
+$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