Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51342 - in sandbox/numeric_bindings/libs/numeric/bindings/tools: . templates
From: rutger_at_[hidden]
Date: 2009-02-20 03:16:25


Author: rutger
Date: 2009-02-20 03:16:24 EST (Fri, 20 Feb 2009)
New Revision: 51342
URL: http://svn.boost.org/trac/boost/changeset/51342

Log:
Bugfixes to the lapack generator, cleanups

Text files modified:
   sandbox/numeric_bindings/libs/numeric/bindings/tools/bindings.py | 15 +
   sandbox/numeric_bindings/libs/numeric/bindings/tools/blas_generator.py | 546 ---------------------------------------
   sandbox/numeric_bindings/libs/numeric/bindings/tools/lapack_generator.py | 543 ---------------------------------------
   sandbox/numeric_bindings/libs/numeric/bindings/tools/netlib.py | 25 +
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/blas.hpp | 3
   5 files changed, 40 insertions(+), 1092 deletions(-)

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/bindings.py
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/bindings.py (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/bindings.py 2009-02-20 03:16:24 EST (Fri, 20 Feb 2009)
@@ -10,6 +10,21 @@
 import re
 
 #
+# Desired order of routines in C++ code: float, double, single complex, double complex
+#
+def routine_cmp( a, b ):
+ letter_a = a[0]
+ letter_b = b[0]
+ value_map = { 'S': 0, 'D': 1, 'C': 2, 'Z': 3 }
+ result = 0
+ if value_map[ a[0] ] < value_map[ b[ 0] ]:
+ result = -1
+ if value_map[ a[0] ] > value_map[ b[ 0] ]:
+ result = 1
+ return result
+
+
+#
 # This routine actually does what it's named after :-).
 # Changes:
 # * used regex matching on delimiter instead of .find

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-20 03:16:24 EST (Fri, 20 Feb 2009)
@@ -17,552 +17,10 @@
 import pprint
 
 
-global_type_map = {
- 'CHARACTER': 'char',
- 'LOGICAL': 'logical_t',
- 'INTEGER': 'integer_t',
- 'REAL': 'float',
- 'DOUBLE PRECISION': 'double' }
-
-templates = {}
-
-
-
-def c_type( name, properties ):
- m_type_map = global_type_map
- m_type_map[ 'COMPLEX' ] = 'fcomplex_t'
- m_type_map[ 'COMPLEX*16' ] = 'dcomplex_t'
-
- result = m_type_map[ properties[ 'value_type' ] ];
- if properties[ 'io' ] == [ 'input' ]:
- result += ' const'
- result += '*'
- result += ' ' + name.lower() # is this really needed?
-
- return result
-
-
-def cpp_type( name, properties ):
- m_type_map = global_type_map
- m_type_map[ 'COMPLEX' ] = 'traits::complex_f'
- m_type_map[ 'COMPLEX*16' ] = 'traits::complex_d'
-
- result = m_type_map[ properties[ 'value_type' ] ]
-
- if properties[ 'type' ] == 'scalar':
- if properties[ 'io' ] == [ 'input' ]:
- result += ' const'
- elif properties[ 'io' ] == [ 'external procedure' ]:
- result += '*'
- else:
- result += '&'
-
- if properties[ 'type' ] == 'vector' or properties[ 'type' ] == 'matrix':
- result += '*'
-
- result += ' ' + name.lower()
-
- return result
-
-def call_c_type( name, properties ):
- result = ''
- if properties[ 'type' ] == 'vector' or properties[ 'type' ] == 'matrix':
- if properties[ 'value_type' ][ 0:7] == 'COMPLEX':
- result = 'traits::complex_ptr(' + name.lower() + ')'
- else:
- result = name.lower()
- elif properties[ 'type' ] == 'scalar':
- if properties[ 'value_type' ][ 0:7] == 'COMPLEX':
- result = 'traits::complex_ptr(&' + name.lower() + ')'
- else:
- result = '&' + name.lower()
-
- return result
-
-
-def call_level0_type( name, properties, arg_map ):
- result = ''
- if properties[ 'type' ] == 'matrix':
- result = "traits::matrix_storage(" + name.lower() + ")"
- elif properties[ 'type' ] == 'vector':
- my_name = name.lower()
- if 'workspace' in properties[ 'io' ]:
- my_name = 'work.select(' + workspace_type( name, properties ) + '())'
- result = "traits::vector_storage(" + my_name + ")"
- elif properties.has_key( 'trait_type' ):
- if properties[ 'trait_type' ] == 'lda':
- result = "traits::leading_dimension(" + properties[ 'trait_of' ].lower() + ")"
- if properties[ 'trait_type' ] == 'num_columns':
- result = "traits::matrix_size2(" + properties[ 'trait_of' ].lower() + ")"
- if properties[ 'trait_type' ] == 'num_rows':
- result = "traits::matrix_size1(" + properties[ 'trait_of' ].lower() + ")"
- if properties[ 'trait_type' ] == 'size':
- my_name = properties[ 'trait_of' ].lower()
- referring_to_properties = arg_map[ properties[ 'trait_of' ] ]
- if 'workspace' in referring_to_properties[ 'io' ]:
- my_name = 'work.select(' + workspace_type( properties[ 'trait_of' ].lower(), referring_to_properties ) + \
- '())'
- result = "traits::vector_size(" + my_name + ")"
- if properties[ 'trait_type' ] == 'uplo':
- result = "traits::matrix_uplo_tag(" + properties[ 'trait_of' ].lower() + ")"
- else:
- result = name.lower()
- return result
-
-
-def level1_type( name, properties ):
- result = None
- if not properties.has_key( 'trait_of' ) and 'workspace' not in properties[ 'io' ]:
- if properties[ 'type' ] == 'matrix':
- result = "Matrix" + name + "& " + name.lower()
- elif properties[ 'type' ] == 'vector':
- result = "Vector" + name + "& " + name.lower()
- else:
- result = cpp_type( name, properties )
- if properties[ 'value_type' ] == 'REAL':
- result = result.replace( "float", "real_type" )
- if properties[ 'value_type' ] == 'DOUBLE PRECISION':
- result = result.replace( "double", "real_type" )
- return result
-
-
-def level2_type( name, properties ):
- result = level1_type( name, properties )
- if name == 'INFO' and 'output' in properties[ 'io' ]:
- result = None
-
- if result != None:
- if properties[ 'value_type' ] == 'REAL' or properties[ 'value_type' ] == 'DOUBLE PRECISION':
- result = result.replace( "real_type", "typename traits::$TYPEOF_FIRST_TYPENAME" + \
- "_traits< $FIRST_TYPENAME >::value_type" )
-
- return result
-
-
-def level1_typename( name, properties ):
- result = None
- if 'workspace' not in properties[ 'io' ]:
- if properties[ 'type' ] == 'matrix':
- result = "typename Matrix" + name
- if properties[ 'type' ] == 'vector':
- result = "typename Vector" + name
- return result
-
-
-
-def nested_list_args( arg ):
- print "finding nested list arguments of", arg
- if type( arg ) == StringType:
- if re.compile( '^[A-Z]+$' ).match( arg ) == None:
- return [ None ]
- else:
- return [ arg.upper() ]
-
- # we are dealing with a list-type, e.g.,
- # [ '*', [ 'A', 'B' ] ]
- # [ 'A', 'B' ]
- result = []
- if re.compile( '^[A-Z]+$' ).match( arg[0] ) == None:
- for a in arg[1]:
- sub_result = nested_list_args( a )
- if sub_result != [ None ]:
- for r in sub_result:
- if r not in result:
- result.append( r )
-
- else:
- for a in arg:
- result.append( a )
-
- print "returning ",result
- return result
-
-
-
-
-def expand_nested_list( arg, arg_map, use_arg_map = True ):
-
- print "Expanding nested list: ", arg, len(arg)
- if type( arg ) == StringType:
- print "Type is string"
- # .....
- if re.compile( '^[A-Z]+$' ).match( arg ) == None:
- return arg
- else:
- if use_arg_map:
- if not arg_map.has_key( arg ):
- return '?' + arg.upper()
- else:
- return arg_map[ arg ][ 'code' ][ 'call_level_0' ]
- else:
- return arg.lower()
-
- if arg[0] == '()':
- result = '(' + expand_nested_list( arg[1], arg_map, use_arg_map ) + ')'
- return result
-
- if arg[0] == 'max' or arg[0] == 'min':
- print "arg1: ", arg[1]
- result = 'std::' + arg[0] + '('
- i = 0
- for a in arg[1]:
- result += expand_nested_list( a, arg_map, use_arg_map )
- i += 1
- if i != len(arg[1]):
- result += ","
- result += ')'
- return result
-
- if arg[0] == '*' or arg[0] == '/' or arg[0] == '+' or arg[0] == '-':
- print "arg1: ", arg[1]
- arg_list = []
- for a in arg[1]:
- arg_list += [ expand_nested_list( a, arg_map, use_arg_map ) ]
- result = arg[0].join( arg_list )
- return result
-
- print "ERROR: Don't know what to do!!"
- return 'ERROR'
-
-def level1_assert( name, properties, arg_map ):
- result = None
-
- if properties.has_key( 'assert_char' ):
- result = "assert( "
- result_array = []
- for char in properties[ 'assert_char' ]:
- result_array += [ call_level0_type( name, properties, arg_map ) + ' == \'' + char + '\'' ]
- result += " || ".join( result_array )
- result += " );"
-
- if properties.has_key( 'assert_ge' ) and not properties.has_key( 'workspace_query_for' ):
- result = "assert( " + call_level0_type( name, properties, arg_map ) + " >= " + expand_nested_list( properties[ 'assert_ge' ], arg_map ) + ' );'
-
- if 'workspace' in properties[ 'io' ]:
- min_workspace_call = min_workspace_call_type( name, properties, arg_map )
- if min_workspace_call == None:
- min_workspace_call = '$CALL_MIN_SIZE'
- result = 'assert( traits::vector_size(work.select(' + workspace_type( name, properties ) + '()) >= ' + \
- 'min_size_' + name.lower() + '( ' + min_workspace_call + ' )));'
-
- elif properties.has_key( 'assert_size' ):
- result = "assert( traits::vector_size(" + call_level0_type( name, properties, arg_map ) + ") >= " + \
- expand_nested_list( properties[ 'assert_size' ], arg_map ) + ' );'
-
- return result
-
-
-def call_level1_type( name, properties ):
- result = None
- if level1_type( name, properties ) != None:
- result = name.lower()
- return result
-
-
-def workspace_type( name, properties ):
- result = None
- if 'workspace' in properties[ 'io' ]:
- if properties[ 'value_type' ] == 'INTEGER':
- result = 'integer_t'
- elif properties[ 'value_type' ] == 'LOGICAL':
- result = 'bool'
- elif properties[ 'value_type' ] == 'REAL' or properties[ 'value_type' ] == 'DOUBLE PRECISION':
- result = 'real_type'
- else:
- result = 'value_type'
- return result
-
-
-
-
-def opt_workspace_pre_type( name, properties, arg_map ):
- result = None
- if 'workspace' in properties[ 'io' ]:
- if properties.has_key( 'workspace_query_by' ):
- result = workspace_type( name, properties ) + ' opt_size_' + name.lower() + ';'
- else:
- min_workspace_call = min_workspace_call_type( name, properties, arg_map )
- if min_workspace_call == None:
- min_workspace_call = '$CALL_MIN_SIZE'
- result = 'traits::detail::array< ' + workspace_type( name, properties ) + ' >' + \
- ' tmp_' + name.lower() + '( min_size_' + name.lower() + '( ' + min_workspace_call + ' ) );'
- return result
-
-
-def opt_workspace_post_type( name, properties ):
- result = None
- if 'workspace' in properties[ 'io' ]:
- if properties.has_key( 'workspace_query_by' ):
- if properties['value_type'] == 'INTEGER':
- result = 'traits::detail::array< ' + workspace_type( name, properties ) + ' >' + \
- ' tmp_' + name.lower() + '( opt_size_' + name.lower() + ' );'
- else:
- result = 'traits::detail::array< ' + workspace_type( name, properties ) + ' >' + \
- ' tmp_' + name.lower() + '( traits::detail::to_int( opt_size_' + name.lower() + ' ) );'
- return result
-
-
-
-def opt_workspace_query_type( name, properties, arg_map ):
- result = None
- if properties.has_key( 'workspace_query_for' ):
- result = '-1'
- elif 'workspace' in properties[ 'io' ]:
- if properties.has_key( 'workspace_query_by' ):
- result = '&opt_size_' + name.lower();
- else:
- result = 'traits::vector_storage(tmp_' + name.lower() + ')'
- else:
- result = call_level0_type( name, properties, arg_map )
- return result
-
-
-def min_workspace_size_type( name, properties, arg_map ):
- result = None
- if 'workspace' in properties[ 'io' ] and properties.has_key( 'assert_size' ):
- result = expand_nested_list( properties[ 'assert_size' ], arg_map, False );
- return result
-
-
-def min_workspace_arg_type( name, properties, arg_map ):
- result = None
- if 'workspace' in properties[ 'io' ] and properties.has_key( 'assert_size_args' ):
- code_result = []
- for arg in properties[ 'assert_size_args' ]:
- if arg_map.has_key( arg ):
- code_result += [ cpp_type( arg, arg_map[ arg ] ) ]
- else:
- code_result += [ '?' + arg.upper() ]
- result = ", ".join( code_result )
- return result
-
-
-def min_workspace_call_type( name, properties, arg_map ):
- result = None
- if 'workspace' in properties[ 'io' ] and properties.has_key( 'assert_size_args' ):
- code_result = []
- for arg in properties[ 'assert_size_args' ]:
- if arg_map.has_key( arg ):
- code_result += [ call_level0_type( arg, arg_map[ arg ], arg_map ) ]
- else:
- code_result += [ '?' + arg.upper() ]
-
- result = ", ".join( code_result )
- return result
-
-
-def user_defined_type( name, properties, arg_map ):
- result = None
- if properties.has_key( 'user_defined' ):
- result = properties[ 'user_defined' ]
- return result
-
-
-
-#
-#
-#
-#
-def match_formulae( text_field ):
- find_start = re.compile( '([A-Z]+)\s?(>=|is\sat\sleast)\s?(.*)the\scode\swill', re.M | re.S ).findall( text_field )
- for element in find_start:
- print element
-
-
-
-#
-# Split string using a list of delimiters
-# Delimiters may be substrings of length 1 or 2 (may be increased if necessary)
-#
-def split_delim( s, delim = [','] ):
- result = []
- parentheses = 0
- cur_pos = 0
- prev_pos = 0
- for index in range( 0, len(s) ):
- if s[ index ] == '(':
- parentheses += 1
- elif s[ index ] == ')':
- parentheses -= 1
- for length in range( 1, 3 ):
- if index >= (length-1) and parentheses == 0:
- c = s[ index-(length-1): index+1 ]
- if c in delim:
- result += [ s[ prev_pos:(index-(length-1)) ] ]
- prev_pos = index+1
-
- result += [ s[ prev_pos:len(s) ] ]
- return result
-
-
-
-#
-# Look for implicit products, like 5N, and replace with 5*N
-#
-def replace_implicit_products( text_field ):
- result = re.sub( '([0-9])+([A-Z]+)', '\\1*\\2', text_field )
- return result
-
-
-
-
-def decompose_formula( text_field ):
- text_field = text_field.strip()
- print "Decompose: ", text_field
-
- if text_field[0] == '(' and text_field[-1] == ')':
- result = text_field[ 1:-1 ]
- return [ '()', decompose_formula( result ) ]
-
- if len( split_delim( text_field, [ ',' ] ) ) > 1:
- print "ERROR! (in BLAS?)"
- return [ 'ERROR' ]
-
- #
- # Detect leaf: if text_field equals a argument (like N), or a number
- #
- if re.compile( '^([a-zA-Z]+|[0-9]+)$' ).match( text_field ):
- print "decompose: at leaf: '" + text_field + "'"
- return text_field.upper()
-
-
- if len( split_delim( text_field, [ '**' ] ) ) > 1:
- print 'decompose: inserting pow'
- arguments = split_delim( text_field, [ '**' ] )
- print arguments
- result = []
- for arg in arguments:
- result.append( decompose_formula( arg ) )
- return [ 'pow', result ]
-
- for operator in [ '*', '/', '+', '-' ]:
- if len( split_delim( text_field, [ operator ] ) ) > 1:
- print 'decompose: inserting ' + operator
- arguments = split_delim( text_field, operator )
- print arguments
- result = []
- for arg in arguments:
- result.append( decompose_formula( arg ) )
- return [ operator, result ]
-
-
- if (text_field[ 0:4 ] == 'max(' or text_field[ 0:4 ] == 'MAX(') and \
- text_field[ -1 ] == ')':
- print "decompose: inserting max"
- arguments = split_delim( text_field[ 4:-1 ] )
- print arguments, len(arguments)
- # keep max a binary function ... :-)
- if len( arguments ) > 2:
- return [ 'max', [ decompose_formula( arguments[0] ), decompose_formula( 'max(' + ",".join( arguments[1:] ) + ')' ) ] ]
- else:
- result = []
- for arg in arguments:
- result.append( decompose_formula( arg ) )
- #result = [ decompose_formula( arguments[0] ), decompose_formula( arguments[1] ) ]
- return [ 'max', result ]
-
-
- if (text_field[ 0:4 ] == 'min(' or text_field[ 0:4 ] == 'MIN(') and \
- text_field[ -1 ] == ')':
- print "decompose: inserting min"
- arguments = split_delim( text_field[ 4:-1 ] )
- print arguments, len(arguments)
- # keep max a binary function ... :-)
- if len( arguments ) > 2:
- return [ 'min', [ decompose_formula( arguments[0] ), decompose_formula( 'min(' + ",".join( arguments[1:] ) + ')' ) ] ]
- else:
- result = []
- for arg in arguments:
- result.append( decompose_formula( arg ) )
- #result = [ decompose_formula( arguments[0] ), decompose_formula( arguments[1] ) ]
- return [ 'min', result ]
-
-
-#
-#
-def match_assert_ge( argument_map, text_field ):
- #print "Match assert GE..."
- match_it = re.compile( ' +[A-Z]+[ ]{0,3}(>=|must be at least)[ ]{0,3}([0-9]|(min|max|MIN|MAX|[\(\)\,0-9A-Z\+\*\-])+)' ).findall( text_field )
- if len( match_it ) == 1:
- print "Match assert GE:", match_it
- #print match_it
- #if len( match_it[ 0 ][ 2 ] ) > 0:
- return decompose_formula( match_it[ 0 ][ 1 ] )
- else:
- print "nr of matches: ", len( match_it )
- return None
-
-
-
-
-
-# try different keys, return the one that exists, if any
-
-def my_has_key( key_name, template_map ):
- # try, e.g., gelsd.all.
- m_all_key = key_name.replace( ".complex", ".all" ).replace( ".real", ".all" )
- if template_map.has_key( key_name ):
- print "using key ", key_name
- return key_name
- if template_map.has_key( m_all_key ):
- print "using key ", m_all_key
- return m_all_key
- print "tried keys ", key_name, "and", m_all_key,", no results"
- return None
-
-
-
-#
-# Default user-defined arg is of type scalar INTEGER
-#
-def add_user_defined_args( arg, argument_map, template_map, base_name ):
- print "Trying to add user-defined argument definitions for", arg
-
- argument_map[ arg ] = {}
-
- base_key = base_name.lower() + '.' + arg
- print "base_key",base_key
-
- if my_has_key( base_key + '.value_type', template_map ) != None:
- argument_map[ arg ][ 'value_type' ] = template_map[ my_has_key( base_key + '.value_type', template_map ) ].strip()
- else:
- argument_map[ arg ][ 'value_type' ] = 'INTEGER'
-
- if my_has_key( base_key + '.type', template_map ) != None:
- argument_map[ arg ][ 'type' ] = template_map[ my_has_key( base_key + '.type', template_map ) ].strip()
- else:
- argument_map[ arg ][ 'type' ] = 'scalar'
-
- if my_has_key( base_key + '.init', template_map ) != None:
- argument_map[ arg ][ 'user_defined' ] = template_map[ my_has_key( base_key + '.init', template_map ) ].strip()
- else:
- argument_map[ arg ][ 'user_defined' ] = 'UNDEFINED'
-
- argument_map[ arg ][ 'io' ] = [ 'input' ]
-
- return
-
-
-
-#
-# Desired order of routines in C++ code: float, double, single complex, double complex
-#
-def routine_cmp( a, b ):
- letter_a = a[0]
- letter_b = b[0]
- value_map = { 'S': 0, 'D': 1, 'C': 2, 'Z': 3 }
- result = 0
- if value_map[ a[0] ] < value_map[ b[ 0] ]:
- result = -1
- if value_map[ a[0] ] > value_map[ b[ 0] ]:
- result = 1
- return result
-
-
 #
 # Group subroutines on their name, with the first character removed. This will
 # group them in the same .hpp file as well. Sort these subroutines based on
-# routine_cmp above.
+# routine_cmp from bindings.py.
 #
 def group_by_value_type( global_info_map ):
   group_map = {}
@@ -572,7 +30,7 @@
       group_map[ short_name ] = []
     group_map[ short_name ] += [ i ]
   for value in group_map.values():
- value.sort( routine_cmp )
+ value.sort( bindings.routine_cmp )
   return group_map
   
 

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/lapack_generator.py
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/lapack_generator.py (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/lapack_generator.py 2009-02-20 03:16:24 EST (Fri, 20 Feb 2009)
@@ -17,547 +17,6 @@
 import pprint
 
 
-global_type_map = {
- 'CHARACTER': 'char',
- 'LOGICAL': 'logical_t',
- 'INTEGER': 'integer_t',
- 'REAL': 'float',
- 'DOUBLE PRECISION': 'double' }
-
-templates = {}
-
-
-
-def c_type( name, properties ):
- m_type_map = global_type_map
- m_type_map[ 'COMPLEX' ] = 'fcomplex_t'
- m_type_map[ 'COMPLEX*16' ] = 'dcomplex_t'
-
- result = m_type_map[ properties[ 'value_type' ] ];
- if properties[ 'io' ] == [ 'input' ]:
- result += ' const'
- result += '*'
- result += ' ' + name.lower() # is this really needed?
-
- return result
-
-
-def cpp_type( name, properties ):
- m_type_map = global_type_map
- m_type_map[ 'COMPLEX' ] = 'traits::complex_f'
- m_type_map[ 'COMPLEX*16' ] = 'traits::complex_d'
-
- result = m_type_map[ properties[ 'value_type' ] ]
-
- if properties[ 'type' ] == 'scalar':
- if properties[ 'io' ] == [ 'input' ]:
- result += ' const'
- elif properties[ 'io' ] == [ 'external procedure' ]:
- result += '*'
- else:
- result += '&'
-
- if properties[ 'type' ] == 'vector' or properties[ 'type' ] == 'matrix':
- result += '*'
-
- result += ' ' + name.lower()
-
- return result
-
-def call_c_type( name, properties ):
- result = ''
- if properties[ 'type' ] == 'vector' or properties[ 'type' ] == 'matrix':
- if properties[ 'value_type' ][ 0:7] == 'COMPLEX':
- result = 'traits::complex_ptr(' + name.lower() + ')'
- else:
- result = name.lower()
- elif properties[ 'type' ] == 'scalar':
- if properties[ 'value_type' ][ 0:7] == 'COMPLEX':
- result = 'traits::complex_ptr(&' + name.lower() + ')'
- else:
- result = '&' + name.lower()
-
- return result
-
-
-def call_level0_type( name, properties, arg_map ):
- result = ''
- if properties[ 'type' ] == 'matrix':
- result = "traits::matrix_storage(" + name.lower() + ")"
- elif properties[ 'type' ] == 'vector':
- my_name = name.lower()
- if 'workspace' in properties[ 'io' ]:
- my_name = 'work.select(' + workspace_type( name, properties ) + '())'
- result = "traits::vector_storage(" + my_name + ")"
- elif properties.has_key( 'trait_type' ):
- if properties[ 'trait_type' ] == 'lda':
- result = "traits::leading_dimension(" + properties[ 'trait_of' ].lower() + ")"
- if properties[ 'trait_type' ] == 'num_columns':
- result = "traits::matrix_size2(" + properties[ 'trait_of' ].lower() + ")"
- if properties[ 'trait_type' ] == 'num_rows':
- result = "traits::matrix_size1(" + properties[ 'trait_of' ].lower() + ")"
- if properties[ 'trait_type' ] == 'size':
- my_name = properties[ 'trait_of' ].lower()
- referring_to_properties = arg_map[ properties[ 'trait_of' ] ]
- if 'workspace' in referring_to_properties[ 'io' ]:
- my_name = 'work.select(' + workspace_type( properties[ 'trait_of' ].lower(), referring_to_properties ) + \
- '())'
- result = "traits::vector_size(" + my_name + ")"
- if properties[ 'trait_type' ] == 'uplo':
- result = "traits::matrix_uplo_tag(" + properties[ 'trait_of' ].lower() + ")"
- else:
- result = name.lower()
- return result
-
-
-def level1_type( name, properties ):
- result = None
- if not properties.has_key( 'trait_of' ) and 'workspace' not in properties[ 'io' ]:
- if properties[ 'type' ] == 'matrix':
- result = "Matrix" + name + "& " + name.lower()
- elif properties[ 'type' ] == 'vector':
- result = "Vector" + name + "& " + name.lower()
- else:
- result = cpp_type( name, properties )
- if properties[ 'value_type' ] == 'REAL':
- result = result.replace( "float", "real_type" )
- if properties[ 'value_type' ] == 'DOUBLE PRECISION':
- result = result.replace( "double", "real_type" )
- return result
-
-
-def level2_type( name, properties ):
- result = level1_type( name, properties )
- if name == 'INFO' and 'output' in properties[ 'io' ]:
- result = None
-
- if result != None:
- if properties[ 'value_type' ] == 'REAL' or properties[ 'value_type' ] == 'DOUBLE PRECISION':
- result = result.replace( "real_type", "typename traits::$TYPEOF_FIRST_TYPENAME" + \
- "_traits< $FIRST_TYPENAME >::value_type" )
-
- return result
-
-
-def level1_typename( name, properties ):
- result = None
- if 'workspace' not in properties[ 'io' ]:
- if properties[ 'type' ] == 'matrix':
- result = "typename Matrix" + name
- if properties[ 'type' ] == 'vector':
- result = "typename Vector" + name
- return result
-
-
-
-def nested_list_args( arg ):
- print "finding nested list arguments of", arg
- if type( arg ) == StringType:
- if re.compile( '^[A-Z]+$' ).match( arg ) == None:
- return [ None ]
- else:
- return [ arg.upper() ]
-
- # we are dealing with a list-type, e.g.,
- # [ '*', [ 'A', 'B' ] ]
- # [ 'A', 'B' ]
- result = []
- if re.compile( '^[A-Z]+$' ).match( arg[0] ) == None:
- for a in arg[1]:
- sub_result = nested_list_args( a )
- if sub_result != [ None ]:
- for r in sub_result:
- if r not in result:
- result.append( r )
-
- else:
- for a in arg:
- result.append( a )
-
- print "returning ",result
- return result
-
-
-
-
-def expand_nested_list( arg, arg_map, use_arg_map = True ):
-
- print "Expanding nested list: ", arg, len(arg)
- if type( arg ) == StringType:
- print "Type is string"
- # .....
- if re.compile( '^[A-Z]+$' ).match( arg ) == None:
- return arg
- else:
- if use_arg_map:
- if not arg_map.has_key( arg ):
- return '?' + arg.upper()
- else:
- return arg_map[ arg ][ 'code' ][ 'call_level_0' ]
- else:
- return arg.lower()
-
- if arg[0] == '()':
- result = '(' + expand_nested_list( arg[1], arg_map, use_arg_map ) + ')'
- return result
-
- if arg[0] == 'max' or arg[0] == 'min':
- print "arg1: ", arg[1]
- result = 'std::' + arg[0] + '('
- i = 0
- for a in arg[1]:
- result += expand_nested_list( a, arg_map, use_arg_map )
- i += 1
- if i != len(arg[1]):
- result += ","
- result += ')'
- return result
-
- if arg[0] == '*' or arg[0] == '/' or arg[0] == '+' or arg[0] == '-':
- print "arg1: ", arg[1]
- arg_list = []
- for a in arg[1]:
- arg_list += [ expand_nested_list( a, arg_map, use_arg_map ) ]
- result = arg[0].join( arg_list )
- return result
-
- print "ERROR: Don't know what to do!!"
- return 'ERROR'
-
-def level1_assert( name, properties, arg_map ):
- result = None
-
- if properties.has_key( 'assert_char' ):
- result = "assert( "
- result_array = []
- for char in properties[ 'assert_char' ]:
- result_array += [ call_level0_type( name, properties, arg_map ) + ' == \'' + char + '\'' ]
- result += " || ".join( result_array )
- result += " );"
-
- if properties.has_key( 'assert_ge' ) and not properties.has_key( 'workspace_query_for' ):
- result = "assert( " + call_level0_type( name, properties, arg_map ) + " >= " + expand_nested_list( properties[ 'assert_ge' ], arg_map ) + ' );'
-
- if 'workspace' in properties[ 'io' ]:
- min_workspace_call = min_workspace_call_type( name, properties, arg_map )
- if min_workspace_call == None:
- min_workspace_call = '$CALL_MIN_SIZE'
- result = 'assert( traits::vector_size(work.select(' + workspace_type( name, properties ) + '()) >= ' + \
- 'min_size_' + name.lower() + '( ' + min_workspace_call + ' )));'
-
- elif properties.has_key( 'assert_size' ):
- result = "assert( traits::vector_size(" + call_level0_type( name, properties, arg_map ) + ") >= " + \
- expand_nested_list( properties[ 'assert_size' ], arg_map ) + ' );'
-
- return result
-
-
-def call_level1_type( name, properties ):
- result = None
- if level1_type( name, properties ) != None:
- result = name.lower()
- return result
-
-
-def workspace_type( name, properties ):
- result = None
- if 'workspace' in properties[ 'io' ]:
- if properties[ 'value_type' ] == 'INTEGER':
- result = 'integer_t'
- elif properties[ 'value_type' ] == 'LOGICAL':
- result = 'bool'
- elif properties[ 'value_type' ] == 'REAL' or properties[ 'value_type' ] == 'DOUBLE PRECISION':
- result = 'real_type'
- else:
- result = 'value_type'
- return result
-
-
-
-
-def opt_workspace_pre_type( name, properties, arg_map ):
- result = None
- if 'workspace' in properties[ 'io' ]:
- if properties.has_key( 'workspace_query_by' ):
- result = workspace_type( name, properties ) + ' opt_size_' + name.lower() + ';'
- else:
- min_workspace_call = min_workspace_call_type( name, properties, arg_map )
- if min_workspace_call == None:
- min_workspace_call = '$CALL_MIN_SIZE'
- result = 'traits::detail::array< ' + workspace_type( name, properties ) + ' >' + \
- ' tmp_' + name.lower() + '( min_size_' + name.lower() + '( ' + min_workspace_call + ' ) );'
- return result
-
-
-def opt_workspace_post_type( name, properties ):
- result = None
- if 'workspace' in properties[ 'io' ]:
- if properties.has_key( 'workspace_query_by' ):
- if properties['value_type'] == 'INTEGER':
- result = 'traits::detail::array< ' + workspace_type( name, properties ) + ' >' + \
- ' tmp_' + name.lower() + '( opt_size_' + name.lower() + ' );'
- else:
- result = 'traits::detail::array< ' + workspace_type( name, properties ) + ' >' + \
- ' tmp_' + name.lower() + '( traits::detail::to_int( opt_size_' + name.lower() + ' ) );'
- return result
-
-
-
-def opt_workspace_query_type( name, properties, arg_map ):
- result = None
- if properties.has_key( 'workspace_query_for' ):
- result = '-1'
- elif 'workspace' in properties[ 'io' ]:
- if properties.has_key( 'workspace_query_by' ):
- result = '&opt_size_' + name.lower();
- else:
- result = 'traits::vector_storage(tmp_' + name.lower() + ')'
- else:
- result = call_level0_type( name, properties, arg_map )
- return result
-
-
-def min_workspace_size_type( name, properties, arg_map ):
- result = None
- if 'workspace' in properties[ 'io' ] and properties.has_key( 'assert_size' ):
- result = expand_nested_list( properties[ 'assert_size' ], arg_map, False );
- return result
-
-
-def min_workspace_arg_type( name, properties, arg_map ):
- result = None
- if 'workspace' in properties[ 'io' ] and properties.has_key( 'assert_size_args' ):
- code_result = []
- for arg in properties[ 'assert_size_args' ]:
- if arg_map.has_key( arg ):
- code_result += [ cpp_type( arg, arg_map[ arg ] ) ]
- else:
- code_result += [ '?' + arg.upper() ]
- result = ", ".join( code_result )
- return result
-
-
-def min_workspace_call_type( name, properties, arg_map ):
- result = None
- if 'workspace' in properties[ 'io' ] and properties.has_key( 'assert_size_args' ):
- code_result = []
- for arg in properties[ 'assert_size_args' ]:
- if arg_map.has_key( arg ):
- code_result += [ call_level0_type( arg, arg_map[ arg ], arg_map ) ]
- else:
- code_result += [ '?' + arg.upper() ]
-
- result = ", ".join( code_result )
- return result
-
-
-def user_defined_type( name, properties, arg_map ):
- result = None
- if properties.has_key( 'user_defined' ):
- result = properties[ 'user_defined' ]
- return result
-
-
-
-#
-#
-#
-#
-def match_formulae( text_field ):
- find_start = re.compile( '([A-Z]+)\s?(>=|is\sat\sleast)\s?(.*)the\scode\swill', re.M | re.S ).findall( text_field )
- for element in find_start:
- print element
-
-
-
-#
-# Split string using a list of delimiters
-# Delimiters may be substrings of length 1 or 2 (may be increased if necessary)
-#
-def split_delim( s, delim = [','] ):
- result = []
- parentheses = 0
- cur_pos = 0
- prev_pos = 0
- for index in range( 0, len(s) ):
- if s[ index ] == '(':
- parentheses += 1
- elif s[ index ] == ')':
- parentheses -= 1
- for length in range( 1, 3 ):
- if index >= (length-1) and parentheses == 0:
- c = s[ index-(length-1): index+1 ]
- if c in delim:
- result += [ s[ prev_pos:(index-(length-1)) ] ]
- prev_pos = index+1
-
- result += [ s[ prev_pos:len(s) ] ]
- return result
-
-
-
-#
-# Look for implicit products, like 5N, and replace with 5*N
-#
-def replace_implicit_products( text_field ):
- result = re.sub( '([0-9])+([A-Z]+)', '\\1*\\2', text_field )
- return result
-
-
-
-
-def decompose_formula( text_field ):
- text_field = text_field.strip()
- print "Decompose: ", text_field
-
- if text_field[0] == '(' and text_field[-1] == ')':
- result = text_field[ 1:-1 ]
- return [ '()', decompose_formula( result ) ]
-
- if len( split_delim( text_field, [ ',' ] ) ) > 1:
- print "ERROR! (in LAPACK?)"
- return [ 'ERROR' ]
-
- #
- # Detect leaf: if text_field equals a argument (like N), or a number
- #
- if re.compile( '^([a-zA-Z]+|[0-9]+)$' ).match( text_field ):
- print "decompose: at leaf: '" + text_field + "'"
- return text_field.upper()
-
-
- if len( split_delim( text_field, [ '**' ] ) ) > 1:
- print 'decompose: inserting pow'
- arguments = split_delim( text_field, [ '**' ] )
- print arguments
- result = []
- for arg in arguments:
- result.append( decompose_formula( arg ) )
- return [ 'pow', result ]
-
- for operator in [ '*', '/', '+', '-' ]:
- if len( split_delim( text_field, [ operator ] ) ) > 1:
- print 'decompose: inserting ' + operator
- arguments = split_delim( text_field, operator )
- print arguments
- result = []
- for arg in arguments:
- result.append( decompose_formula( arg ) )
- return [ operator, result ]
-
-
- if (text_field[ 0:4 ] == 'max(' or text_field[ 0:4 ] == 'MAX(') and \
- text_field[ -1 ] == ')':
- print "decompose: inserting max"
- arguments = split_delim( text_field[ 4:-1 ] )
- print arguments, len(arguments)
- # keep max a binary function ... :-)
- if len( arguments ) > 2:
- return [ 'max', [ decompose_formula( arguments[0] ), decompose_formula( 'max(' + ",".join( arguments[1:] ) + ')' ) ] ]
- else:
- result = []
- for arg in arguments:
- result.append( decompose_formula( arg ) )
- #result = [ decompose_formula( arguments[0] ), decompose_formula( arguments[1] ) ]
- return [ 'max', result ]
-
-
- if (text_field[ 0:4 ] == 'min(' or text_field[ 0:4 ] == 'MIN(') and \
- text_field[ -1 ] == ')':
- print "decompose: inserting min"
- arguments = split_delim( text_field[ 4:-1 ] )
- print arguments, len(arguments)
- # keep max a binary function ... :-)
- if len( arguments ) > 2:
- return [ 'min', [ decompose_formula( arguments[0] ), decompose_formula( 'min(' + ",".join( arguments[1:] ) + ')' ) ] ]
- else:
- result = []
- for arg in arguments:
- result.append( decompose_formula( arg ) )
- #result = [ decompose_formula( arguments[0] ), decompose_formula( arguments[1] ) ]
- return [ 'min', result ]
-
-
-#
-#
-def match_assert_ge( argument_map, text_field ):
- #print "Match assert GE..."
- match_it = re.compile( ' +[A-Z]+[ ]{0,3}(>=|must be at least)[ ]{0,3}([0-9]|(min|max|MIN|MAX|[\(\)\,0-9A-Z\+\*\-])+)' ).findall( text_field )
- if len( match_it ) == 1:
- print "Match assert GE:", match_it
- #print match_it
- #if len( match_it[ 0 ][ 2 ] ) > 0:
- return decompose_formula( match_it[ 0 ][ 1 ] )
- else:
- print "nr of matches: ", len( match_it )
- return None
-
-
-
-
-
-# try different keys, return the one that exists, if any
-
-def my_has_key( key_name, template_map ):
- # try, e.g., gelsd.all.
- m_all_key = key_name.replace( ".complex", ".all" ).replace( ".real", ".all" )
- if template_map.has_key( key_name ):
- print "using key ", key_name
- return key_name
- if template_map.has_key( m_all_key ):
- print "using key ", m_all_key
- return m_all_key
- print "tried keys ", key_name, "and", m_all_key,", no results"
- return None
-
-
-
-#
-# Default user-defined arg is of type scalar INTEGER
-#
-def add_user_defined_args( arg, argument_map, template_map, base_name ):
- print "Trying to add user-defined argument definitions for", arg
-
- argument_map[ arg ] = {}
-
- base_key = base_name.lower() + '.' + arg
- print "base_key",base_key
-
- if my_has_key( base_key + '.value_type', template_map ) != None:
- argument_map[ arg ][ 'value_type' ] = template_map[ my_has_key( base_key + '.value_type', template_map ) ].strip()
- else:
- argument_map[ arg ][ 'value_type' ] = 'INTEGER'
-
- if my_has_key( base_key + '.type', template_map ) != None:
- argument_map[ arg ][ 'type' ] = template_map[ my_has_key( base_key + '.type', template_map ) ].strip()
- else:
- argument_map[ arg ][ 'type' ] = 'scalar'
-
- if my_has_key( base_key + '.init', template_map ) != None:
- argument_map[ arg ][ 'user_defined' ] = template_map[ my_has_key( base_key + '.init', template_map ) ].strip()
- else:
- argument_map[ arg ][ 'user_defined' ] = 'UNDEFINED'
-
- argument_map[ arg ][ 'io' ] = [ 'input' ]
-
- return
-
-
-#
-# Desired order of routines in C++ code: float, double, single complex, double complex
-#
-def routine_cmp( a, b ):
- letter_a = a[0]
- letter_b = b[0]
- value_map = { 'S': 0, 'D': 1, 'C': 2, 'Z': 3 }
- result = 0
- if value_map[ a[0] ] < value_map[ b[ 0] ]:
- result = -1
- if value_map[ a[0] ] > value_map[ b[ 0] ]:
- result = 1
- return result
-
-
 #
 # Group subroutines on their name, with the first character removed. This will
 # group them in the same .hpp file as well. Sort these subroutines based on
@@ -571,7 +30,7 @@
       group_map[ short_name ] = []
     group_map[ short_name ] += [ i ]
   for value in group_map.values():
- value.sort( routine_cmp )
+ value.sort( bindings.routine_cmp )
   return group_map
   
 

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-20 03:16:24 EST (Fri, 20 Feb 2009)
@@ -260,11 +260,12 @@
       min_workspace_call = '$CALL_MIN_SIZE'
     result = 'assert( traits::vector_size(work.select(' + workspace_type( name, properties ) + '()) >= ' + \
              'min_size_' + name.lower() + '( ' + min_workspace_call + ' )));'
-
+
+ # assert_size is vector-type specific
   elif properties.has_key( 'assert_size' ):
- result = "assert( traits::vector_size(" + call_level0_type( name, properties, arg_map ) + ") >= " + \
+ result = "assert( traits::vector_size(" + call_level1_type( name, properties ) + ") >= " + \
       expand_nested_list( properties[ 'assert_size' ], arg_map ) + ' );'
-
+
   return result
 
 
@@ -348,7 +349,10 @@
       if arg_map.has_key( arg ):
         code_result += [ cpp_type( arg, arg_map[ arg ] ) ]
       else:
- code_result += [ '?' + arg.upper() ]
+ if type( properties[ 'assert_size' ] ) == StringType:
+ code_result += [ '?' + properties[ 'assert_size' ] ]
+ else:
+ code_result += [ '??' ]
     result = ", ".join( code_result )
   return result
 
@@ -361,7 +365,13 @@
       if arg_map.has_key( arg ):
         code_result += [ call_level0_type( arg, arg_map[ arg ], arg_map ) ]
       else:
- code_result += [ '?' + arg.upper() ]
+ if arg != None:
+ code_result += [ '?' + arg.upper() ]
+ else:
+ if type( properties[ 'assert_size' ] ) == StringType:
+ code_result += [ '?' + properties[ 'assert_size' ] ]
+ else:
+ code_result += [ '??' ]
     result = ", ".join( code_result )
   return result
 
@@ -639,6 +649,11 @@
     print "Could not find function/subroutine statement, bailing out."
     return None, None
 
+ # IF there are no arguments, bail out
+ if subroutine_arguments == ['']:
+ print "Function without arguments not supported."
+ return None, None
+
   #
   # Do some further analysis as to what kind of routine this is
   #

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-20 03:16:24 EST (Fri, 20 Feb 2009)
@@ -43,10 +43,11 @@
 struct $groupname_impl {
 
     typedef ValueType value_type;
+ typedef $RETURN_TYPE return_type;
 
     // templated specialization
     template< $TYPES >
- static $RETURN_TYPE compute( $LEVEL1 ) {
+ static return_type compute( $LEVEL1 ) {
         $RETURN_STATEMENTdetail::$groupname( $CALL_LEVEL0 );
     }
 };


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