Skip to content

Commit

Permalink
Possible bug fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
Pencilcaseman committed Aug 2, 2023
1 parent 056558e commit 160003c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion librapid/include/librapid/librapid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include "core/core.hpp"
#include "utils/utils.hpp"
#include "math/math.hpp"
#include "simd/simd.hpp"
#include "math/math.hpp"
#include "array/array.hpp"
#include "autodiff/autodiff.hpp"
#include "core/literals.hpp"
Expand Down
43 changes: 23 additions & 20 deletions librapid/include/librapid/simd/vecOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ namespace librapid {
template<typename T>
struct IsVector : std::false_type {};

template<typename T>
struct IsVector<Vc::Vector<T>> : std::true_type {};
// template<typename T>
// struct IsVector<Vc::Vector<T>> : std::true_type {};

template<typename T, typename U>
struct IsVector<Vc_1::Vector<T, U>> : std::true_type {};
} // namespace typetraits

#define REQUIRE_VECTOR(TYPE) typename std::enable_if_t<typetraits::IsVector<TYPE>::value, int> = 0
#define IF_FLOATING(TYPE) if constexpr (std::is_floating_point_v<typename TYPE::value_type>)

template<typename T, REQUIRE_VECTOR(T)>
T sin(const T &x) {
auto sin(const T &x) -> T {
IF_FLOATING(T) { return Vc::sin(x); }
else {
T result;
Expand All @@ -24,7 +27,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T cos(const T &x) {
auto cos(const T &x) -> T {
IF_FLOATING(T) { return Vc::cos(x); }
else {
T result;
Expand All @@ -34,7 +37,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T tan(const T &x) {
auto tan(const T &x) -> T {
IF_FLOATING(T) { return Vc::sin(x) / Vc::cos(x); }
else {
T result;
Expand All @@ -44,7 +47,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T asin(const T &x) {
auto asin(const T &x) -> T {
IF_FLOATING(T) { return Vc::asin(x); }
else {
T result;
Expand All @@ -54,7 +57,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T acos(const T &x) {
auto acos(const T &x) -> T {
IF_FLOATING(T) {
static const auto asin1 = Vc::asin(T(1));
return asin1 - Vc::asin(x);
Expand All @@ -67,7 +70,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T atan(const T &x) {
auto atan(const T &x) -> T {
IF_FLOATING(T) { return Vc::atan(x); }
else {
T result;
Expand All @@ -77,7 +80,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T sinh(const T &x) {
auto sinh(const T &x) -> T {
IF_FLOATING(T) { return (Vc::exp(x) - Vc::exp(-x)) * T(0.5); }
else {
T result;
Expand All @@ -87,7 +90,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T cosh(const T &x) {
auto cosh(const T &x) -> T {
IF_FLOATING(T) { return (Vc::exp(x) + Vc::exp(-x)) * T(0.5); }
else {
T result;
Expand All @@ -97,7 +100,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T tanh(const T &x) {
auto tanh(const T &x) -> T {
IF_FLOATING(T) { return (Vc::exp(2 * x) - 1) / (Vc::exp(2 * x) + 1); }
else {
T result;
Expand All @@ -107,7 +110,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T exp(const T &x) {
auto exp(const T &x) -> T {
IF_FLOATING(T) { return Vc::exp(x); }
else {
T result;
Expand All @@ -117,7 +120,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T log(const T &x) {
auto log(const T &x) -> T {
IF_FLOATING(T) { return Vc::log(x); }
else {
T result;
Expand All @@ -127,7 +130,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T log2(const T &x) {
auto log2(const T &x) -> T {
IF_FLOATING(T) { return Vc::log2(x); }
else {
T result;
Expand All @@ -137,7 +140,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T log10(const T &x) {
auto log10(const T &x) -> T {
IF_FLOATING(T) { return Vc::log10(x); }
else {
T result;
Expand All @@ -147,7 +150,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T sqrt(const T &x) {
auto sqrt(const T &x) -> T {
IF_FLOATING(T) { return Vc::sqrt(x); }
else {
T result;
Expand All @@ -157,14 +160,14 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T cbrt(const T &x) {
auto cbrt(const T &x) -> T {
T result;
for (int i = 0; i < x.size(); ++i) { result[i] = cbrt(x[i]); }
return result;
}

template<typename T, REQUIRE_VECTOR(T)>
T abs(const T &x) {
auto abs(const T &x) -> T {
IF_FLOATING(T) { return Vc::abs(x); }
else {
T result;
Expand All @@ -174,7 +177,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T floor(const T &x) {
auto floor(const T &x) -> T {
IF_FLOATING(T) { return Vc::floor(x); }
else {
T result;
Expand All @@ -184,7 +187,7 @@ namespace librapid {
}

template<typename T, REQUIRE_VECTOR(T)>
T ceil(const T &x) {
auto ceil(const T &x) -> T {
IF_FLOATING(T) { return Vc::ceil(x); }
else {
T result;
Expand Down

0 comments on commit 160003c

Please sign in to comment.