Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/a2ddefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ A2D_FUNCTION T fabs(T val) {
return std::fabs(val);
}

template <typename T, std::enable_if_t<is_scalar_type<T>::value, bool> = true>
A2D_FUNCTION T fsgn(T val) {
return std::copysign(1.0, val);
}

template <typename T, std::enable_if_t<is_scalar_type<T>::value, bool> = true>
A2D_FUNCTION T sqrt(T val) {
#ifndef __CUDACC__
Expand Down Expand Up @@ -329,7 +334,7 @@ A2D_FUNCTION T acos(T val) {
}

template <class ForwardIt, class T>
A2D_FUNCTION void fill(ForwardIt first, ForwardIt last, const T& value) {
A2D_FUNCTION void fill(ForwardIt first, ForwardIt last, const T &value) {
#ifdef __CUDACC__
thrust::fill(first, last, value);
#else
Expand Down
2 changes: 1 addition & 1 deletion include/ad/core/a2dsymmatveccore.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ A2D_FUNCTION void SymMatVecCore3x3(const T A[], const T x[], T b[]) {
}

template <typename T, bool additive = false>
A2D_FUNCTION void SymMatVecCoreScale3x3(const T& scale, const T A[],
A2D_FUNCTION void SymMatVecCoreScale3x3(const T &scale, const T A[],
const T x[], T b[]) {
// compute b = A * x
if constexpr (additive) {
Expand Down
52 changes: 52 additions & 0 deletions include/adscalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,21 @@ A2D_FUNCTION inline ADScalar<X, M> operator/(const ADScalar<X, M> &l,
return out;
}

// sign function
// template <class X, int M>
// A2D_FUNCTION inline ADScalar<X, M> fsgn(const ADScalar<X, M> &r) {
// X sign = 1.0;
// if (r.value < 0.0) {
// sign = -1.0;
// }
// // device compatible fsgn
// ADScalar<X, M> out(::fsgn(r.value));
// for (int i = 0; i < M; i++) {
// out.deriv[i] = sign * r.deriv[i];
// }
// return out;
// }

// fabs, sqrt
template <class X, int M>
A2D_FUNCTION inline ADScalar<X, M> fabs(const ADScalar<X, M> &r) {
Expand Down Expand Up @@ -371,6 +386,43 @@ A2D_FUNCTION inline ADScalar<X, M> cos(const ADScalar<X, M> &r) {
return out;
}

template <class X, int M>
A2D_FUNCTION inline ADScalar<X, M> atan(const ADScalar<X, M> &r) {
// device compatible sin, cos
ADScalar<X, M> out(::atan(r.value));
X d = 1.0 / (1.0 + r.value * r.value); // 1/(1+x^2)
for (int i = 0; i < M; i++) {
out.deriv[i] = d * r.deriv[i];
}
return out;
}

template <class X, int M>
A2D_FUNCTION inline ADScalar<X, M> atan2(const ADScalar<X, M> &y,
const ADScalar<X, M> &x) {
/** atan2(y,x) => theta */
ADScalar<X, M> out(::atan2(y.value, x.value));
X denom = x.value * x.value + y.value * y.value;
X dx = -y.value / denom;
X dy = x.value / denom;

for (int i = 0; i < M; i++) {
out.deriv[i] = dx * x.deriv[0] + dy * y.deriv[0];
}
return out;
}

template <class X, int M>
A2D_FUNCTION inline ADScalar<X, M> tanh(const ADScalar<X, M> &r) {
// for smooth sign function essentially
ADScalar<X, M> out(::tanh(r.value));
X d = 1.0 / ::cosh(r.value) / ::cosh(r.value);
for (int i = 0; i < M; i++) {
out.deriv[i] = d * r.deriv[i];
}
return out;
}

// for A2D Objects

// template <int N>
Expand Down