feat(math): operation fundamentals

This commit is contained in:
2026-10-29 10:01:26 +01:00
parent 1f95dd51db
commit 0734de1386
4 changed files with 233 additions and 5 deletions
+56
View File
@@ -0,0 +1,56 @@
#ifndef CENET_MATH_OPS_HPP
#define CENET_MATH_OPS_HPP
#include "tensor_traits.hpp"
#include <cstddef>
namespace cenet {
namespace math {
namespace ops {
class plus {
private:
template <typename L, typename R>
struct result_type_impl {};
template <typename LT, typename RT, std::size_t... Dims>
struct result_type_impl<tensor_view<LT, Dims...>, tensor_view<RT, Dims...>> {
using type =
tensor<decltype(std::declval<detach_storage_t<LT>>() + std::declval<detach_storage_t<RT>>()), Dims...>;
};
public:
template <typename L, typename R>
using result_type = typename result_type_impl<L, R>::type;
template <typename LT, typename R>
constexpr auto operator()(std::size_t index, LT lhs, const R& rhs) const {
return lhs + rhs.coeff(index);
}
};
class minus {
private:
template <typename L, typename R>
struct result_type_impl {};
template <typename LT, typename RT, std::size_t... Dims>
struct result_type_impl<tensor_view<LT, Dims...>, tensor_view<RT, Dims...>> {
using type =
tensor<decltype(std::declval<detach_storage_t<LT>>() - std::declval<detach_storage_t<RT>>()), Dims...>;
};
public:
template <typename L, typename R>
using result_type = typename result_type_impl<L, R>::type;
template <typename LT, typename R>
constexpr auto operator()(std::size_t index, LT lhs, const R& rhs) const {
return lhs - rhs.coeff(index);
}
};
} // namespace ops
} // namespace math
} // namespace cenet
#endif // CENET_MATH_OPS_HPP