From 41699e8e0b8e7c45a280b3bfdde5bc3cc73cf694 Mon Sep 17 00:00:00 2001 From: Vaibhav Thakkar Date: Tue, 3 Oct 2023 23:55:39 +0530 Subject: [PATCH] Fix formatting of const& qualifier --- .clang-format | 1 + include/clad/Differentiator/Array.h | 48 +++++++-------- include/clad/Differentiator/ArrayExpression.h | 58 +++++++++---------- include/clad/Differentiator/ArrayRef.h | 44 +++++++------- 4 files changed, 76 insertions(+), 75 deletions(-) diff --git a/.clang-format b/.clang-format index 9d3caf0f5..3cae5f179 100644 --- a/.clang-format +++ b/.clang-format @@ -4,6 +4,7 @@ Language: Cpp Standard: Cpp11 PointerAlignment: Left RemoveBracesLLVM: true +QualifierAlignment: Left IncludeCategories: - Regex: '^"[^/]+\"' diff --git a/include/clad/Differentiator/Array.h b/include/clad/Differentiator/Array.h index c7c45d2f8..a78083b64 100644 --- a/include/clad/Differentiator/Array.h +++ b/include/clad/Differentiator/Array.h @@ -300,9 +300,9 @@ template class array { } /// Negate the array and return a new array. - CUDA_HOST_DEVICE array_expression const&> + CUDA_HOST_DEVICE array_expression&> operator-() const { - return array_expression const&>(static_cast(0), + return array_expression&>(static_cast(0), *this); } @@ -310,9 +310,9 @@ template class array { /// array, when the number is on the left side. template ::value, int>::type = 0> - CUDA_HOST_DEVICE friend array_expression const&> + CUDA_HOST_DEVICE friend array_expression&> operator-(U n, const array& arr) { - return array_expression const&>(n, arr); + return array_expression&>(n, arr); } /// Implicitly converts from clad::array to pointer to an array of type T @@ -342,88 +342,88 @@ template CUDA_HOST_DEVICE array zero_vector(std::size_t n) { /// expression. template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinaryMul, U> +CUDA_HOST_DEVICE array_expression&, BinaryMul, U> operator*(const array& arr, U n) { - return array_expression const&, BinaryMul, U>(arr, n); + return array_expression&, 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 ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinaryMul, U> +CUDA_HOST_DEVICE array_expression&, BinaryMul, U> operator*(U n, const array& arr) { - return array_expression const&, BinaryMul, U>(arr, n); + return array_expression&, BinaryMul, U>(arr, n); } /// Divides the number from every element in the array and returns an array /// expression. template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinaryDiv, U> +CUDA_HOST_DEVICE array_expression&, BinaryDiv, U> operator/(const array& arr, U n) { - return array_expression const&, BinaryDiv, U>(arr, n); + return array_expression&, BinaryDiv, U>(arr, n); } /// Adds the number to every element in the array and returns a new array template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinaryAdd, U> +CUDA_HOST_DEVICE array_expression&, BinaryAdd, U> operator+(const array& arr, U n) { - return array_expression const&, BinaryAdd, U>(arr, n); + return array_expression&, 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 ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinaryAdd, U> +CUDA_HOST_DEVICE array_expression&, BinaryAdd, U> operator+(U n, const array& arr) { - return array_expression const&, BinaryAdd, U>(arr, n); + return array_expression&, BinaryAdd, U>(arr, n); } /// Subtracts the number from every element in the array and returns an array /// expression. template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinarySub, U> +CUDA_HOST_DEVICE array_expression&, BinarySub, U> operator-(const array& arr, U n) { - return array_expression const&, BinarySub, U>(arr, n); + return array_expression&, BinarySub, U>(arr, n); } /// Function to define element wise adding of two arrays. template -CUDA_HOST_DEVICE array_expression const&, BinaryAdd, array const&> +CUDA_HOST_DEVICE array_expression&, BinaryAdd, const array&> operator+(const array& arr1, const array& arr2) { assert(arr1.size() == arr2.size()); - return array_expression const&, BinaryAdd, array const&>(arr1, + return array_expression&, BinaryAdd, const array&>(arr1, arr2); } /// Function to define element wise subtraction of two arrays. template -CUDA_HOST_DEVICE array_expression const&, BinarySub, array const&> +CUDA_HOST_DEVICE array_expression&, BinarySub, const array&> operator-(const array& arr1, const array& arr2) { assert(arr1.size() == arr2.size()); - return array_expression const&, BinarySub, array const&>(arr1, + return array_expression&, BinarySub, const array&>(arr1, arr2); } /// Function to define element wise multiplication of two arrays. template -CUDA_HOST_DEVICE array_expression const&, BinaryMul, array const&> +CUDA_HOST_DEVICE array_expression&, BinaryMul, const array&> operator*(const array& arr1, const array& arr2) { assert(arr1.size() == arr2.size()); - return array_expression const&, BinaryMul, array const&>(arr1, + return array_expression&, BinaryMul, const array&>(arr1, arr2); } /// Function to define element wise division of two arrays. template -CUDA_HOST_DEVICE array_expression const&, BinaryDiv, array const&> +CUDA_HOST_DEVICE array_expression&, BinaryDiv, const array&> operator/(const array& arr1, const array& arr2) { assert(arr1.size() == arr2.size()); - return array_expression const&, BinaryDiv, array const&>(arr1, + return array_expression&, BinaryDiv, const array&>(arr1, arr2); } diff --git a/include/clad/Differentiator/ArrayExpression.h b/include/clad/Differentiator/ArrayExpression.h index b608bc902..c420f9177 100644 --- a/include/clad/Differentiator/ArrayExpression.h +++ b/include/clad/Differentiator/ArrayExpression.h @@ -12,7 +12,7 @@ namespace clad { // Operator to add two elements. struct BinaryAdd { template - 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; } }; @@ -20,7 +20,7 @@ struct BinaryAdd { // Operator to add two elements. struct BinaryMul { template - 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; } }; @@ -28,7 +28,7 @@ struct BinaryMul { // Operator to divide two elements. struct BinaryDiv { template - 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; } }; @@ -36,7 +36,7 @@ struct BinaryDiv { // Operator to subtract two elements. struct BinarySub { template - 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; } }; @@ -53,24 +53,24 @@ class array_expression { // for scalars template ::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 ::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 ::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 ::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]; } @@ -84,41 +84,41 @@ class array_expression { // Operator overload for addition. template - array_expression const&, + array_expression&, BinaryAdd, RE> - operator+(RE const& r) const { + operator+(const RE& r) const { return array_expression< - array_expression const&, BinaryAdd, RE>( + const array_expression&, BinaryAdd, RE>( *this, r); } // Operator overload for multiplication. template - array_expression const&, + array_expression&, BinaryMul, RE> - operator*(RE const& r) const { + operator*(const RE& r) const { return array_expression< - array_expression const&, BinaryMul, RE>( + const array_expression&, BinaryMul, RE>( *this, r); } // Operator overload for subtraction. template - array_expression const&, + array_expression&, BinarySub, RE> - operator-(RE const& r) const { + operator-(const RE& r) const { return array_expression< - array_expression const&, BinarySub, RE>( + const array_expression&, BinarySub, RE>( *this, r); } // Operator overload for division. template - array_expression const&, + array_expression&, BinaryDiv, RE> - operator/(RE const& r) const { + operator/(const RE& r) const { return array_expression< - array_expression const&, BinaryDiv, RE>( + const array_expression&, BinaryDiv, RE>( *this, r); } }; @@ -128,10 +128,10 @@ class array_expression { template ::value, int>::type = 0> array_expression const&> -operator+(T const& l, array_expression const& r) { + const array_expression&> +operator+(const T& l, const array_expression& r) { return array_expression const&>( + const array_expression&>( l, r); } @@ -140,10 +140,10 @@ operator+(T const& l, array_expression const& r) { template ::value, int>::type = 0> array_expression const&> -operator*(T const& l, array_expression const& r) { + const array_expression&> +operator*(const T& l, const array_expression& r) { return array_expression const&>( + const array_expression&>( l, r); } @@ -152,10 +152,10 @@ operator*(T const& l, array_expression const& r) { template ::value, int>::type = 0> array_expression const&> -operator-(T const& l, array_expression const& r) { + const array_expression&> +operator-(const T& l, const array_expression& r) { return array_expression const&>( + const array_expression&>( l, r); } } // namespace clad diff --git a/include/clad/Differentiator/ArrayRef.h b/include/clad/Differentiator/ArrayRef.h index 0ceaa52fb..efc227522 100644 --- a/include/clad/Differentiator/ArrayRef.h +++ b/include/clad/Differentiator/ArrayRef.h @@ -164,106 +164,106 @@ template class array_ref { /// Multiplies the arrays element wise template CUDA_HOST_DEVICE - array_expression const&, BinaryMul, array_ref const&> + array_expression&, BinaryMul, const array_ref&> operator*(const array_ref& Ar, const array_ref& Br) { assert(Ar.size() == Br.size() && "Size of both the array_refs must be equal for carrying out " "multiplication assignment"); - return array_expression const&, BinaryMul, array_ref const&>( + return array_expression&, BinaryMul, const array_ref&>( Ar, Br); } /// Adds the arrays element wise template CUDA_HOST_DEVICE - array_expression const&, BinaryAdd, array_ref const&> + array_expression&, BinaryAdd, const array_ref&> operator+(const array_ref& Ar, const array_ref& Br) { assert(Ar.size() == Br.size() && "Size of both the array_refs must be equal for carrying out addition " "assignment"); - return array_expression const&, BinaryAdd, array_ref const&>( + return array_expression&, BinaryAdd, const array_ref&>( Ar, Br); } /// Subtracts the arrays element wise template CUDA_HOST_DEVICE - array_expression const&, BinarySub, array_ref const&> + array_expression&, BinarySub, const array_ref&> operator-(const array_ref& Ar, const array_ref& Br) { assert( Ar.size() == Br.size() && "Size of both the array_refs must be equal for carrying out subtraction " "assignment"); - return array_expression const&, BinarySub, array_ref const&>( + return array_expression&, BinarySub, const array_ref&>( Ar, Br); } /// Divides the arrays element wise template CUDA_HOST_DEVICE - array_expression const&, BinaryDiv, array_ref const&> + array_expression&, BinaryDiv, const array_ref&> operator/(const array_ref& Ar, const array_ref& Br) { assert(Ar.size() == Br.size() && "Size of both the array_refs must be equal for carrying out division " "assignment"); - return array_expression const&, BinaryDiv, array_ref const&>( + return array_expression&, BinaryDiv, const array_ref&>( Ar, Br); } /// Multiplies array_ref by a scalar template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinaryMul, U> +CUDA_HOST_DEVICE array_expression&, BinaryMul, U> operator*(const array_ref& Ar, U a) { - return array_expression const&, BinaryMul, U>(Ar, a); + return array_expression&, BinaryMul, U>(Ar, a); } /// Multiplies array_ref by a scalar (reverse order) template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinaryMul, U> +CUDA_HOST_DEVICE array_expression&, BinaryMul, U> operator*(U a, const array_ref& Ar) { - return array_expression const&, BinaryMul, U>(Ar, a); + return array_expression&, BinaryMul, U>(Ar, a); } /// Divides array_ref by a scalar template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinaryDiv, U> +CUDA_HOST_DEVICE array_expression&, BinaryDiv, U> operator/(const array_ref& Ar, U a) { - return array_expression const&, BinaryDiv, U>(Ar, a); + return array_expression&, BinaryDiv, U>(Ar, a); } /// Adds array_ref by a scalar template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinaryAdd, U> +CUDA_HOST_DEVICE array_expression&, BinaryAdd, U> operator+(const array_ref& Ar, U a) { - return array_expression const&, BinaryAdd, U>(Ar, a); + return array_expression&, BinaryAdd, U>(Ar, a); } /// Adds array_ref by a scalar (reverse order) template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinaryAdd, U> +CUDA_HOST_DEVICE array_expression&, BinaryAdd, U> operator+(U a, const array_ref& Ar) { - return array_expression const&, BinaryAdd, U>(Ar, a); + return array_expression&, BinaryAdd, U>(Ar, a); } /// Subtracts array_ref by a scalar template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&, BinarySub, U> +CUDA_HOST_DEVICE array_expression&, BinarySub, U> operator-(const array_ref& Ar, U a) { - return array_expression const&, BinarySub, U>(Ar, a); + return array_expression&, BinarySub, U>(Ar, a); } /// Subtracts array_ref by a scalar (reverse order) template ::value, int>::type = 0> -CUDA_HOST_DEVICE array_expression const&> +CUDA_HOST_DEVICE array_expression&> operator-(U a, const array_ref& Ar) { - return array_expression const&>(a, Ar); + return array_expression&>(a, Ar); } /// `array_ref` specialisation is created to be used as a placeholder