From a53fa1cdcb6af8bfd47e520f6a82963090214629 Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Fri, 7 Feb 2025 15:03:44 -0500 Subject: [PATCH] clang-tidy fixes --- freud/density/CorrelationFunction.cc | 14 ++++++++++---- freud/density/CorrelationFunction.h | 9 +++++---- freud/density/GaussianDensity.cc | 21 +++++++++++++++------ freud/density/GaussianDensity.h | 1 - freud/density/LocalDensity.cc | 11 +++++++++++ freud/density/LocalDensity.h | 4 +++- freud/density/RDF.cc | 19 +++++++++++++------ freud/density/RDF.h | 11 +++++++---- freud/density/SphereVoxelization.cc | 11 ++++++++--- freud/density/SphereVoxelization.h | 2 +- freud/density/export-CorrelationFunction.cc | 7 ++++--- freud/density/export-GaussianDensity.cc | 5 +---- freud/density/export-LocalDensity.cc | 5 +++-- freud/density/export-SphereVoxelization.cc | 5 ++--- 14 files changed, 83 insertions(+), 42 deletions(-) diff --git a/freud/density/CorrelationFunction.cc b/freud/density/CorrelationFunction.cc index 9254b8ac1..f5846ab87 100644 --- a/freud/density/CorrelationFunction.cc +++ b/freud/density/CorrelationFunction.cc @@ -2,14 +2,20 @@ // This file is from the freud project, released under the BSD 3-Clause License. #include +#include +#include #include #ifdef __SSE2__ #include #endif +#include "BondHistogramCompute.h" #include "CorrelationFunction.h" +#include "Histogram.h" #include "NeighborBond.h" -#include "NeighborComputeFunctional.h" +#include "NeighborList.h" +#include "NeighborQuery.h" +#include "VectorMath.h" /*! \file CorrelationFunction.cc \brief Generic pairwise correlation functions. @@ -46,7 +52,7 @@ void CorrelationFunction::reduce() // Reduce the bin counts over all threads, then use them to normalize m_histogram.reduceOverThreads(m_local_histograms); m_correlation_function.reduceOverThreadsPerBin(m_local_correlation_function, [&](size_t i) { - if (m_histogram[i]) + if (m_histogram[i] != 0) { m_correlation_function[i] /= m_histogram[i]; } @@ -71,10 +77,10 @@ inline double product(double x, double y) return x * y; } -void CorrelationFunction::accumulate(std::shared_ptr neighbor_query, +void CorrelationFunction::accumulate(const std::shared_ptr& neighbor_query, const std::complex* values, const vec3* query_points, const std::complex* query_values, unsigned int n_query_points, - std::shared_ptr nlist, + const std::shared_ptr& nlist, const freud::locality::QueryArgs& qargs) { accumulateGeneral( diff --git a/freud/density/CorrelationFunction.h b/freud/density/CorrelationFunction.h index 26e731c5b..ecbd696dc 100644 --- a/freud/density/CorrelationFunction.h +++ b/freud/density/CorrelationFunction.h @@ -4,14 +4,15 @@ #ifndef CORRELATION_FUNCTION_H #define CORRELATION_FUNCTION_H +#include +#include + #include "BondHistogramCompute.h" -#include "Box.h" #include "Histogram.h" #include "ManagedArray.h" #include "NeighborList.h" #include "NeighborQuery.h" #include "VectorMath.h" -#include /*! \file CorrelationFunction.h \brief Generic pairwise correlation functions. @@ -57,10 +58,10 @@ class CorrelationFunction : public locality::BondHistogramCompute void reset() override; //! accumulate the correlation function - void accumulate(std::shared_ptr neighbor_query, + void accumulate(const std::shared_ptr& neighbor_query, const std::complex* values, const vec3* query_points, const std::complex* query_values, unsigned int n_query_points, - std::shared_ptr nlist, + const std::shared_ptr& nlist, const freud::locality::QueryArgs& qargs); //! \internal diff --git a/freud/density/GaussianDensity.cc b/freud/density/GaussianDensity.cc index f2bf0a99a..d20b937fc 100644 --- a/freud/density/GaussianDensity.cc +++ b/freud/density/GaussianDensity.cc @@ -2,9 +2,18 @@ // This file is from the freud project, released under the BSD 3-Clause License. #include +#include +#include #include +#include +#include "Box.h" #include "GaussianDensity.h" +#include "ManagedArray.h" +#include "NeighborQuery.h" +#include "ThreadStorage.h" +#include "VectorMath.h" +#include "utils.h" /*! \file GaussianDensity.cc \brief Routines for computing Gaussian smeared densities from points. @@ -87,11 +96,11 @@ void GaussianDensity::compute(const freud::locality::NeighborQuery* nq, const fl for (size_t idx = begin; idx < end; ++idx) { const vec3 point = (*nq)[idx]; - const float value = (values != nullptr) ? values[idx] : 1.0f; + const float value = (values != nullptr) ? values[idx] : 1.0F; // Find which bin the particle is in - int bin_x = int((point.x + Lx / float(2.0)) / grid_size_x); - int bin_y = int((point.y + Ly / float(2.0)) / grid_size_y); + const int bin_x = int((point.x + Lx / float(2.0)) / grid_size_x); + const int bin_y = int((point.y + Ly / float(2.0)) / grid_size_y); int bin_z = int((point.z + Lz / float(2.0)) / grid_size_z); // In 2D, only loop over the z=0 plane @@ -143,9 +152,9 @@ void GaussianDensity::compute(const freud::locality::NeighborQuery* nq, const fl // Assure that out of range indices are corrected for storage // in the array i.e. bin -1 is actually bin 29 for nbins = 30 - const float ni = (i + m_width.x) % m_width.x; - const float nj = (j + m_width.y) % m_width.y; - const float nk = (k + m_width.z) % m_width.z; + const float ni = (unsigned int) (i + m_width.x) % m_width.x; + const float nj = (unsigned int) (j + m_width.y) % m_width.y; + const float nk = (unsigned int) (k + m_width.z) % m_width.z; // Store the gaussian contribution local_bin_counts.local()(ni, nj, nk) += gaussian; diff --git a/freud/density/GaussianDensity.h b/freud/density/GaussianDensity.h index 31cc1658a..9325b7bb0 100644 --- a/freud/density/GaussianDensity.h +++ b/freud/density/GaussianDensity.h @@ -7,7 +7,6 @@ #include "Box.h" #include "ManagedArray.h" #include "NeighborQuery.h" -#include "ThreadStorage.h" #include "VectorMath.h" /*! \file GaussianDensity.h diff --git a/freud/density/LocalDensity.cc b/freud/density/LocalDensity.cc index 437f4b762..bfa6cf8d9 100644 --- a/freud/density/LocalDensity.cc +++ b/freud/density/LocalDensity.cc @@ -1,8 +1,19 @@ // Copyright (c) 2010-2025 The Regents of the University of Michigan // This file is from the freud project, released under the BSD 3-Clause License. +#include +#include // NOLINT(modernize-deprecated-headers): Use std::numbers when c++20 is default. +#include +#include +#include + #include "LocalDensity.h" +#include "NeighborBond.h" #include "NeighborComputeFunctional.h" +#include "NeighborList.h" +#include "NeighborPerPointIterator.h" +#include "NeighborQuery.h" +#include "VectorMath.h" /*! \file LocalDensity.cc \brief Routines for computing local density around a point. diff --git a/freud/density/LocalDensity.h b/freud/density/LocalDensity.h index 661dab0f0..226d58115 100644 --- a/freud/density/LocalDensity.h +++ b/freud/density/LocalDensity.h @@ -4,6 +4,8 @@ #ifndef LOCAL_DENSITY_H #define LOCAL_DENSITY_H +#include + #include "Box.h" #include "ManagedArray.h" #include "NeighborList.h" @@ -53,7 +55,7 @@ class LocalDensity const freud::locality::QueryArgs& qargs); //! Get a shared pointer to the last computed density - const std::shared_ptr> getDensity() const + std::shared_ptr> getDensity() const { return m_density_array; } diff --git a/freud/density/RDF.cc b/freud/density/RDF.cc index f573fbda4..fa466c216 100644 --- a/freud/density/RDF.cc +++ b/freud/density/RDF.cc @@ -1,8 +1,15 @@ // Copyright (c) 2010-2025 The Regents of the University of Michigan // This file is from the freud project, released under the BSD 3-Clause License. +#include +#include // NOLINT(modernize-deprecated-headers): Use std::numbers when c++20 is default. +#include #include +#include +#include "BondHistogramCompute.h" +#include "Histogram.h" +#include "NeighborBond.h" #include "RDF.h" /*! \file RDF.cc @@ -40,7 +47,7 @@ RDF::RDF(unsigned int bins, float r_max, float r_min) : BondHistogramCompute() // Precompute the cell volumes to speed up later calculations. m_vol_array2D = std::make_shared>(std::vector {bins, bins}); m_vol_array3D = std::make_shared>(std::vector {bins, bins, bins}); - float volume_prefactor = (float(4.0) / float(3.0)) * M_PI; + const float volume_prefactor = (float(4.0) / float(3.0)) * M_PI; std::vector bin_boundaries = getBinEdges()[0]; for (unsigned int i = 0; i < bins; i++) @@ -74,22 +81,22 @@ void RDF::reduce() std::shared_ptr> vol_array = m_box.is2D() ? m_vol_array2D : m_vol_array3D; m_histogram.reduceOverThreadsPerBin(m_local_histograms, [this, &prefactor, &vol_array](size_t i) { - (*m_pcf)[i] = m_histogram[i] * prefactor / (*vol_array)[i]; + (*m_pcf)[i] = float(m_histogram[i]) * prefactor / (*vol_array)[i]; }); // The accumulation of the cumulative density must be performed in // sequence, so it is done after the reduction. prefactor = float(1.0) / (nqp * static_cast(m_frame_counter)); - (*m_N_r)[0] = m_histogram[0] * prefactor; + (*m_N_r)[0] = float(m_histogram[0]) * prefactor; for (unsigned int i = 1; i < getAxisSizes()[0]; i++) { - (*m_N_r)[i] = (*m_N_r)[i - 1] + m_histogram[i] * prefactor; + (*m_N_r)[i] = (*m_N_r)[i - 1] + float(m_histogram[i]) * prefactor; } } -void RDF::accumulate(const std::shared_ptr neighbor_query, +void RDF::accumulate(const std::shared_ptr& neighbor_query, const vec3* query_points, unsigned int n_query_points, - std::shared_ptr nlist, + const std::shared_ptr& nlist, const freud::locality::QueryArgs& qargs) { accumulateGeneral(neighbor_query, query_points, n_query_points, nlist, qargs, diff --git a/freud/density/RDF.h b/freud/density/RDF.h index 12c9f06d7..e5064cabb 100644 --- a/freud/density/RDF.h +++ b/freud/density/RDF.h @@ -4,9 +4,12 @@ #ifndef RDF_H #define RDF_H +#include + #include "BondHistogramCompute.h" -#include "Box.h" -#include "Histogram.h" +#include "ManagedArray.h" +#include "NeighborQuery.h" +#include "VectorMath.h" /*! \file RDF.h \brief Routines for computing radial density functions. @@ -36,9 +39,9 @@ class RDF : public locality::BondHistogramCompute * in parallel on thread-local copies of the data, which are reduced into * the primary data arrays when the user requests outputs. */ - void accumulate(const std::shared_ptr neighbor_query, + void accumulate(const std::shared_ptr& neighbor_query, const vec3* query_points, unsigned int n_query_points, - std::shared_ptr nlist, + const std::shared_ptr& nlist, const freud::locality::QueryArgs& qargs); //! Reduce thread-local arrays onto the primary data arrays. diff --git a/freud/density/SphereVoxelization.cc b/freud/density/SphereVoxelization.cc index a03aa5a61..68b3af6bd 100644 --- a/freud/density/SphereVoxelization.cc +++ b/freud/density/SphereVoxelization.cc @@ -1,10 +1,15 @@ // Copyright (c) 2010-2025 The Regents of the University of Michigan // This file is from the freud project, released under the BSD 3-Clause License. -#include +#include +#include #include +#include "ManagedArray.h" +#include "NeighborQuery.h" #include "SphereVoxelization.h" +#include "VectorMath.h" +#include "utils.h" /*! \file SphereVoxelization.cc \brief Routines for computing voxelized densities from spheres centered at points. @@ -22,7 +27,7 @@ SphereVoxelization::SphereVoxelization(vec3 width, float r_max) } //! Get a reference to the last computed voxels. -const std::shared_ptr> SphereVoxelization::getVoxels() const +std::shared_ptr> SphereVoxelization::getVoxels() const { return m_voxels_array; } @@ -114,7 +119,7 @@ void SphereVoxelization::compute(const std::shared_ptr& { continue; } - const float dx = ((grid_size_x * static_cast(i)) + (grid_size_x / 2.0f) + const float dx = ((grid_size_x * static_cast(i)) + (grid_size_x / 2.0F) - point.x - (Lx / float(2.0))); // Calculate the distance from the particle to the grid cell diff --git a/freud/density/SphereVoxelization.h b/freud/density/SphereVoxelization.h index d5f48aefc..430503057 100644 --- a/freud/density/SphereVoxelization.h +++ b/freud/density/SphereVoxelization.h @@ -48,7 +48,7 @@ class SphereVoxelization void compute(const std::shared_ptr& neighbor_query); //! Get a reference to the last computed voxels. - const std::shared_ptr> getVoxels() const; + std::shared_ptr> getVoxels() const; vec3 getWidth() const; diff --git a/freud/density/export-CorrelationFunction.cc b/freud/density/export-CorrelationFunction.cc index 4cd91242e..a393bb45e 100644 --- a/freud/density/export-CorrelationFunction.cc +++ b/freud/density/export-CorrelationFunction.cc @@ -1,11 +1,12 @@ // Copyright (c) 2010-2025 The Regents of the University of Michigan // This file is from the freud project, released under the BSD 3-Clause License. +#include #include #include #include -#include -#include +#include // NOLINT(misc-include-cleaner): used implicitly +#include // NOLINT(misc-include-cleaner): used implicitly #include "CorrelationFunction.h" #include "NeighborList.h" @@ -21,7 +22,7 @@ namespace wrap { // Wrapper function for accumulate void accumulateCF(const std::shared_ptr& self, - const std::shared_ptr neighbor_query, + const std::shared_ptr& neighbor_query, const nb_array, nanobind::shape<-1>>& values, const nb_array>& query_points, const nb_array, nanobind::shape<-1>>& query_values, diff --git a/freud/density/export-GaussianDensity.cc b/freud/density/export-GaussianDensity.cc index cab0d0f62..8be94399d 100644 --- a/freud/density/export-GaussianDensity.cc +++ b/freud/density/export-GaussianDensity.cc @@ -6,10 +6,7 @@ #include #include // NOLINT(misc-include-cleaner): used implicitly -#include - #include "GaussianDensity.h" -#include "NeighborList.h" #include "NeighborQuery.h" #include "VectorMath.h" @@ -25,7 +22,7 @@ std::shared_ptr make_gaussian_density(unsigned int width_x, uns return std::make_shared(vec3(width_x, width_y, width_z), r_max, sigma); } -nanobind::tuple get_width(std::shared_ptr self) +nanobind::tuple get_width(const std::shared_ptr& self) { auto width = self->getWidth(); return nanobind::make_tuple(width.x, width.y, width.z); diff --git a/freud/density/export-LocalDensity.cc b/freud/density/export-LocalDensity.cc index 5aeb5c009..fa92ab3a9 100644 --- a/freud/density/export-LocalDensity.cc +++ b/freud/density/export-LocalDensity.cc @@ -6,9 +6,10 @@ #include #include // NOLINT(misc-include-cleaner): used implicitly -#include - #include "LocalDensity.h" +#include "NeighborList.h" +#include "NeighborQuery.h" +#include "VectorMath.h" namespace freud { namespace density { diff --git a/freud/density/export-SphereVoxelization.cc b/freud/density/export-SphereVoxelization.cc index 519916c91..c1ad3002d 100644 --- a/freud/density/export-SphereVoxelization.cc +++ b/freud/density/export-SphereVoxelization.cc @@ -5,9 +5,8 @@ #include #include // NOLINT(misc-include-cleaner): used implicitly -#include - #include "SphereVoxelization.h" +#include "VectorMath.h" namespace freud { namespace density { @@ -18,7 +17,7 @@ std::shared_ptr make_sphere_voxelization(unsigned int width_ return std::make_shared(vec3(width_x, width_y, width_z), r_max); } -nanobind::tuple get_width(std::shared_ptr self) +nanobind::tuple get_width(const std::shared_ptr& self) { auto width = self->getWidth(); return nanobind::make_tuple(width.x, width.y, width.z);