Skip to content

Commit d6ba211

Browse files
committed
custom is_arithmetic
1 parent 3863d94 commit d6ba211

6 files changed

Lines changed: 16 additions & 10 deletions

File tree

include/Peanut/impl/binary_expr/matrix_div_scalar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace Peanut::Impl {
4141
* @tparam T Right hand side scalar type.
4242
*/
4343
template<typename E, typename T>
44-
requires is_matrix_v<E> && std::is_arithmetic_v<T>
44+
requires is_matrix_v<E> && is_arithmetic<T>
4545
struct MatrixDivScalar : public MatrixExpr<MatrixDivScalar<E, T>> {
4646
using Type = Float;
4747
MatrixDivScalar(const E &x, T y) : x{x}, y{y} {
@@ -80,7 +80,7 @@ namespace Peanut {
8080
* @return Constructed `Impl::MatrixDivScalar` instance
8181
*/
8282
template<typename E, typename T>
83-
requires is_matrix_v<E> && std::is_arithmetic_v<T>
83+
requires is_matrix_v<E> && is_arithmetic<T>
8484
Impl::MatrixDivScalar<E, T> operator/(const MatrixExpr<E> &x, const T &y) {
8585
return Impl::MatrixDivScalar<E, T>(static_cast<const E &>(x), y);
8686
}

include/Peanut/impl/binary_expr/matrix_mult_scalar.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace Peanut::Impl {
3939
* @tparam T Scalar type operand.
4040
*/
4141
template<typename E, typename T>
42-
requires is_matrix_v<E> && std::is_arithmetic_v<T>
42+
requires is_matrix_v<E> && is_arithmetic<T>
4343
struct MatrixMultScalar : public MatrixExpr<MatrixMultScalar<E, T>> {
4444
using Type = typename std::conditional<
4545
std::is_floating_point_v<typename E::Type> || std::is_floating_point_v<T>,
@@ -76,7 +76,7 @@ namespace Peanut {
7676
* @return Constructed `Impl::MatrixMultScalar` instance
7777
*/
7878
template<typename E, typename T>
79-
requires is_matrix_v<E> && std::is_arithmetic_v<T>
79+
requires is_matrix_v<E> && is_arithmetic<T>
8080
Impl::MatrixMultScalar<E, T> operator*(const MatrixExpr<E> &x, const T &y) {
8181
return Impl::MatrixMultScalar<E, T>(static_cast<const E &>(x), y);
8282
}
@@ -88,7 +88,7 @@ namespace Peanut {
8888
* @return Constructed `Impl::MatrixMultScalar` instance
8989
*/
9090
template<typename E, typename T>
91-
requires is_matrix_v<E> && std::is_arithmetic_v<T>
91+
requires is_matrix_v<E> && is_arithmetic<T>
9292
Impl::MatrixMultScalar<E, T> operator*(const T x, const MatrixExpr<E> &y) {
9393
return Impl::MatrixMultScalar<E, T>(static_cast<const E &>(y), x);
9494
}

include/Peanut/impl/common.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626

2727
// Standard headers
2828
#include <cmath>
29+
#include <iostream>
2930
#include <limits>
3031
#include <utility>
31-
#include <iostream>
3232

3333
// Peanut headers
34+
#include <Peanut/impl/matrix_type_traits.h>
3435

3536
// Dependencies headers
3637

@@ -52,7 +53,7 @@ namespace Peanut {
5253
* If \p T is not a floating point type, returns true if \p val is zero, false if not.
5354
*/
5455
template<typename T>
55-
bool is_zero(T val) requires std::is_arithmetic_v<T>{
56+
bool is_zero(T val) requires is_arithmetic<T>{
5657
if constexpr (std::is_floating_point_v<T>){
5758
return std::fabs(val-static_cast<T>(0)) <= std::numeric_limits<T>::epsilon() ||
5859
std::fabs(val-static_cast<T>(0)) < std::numeric_limits<T>::min();

include/Peanut/impl/matrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace Peanut {
7777
* @tparam R Row size.
7878
* @tparam C Column size.
7979
*/
80-
template<typename T, Index R, Index C> requires std::is_arithmetic_v<T> && (R > 0) && (C > 0)
80+
template<typename T, Index R, Index C> requires is_arithmetic<T> && (R > 0) && (C > 0)
8181
struct Matrix : public MatrixExpr<Matrix<T, R, C>>{
8282

8383
/**

include/Peanut/impl/matrix_type_traits.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,9 @@ namespace Peanut {
137137
*/
138138
template <typename E1, typename E2>
139139
constexpr bool is_equal_type_size_v = is_equal_type_size<E1, E2>::value;
140+
141+
// =========================================================================
142+
143+
template<typename T>
144+
concept is_arithmetic = std::is_arithmetic_v<T>; // || simd || gpu || etc
140145
}

include/Peanut/impl/unary_expr/cast.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace Peanut::Impl {
3838
* @tparam E Matrix expression type.
3939
*/
4040
template<typename T, typename E>
41-
requires std::is_arithmetic_v<T> && is_matrix_v<E>
41+
requires is_arithmetic<T> && is_matrix_v<E>
4242
struct MatrixCastType : public MatrixExpr<MatrixCastType<T, E>> {
4343
using Type = T;
4444
MatrixCastType(const E &x) : x{x} {}
@@ -77,7 +77,7 @@ namespace Peanut {
7777
*
7878
*/
7979
template<typename T, typename E>
80-
requires std::is_arithmetic_v<T> && is_matrix_v<E>
80+
requires is_arithmetic<T> && is_matrix_v<E>
8181
Impl::MatrixCastType<T, E> Cast(const MatrixExpr<E> &x) {
8282
return Impl::MatrixCastType<T, E>(static_cast<const E &>(x));
8383
}

0 commit comments

Comments
 (0)