Esempio n. 1
0
def run(target_dir):
    f = join_open(reference_tables_directory, "fpwide.tbl", "r")
    tables_wide = collect_tables(f, 0)
    f.close()
    f = join_open(reference_tables_directory, "fpk.tbl", "r")
    tables_k = collect_tables(f, 1)
    f.close()
    f = join_open(reference_tables_directory, "fpl.tbl", "r")
    tables_l = collect_tables(f, 1)
    f.close()
    tables_combined = combine_tables(tables_wide, tables_k, tables_l)
    f = join_open(target_dir, "sasaki.cpp", "w")
    print_header(f)
    print_ftp_info(f)
    print_sasaki_cpp(f, tables_combined)
    f.close()
    block_size = 12
    for i_begin in range(0, len(tables_combined), block_size):
        i_end = min(len(tables_combined), i_begin + block_size)
        f = join_open(target_dir,
                      "sasaki_tables_%02d_%02d.cpp" % (i_begin + 1, i_end),
                      "w")
        print_header(f)
        print_table_block(f, tables_combined, i_begin, i_end)
        f.close()
def one_type(target_dir, subs):
  array_type = subs["array_type"]
  subs["array_type_plain"] = array_type + "_plain"
  subs["ARRAY_TYPE"] = array_type.upper()
  f = utils.join_open(target_dir, "%s_reductions.h" % array_type, "w")
  utils.write_this_is_auto_generated(f, this)
  print >> f, substitute(subs, """
#ifndef SCITBX_ARRAY_FAMILY_${ARRAY_TYPE}_REDUCTIONS_H
#define SCITBX_ARRAY_FAMILY_${ARRAY_TYPE}_REDUCTIONS_H

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#include <scitbx/array_family/ref_reductions.h>
#include <scitbx/array_family/${array_type_plain}.h>

namespace scitbx { namespace af {
""")

  generate_order(f, subs)
  generate_max_index_etc(f, subs)
  generate_max_etc(f, subs)
  generate_mean_weighted_etc(f, subs)
  generate_first_index_etc(f, subs)

  print >> f, substitute(subs, """
}} // namespace scitbx::af

#endif // DOXYGEN_SHOULD_SKIP_THIS

#endif // SCITBX_ARRAY_FAMILY_${ARRAY_TYPE}_REDUCTIONS_H
""")

  f.close()
Esempio n. 3
0
def one_type(target_dir, array_type_name):
  f = utils.join_open(target_dir, "%s_apply.h" % array_type_name, "w")
  utils.write_this_is_auto_generated(f, this)
  include_array_type_name = array_type_name
  if (array_type_name == "ref"):
    include_array_type_name = "versa"
  generic_include = "functors"
  if (generate_algebras.base_array_type_name(array_type_name) == "tiny"):
    generic_include = "operators"
  print("""\
#ifndef SCITBX_ARRAY_FAMILY_%s_APPLY_H
#define SCITBX_ARRAY_FAMILY_%s_APPLY_H

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#include <scitbx/type_holder.h>
#include <scitbx/array_family/%s.h>
#include <scitbx/array_family/detail/generic_array_%s.h>

namespace scitbx { namespace af {
""" % ((array_type_name.upper(),) * 2 + (
    include_array_type_name, generic_include)), file=f)

  generate_algebras.generate_unary_apply(f, array_type_name)

  print("""}} // namespace scitbx::af

#endif // DOXYGEN_SHOULD_SKIP_THIS

#endif // SCITBX_ARRAY_FAMILY_%s_APPLY_H""" % (array_type_name.upper(),), file=f)
  f.close()
