feat(math): operation fundamentals
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user