Beispiel #1
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()
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()
Beispiel #3
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 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()
Beispiel #5
0
def print_header(f):
    write_this_is_auto_generated(f, this)
    print("""\
#include <cctbx/eltbx/henke.h>

namespace cctbx { namespace eltbx { namespace henke {
""",
          file=f)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
0
def print_header(f):
  write_this_is_auto_generated(f, this)
  print("""\
#include <cctbx/eltbx/sasaki.h>
#include <scitbx/constants.h>

namespace cctbx { namespace eltbx { namespace sasaki {

namespace table_data {

using namespace detail;
""", file=f)
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()
Beispiel #11
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()
def print_header(f):
    write_this_is_auto_generated(f, this)
    print >> f, """\
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()
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()
def print_header(f):
  write_this_is_auto_generated(f, this)
  print >> f, """\