// // Copyright (C) 2011-15 DyND Developers // BSD 2-Clause License, see LICENSE.txt // #include #include #include #include namespace dynd { namespace nd { template class KernelType> struct comparison_operator : declfunc { static decltype(auto) make_children() { typedef type_id_sequence numeric_ids; auto children = callable::make_all(); callable self = functional::call(ndt::type("(Any, Any) -> Any")); for (type_id_t i0 : i2a()) { for (type_id_t i1 : i2a()) { const ndt::type child_tp = ndt::callable_type::make(ndt::type("Any"), {ndt::type(i0), ndt::type(i1)}); children[{{i0, i1}}] = functional::elwise(child_tp, self); } } for (type_id_t i : i2a()) { children[{{option_id, i}}] = functional::forward_na<0>(self); children[{{i, option_id}}] = functional::forward_na<1>(self); } children[{{option_id, option_id}}] = callable::make>(); for (type_id_t dim_tp_id : i2a()) { children[{{dim_tp_id, option_id}}] = functional::elwise(self); children[{{option_id, dim_tp_id}}] = functional::elwise(self); } for (type_id_t i0 : i2a()) { typedef join::type type_ids; for (type_id_t i1 : i2a()) { const ndt::type child_tp = ndt::callable_type::make(ndt::type("Any"), {ndt::type(i0), ndt::type(i1)}); children[{{i0, i1}}] = functional::elwise(child_tp, self); } } children[{{string_id, string_id}}] = callable::make>(); return children; } static callable make() { auto children = FuncType::make_children(); return functional::dispatch(ndt::type("(Any, Any) -> Any"), [children](const ndt::type &DYND_UNUSED(dst_tp), intptr_t DYND_UNUSED(nsrc), const ndt::type *src_tp) mutable -> callable & { callable &child = children[{{src_tp[0].get_id(), src_tp[1].get_id()}}]; if (child.is_null()) { throw std::runtime_error("no child found"); } return child; }); } }; extern DYND_API struct DYND_API less : comparison_operator { static callable &get(); } less; extern DYND_API struct DYND_API less_equal : comparison_operator { static callable &get(); } less_equal; extern DYND_API struct DYND_API equal : comparison_operator { static std::map, callable> make_children() { std::map, callable> children = comparison_operator::make_children(); children[{{complex_float32_id, complex_float32_id}}] = callable::make>(); children[{{complex_float64_id, complex_float64_id}}] = callable::make>(); children[{{tuple_id, tuple_id}}] = callable::make>(); children[{{struct_id, struct_id}}] = callable::make>(); children[{{type_id, type_id}}] = callable::make>(); children[{{bytes_id, bytes_id}}] = callable::make>(); return children; } static callable &get(); } equal; extern DYND_API struct DYND_API not_equal : comparison_operator { static std::map, callable> make_children() { std::map, callable> children = comparison_operator::make_children(); children[{{complex_float32_id, complex_float32_id}}] = callable::make>(); children[{{complex_float64_id, complex_float64_id}}] = callable::make>(); children[{{tuple_id, tuple_id}}] = callable::make>(); children[{{struct_id, struct_id}}] = callable::make>(); children[{{type_id, type_id}}] = callable::make>(); children[{{bytes_id, bytes_id}}] = callable::make>(); return children; } static callable &get(); } not_equal; extern DYND_API struct DYND_API greater_equal : comparison_operator { static callable &get(); } greater_equal; extern DYND_API struct DYND_API greater : comparison_operator { static callable &get(); } greater; extern DYND_API struct DYND_API total_order : declfunc { static callable make(); static callable &get(); } total_order; } // namespace dynd::nd } // namespace dynd