Esempio n. 4
0
def run(target_dir):
    tables = collect_tables()
    compare_points(tables)  # establish that each list of data points is unique
    f = join_open(target_dir, "henke.cpp", "w")
    print_header(f)
    print_ftp_info(f)
    print_henke_cpp(f, tables)
    f.close()
    Z_block = 12
    for Z_begin in range(1, len(tables), Z_block):
        Z_end = min(len(tables), Z_begin + Z_block)
        f = join_open(target_dir,
                      "henke_tables_%02d_%02d.cpp" % (Z_begin, Z_end - 1), "w")
        print_header(f)
        print_table_block(f, tables, Z_begin, Z_end)
        f.close()
Esempio n. 5
0
def collect_tables():
    nff_files = []
    for file in os.listdir(reference_tables_directory):
        fn = file.lower().capitalize()
        if (fn[-4:] == ".nff"): nff_files.append(file)
    tables = [0] * 120
    for file in nff_files:
        f = join_open(reference_tables_directory, file, "r")
        header = f.readline()
        table = f.readlines()
        f.close()
        Symbol = header[1:3].strip()
        Z = int(header[7:9])
        assert len(Symbol) > 0
        assert Symbol[0] in 'abcdefghijklmnopqrstuvwxyz'
        assert Symbol[-1] in 'abcdefghijklmnopqrstuvwxyz'
        assert Z > 0 and Z < len(tables)
        assert tables[Z] == 0
        Symbol = Symbol.capitalize()
        tables[Z] = (Symbol, table)
    Z = tables[1:].index(0) + 1
    rest = tables[Z:]
    assert rest == [0] * len(rest)
    tables = tables[:Z]
    return tables
Esempio n. 6
0
def one_type(target_dir, array_type_name):
  f = utils.join_open(target_dir, "%s_apply.h" % array_type_name, "w")
  utils.write_this_is_auto_generated(f, this)
  include_array_type_name = array_type_name
  if (array_type_name == "ref"):
    include_array_type_name = "versa"
  generic_include = "functors"
  if (generate_algebras.base_array_type_name(array_type_name) == "tiny"):
    generic_include = "operators"
  print >> f, """\
#ifndef SCITBX_ARRAY_FAMILY_%s_APPLY_H
#define SCITBX_ARRAY_FAMILY_%s_APPLY_H

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#include <scitbx/type_holder.h>
#include <scitbx/array_family/%s.h>
#include <scitbx/array_family/detail/generic_array_%s.h>

namespace scitbx { namespace af {
""" % ((array_type_name.upper(),) * 2 + (
    include_array_type_name, generic_include))

  generate_algebras.generate_unary_apply(f, array_type_name)

  print >> f, """}} // namespace scitbx::af

#endif // DOXYGEN_SHOULD_SKIP_THIS

#endif // SCITBX_ARRAY_FAMILY_%s_APPLY_H""" % (array_type_name.upper(),)
  f.close()
Esempio n. 7
0
def one_type(target_dir, subs):
    array_type = subs["array_type"]
    subs["array_type_plain"] = array_type + "_plain"
    subs["ARRAY_TYPE"] = array_type.upper()
    f = utils.join_open(target_dir, "%s_reductions.h" % array_type, "w")
    utils.write_this_is_auto_generated(f, this)
    print >> f, substitute(
        subs, """
#ifndef SCITBX_ARRAY_FAMILY_${ARRAY_TYPE}_REDUCTIONS_H
#define SCITBX_ARRAY_FAMILY_${ARRAY_TYPE}_REDUCTIONS_H

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#include <scitbx/array_family/ref_reductions.h>
#include <scitbx/array_family/${array_type_plain}.h>

namespace scitbx { namespace af {
""")

    generate_order(f, subs)
    generate_max_index_etc(f, subs)
    generate_max_etc(f, subs)
    generate_mean_weighted_etc(f, subs)
    generate_first_index_etc(f, subs)

    print >> f, substitute(
        subs, """
}} // namespace scitbx::af

#endif // DOXYGEN_SHOULD_SKIP_THIS

#endif // SCITBX_ARRAY_FAMILY_${ARRAY_TYPE}_REDUCTIONS_H
""")

    f.close()
def collect_tables():
  nff_files = []
  for file in os.listdir(reference_tables_directory):
    fn = file.lower().capitalize()
    if (fn[-4:] == ".nff"): nff_files.append(file)
  tables = [0] * 120
  for file in nff_files:
    f = join_open(reference_tables_directory, file, "r")
    header = f.readline()
    table = f.readlines()
    f.close()
    Symbol = header[1:3].strip()
    Z = int(header[7:9])
    assert len(Symbol) > 0
    assert Symbol[0] in string.lowercase
    assert Symbol[-1] in string.lowercase
    assert Z > 0 and Z < len(tables)
    assert tables[Z] == 0
    Symbol = Symbol.capitalize()
    tables[Z] = (Symbol, table)
  Z = tables[1:].index(0) + 1
  rest = tables[Z:]
  assert rest == [0] * len(rest)
  tables = tables[:Z]
  return tables
def run(target_dir):
  tables = collect_tables()
  compare_points(tables) # establish that each list of data points is unique
  f = join_open(target_dir, "henke.cpp", "w")
  print_header(f)
  print_ftp_info(f)
  print_henke_cpp(f, tables)
  f.close()
  Z_block = 12
  for Z_begin in xrange(1, len(tables), Z_block):
    Z_end = min(len(tables), Z_begin + Z_block)
    f = join_open(
      target_dir, "henke_tables_%02d_%02d.cpp" % (Z_begin, Z_end-1), "w")
    print_header(f)
    print_table_block(f, tables, Z_begin, Z_end)
    f.close()
Esempio n. 10
0
def write(this, target_dir, common_code, full_code):
  f = join_open(target_dir, "flex_fwd.h", "w")
  write_this_is_auto_generated(f, this)
  if (libtbx.env.build_options.write_full_flex_fwd_h):
    code = full_code % motivation
  else:
    code = ""
  f.write(common_code % code)
Esempio n. 11
0
def write(this, target_dir, common_code, full_code):
    f = join_open(target_dir, "flex_fwd.h", "w")
    write_this_is_auto_generated(f, this)
    if (libtbx.env.build_options.write_full_flex_fwd_h):
        code = full_code % motivation
    else:
        code = ""
    f.write(common_code % code)
Esempio n. 12
0
def run(target_dir):
    f = join_open(reference_tables_directory, "fpwide.tbl", "r")
    tables_wide = collect_tables(f, 0)
    f.close()
    f = join_open(reference_tables_directory, "fpk.tbl", "r")
    tables_k = collect_tables(f, 1)
    f.close()
    f = join_open(reference_tables_directory, "fpl.tbl", "r")
    tables_l = collect_tables(f, 1)
    f.close()
    tables_combined = combine_tables(tables_wide, tables_k, tables_l)
    f = join_open(target_dir, "sasaki.cpp", "w")
    print_header(f)
    print_ftp_info(f)
    print_sasaki_cpp(f, tables_combined)
    f.close()
    block_size = 12
    for i_begin in xrange(0, len(tables_combined), block_size):
        i_end = min(len(tables_combined), i_begin + block_size)
        f = join_open(target_dir, "sasaki_tables_%02d_%02d.cpp" % (i_begin + 1, i_end), "w")
        print_header(f)
        print_table_block(f, tables_combined, i_begin, i_end)
        f.close()
