Skip to content

Commit

Permalink
clang-tidy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander committed Feb 7, 2025
1 parent 8688f8e commit a53fa1c
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 42 deletions.
14 changes: 10 additions & 4 deletions freud/density/CorrelationFunction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
// This file is from the freud project, released under the BSD 3-Clause License.

#include <complex>
#include <cstddef>
#include <memory>
#include <stdexcept>
#ifdef __SSE2__
#include <emmintrin.h>
#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.
Expand Down Expand Up @@ -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];
}
Expand All @@ -71,10 +77,10 @@ inline double product(double x, double y)
return x * y;
}

void CorrelationFunction::accumulate(std::shared_ptr<freud::locality::NeighborQuery> neighbor_query,
void CorrelationFunction::accumulate(const std::shared_ptr<freud::locality::NeighborQuery>& neighbor_query,
const std::complex<double>* values, const vec3<float>* query_points,
const std::complex<double>* query_values, unsigned int n_query_points,
std::shared_ptr<freud::locality::NeighborList> nlist,
const std::shared_ptr<freud::locality::NeighborList>& nlist,
const freud::locality::QueryArgs& qargs)
{
accumulateGeneral(
Expand Down
9 changes: 5 additions & 4 deletions freud/density/CorrelationFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#ifndef CORRELATION_FUNCTION_H
#define CORRELATION_FUNCTION_H

#include <complex>
#include <memory>

#include "BondHistogramCompute.h"
#include "Box.h"
#include "Histogram.h"
#include "ManagedArray.h"
#include "NeighborList.h"
#include "NeighborQuery.h"
#include "VectorMath.h"
#include <complex>

/*! \file CorrelationFunction.h
\brief Generic pairwise correlation functions.
Expand Down Expand Up @@ -57,10 +58,10 @@ class CorrelationFunction : public locality::BondHistogramCompute
void reset() override;

//! accumulate the correlation function
void accumulate(std::shared_ptr<freud::locality::NeighborQuery> neighbor_query,
void accumulate(const std::shared_ptr<freud::locality::NeighborQuery>& neighbor_query,
const std::complex<double>* values, const vec3<float>* query_points,
const std::complex<double>* query_values, unsigned int n_query_points,
std::shared_ptr<freud::locality::NeighborList> nlist,
const std::shared_ptr<freud::locality::NeighborList>& nlist,
const freud::locality::QueryArgs& qargs);

//! \internal
Expand Down
21 changes: 15 additions & 6 deletions freud/density/GaussianDensity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
// This file is from the freud project, released under the BSD 3-Clause License.

#include <cmath>
#include <cstddef>
#include <memory>
#include <stdexcept>
#include <vector>

#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.
Expand Down Expand Up @@ -87,11 +96,11 @@ void GaussianDensity::compute(const freud::locality::NeighborQuery* nq, const fl
for (size_t idx = begin; idx < end; ++idx)
{
const vec3<float> 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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion freud/density/GaussianDensity.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Box.h"
#include "ManagedArray.h"
#include "NeighborQuery.h"
#include "ThreadStorage.h"
#include "VectorMath.h"

/*! \file GaussianDensity.h
Expand Down
11 changes: 11 additions & 0 deletions freud/density/LocalDensity.cc
Original file line number Diff line number Diff line change
@@ -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 <cstddef>
#include <math.h> // NOLINT(modernize-deprecated-headers): Use std::numbers when c++20 is default.
#include <memory>
#include <stdexcept>
#include <vector>

#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.
Expand Down
4 changes: 3 additions & 1 deletion freud/density/LocalDensity.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#ifndef LOCAL_DENSITY_H
#define LOCAL_DENSITY_H

#include <memory>

#include "Box.h"
#include "ManagedArray.h"
#include "NeighborList.h"
Expand Down Expand Up @@ -53,7 +55,7 @@ class LocalDensity
const freud::locality::QueryArgs& qargs);

//! Get a shared pointer to the last computed density
const std::shared_ptr<util::ManagedArray<float>> getDensity() const
std::shared_ptr<const util::ManagedArray<float>> getDensity() const
{
return m_density_array;
}
Expand Down
19 changes: 13 additions & 6 deletions freud/density/RDF.cc
Original file line number Diff line number Diff line change
@@ -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 <cstddef>
#include <math.h> // NOLINT(modernize-deprecated-headers): Use std::numbers when c++20 is default.
#include <memory>
#include <stdexcept>
#include <vector>

#include "BondHistogramCompute.h"
#include "Histogram.h"
#include "NeighborBond.h"
#include "RDF.h"

/*! \file RDF.cc
Expand Down Expand Up @@ -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<util::ManagedArray<float>>(std::vector<size_t> {bins, bins});
m_vol_array3D = std::make_shared<util::ManagedArray<float>>(std::vector<size_t> {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<float> bin_boundaries = getBinEdges()[0];

for (unsigned int i = 0; i < bins; i++)
Expand Down Expand Up @@ -74,22 +81,22 @@ void RDF::reduce()

std::shared_ptr<util::ManagedArray<float>> 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<float>(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<freud::locality::NeighborQuery> neighbor_query,
void RDF::accumulate(const std::shared_ptr<freud::locality::NeighborQuery>& neighbor_query,
const vec3<float>* query_points, unsigned int n_query_points,
std::shared_ptr<freud::locality::NeighborList> nlist,
const std::shared_ptr<freud::locality::NeighborList>& nlist,
const freud::locality::QueryArgs& qargs)
{
accumulateGeneral(neighbor_query, query_points, n_query_points, nlist, qargs,
Expand Down
11 changes: 7 additions & 4 deletions freud/density/RDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#ifndef RDF_H
#define RDF_H

#include <memory>

#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.
Expand Down Expand Up @@ -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<freud::locality::NeighborQuery> neighbor_query,
void accumulate(const std::shared_ptr<freud::locality::NeighborQuery>& neighbor_query,
const vec3<float>* query_points, unsigned int n_query_points,
std::shared_ptr<freud::locality::NeighborList> nlist,
const std::shared_ptr<freud::locality::NeighborList>& nlist,
const freud::locality::QueryArgs& qargs);

//! Reduce thread-local arrays onto the primary data arrays.
Expand Down
11 changes: 8 additions & 3 deletions freud/density/SphereVoxelization.cc
Original file line number Diff line number Diff line change
@@ -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 <cmath>
#include <cstddef>
#include <memory>
#include <stdexcept>

#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.
Expand All @@ -22,7 +27,7 @@ SphereVoxelization::SphereVoxelization(vec3<unsigned int> width, float r_max)
}

//! Get a reference to the last computed voxels.
const std::shared_ptr<util::ManagedArray<unsigned int>> SphereVoxelization::getVoxels() const
std::shared_ptr<const util::ManagedArray<unsigned int>> SphereVoxelization::getVoxels() const
{
return m_voxels_array;
}
Expand Down Expand Up @@ -114,7 +119,7 @@ void SphereVoxelization::compute(const std::shared_ptr<locality::NeighborQuery>&
{
continue;
}
const float dx = ((grid_size_x * static_cast<float>(i)) + (grid_size_x / 2.0f)
const float dx = ((grid_size_x * static_cast<float>(i)) + (grid_size_x / 2.0F)
- point.x - (Lx / float(2.0)));

// Calculate the distance from the particle to the grid cell
Expand Down
2 changes: 1 addition & 1 deletion freud/density/SphereVoxelization.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SphereVoxelization
void compute(const std::shared_ptr<locality::NeighborQuery>& neighbor_query);

//! Get a reference to the last computed voxels.
const std::shared_ptr<util::ManagedArray<unsigned int>> getVoxels() const;
std::shared_ptr<const util::ManagedArray<unsigned int>> getVoxels() const;

vec3<unsigned int> getWidth() const;

Expand Down
7 changes: 4 additions & 3 deletions freud/density/export-CorrelationFunction.cc
Original file line number Diff line number Diff line change
@@ -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 <complex>
#include <memory>
#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/shared_ptr.h>
#include <nanobind/stl/vector.h>
#include <nanobind/stl/shared_ptr.h> // NOLINT(misc-include-cleaner): used implicitly
#include <nanobind/stl/vector.h> // NOLINT(misc-include-cleaner): used implicitly

#include "CorrelationFunction.h"
#include "NeighborList.h"
Expand All @@ -21,7 +22,7 @@ namespace wrap {

// Wrapper function for accumulate
void accumulateCF(const std::shared_ptr<CorrelationFunction>& self,
const std::shared_ptr<locality::NeighborQuery> neighbor_query,
const std::shared_ptr<locality::NeighborQuery>& neighbor_query,
const nb_array<std::complex<double>, nanobind::shape<-1>>& values,
const nb_array<float, nanobind::shape<-1, 3>>& query_points,
const nb_array<std::complex<double>, nanobind::shape<-1>>& query_values,
Expand Down
5 changes: 1 addition & 4 deletions freud/density/export-GaussianDensity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
#include <nanobind/ndarray.h>
#include <nanobind/stl/shared_ptr.h> // NOLINT(misc-include-cleaner): used implicitly

#include <utility>

#include "GaussianDensity.h"
#include "NeighborList.h"
#include "NeighborQuery.h"
#include "VectorMath.h"

Expand All @@ -25,7 +22,7 @@ std::shared_ptr<GaussianDensity> make_gaussian_density(unsigned int width_x, uns
return std::make_shared<GaussianDensity>(vec3<unsigned int>(width_x, width_y, width_z), r_max, sigma);
}

nanobind::tuple get_width(std::shared_ptr<GaussianDensity> self)
nanobind::tuple get_width(const std::shared_ptr<GaussianDensity>& self)
{
auto width = self->getWidth();
return nanobind::make_tuple(width.x, width.y, width.z);
Expand Down
5 changes: 3 additions & 2 deletions freud/density/export-LocalDensity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include <nanobind/ndarray.h>
#include <nanobind/stl/shared_ptr.h> // NOLINT(misc-include-cleaner): used implicitly

#include <utility>

#include "LocalDensity.h"
#include "NeighborList.h"
#include "NeighborQuery.h"
#include "VectorMath.h"

namespace freud { namespace density {

Expand Down
5 changes: 2 additions & 3 deletions freud/density/export-SphereVoxelization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
#include <nanobind/nanobind.h>
#include <nanobind/stl/shared_ptr.h> // NOLINT(misc-include-cleaner): used implicitly

#include <utility>

#include "SphereVoxelization.h"
#include "VectorMath.h"

namespace freud { namespace density {

Expand All @@ -18,7 +17,7 @@ std::shared_ptr<SphereVoxelization> make_sphere_voxelization(unsigned int width_
return std::make_shared<SphereVoxelization>(vec3<unsigned int>(width_x, width_y, width_z), r_max);
}

nanobind::tuple get_width(std::shared_ptr<SphereVoxelization> self)
nanobind::tuple get_width(const std::shared_ptr<SphereVoxelization>& self)
{
auto width = self->getWidth();
return nanobind::make_tuple(width.x, width.y, width.z);
Expand Down

0 comments on commit a53fa1c

Please sign in to comment.