Files
Flux/include/numerics/clip.h
T
Bausager 9709949a5b
Sync public mirror / sync (push) Failing after 27s
Refactor progress
Next step is ramdom and equal. I also need to have a look at add and the serial naming of the functions.
2026-01-13 20:07:27 +01:00

128 lines
3.5 KiB
C++

#pragma once
#include "./core/omp_config.h"
#include "detail/clip_serial.h"
namespace numerics{
//---------------------------------------------
// ----------------- Clip ---------------
//---------------------------------------------
// ---------------- Elementwise ----------------
template <typename T>
inline void inplace_clip(T& c, const T low, const T high) {
detail::inplace_clip_scalar_serial(c, low, high);
}
template <typename T>
inline T clip(const T c, const T low, const T high) {
T out = c;
inplace_clip(out, low, high);
return out;
}
template <typename T>
inline void inplace_clip(utils::Matrix<T>& A, const T low, const T high) {
detail::inplace_clip_elementwise_serial(A, low, high);
}
template <typename T>
inline utils::Matrix<T> clip(const utils::Matrix<T>& A, const T low, const T high) {
utils::Matrix<T> out = A;
inplace_clip(out, low, high);
return out;
}
template <typename T>
inline void inplace_clip(utils::Vector<T>& v, const T low, const T high) {
detail::inplace_clip_elementwise_serial(v, low, high);
}
template <typename T>
inline utils::Vector<T> clip(const utils::Vector<T>& v, const T low, const T high) {
utils::Vector<T> out = v;
inplace_clip(out, low, high);
return out;
}
//---------------------------------------------
// ----------------- Clip Low ---------------
//---------------------------------------------
// ---------------- Elementwise ----------------
template <typename T>
inline void inplace_clip_low(T& c, const T low) {
detail::inplace_clip_low_scalar_serial(c, low);
}
template <typename T>
inline T clip_low(const T c, const T low) {
T out = c;
inplace_clip_low(out, low);
return out;
}
template <typename T>
inline void inplace_clip_low(utils::Matrix<T>& A, const T low) {
detail::inplace_clip_low_elementwise_serial(A, low);
}
template <typename T>
inline utils::Matrix<T> clip_low(const utils::Matrix<T>& A, const T low) {
utils::Matrix<T> out = A;
inplace_clip_low(out, low);
return out;
}
template <typename T>
inline void inplace_clip_low(utils::Vector<T>& v, const T low) {
detail::inplace_clip_low_elementwise_serial(v, low);
}
template <typename T>
inline utils::Vector<T> clip_low(const utils::Vector<T>& v, const T low) {
utils::Vector<T> out = v;
inplace_clip_low(out, low);
return out;
}
//---------------------------------------------
// ----------------- Clip High ---------------
//---------------------------------------------
// ---------------- Elementwise ----------------
template <typename T>
inline void inplace_clip_high(T& c, const T high) {
detail::inplace_clip_high_scalar_serial(c, high);
}
template <typename T>
inline T clip_high(const T c, const T high) {
T out = c;
inplace_clip_high(out, high);
return out;
}
template <typename T>
inline void inplace_clip_high(utils::Matrix<T>& A, const T high) {
detail::inplace_clip_high_elementwise_serial(A, high);
}
template <typename T>
inline utils::Matrix<T> clip_high(const utils::Matrix<T>& A, const T high) {
utils::Matrix<T> out = A;
inplace_clip_high(out, high);
return out;
}
template <typename T>
inline void inplace_clip_high(utils::Vector<T>& v, const T high) {
detail::inplace_clip_high_elementwise_serial(v, high);
}
template <typename T>
inline utils::Vector<T> clip_high(const utils::Vector<T>& v, const T high) {
utils::Vector<T> out = v;
inplace_clip_high(out, high);
return out;
}
}