def run(target_dir):
    op_types, result_type = build_pairs()
    assert len(op_types) == len(result_type)
    if ("--Raw" in sys.argv):
        for i, optype in enumerate(op_types):
            print("%s + %s = %s" % (optype[0], optype[1], result_type[i]),
                  file=f)
    else:
        f = utils.join_open(target_dir, "operator_traits_builtin.h", "w")
        utils.write_this_is_auto_generated(f, this)
        print("""\
#ifndef SCITBX_ARRAY_FAMILY_OPERATOR_TRAITS_BUILTIN_H
#define SCITBX_ARRAY_FAMILY_OPERATOR_TRAITS_BUILTIN_H

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#include <complex>

namespace scitbx { namespace af {

  // The default traits: the result type is the type of the lhs argument.
  template<typename TypeLHS, typename TypeRHS>
  struct binary_operator_traits {
    typedef TypeLHS arithmetic;
  };

  // The remainder of this file defines the traits where the
  // result type is the type of the rhs argument.
""",
              file=f)

        for i, optype in enumerate(op_types):
            if (result_type[i]):
                print("""  template<>
  struct binary_operator_traits<%s, %s > {
    typedef %s arithmetic;
  };
""" % (optype[0], optype[1], result_type[i]),
                      file=f)

        print("}} // namespace scitbx::af", file=f)
        print(file=f)
        print("#endif // DOXYGEN_SHOULD_SKIP_THIS", file=f)
        print(file=f)
        print("#endif // SCITBX_ARRAY_FAMILY_OPERATOR_TRAITS_BUILTIN_H",
              file=f)
        f.close()
def run(target_dir):
  op_types, result_type = build_pairs()
  assert len(op_types) == len(result_type)
  if ("--Raw" in sys.argv):
    for i in xrange(len(op_types)):
      print >> f, "%s + %s = %s" % (
        op_types[i].lhs, op_types[i].rhs, result_type[i])
  else:
    f = utils.join_open(target_dir, "operator_traits_builtin.h", "w")
    utils.write_this_is_auto_generated(f, this)
    print >> f, """\
#ifndef SCITBX_ARRAY_FAMILY_OPERATOR_TRAITS_BUILTIN_H
#define SCITBX_ARRAY_FAMILY_OPERATOR_TRAITS_BUILTIN_H

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#include <complex>

namespace scitbx { namespace af {

  // The default traits: the result type is the type of the lhs argument.
  template<typename TypeLHS, typename TypeRHS>
  struct binary_operator_traits {
    typedef TypeLHS arithmetic;
  };

  // The remainder of this file defines the traits where the
  // result type is the type of the rhs argument.
"""

    for i in xrange(len(op_types)):
      if (result_type[i]):
        print >> f, """  template<>
  struct binary_operator_traits<%s, %s > {
    typedef %s arithmetic;
  };
""" % (op_types[i].lhs, op_types[i].rhs, result_type[i])

    print >> f, "}} // namespace scitbx::af"
    print >> f
    print >> f, "#endif // DOXYGEN_SHOULD_SKIP_THIS"
    print >> f
    print >> f, "#endif // SCITBX_ARRAY_FAMILY_OPERATOR_TRAITS_BUILTIN_H"
    f.close()
Esempio n. 15
0
def run(target_dir):
    f = utils.join_open(target_dir, "detail/std_imports.h", "w")
    utils.write_this_is_auto_generated(f, this)
    print("""\
#ifndef SCITBX_ARRAY_FAMILY_STD_IMPORTS_H
#define SCITBX_ARRAY_FAMILY_STD_IMPORTS_H

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#include <cmath>
#include <cstdlib>
#include <complex>

namespace scitbx { namespace fn {
""",
          file=f)

    all_function_names = []
    for function_name in (cmath_1arg + cmath_2arg + cstdlib_1arg +
                          algorithm_2arg + complex_1arg):
        if (not function_name in all_function_names):
            all_function_names.append(function_name)
    for entry in complex_special:
        function_name = entry[1]
        if (not function_name in all_function_names):
            all_function_names.append(function_name)

    for function_name in all_function_names:
        print("  using std::" + filter_function_name(function_name) + ";",
              file=f)

    generate_1arg(f)
    generate_2arg(f)

    print("""
}} // namespace scitbx::af

#endif // DOXYGEN_SHOULD_SKIP_THIS

#endif // SCITBX_ARRAY_FAMILY_STD_IMPORTS_H""",
          file=f)
    f.close()
