26namespace stratax::core::math_detail {
34template<Array A, DType Result,
typename Op>
40 result_type result(arr.shape());
42 for (std::size_t i = 0; i < arr.size(); ++i)
44 result[i] =
static_cast<Result
>(op(arr[i]));
55 using type = std::remove_cvref_t<T>;
77template<Array A,
typename Op>
80 using result_value_type =
83 return unary_op<A, result_value_type>(arr, op);
87template<
typename L,
typename R>
93 std::remove_cvref_t<L>,
94 std::remove_cvref_t<R>>;
97 using type = std::conditional_t<
104template<
typename L,
typename R>
113 using type = std::remove_cvref_t<T>;
136namespace stratax::core {
143 return math_detail::standard_math_op(
144 arr, [](
const auto& value)
146 return std::sqrt(value);
155 return math_detail::standard_math_op(
156 arr, [](
const auto& value)
158 return std::cbrt(value);
167 return math_detail::standard_math_op(
168 arr, [](
const auto& value)
170 return std::exp(value);
179 return math_detail::standard_math_op(
180 arr, [](
const auto& value)
182 return std::exp2(value);
191 return math_detail::standard_math_op(
192 arr, [](
const auto& value)
194 return std::expm1(value);
203 return math_detail::standard_math_op(
204 arr, [](
const auto& value)
206 return std::log(value);
215 return math_detail::standard_math_op(
216 arr, [](
const auto& value)
218 return std::log2(value);
227 return math_detail::standard_math_op(
228 arr, [](
const auto& value)
230 return std::log10(value);
239 return math_detail::standard_math_op(
240 arr, [](
const auto& value)
242 return std::log1p(value);
251 return math_detail::standard_math_op(
252 arr, [](
const auto& value)
254 return std::logb(value);
263 return math_detail::standard_math_op(
264 arr, [](
const auto& value)
266 return std::sin(value);
275 return math_detail::standard_math_op(
276 arr, [](
const auto& value)
278 return std::cos(value);
287 return math_detail::standard_math_op(
288 arr, [](
const auto& value)
290 return std::tan(value);
299 return math_detail::standard_math_op(
300 arr, [](
const auto& value)
302 return std::asin(value);
311 return math_detail::standard_math_op(
312 arr, [](
const auto& value)
314 return std::acos(value);
323 return math_detail::standard_math_op(
324 arr, [](
const auto& value)
326 return std::atan(value);
335 return math_detail::standard_math_op(
336 arr, [](
const auto& value)
338 return std::sinh(value);
347 return math_detail::standard_math_op(
348 arr, [](
const auto& value)
350 return std::cosh(value);
359 return math_detail::standard_math_op(
360 arr, [](
const auto& value)
362 return std::tanh(value);
371 return math_detail::standard_math_op(
372 arr, [](
const auto& value)
374 return std::asinh(value);
383 return math_detail::standard_math_op(
384 arr, [](
const auto& value)
386 return std::acosh(value);
395 return math_detail::standard_math_op(
396 arr, [](
const auto& value)
398 return std::atanh(value);
407 return math_detail::standard_math_op(
408 arr, [](
const auto& value)
410 return std::erf(value);
419 return math_detail::standard_math_op(
420 arr, [](
const auto& value)
422 return std::erfc(value);
431 return math_detail::standard_math_op(
432 arr, [](
const auto& value)
434 return std::tgamma(value);
443 return math_detail::standard_math_op(
444 arr, [](
const auto& value)
446 return std::lgamma(value);
461 using result_value_type =
464 return math_detail::unary_op<A, result_value_type>(
466 [](
const auto& value)
478 using result_value_type =
typename A::value_type;
480 return math_detail::unary_op<A, result_value_type>(
482 [](
const auto& value)
484 return std::floor(value);
493 using result_value_type =
typename A::value_type;
495 return math_detail::unary_op<A, result_value_type>(
497 [](
const auto& value)
499 return std::ceil(value);
508 using result_value_type =
typename A::value_type;
510 return math_detail::unary_op<A, result_value_type>(
512 [](
const auto& value)
514 return std::trunc(value);
523 using result_value_type =
typename A::value_type;
525 return math_detail::unary_op<A, result_value_type>(
527 [](
const auto& value)
529 return std::round(value);
538 using result_value_type =
typename A::value_type;
540 return math_detail::unary_op<A, result_value_type>(
542 [](
const auto& value)
544 return std::nearbyint(value);
553 using result_value_type =
typename A::value_type;
555 return math_detail::unary_op<A, result_value_type>(
557 [](
const auto& value)
559 return std::rint(value);
569template<Array L, Array R>
570auto pow(
const L& lhs,
const R& rhs)
574 typename L::value_type,
575 typename R::value_type>;
577 return broadcasted_op<result_type>(
580 [](
const auto& a,
const auto& b)
582 return std::pow(a, b);
592template<Array L, Array R>
593auto atan2(
const L& lhs,
const R& rhs)
597 typename L::value_type,
598 typename R::value_type>;
600 return broadcasted_op<result_type>(
603 [](
const auto& a,
const auto& b)
605 return std::atan2(a, b);
610template<Array L, Array R>
611auto hypot(
const L& lhs,
const R& rhs)
615 typename L::value_type,
616 typename R::value_type>;
618 return broadcasted_op<result_type>(
621 [](
const auto& a,
const auto& b)
623 return std::hypot(a, b);
628template<Array L, Array R>
629auto fmod(
const L& lhs,
const R& rhs)
633 typename L::value_type,
634 typename R::value_type>;
636 return broadcasted_op<result_type>(
639 [](
const auto& a,
const auto& b)
641 return std::fmod(a, b);
646template<Array L, Array R>
651 typename L::value_type,
652 typename R::value_type>;
654 return broadcasted_op<result_type>(
657 [](
const auto& a,
const auto& b)
659 return std::remainder(a, b);
664template<Array L, Array R>
669 typename L::value_type,
670 typename R::value_type>;
672 return broadcasted_op<result_type>(
675 [](
const auto& a,
const auto& b)
677 return std::copysign(a, b);
682template<Array L, Array R>
683auto fmax(
const L& lhs,
const R& rhs)
687 typename L::value_type,
688 typename R::value_type>;
690 return broadcasted_op<result_type>(
693 [](
const auto& a,
const auto& b)
695 return std::fmax(a, b);
700template<Array L, Array R>
701auto fmin(
const L& lhs,
const R& rhs)
705 typename L::value_type,
706 typename R::value_type>;
708 return broadcasted_op<result_type>(
711 [](
const auto& a,
const auto& b)
713 return std::fmin(a, b);
718template<Array L, Array R>
723auto fdim(
const L& lhs,
const R& rhs)
727 typename L::value_type,
728 typename R::value_type>;
730 return broadcasted_op<result_type>(
733 [](
const auto& a,
const auto& b)
735 return std::fdim(a, b);
740template<Array L, Array R>
749 typename L::value_type,
750 typename R::value_type>;
752 return broadcasted_op<result_type>(
755 [](
const auto& a,
const auto& b)
757 return std::nextafter(a, b);
Result-container rebinding and promotion for owning arrays.
typename RebindArray< std::remove_cvref_t< A >, std::remove_cvref_t< T > >::type rebind_array_t
Convenience alias for rebinding an array to a new value type.
Trailing-axis shape compatibility and element projection.
Dtype and array interface concepts.
typename ComplexComponent< std::remove_cvref_t< T > >::type complex_component_t
Underlying real dtype of a complex dtype.
auto trunc(const A &arr)
Rounds each element toward zero.
auto hypot(const L &lhs, const R &rhs)
Computes element-wise hypotenuses after broadcasting.
auto pow(const L &lhs, const R &rhs)
Raises each broadcasted left element to its corresponding right power.
auto remainder(const L &lhs, const R &rhs)
Computes element-wise IEEE remainders after broadcasting.
auto asin(const A &arr)
Computes the element-wise inverse sine.
auto log10(const A &arr)
Computes the element-wise base-10 logarithm.
auto rint(const A &arr)
Rounds each element using the current floating-point rounding mode.
auto acos(const A &arr)
Computes the element-wise inverse cosine.
auto cosh(const A &arr)
Computes the element-wise hyperbolic cosine.
auto sin(const A &arr)
Computes the element-wise sine in radians.
auto erfc(const A &arr)
Computes the element-wise complementary error function.
typename AbsResult< std::remove_cvref_t< T > >::type abs_result_t
Absolute-value result dtype, using the real component for complex inputs.
auto cbrt(const A &arr)
Computes the element-wise real cube root.
auto sinh(const A &arr)
Computes the element-wise hyperbolic sine.
auto fmin(const L &lhs, const R &rhs)
Selects the element-wise floating-point minimum after broadcasting.
auto fdim(const L &lhs, const R &rhs)
Computes the positive difference of each broadcasted element pair.
auto round(const A &arr)
Rounds each element to the nearest integer value, with halfway cases away from zero.
auto sqrt(const A &arr)
Computes the element-wise principal square root.
auto abs(const A &arr)
Computes the absolute value or complex magnitude of each element.
auto copysign(const L &lhs, const R &rhs)
Copies each broadcasted right sign onto the corresponding left magnitude.
auto atanh(const A &arr)
Computes the element-wise inverse hyperbolic tangent.
auto log(const A &arr)
Computes the element-wise natural logarithm.
auto standard_math_op(const A &arr, Op op)
Applies a unary math callable using the standard result dtype.
auto cos(const A &arr)
Computes the element-wise cosine in radians.
auto log1p(const A &arr)
Computes the natural logarithm of one plus each element.
auto erf(const A &arr)
Computes the element-wise error function.
auto atan(const A &arr)
Computes the element-wise inverse tangent.
typename PowResult< L, R >::type pow_result_t
Binary math result dtype: promoted dtype, with integral results changed to float64.
auto nearbyint(const A &arr)
Rounds each element using the current rounding mode without raising inexact.
auto lgamma(const A &arr)
Computes the logarithm of the absolute gamma function element-wise.
auto exp2(const A &arr)
Computes 2 raised to each element.
auto expm1(const A &arr)
Computes e raised to each element minus one.
auto fmod(const L &lhs, const R &rhs)
Computes element-wise floating-point remainders after broadcasting.
auto tan(const A &arr)
Computes the element-wise tangent in radians.
auto fmax(const L &lhs, const R &rhs)
Selects the element-wise floating-point maximum after broadcasting.
auto atan2(const L &lhs, const R &rhs)
Computes the two-argument arctangent of each broadcasted element pair.
auto tanh(const A &arr)
Computes the element-wise hyperbolic tangent.
auto unary_op(const A &arr, Op op)
Applies a unary callable to every element of an array.
auto exp(const A &arr)
Computes e raised to each element.
auto tgamma(const A &arr)
Computes the element-wise gamma function.
auto logb(const A &arr)
Extracts the unbiased floating-point exponent of each element.
typename MathResult< std::remove_cvref_t< T > >::type math_result_t
Unary math result dtype: float64 for integers, otherwise the input dtype.
auto acosh(const A &arr)
Computes the element-wise inverse hyperbolic cosine.
auto nextafter(const L &lhs, const R &rhs)
Finds the next representable value from each left element toward its broadcasted right element.
auto floor(const A &arr)
Rounds each element downward.
auto log2(const A &arr)
Computes the element-wise base-2 logarithm.
auto ceil(const A &arr)
Rounds each element upward.
auto asinh(const A &arr)
Computes the element-wise inverse hyperbolic sine.
Supported scalar dtype aliases.
double float64
Native double dtype.
Supported integer dtype, excluding bool.
Supported integer, floating-point, or complex dtype, excluding bool.
Supported integer or standard floating-point type, excluding bool and complex.
Provides compile-time metadata for a supported Stratax dtype.
complex_component_t< std::remove_cvref_t< T > > type
Real magnitude dtype corresponding to the complex input.
Preserves the dtype of a real absolute-value operation.
std::remove_cvref_t< T > type
Absolute-value result dtype.
dtype::float64 type
Floating-point result dtype used for integral input.
Maps a non-integral input dtype to the same result dtype.
std::remove_cvref_t< T > type
Result dtype for a standard unary math operation.
Determines the common result dtype for a binary math operation.
promote_t< std::remove_cvref_t< L >, std::remove_cvref_t< R > > promoted_type
Dtype obtained from the ordinary Stratax promotion rules.
std::conditional_t< Integral< promoted_type >, dtype::float64, promoted_type > type
Promoted dtype, with integral-only results changed to float64.