From 358ce115bb4df5dae0c7c75057f835167b91fa17 Mon Sep 17 00:00:00 2001 From: Ewan Miller Date: Fri, 26 Jul 2024 13:43:23 -0400 Subject: [PATCH] MORE linting --- nuTens/logging.hpp | 2 +- nuTens/propagator/propagator.cpp | 4 ++-- nuTens/propagator/propagator.hpp | 4 ++-- nuTens/tensors/tensor.hpp | 28 ++++++++++++++-------------- tests/barger-propagator.hpp | 8 ++++---- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/nuTens/logging.hpp b/nuTens/logging.hpp index e0e40e6..2920dc4 100644 --- a/nuTens/logging.hpp +++ b/nuTens/logging.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include /*! \file logging.hpp \brief Define the logging utilities for nuTens diff --git a/nuTens/propagator/propagator.cpp b/nuTens/propagator/propagator.cpp index 5b83cee..098cd5f 100644 --- a/nuTens/propagator/propagator.cpp +++ b/nuTens/propagator/propagator.cpp @@ -31,8 +31,8 @@ Tensor Propagator::_calculateProbs(const Tensor &energies, const Tensor &massesS weightMatrix.ones({energies.getBatchDim(), _nGenerations, _nGenerations}, NTdtypes::kComplexFloat) .requiresGrad(false); - Tensor weightVector = - Tensor::exp(Tensor::div(Tensor::scale(massesSq, -1.0J * _baseline), Tensor::scale(energies, 2.0))); + Tensor weightVector = Tensor::exp( + Tensor::div(Tensor::scale(massesSq, std::complex(-1.0J) * _baseline), Tensor::scale(energies, 2.0))); for (int i = 0; i < _nGenerations; i++) { diff --git a/nuTens/propagator/propagator.hpp b/nuTens/propagator/propagator.hpp index 8035b1a..e2f026d 100644 --- a/nuTens/propagator/propagator.hpp +++ b/nuTens/propagator/propagator.hpp @@ -31,7 +31,7 @@ class Propagator /// @brief Calculate the oscillation probabilities /// @param energies The energies of the neutrinos - Tensor calculateProbs(const Tensor &energies) const; + [[nodiscard]] Tensor calculateProbs(const Tensor &energies) const; /// @name Setters /// @{ @@ -99,7 +99,7 @@ class Propagator private: // For calculating with alternate masses and PMNS, e.g. if using effective // values from massSolver - Tensor _calculateProbs(const Tensor &energies, const Tensor &masses, const Tensor &PMNS) const; + [[nodiscard]] Tensor _calculateProbs(const Tensor &energies, const Tensor &masses, const Tensor &PMNS) const; private: Tensor _PMNSmatrix; diff --git a/nuTens/tensors/tensor.hpp b/nuTens/tensors/tensor.hpp index f5bdc09..1253694 100644 --- a/nuTens/tensors/tensor.hpp +++ b/nuTens/tensors/tensor.hpp @@ -194,23 +194,23 @@ class Tensor /// @} /// @brief Get the real part of a complex tensor - Tensor real() const; + [[nodiscard]] Tensor real() const; /// @brief Get the imaginary part of a complex tensor - Tensor imag() const; + [[nodiscard]] Tensor imag() const; /// @brief Get the complex conjugate of this tensor. If the underlying tensor /// is not complex, this will just return the tensor. - Tensor conj() const; + [[nodiscard]] Tensor conj() const; /// @brief Get elementwise absolute magnitude of a complex tensor - Tensor abs() const; + [[nodiscard]] Tensor abs() const; /// @brief Get elementwise phases of a complex tensor - Tensor angle() const; + [[nodiscard]] Tensor angle() const; /// @brief Get the result of summing this tensor over some dimension /// @param dim The dimension to sum over - Tensor cumsum(int dim) const; + [[nodiscard]] Tensor cumsum(int dim) const; /// @brief Get the result of summing this tensor over all dimensions - Tensor sum() const; + [[nodiscard]] Tensor sum() const; /// @name Gradients /// @{ @@ -221,7 +221,7 @@ class Tensor /// @brief Return a tensor containing the accumulated gradients calculated /// for this tensor after calling backward() - Tensor grad() const; + [[nodiscard]] Tensor grad() const; /// @} @@ -246,7 +246,7 @@ class Tensor }; /// Print this object to a summary string - std::string toString() const; + [[nodiscard]] std::string toString() const; /// @brief Set the value at a particular index of the tensor /// @arg indices The indices of the value to set @@ -258,16 +258,16 @@ class Tensor /// @brief Get the value at a certain entry in the tensor /// @param indices The index of the entry to get - Tensor getValue(const std::vector> &indices) const; + [[nodiscard]] Tensor getValue(const std::vector> &indices) const; /// @brief Get the number of dimensions in the tensor - size_t getNdim() const; + [[nodiscard]] size_t getNdim() const; /// @brief Get the batch dimension size of the tensor - int getBatchDim() const; + [[nodiscard]] int getBatchDim() const; /// @brief Get the shape of the tensor - std::vector getShape() const; + [[nodiscard]] std::vector getShape() const; // Defining this here as it has to be in a header due to using template :( #if USE_PYTORCH @@ -297,7 +297,7 @@ class Tensor #if USE_PYTORCH public: - inline const torch::Tensor &getTensor() const + [[nodiscard]] inline const torch::Tensor &getTensor() const { return _tensor; } diff --git a/tests/barger-propagator.hpp b/tests/barger-propagator.hpp index ea06686..9650cd8 100644 --- a/tests/barger-propagator.hpp +++ b/tests/barger-propagator.hpp @@ -35,19 +35,19 @@ class TwoFlavourBarger }; // characteristic length in vacuum - inline float lv(float energy) const + [[nodiscard]] inline float lv(float energy) const { return 4.0 * M_PI * energy / (_m1 * _m1 - _m2 * _m2); } // characteristic length in matter - inline float lm() const + [[nodiscard]] inline float lm() const { return 2.0 * M_PI / (Constants::Groot2 * _density); } // calculate the modified rotation angle - inline float calculateEffectiveAngle(float energy) + [[nodiscard]] inline float calculateEffectiveAngle(float energy) const { float ret = NAN; @@ -64,7 +64,7 @@ class TwoFlavourBarger } // calculate the modified delta M^2 - inline float calculateEffectiveDm2(float energy) const + [[nodiscard]] inline float calculateEffectiveDm2(float energy) const { float ret = NAN;