def run(target_dir):
  f = utils.join_open(target_dir, "detail/operator_functors.h", "w")
  utils.write_this_is_auto_generated(f, this)
  print >> f, """\
#ifndef SCITBX_ARRAY_FAMILY_OPERATOR_FUNCTORS_H
#define SCITBX_ARRAY_FAMILY_OPERATOR_FUNCTORS_H

namespace scitbx { namespace fn {"""

  for op, ftor_name in operator_functor_info.unary_functors.items():
    generate_unary(f, ftor_name, op + "x")
  for op, ftor_name in operator_functor_info.binary_functors.items():
    generate_binary(f, ftor_name, "x " + op + " y")
  for op, ftor_name in operator_functor_info.in_place_binary_functors.items():
    generate_in_place_binary(f, ftor_name, "x " + op + " y")

  print >> f, """
}} // namespace scitbx::fn

#endif // SCITBX_ARRAY_FAMILY_OPERATOR_FUNCTORS_H"""
  f.close()
def run(target_dir):
  f = utils.join_open(target_dir, "detail/std_imports.h", "w")
  utils.write_this_is_auto_generated(f, this)
  print >> f, """\
#ifndef SCITBX_ARRAY_FAMILY_STD_IMPORTS_H
#define SCITBX_ARRAY_FAMILY_STD_IMPORTS_H

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#include <cmath>
#include <cstdlib>
#include <complex>

namespace scitbx { namespace fn {
"""

  all_function_names = []
  for function_name in (cmath_1arg + cmath_2arg + cstdlib_1arg
                        + algorithm_2arg + complex_1arg):
    if (not function_name in all_function_names):
      all_function_names.append(function_name)
  for entry in complex_special:
    function_name = entry[1]
    if (not function_name in all_function_names):
      all_function_names.append(function_name)

  for function_name in all_function_names:
    print >> f, "  using std::" + filter_function_name(function_name) + ";"

  generate_1arg(f)
  generate_2arg(f)

  print >> f, """
}} // namespace scitbx::af

#endif // DOXYGEN_SHOULD_SKIP_THIS

#endif // SCITBX_ARRAY_FAMILY_STD_IMPORTS_H"""
  f.close()
def run(target_dir):
    f = utils.join_open(target_dir, "detail/operator_functors.h", "w")
    utils.write_this_is_auto_generated(f, this)
    print >> f, """\
#ifndef SCITBX_ARRAY_FAMILY_OPERATOR_FUNCTORS_H
#define SCITBX_ARRAY_FAMILY_OPERATOR_FUNCTORS_H

namespace scitbx { namespace fn {"""

    for op, ftor_name in operator_functor_info.unary_functors.items():
        generate_unary(f, ftor_name, op + "x")
    for op, ftor_name in operator_functor_info.binary_functors.items():
        generate_binary(f, ftor_name, "x " + op + " y")
    for op, ftor_name in operator_functor_info.in_place_binary_functors.items(
    ):
        generate_in_place_binary(f, ftor_name, "x " + op + " y")

    print >> f, """
}} // namespace scitbx::fn

#endif // SCITBX_ARRAY_FAMILY_OPERATOR_FUNCTORS_H"""
    f.close()
Esempio n. 19
0
def run(dr):
    f = join_open(dr, "reference_table.cpp", "w")
    s1md5 = make_md5("sgtbx/direct_space_asu/reference_table.py")
    s2md5 = make_md5("sgtbx/direct_space_asu/proto/generate_cpp_asu_table.py")
    s3md5 = make_md5("sgtbx/direct_space_asu/short_cuts.py")
    print s1md5, '\n', s2md5, '\n', s3md5
    print >> f, head1
    # comma in print adds one whitespace between parameters
    # so it is better to use + to concatanete strings
    # to avoid trailing white spaces
    print >> f, "////////////////\n" + s1md5 + "\n" + s2md5 + "\n" + s3md5 + "\n////////////////\n"
    print >> f, head2
    table = "asu_func asu_table[230] = {"
    i = 0
    for sg in xrange(1, 231):
        if (i % 8 == 0):
            table += "\n "
        func = show_cpp(sg, f)
        table += " "
        table += func
        if i < 229:
            table += ","
        i += 1
    print >> f, "} // end of unnamed namespace\n\n" + table + "\n};\n\n}}}\n"
