Skip to content

Instantly share code, notes, and snippets.

@insertinterestingnamehere
Created June 11, 2015 05:43
Show Gist options
  • Save insertinterestingnamehere/21c77e40c10c4b79821b to your computer and use it in GitHub Desktop.
Save insertinterestingnamehere/21c77e40c10c4b79821b to your computer and use it in GitHub Desktop.
Namespace Separating script for dynd-python
beginning_rules = {'using namespace dynd;\n' : '',
'using namespace dynd::nd;\n\n' : '',
'using namespace dynd::ndt;\n\n' : '',
'using namespace pydynd;\n' : '',
' complex_float32_type_id,' : ' dynd::complex_float32_type_id,',
'complex_float64_type_id' : 'dynd::complex_float64_type_id',
'complex_float128_type_id' : 'dynd::complex_float128_type_id',
'nd::string' : 'dynd::nd::string',
'<complex_float32_type_id>' : '<dynd::complex_float32_type_id>',
' complex_float32_type_id:' : ' dynd::complex_float32_type_id:',}
rules = {'ndt::type' : 'dynd::ndt::type',
'type_id_t' : 'dynd::type_id_t',
'int8_type_id': 'dynd::int8_type_id',
'int16_type_id' : 'dynd::int16_type_id',
'int32_type_id' : 'dynd::int32_type_id',
'int64_type_id' : 'dynd::int64_type_id',
'dynd_int128' : 'dynd::dynd_int128',
'int128_type_id' : 'dynd::int128_type_id',
'nd::array ' : 'dynd::nd::array ',
'nd::array(' : 'dynd::nd::array(',
'ndt::substitute' : 'dynd::ndt::substitute',
'float16_type_id' : 'dynd::float16_type_id',
'dynd_float16' : 'dynd::dynd_float16',
'float32_type_id' : 'dynd::float32_type_id',
'float64_type_id' : 'dynd::float64_type_id',
'bool_type_id' : 'dynd::bool_type_id',
' base_kernel<' : ' dynd::nd::base_kernel<',
' kernel_request_host' : ' dynd::kernel_request_host',
'ndt::make_type' : 'dynd::ndt::make_type',
' declfunc<' : ' dynd::nd::declfunc<',
' arrfunc ' : ' dynd::nd::arrfunc ',
'nd::read_access_flag' : 'dynd::nd::read_access_flag',
'nd::write_access_flag' : 'dynd::nd::write_access_flag',
'kwds("dst", tmp_dst' : 'dynd::kwds("dst", tmp_dst',
' eval::eval_context ' : ' dynd::eval::eval_context ',
' &eval::default_eval_context': ' &dynd::eval::default_eval_context',
' arrfunc_type_data ' : ' dynd::arrfunc_type_data ',
' ndt::arrfunc_type ' : ' dynd::ndt::arrfunc_type ',
'<ndt::arrfunc_type>' : '<dynd::ndt::arrfunc_type>',
' kernel_request_t ' : ' dynd::kernel_request_t ',
'(make_array_memory_block(' : '(dynd::make_array_memory_block(',
' arrfunc_type_id' : ' dynd::arrfunc_type_id',
'ndt::make_arrfunc(' : 'dynd::ndt::make_arrfunc(',
'throw type_error(' : 'throw dynd::type_error(',
'(arrfunc_type_data ' : '(dynd::arrfunc_type_data ',
' base_virtual_kernel<' : ' dynd::nd::base_virtual_kernel<',
' fixed_dim_type_arrmeta ' : ' dynd::fixed_dim_type_arrmeta ',
' void_type_id)' : ' dynd::void_type_id)',
' make_assignment_kernel(' : ' dynd::make_assignment_kernel(',
' struct_kind ' : ' dynd::struct_kind ',
' struct_kind)' : ' dynd::struct_kind)',
'<ndt::base_struct_type>' : '<dynd::ndt::base_struct_type>',
' tuple_kind ' : ' dynd::tuple_kind ',
' tuple_kind)' : ' dynd::tuple_kind)',
'<ndt::base_tuple_type>' : '<dynd::ndt::base_tuple_type>',
'shortvector<' : 'dynd::shortvector<',
' functional::elwise' : ' dynd::nd::functional::elwise',
'arrfunc::make<' : 'dynd::nd::arrfunc::make<',
'const array &kwds,' : 'const dynd::nd::array &kwds,',
'<dynd_bool>' : '<dynd::dynd_bool>',
'(dynd_bool)' : '(dynd::dynd_bool)',
'(parse::overflow_check<' : '(dynd::parse::overflow_check<',
' ndt::make_bytes(' : ' dynd::ndt::make_bytes(',
' string_type_data ' : ' dynd::string_type_data ',
' string_type_arrmeta ' : ' dynd::string_type_arrmeta ',
'<fixed_bytes_type_id>' : '<dynd::fixed_bytes_type_id>',
'<bytes_type_id>' : '<dynd::bytes_type_id>',
'<string_type_id>' : '<dynd::string_type_id>',
' ndt::make_string(' : ' dynd::ndt::make_string(',
' typed_data_assign(' : ' dynd::typed_data_assign(',
'<fixed_string_type_id>' : '<dynd::fixed_string_type_id>',
' fixed_string_type_id:' : ' dynd::fixed_string_type_id:',
' fixed_string_type_id)' : ' dynd::fixed_string_type_id)',
'<date_type_id>' : '<dynd::date_type_id>',
' ndt::date_type ' : ' dynd::ndt::date_type ',
'<ndt::date_type>' : '<dynd::ndt::date_type>',
'<time_type_id>' : '<dynd::time_type_id>',
' ndt::time_type ' : ' dynd::ndt::time_type ',
'<ndt::time_type>' : '<dynd::ndt::time_type>',
' assign_error_fractional,' : ' dynd::assign_error_fractional,',
'<datetime_type_id>' : '<dynd::datetime_type_id>',
' ndt::datetime_type ' : ' dynd::ndt::datetime_type ',
'<ndt::datetime_type>' : '<dynd::ndt::datetime_type>',
'<type_type_id>' : '<dynd::type_type_id>',
'<option_type_id>' : '<dynd::option_type_id>',
'<ndt::option_type>' : '<dynd::ndt::option_type>',
' expr_single_t ' : ' dynd::expr_single_t ',
'<expr_single_t>' : '<dynd::expr_single_t>',
' string_kind ' : ' dynd::string_kind ',
' kernel_request_single,' : ' dynd::kernel_request_single,',
'<ckernel_builder' : '<dynd::ckernel_builder',
'<kernel_request_host>' : '<dynd::kernel_request_host>',
'categorical_type_id>' : 'dynd::categorical_type_id>',
'<ndt::categorical_type>' : '<dynd::ndt::categorical_type>',
' assign_error_default)' : ' dynd::assign_error_default)',
' expr_strided_t ' : ' dynd::expr_strided_t ',
'<expr_strided_t>' : '<dynd::expr_strided_t>',
'throw broadcast_error(' : 'throw dynd::broadcast_error(',
'<fixed_dim_type_id>' : '<dynd::fixed_dim_type_id>',
' kernel_request_strided,' : ' dynd::kernel_request_strided,',
'<var_dim_type_id>' : '<dynd::var_dim_type_id>',
' var_dim_type_data ' : ' dynd::var_dim_type_data ',
'<var_dim_type_data ' : '<dynd::var_dim_type_data ',
' var_dim_type_arrmeta ' : ' dynd::var_dim_type_arrmeta ',
'(var_dim_type_arrmeta)' : '(dynd::var_dim_type_arrmeta)',
'<ndt::var_dim_type>' : '<dynd::ndt::var_dim_type>',
'<tuple_type_id>' : '<dynd::tuple_type_id>',
' tuple_type_id,' : ' dynd::tuple_type_id,',
'<struct_type_id>' : '<dynd::struct_type_id>',
' struct_type_id,' : ' dynd::struct_type_id,',
' struct_type_id>' : ' dynd::struct_type_id>',
' struct_type_id:' : ' dynd::struct_type_id:',
' struct_type_id)' : ' dynd::struct_type_id)',
' print_escaped_utf8_string(' : ' dynd::print_escaped_utf8_string(',
' expr_kind)' : ' dynd::expr_kind)',
' type_id_sequence<' : ' dynd::type_id_sequence<',
' date_type_id,' : ' dynd::date_type_id,',
' time_type_id,' : ' dynd::time_type_id,',
' datetime_type_id,' : ' dynd::datetime_type_id,',
' type_type_id,' : ' dynd::type_type_id,',
' option_type_id,' : ' dynd::option_type_id,',
' bytes_type_id,' : ' dynd::bytes_type_id,',
' fixed_bytes_type_id,' : ' dynd::fixed_bytes_type_id,',
' fixed_bytes_type_id)' : ' dynd::fixed_bytes_type_id)',
' string_type_id,' : ' dynd::string_type_id,',
' fixed_string_type_id,' : ' dynd::fixed_string_type_id,',
' categorical_type_id,' : ' dynd::categorical_type_id,',
' fixed_dim_type_id,' : ' dynd::fixed_dim_type_id,',
' fixed_dim_type_id:' : ' dynd::fixed_dim_type_id:',
' var_dim_type_id,' : ' dynd::var_dim_type_id,',
' arrfunc::make_all' : ' dynd::nd::arrfunc::make_all',
' functional::multidispatch_by_type_id(' : ' dynd::nd::functional::multidispatch_by_type_id(',
'(string_encoding_ascii)' : '(dynd::string_encoding_ascii)',
' copy_to_numpy_arrmeta ' : ' pydynd::copy_to_numpy_arrmeta ',
' copy_to_numpy_ck::instantiate' : ' pydynd::copy_to_numpy_ck::instantiate',
'(fixed_dim_type_arrmeta)' : '(dynd::fixed_dim_type_arrmeta)',
'<fixed_dim_type_arrmeta *>' : '<dynd::fixed_dim_type_arrmeta *>',
'<char_type_id>' : '<dynd::char_type_id>',
' char_type_id,' : ' dynd::char_type_id,',
'<ndt::base_string_type>' : '<dynd::ndt::base_string_type>',
' date_ymd ' : ' dynd::date_ymd ',
' time_hmst ' : ' dynd::time_hmst ',
' type_type_data ' : ' dynd::type_type_data ',
'<pointer_type_id>' : '<dynd::pointer_type_id>',
' pointer_type_id,' : ' dynd::pointer_type_id,',
'<ndt::pointer_type>' : '<dynd::ndt::pointer_type>',
' bytes_type_data ' : ' dynd::bytes_type_data ',
'<ndt::fixed_bytes_type>' : '<dynd::ndt::fixed_bytes_type>',
' string_encoding_ascii:' : ' dynd::string_encoding_ascii:',
' string_encoding_ascii)' : ' dynd::string_encoding_ascii)',
' string_encoding_utf_8:' : ' dynd::string_encoding_utf_8:',
' string_encoding_utf_8)' : ' dynd::string_encoding_utf_8)',
' string_encoding_ucs_2:' : ' dynd::string_encoding_ucs_2:',
' string_encoding_ucs_2)' : ' dynd::string_encoding_ucs_2)',
' string_encoding_utf_16:' : ' dynd::string_encoding_utf_16:',
' string_encoding_utf_16)' : ' dynd::string_encoding_utf_16)',
' string_encoding_utf_32:' : ' dynd::string_encoding_utf_32:',
' string_encoding_utf_32)' : ' dynd::string_encoding_utf_32)',
'functional::chain(' : 'dynd::nd::functional::chain(',
'chain(copy,' : 'chain(dynd::nd::copy,',
' extract_fields_from_numpy_struct(' : ' pydynd::extract_fields_from_numpy_struct(',
'!offset_is_aligned(' : '!dynd::offset_is_aligned(',
'(ndt_type_from_numpy_dtype(' : '(pydynd::ndt_type_from_numpy_dtype(',
' ndt::make_fixed_string(' : ' dynd::ndt::make_fixed_string(',
' ndt::make_adapt(' : ' dynd::ndt::make_adapt(',
' ndt::make_date(' : ' dynd::ndt::make_date(',
' ndt::make_datetime(' : ' dynd::ndt::make_datetime(',
'(tz_utc)' : '(dynd::tz_utc)',
' uninitialized_type_id)' : ' dynd::uninitialized_type_id)',
' ndt::make_byteswap(' : ' dynd::ndt::make_byteswap(',
' ndt::struct_type' : ' dynd::ndt::struct_type',
'<ndt::struct_type>' : '<dynd::ndt::struct_type>',
'<ndt::fixed_dim_type>' : '<dynd::ndt::fixed_dim_type>',
' ndt::fixed_string_type ' : ' dynd::ndt::fixed_string_type ',
'<ndt::fixed_string_type>' : '<dynd::ndt::fixed_string_type>',
' view_type_id:' : ' dynd::view_type_id:',
' byteswap_type_id:' : ' dynd::byteswap_type_id:',
' string_type_data&' : ' dynd::string_type_data&',
' memory_block_ptr ' : ' dynd::memory_block_ptr ',
' make_external_memory_block(' : ' dynd::make_external_memory_block(',
' bool_kind:' : ' dynd::bool_kind:',
' sint_kind:' : ' dynd::sint_kind:',
' uint_kind:' : ' dynd::uint_kind:',
' real_kind:' : ' dynd::real_kind:',
' complex_kind:' : ' dynd::complex_kind:',
' string_kind:' : ' dynd::string_kind:',
' ndt::base_string_type' : ' dynd::ndt::base_string_type',
'(ndt::make_tuple(' : '(dynd::ndt::make_tuple(',
'(WArray ' : '(pydynd::WArray ',
'(WType ' : '(pydynd::WType ',
' make_ndt_type_from_pyobject(' : ' pydynd::make_ndt_type_from_pyobject(',
' pyobject_as_size_t(' : ' pydynd::pyobject_as_size_t(',
' pyarg_strings_to_int(' : ' pydynd::pyarg_strings_to_int(',
'(type_flag_destructor)' : '(dynd::type_flag_destructor)',
'&py_decref_function)' : '&pydynd::py_decref_function)',
' wrap_array(' : ' pydynd::wrap_array(',
' translate_exception(' : ' pydynd::translate_exception(',
' ckernel_builder<' : ' dynd::ckernel_builder<',
' pystring_as_string(' : ' pydynd::pystring_as_string(',
' kernel_request_single;' : ' dynd::kernel_request_single;',
' kernel_request_strided;' : ' dynd::kernel_request_strided;',
' eval_context_from_pyobj(' : ' pydynd::eval_context_from_pyobj(',
' assign_error_mode ' : ' dynd::assign_error_mode ',
' pyarg_error_mode(' : ' pydynd::pyarg_error_mode(',
' arrfunc>' : ' dynd::nd::arrfunc>',
' ::make_arrfunc_from_assignment(' : ' dynd::make_arrfunc_from_assignment(',
'!WArray_Check(' : '!pydynd::WArray_Check(',
' pyobject_as_vector_intp(' : ' pydynd::pyobject_as_vector_intp(',
'throw axis_out_of_bounds(' : 'throw dynd::axis_out_of_bounds(',
' ::lift_reduction_arrfunc(' : ' dynd::lift_reduction_arrfunc(',
'!WArrFunc_Check(' : '!pydynd::WArrFunc_Check(',
' pyobject_as_index(' : ' pydynd::pyobject_as_index(',
' kernels::make_builtin_mean1d_arrfunc(' : ' dynd::kernels::make_builtin_mean1d_arrfunc(',
' py_lowlevel_api_t' : ' pydynd::py_lowlevel_api_t',
' ::make_arrfunc_from_property(' : ' dynd::make_arrfunc_from_property(',
'(WArray_Check(' : '(pydynd::WArray_Check(',
'(WArrFunc ' : '(pydynd::WArrFunc ',
}
ending_rules = {'udynd::int8_type_id' : 'dynd::uint8_type_id',
'udynd::int16_type_id' : 'dynd::uint16_type_id',
'udynd::int32_type_id' : 'dynd::uint32_type_id',
'udynd::int64_type_id' : 'dynd::uint64_type_id',
'dynd_uint128' : 'dynd::dynd_uint128',
'udynd::int128_type_id' :'dynd::uint128_type_id',
'complex_dynd::' : 'complex_'}
more_ending_rules = {'dynd::dynd::' : 'dynd::',
'dynd::nd::dynd::nd::' : 'dynd::nd::',
'dynd::ndt::dynd::ndt::' : 'dynd::ndt::'}
files = ['dynd/include/config.hpp',
'src/array_as_py.cpp',
'dynd/include/copy_to_pyobject_arrfunc.hpp',
'src/array_assign_from_py.cpp',
'dynd/include/copy_from_pyobject_arrfunc.hpp',
'src/arrfunc_from_pyfunc.cpp',
'dynd/kernels/apply_pyobject_kernel.hpp',
'src/arrfunc_from_pyfunc.cpp',
'src/copy_from_numpy_arrfunc.cpp',
'dynd/include/copy_from_numpy_arrfunc.hpp',
'dynd/kernels/copy_from_numpy_kernel.hpp',
'dynd/kernels/copy_from_pyobject_kernel.hpp',
'src/copy_from_pyobject_arrfunc.cpp',
'src/copy_to_numpy_arrfunc.cpp',
'dynd/kernels/copy_to_pyobject_kernel.hpp',
'src/copy_to_pyobject_arrfunc.cpp',
'src/numpy_interop.cpp',
'dynd/kernels/numpy_ufunc.hpp',
'src/numpy_ufunc_kernel.cpp',
'src/py_lowlevel_api.cpp']
if __name__ == '__main__':
for filename in files:
with open(filename, 'r') as f:
stuff = f.read()
for d in [beginning_rules, rules, ending_rules, more_ending_rules]:
for before, after in d.iteritems():
stuff = stuff.replace(before, after)
with open(filename, 'w') as f:
f.write(stuff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment