Skip to content

Commit

Permalink
Fix formatting of const& qualifier
Browse files Browse the repository at this point in the history
  • Loading branch information
vaithak authored and vgvassilev committed Oct 3, 2023
1 parent fe81274 commit 41699e8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 75 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Language: Cpp
Standard: Cpp11
PointerAlignment: Left
RemoveBracesLLVM: true
QualifierAlignment: Left

IncludeCategories:
- Regex: '^"[^/]+\"'
Expand Down
48 changes: 24 additions & 24 deletions include/clad/Differentiator/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,19 @@ template <typename T> class array {
}

/// Negate the array and return a new array.
CUDA_HOST_DEVICE array_expression<T, BinarySub, array<T> const&>
CUDA_HOST_DEVICE array_expression<T, BinarySub, const array<T>&>
operator-() const {
return array_expression<T, BinarySub, array<T> const&>(static_cast<T>(0),
return array_expression<T, BinarySub, const array<T>&>(static_cast<T>(0),
*this);
}

/// Subtracts the number from every element in the array and returns a new
/// array, when the number is on the left side.
template <typename U, typename std::enable_if<std::is_arithmetic<U>::value,
int>::type = 0>
CUDA_HOST_DEVICE friend array_expression<U, BinarySub, array<T> const&>
CUDA_HOST_DEVICE friend array_expression<U, BinarySub, const array<T>&>
operator-(U n, const array<T>& arr) {
return array_expression<U, BinarySub, array<T> const&>(n, arr);
return array_expression<U, BinarySub, const array<T>&>(n, arr);
}

/// Implicitly converts from clad::array to pointer to an array of type T
Expand Down Expand Up @@ -342,88 +342,88 @@ template <typename T> CUDA_HOST_DEVICE array<T> zero_vector(std::size_t n) {
/// expression.
template <typename T, typename U,
typename std::enable_if<std::is_arithmetic<U>::value, int>::type = 0>
CUDA_HOST_DEVICE array_expression<array<T> const&, BinaryMul, U>
CUDA_HOST_DEVICE array_expression<const array<T>&, BinaryMul, U>
operator*(const array<T>& arr, U n) {
return array_expression<array<T> const&, BinaryMul, U>(arr, n);
return array_expression<const array<T>&, BinaryMul, U>(arr, n);
}

/// Multiplies the number to every element in the array and returns an array
/// expression, when the number is on the left side.
template <typename T, typename U,
typename std::enable_if<std::is_arithmetic<U>::value, int>::type = 0>
CUDA_HOST_DEVICE array_expression<array<T> const&, BinaryMul, U>
CUDA_HOST_DEVICE array_expression<const array<T>&, BinaryMul, U>
operator*(U n, const array<T>& arr) {
return array_expression<array<T> const&, BinaryMul, U>(arr, n);
return array_expression<const array<T>&, BinaryMul, U>(arr, n);
}

/// Divides the number from every element in the array and returns an array
/// expression.
template <typename T, typename U,
typename std::enable_if<std::is_arithmetic<U>::value, int>::type = 0>
CUDA_HOST_DEVICE array_expression<array<T> const&, BinaryDiv, U>
CUDA_HOST_DEVICE array_expression<const array<T>&, BinaryDiv, U>
operator/(const array<T>& arr, U n) {
return array_expression<array<T> const&, BinaryDiv, U>(arr, n);
return array_expression<const array<T>&, BinaryDiv, U>(arr, n);
}

/// Adds the number to every element in the array and returns a new array
template <typename T, typename U,
typename std::enable_if<std::is_arithmetic<U>::value, int>::type = 0>
CUDA_HOST_DEVICE array_expression<array<T> const&, BinaryAdd, U>
CUDA_HOST_DEVICE array_expression<const array<T>&, BinaryAdd, U>
operator+(const array<T>& arr, U n) {
return array_expression<array<T> const&, BinaryAdd, U>(arr, n);
return array_expression<const array<T>&, BinaryAdd, U>(arr, n);
}

/// Adds the number to every element in the array and returns an array
/// expression, when the number is on the left side.
template <typename T, typename U,
typename std::enable_if<std::is_arithmetic<U>::value, int>::type = 0>
CUDA_HOST_DEVICE array_expression<array<T> const&, BinaryAdd, U>
CUDA_HOST_DEVICE array_expression<const array<T>&, BinaryAdd, U>
operator+(U n, const array<T>& arr) {
return array_expression<array<T> const&, BinaryAdd, U>(arr, n);
return array_expression<const array<T>&, BinaryAdd, U>(arr, n);
}

/// Subtracts the number from every element in the array and returns an array
/// expression.
template <typename T, typename U,
typename std::enable_if<std::is_arithmetic<U>::value, int>::type = 0>
CUDA_HOST_DEVICE array_expression<array<T> const&, BinarySub, U>
CUDA_HOST_DEVICE array_expression<const array<T>&, BinarySub, U>
operator-(const array<T>& arr, U n) {
return array_expression<array<T> const&, BinarySub, U>(arr, n);
return array_expression<const array<T>&, BinarySub, U>(arr, n);
}

/// Function to define element wise adding of two arrays.
template <typename T, typename U>
CUDA_HOST_DEVICE array_expression<array<T> const&, BinaryAdd, array<U> const&>
CUDA_HOST_DEVICE array_expression<const array<T>&, BinaryAdd, const array<U>&>
operator+(const array<T>& arr1, const array<U>& arr2) {
assert(arr1.size() == arr2.size());
return array_expression<array<T> const&, BinaryAdd, array<U> const&>(arr1,
return array_expression<const array<T>&, BinaryAdd, const array<U>&>(arr1,
arr2);
}

/// Function to define element wise subtraction of two arrays.
template <typename T, typename U>
CUDA_HOST_DEVICE array_expression<array<T> const&, BinarySub, array<U> const&>
CUDA_HOST_DEVICE array_expression<const array<T>&, BinarySub, const array<U>&>
operator-(const array<T>& arr1, const array<U>& arr2) {
assert(arr1.size() == arr2.size());
return array_expression<array<T> const&, BinarySub, array<U> const&>(arr1,
return array_expression<const array<T>&, BinarySub, const array<U>&>(arr1,
arr2);
}

/// Function to define element wise multiplication of two arrays.
template <typename T, typename U>
CUDA_HOST_DEVICE array_expression<array<T> const&, BinaryMul, array<U> const&>
CUDA_HOST_DEVICE array_expression<const array<T>&, BinaryMul, const array<U>&>
operator*(const array<T>& arr1, const array<U>& arr2) {
assert(arr1.size() == arr2.size());
return array_expression<array<T> const&, BinaryMul, array<U> const&>(arr1,
return array_expression<const array<T>&, BinaryMul, const array<U>&>(arr1,
arr2);
}

/// Function to define element wise division of two arrays.
template <typename T, typename U>
CUDA_HOST_DEVICE array_expression<array<T> const&, BinaryDiv, array<U> const&>
CUDA_HOST_DEVICE array_expression<const array<T>&, BinaryDiv, const array<U>&>
operator/(const array<T>& arr1, const array<U>& arr2) {
assert(arr1.size() == arr2.size());
return array_expression<array<T> const&, BinaryDiv, array<U> const&>(arr1,
return array_expression<const array<T>&, BinaryDiv, const array<U>&>(arr1,
arr2);
}

Expand Down
58 changes: 29 additions & 29 deletions include/clad/Differentiator/ArrayExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ namespace clad {
// Operator to add two elements.
struct BinaryAdd {
template <typename T, typename U>
static auto apply(T const& t, U const& u) -> decltype(t + u) {
static auto apply(const T& t, const U& u) -> decltype(t + u) {
return t + u;
}
};

// Operator to add two elements.
struct BinaryMul {
template <typename T, typename U>
static auto apply(T const& t, U const& u) -> decltype(t * u) {
static auto apply(const T& t, const U& u) -> decltype(t * u) {
return t * u;
}
};

// Operator to divide two elements.
struct BinaryDiv {
template <typename T, typename U>
static auto apply(T const& t, U const& u) -> decltype(t / u) {
static auto apply(const T& t, const U& u) -> decltype(t / u) {
return t / u;
}
};

// Operator to subtract two elements.
struct BinarySub {
template <typename T, typename U>
static auto apply(T const& t, U const& u) -> decltype(t - u) {
static auto apply(const T& t, const U& u) -> decltype(t - u) {
return t - u;
}
};
Expand All @@ -53,24 +53,24 @@ class array_expression {
// for scalars
template <typename T, typename std::enable_if<std::is_arithmetic<T>::value,
int>::type = 0>
std::size_t get_size(T const& t) const {
std::size_t get_size(const T& t) const {
return 1;
}
template <typename T, typename std::enable_if<std::is_arithmetic<T>::value,
int>::type = 0>
T get(T const& t, std::size_t i) const {
T get(const T& t, std::size_t i) const {
return t;
}

// for vectors
template <typename T, typename std::enable_if<!std::is_arithmetic<T>::value,
int>::type = 0>
std::size_t get_size(T const& t) const {
std::size_t get_size(const T& t) const {
return t.size();
}
template <typename T, typename std::enable_if<!std::is_arithmetic<T>::value,
int>::type = 0>
auto get(T const& t, std::size_t i) const -> decltype(t[i]) {
auto get(const T& t, std::size_t i) const -> decltype(t[i]) {
return t[i];
}

Expand All @@ -84,41 +84,41 @@ class array_expression {

// Operator overload for addition.
template <typename RE>
array_expression<array_expression<LeftExp, BinaryOp, RightExp> const&,
array_expression<const array_expression<LeftExp, BinaryOp, RightExp>&,
BinaryAdd, RE>
operator+(RE const& r) const {
operator+(const RE& r) const {
return array_expression<
array_expression<LeftExp, BinaryOp, RightExp> const&, BinaryAdd, RE>(
const array_expression<LeftExp, BinaryOp, RightExp>&, BinaryAdd, RE>(
*this, r);
}

// Operator overload for multiplication.
template <typename RE>
array_expression<array_expression<LeftExp, BinaryOp, RightExp> const&,
array_expression<const array_expression<LeftExp, BinaryOp, RightExp>&,
BinaryMul, RE>
operator*(RE const& r) const {
operator*(const RE& r) const {
return array_expression<
array_expression<LeftExp, BinaryOp, RightExp> const&, BinaryMul, RE>(
const array_expression<LeftExp, BinaryOp, RightExp>&, BinaryMul, RE>(
*this, r);
}

// Operator overload for subtraction.
template <typename RE>
array_expression<array_expression<LeftExp, BinaryOp, RightExp> const&,
array_expression<const array_expression<LeftExp, BinaryOp, RightExp>&,
BinarySub, RE>
operator-(RE const& r) const {
operator-(const RE& r) const {
return array_expression<
array_expression<LeftExp, BinaryOp, RightExp> const&, BinarySub, RE>(
const array_expression<LeftExp, BinaryOp, RightExp>&, BinarySub, RE>(
*this, r);
}

// Operator overload for division.
template <typename RE>
array_expression<array_expression<LeftExp, BinaryOp, RightExp> const&,
array_expression<const array_expression<LeftExp, BinaryOp, RightExp>&,
BinaryDiv, RE>
operator/(RE const& r) const {
operator/(const RE& r) const {
return array_expression<
array_expression<LeftExp, BinaryOp, RightExp> const&, BinaryDiv, RE>(
const array_expression<LeftExp, BinaryOp, RightExp>&, BinaryDiv, RE>(
*this, r);
}
};
Expand All @@ -128,10 +128,10 @@ class array_expression {
template <typename T, typename LeftExp, typename BinaryOp, typename RightExp,
typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
array_expression<T, BinaryAdd,
array_expression<LeftExp, BinaryOp, RightExp> const&>
operator+(T const& l, array_expression<LeftExp, BinaryOp, RightExp> const& r) {
const array_expression<LeftExp, BinaryOp, RightExp>&>
operator+(const T& l, const array_expression<LeftExp, BinaryOp, RightExp>& r) {
return array_expression<T, BinaryAdd,
array_expression<LeftExp, BinaryOp, RightExp> const&>(
const array_expression<LeftExp, BinaryOp, RightExp>&>(
l, r);
}

Expand All @@ -140,10 +140,10 @@ operator+(T const& l, array_expression<LeftExp, BinaryOp, RightExp> const& r) {
template <typename T, typename LeftExp, typename BinaryOp, typename RightExp,
typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
array_expression<T, BinaryMul,
array_expression<LeftExp, BinaryOp, RightExp> const&>
operator*(T const& l, array_expression<LeftExp, BinaryOp, RightExp> const& r) {
const array_expression<LeftExp, BinaryOp, RightExp>&>
operator*(const T& l, const array_expression<LeftExp, BinaryOp, RightExp>& r) {
return array_expression<T, BinaryMul,
array_expression<LeftExp, BinaryOp, RightExp> const&>(
const array_expression<LeftExp, BinaryOp, RightExp>&>(
l, r);
}

Expand All @@ -152,10 +152,10 @@ operator*(T const& l, array_expression<LeftExp, BinaryOp, RightExp> const& r) {
template <typename T, typename LeftExp, typename BinaryOp, typename RightExp,
typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
array_expression<T, BinarySub,
array_expression<LeftExp, BinaryOp, RightExp> const&>
operator-(T const& l, array_expression<LeftExp, BinaryOp, RightExp> const& r) {
const array_expression<LeftExp, BinaryOp, RightExp>&>
operator-(const T& l, const array_expression<LeftExp, BinaryOp, RightExp>& r) {
return array_expression<T, BinarySub,
array_expression<LeftExp, BinaryOp, RightExp> const&>(
const array_expression<LeftExp, BinaryOp, RightExp>&>(
l, r);
}
} // namespace clad
Expand Down
Loading

0 comments on commit 41699e8

Please sign in to comment.