def run(dr):
    f = join_open(dr, "reference_table.cpp", "w")
    s1md5 = make_md5("sgtbx/direct_space_asu/reference_table.py")
    s2md5 = make_md5("sgtbx/direct_space_asu/proto/generate_cpp_asu_table.py")
    s3md5 = make_md5("sgtbx/direct_space_asu/short_cuts.py")
    print s1md5, "\n", s2md5, "\n", s3md5
    print >> f, head1
    # comma in print adds one whitespace between parameters
    # so it is better to use + to concatanete strings
    # to avoid trailing white spaces
    print >> f, "////////////////\n" + s1md5 + "\n" + s2md5 + "\n" + s3md5 + "\n////////////////\n"
    print >> f, head2
    table = "asu_func asu_table[230] = {"
    i = 0
    for sg in xrange(1, 231):
        if i % 8 == 0:
            table += "\n "
        func = show_cpp(sg, f)
        table += " "
        table += func
        if i < 229:
            table += ","
        i += 1
    print >> f, "} // end of unnamed namespace\n\n" + table + "\n};\n\n}}}\n"
Esempio n. 21
0
def one_type(target_dir, array_type_name):
  f = utils.join_open(target_dir, "%s_algebra.h" % array_type_name, "w")
  utils.write_this_is_auto_generated(f, this)
  include_array_type_name = array_type_name
  if (array_type_name == "ref"):
    include_array_type_name = "versa"
  generic_include = "functors"
  if (base_array_type_name(array_type_name) == "tiny"):
    generic_include = "operators"
  print >> f, """\
#ifndef SCITBX_ARRAY_FAMILY_%s_ALGEBRA_H
#define SCITBX_ARRAY_FAMILY_%s_ALGEBRA_H

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#include <scitbx/array_family/%s.h>
""" % ((array_type_name.upper(),) * 2 + (include_array_type_name,))
  if (array_type_name == "small"):
    print >> f, """#if (defined(BOOST_MSVC) && BOOST_MSVC <= 1300) // VC++ 7.0
#define SCITBX_ARRAY_FAMILY_SMALL_ALGEBRA_MIN_N1_N2 N1
#else
#define SCITBX_ARRAY_FAMILY_SMALL_ALGEBRA_MIN_N1_N2 (N1<N2?N1:N2)
#endif

"""
  print >> f, """#include <scitbx/array_family/operator_traits_builtin.h>
#include <scitbx/array_family/detail/operator_functors.h>
#include <scitbx/array_family/detail/generic_array_%s.h>
#include <scitbx/array_family/detail/std_imports.h>
#include <scitbx/array_family/misc_functions.h>

namespace scitbx { namespace af {
""" % (generic_include,)

  generate_unary_ops(f, array_type_name)
  for op_symbol in operator_functor_info.arithmetic_binary_ops:
    generate_elementwise_binary_op(f,
      array_type_name, "arithmetic", op_symbol)
    generate_elementwise_inplace_binary_op(f,
      array_type_name, "arithmetic", op_symbol + "=")
  for op_symbol in operator_functor_info.logical_binary_ops:
    generate_elementwise_binary_op(f,
      array_type_name, "logical", op_symbol)
  for op_symbol in operator_functor_info.boolean_binary_ops:
    generate_elementwise_binary_op(f,
      array_type_name, "boolean", op_symbol)
  generate_1arg_element_wise(f,
    array_type_name,
    misc_functions_a
    + generate_std_imports.cmath_1arg
    + generate_std_imports.cstdlib_1arg
    + generate_std_imports.complex_1arg)
  generate_2arg_element_wise(f,
    array_type_name,
    misc_functions_a_a
    + generate_std_imports.cmath_2arg
    + generate_std_imports.algorithm_2arg)
  for special_def in generate_std_imports.complex_special:
    generate_element_wise_special(f, array_type_name, special_def)
  for args in misc_functions_x_x_s:
    apply(generate_x_x_s_element_wise, (f, array_type_name) + args)

  print >> f, "}} // namespace scitbx::af"
  print >> f
  print >> f, "#endif // DOXYGEN_SHOULD_SKIP_THIS"
  print >> f
  print >> f, "#endif // SCITBX_ARRAY_FAMILY_%s_ALGEBRA_H" % (
    array_type_name.upper(),)

  f.close()
Esempio n. 22
0
def one_type(target_dir, array_type_name):
    f = utils.join_open(target_dir, "%s_algebra.h" % array_type_name, "w")
    utils.write_this_is_auto_generated(f, this)
    include_array_type_name = array_type_name
    if (array_type_name == "ref"):
        include_array_type_name = "versa"
    generic_include = "functors"
    if (base_array_type_name(array_type_name) == "tiny"):
        generic_include = "operators"
    print("""\
#ifndef SCITBX_ARRAY_FAMILY_%s_ALGEBRA_H
#define SCITBX_ARRAY_FAMILY_%s_ALGEBRA_H

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#include <scitbx/array_family/%s.h>
""" % ((array_type_name.upper(), ) * 2 + (include_array_type_name, )),
          file=f)
    if (array_type_name == "small"):
        print("""#if (defined(BOOST_MSVC) && BOOST_MSVC <= 1300) // VC++ 7.0
#define SCITBX_ARRAY_FAMILY_SMALL_ALGEBRA_MIN_N1_N2 N1
#else
#define SCITBX_ARRAY_FAMILY_SMALL_ALGEBRA_MIN_N1_N2 (N1<N2?N1:N2)
#endif

""",
              file=f)
    print("""#include <scitbx/array_family/operator_traits_builtin.h>
#include <scitbx/array_family/detail/operator_functors.h>
#include <scitbx/array_family/detail/generic_array_%s.h>
#include <scitbx/array_family/detail/std_imports.h>
#include <scitbx/array_family/misc_functions.h>

namespace scitbx { namespace af {
""" % (generic_include, ),
          file=f)

    generate_unary_ops(f, array_type_name)
    for op_symbol in operator_functor_info.arithmetic_binary_ops:
        generate_elementwise_binary_op(f, array_type_name, "arithmetic",
                                       op_symbol)
        generate_elementwise_inplace_binary_op(f, array_type_name,
                                               "arithmetic", op_symbol + "=")
    for op_symbol in operator_functor_info.logical_binary_ops:
        generate_elementwise_binary_op(f, array_type_name, "logical",
                                       op_symbol)
    for op_symbol in operator_functor_info.boolean_binary_ops:
        generate_elementwise_binary_op(f, array_type_name, "boolean",
                                       op_symbol)
    generate_1arg_element_wise(
        f, array_type_name,
        misc_functions_a + generate_std_imports.cmath_1arg +
        generate_std_imports.cstdlib_1arg + generate_std_imports.complex_1arg)
    generate_2arg_element_wise(
        f, array_type_name, misc_functions_a_a +
        generate_std_imports.cmath_2arg + generate_std_imports.algorithm_2arg)
    for special_def in generate_std_imports.complex_special:
        generate_element_wise_special(f, array_type_name, special_def)
    for args in misc_functions_x_x_s:
        generate_x_x_s_element_wise(*(f, array_type_name) + args)

    print("}} // namespace scitbx::af", file=f)
    print(file=f)
    print("#endif // DOXYGEN_SHOULD_SKIP_THIS", file=f)
    print(file=f)
    print("#endif // SCITBX_ARRAY_FAMILY_%s_ALGEBRA_H" %
          (array_type_name.upper(), ),
          file=f)

    f.close()