Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 25, 2024
1 parent a578b69 commit b98a307
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 88 deletions.
3 changes: 2 additions & 1 deletion CMake/freud-macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function(target_set_install_rpath _target)
endif()

if(_using_conda OR DEFINED ENV{CIBUILDWHEEL})
set_target_properties(${_target} PROPERTIES INSTALL_RPATH_USE_LINK_PATH True)
set_target_properties(${_target} PROPERTIES INSTALL_RPATH_USE_LINK_PATH
True)
endif()
endfunction()
12 changes: 4 additions & 8 deletions cpp/box/export_Box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,31 @@ namespace nb = nanobind;

namespace freud { namespace box { namespace wrap {

void makeAbsolute(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<float> out)
void makeAbsolute(const std::shared_ptr<Box>& box, nb_array<float> vecs, nb_array<float> out)
{
unsigned int Nvecs = vecs.shape(0);
auto* vecs_data = reinterpret_cast<vec3<float>*>(vecs.data());
auto* out_data = reinterpret_cast<vec3<float>*>(out.data());
box->makeAbsolute(vecs_data, Nvecs, out_data);
}

void makeFractional(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<float> out)
void makeFractional(const std::shared_ptr<Box>& box, nb_array<float> vecs, nb_array<float> out)
{
unsigned int Nvecs = vecs.shape(0);
auto* vecs_data = reinterpret_cast<vec3<float>*>(vecs.data());
auto* out_data = reinterpret_cast<vec3<float>*>(out.data());
box->makeFractional(vecs_data, Nvecs, out_data);
}

void getImages(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<int> images)
void getImages(const std::shared_ptr<Box>& box, nb_array<float> vecs, nb_array<int> images)
{
const unsigned int Nvecs = vecs.shape(0);
auto* vecs_data = reinterpret_cast<vec3<float>*>(vecs.data());
auto* images_data = reinterpret_cast<vec3<int>*>(images.data());
box->getImages(vecs_data, Nvecs, images_data);
}

void wrap(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<float> out)
void wrap(const std::shared_ptr<Box>& box, nb_array<float> vecs, nb_array<float> out)
{
const unsigned int Nvecs = vecs.shape(0);
auto* vecs_data = reinterpret_cast<vec3<float>*>(vecs.data());
Expand Down
24 changes: 9 additions & 15 deletions cpp/box/export_Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,26 @@ namespace freud { namespace box { namespace wrap {
template<typename T, typename shape = nanobind::shape<-1, 3>>
using nb_array = nanobind::ndarray<T, shape, nanobind::device::cpu, nanobind::c_contig>;

void makeAbsolute(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<float> out);
void makeAbsolute(const std::shared_ptr<Box>& box, nb_array<float> vecs, nb_array<float> out);

void makeFractional(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<float> out);
void makeFractional(const std::shared_ptr<Box>& box, nb_array<float> vecs, nb_array<float> out);

void getImages(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<int> images);
void getImages(const std::shared_ptr<Box>& box, nb_array<float> vecs, nb_array<int> images);

void wrap(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<float> out);
void wrap(const std::shared_ptr<Box>& box, nb_array<float> vecs, nb_array<float> out);

void unwrap(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<int> images, nb_array<float> out);
void unwrap(const std::shared_ptr<Box>& box, nb_array<float> vecs, nb_array<int> images, nb_array<float> out);

std::vector<float> centerOfMass(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<float, nanobind::shape<-1>> masses);

void center(const std::shared_ptr<Box>& box, nb_array<float> vecs,
nb_array<float, nanobind::ndim<1>> masses);
void center(const std::shared_ptr<Box>& box, nb_array<float> vecs, nb_array<float, nanobind::ndim<1>> masses);

void computeDistances(const std::shared_ptr<Box>& box, nb_array<float> query_points,
nb_array<float> points, nb_array<float, nanobind::ndim<1>> distances);
void computeDistances(const std::shared_ptr<Box>& box, nb_array<float> query_points, nb_array<float> points,
nb_array<float, nanobind::ndim<1>> distances);

void computeAllDistances(const std::shared_ptr<Box>& box, nb_array<float> query_points,
nb_array<float> points, nb_array<float, nanobind::ndim<2>> distances);
nb_array<float> points, nb_array<float, nanobind::ndim<2>> distances);

void contains(const std::shared_ptr<Box>& box, nb_array<float> points,
nb_array<bool, nanobind::ndim<1>> contains_mask);
Expand Down
7 changes: 2 additions & 5 deletions cpp/locality/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
set(locality_extension_sources
export_NeighborQuery.cc
export_NeighborList.cc
export_Filter.cc
export_PeriodicBuffer.cc
export_Voronoi.cc)
export_NeighborQuery.cc export_NeighborList.cc export_Filter.cc
export_PeriodicBuffer.cc export_Voronoi.cc)

# create the target and add the needed properties
nanobind_add_module(_locality SHARED module-locality.cc
Expand Down
2 changes: 1 addition & 1 deletion cpp/locality/PeriodicBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#ifndef PERIODIC_BUFFER_H
#define PERIODIC_BUFFER_H

#include <vector>
#include <array>
#include <vector>

#include "Box.h"
#include "NeighborQuery.h"
Expand Down
6 changes: 2 additions & 4 deletions cpp/locality/export_Filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ namespace freud { namespace locality {

namespace wrap {

void compute(std::shared_ptr<Filter> filter, std::shared_ptr<NeighborQuery> nq,
nb_array<float> query_points, std::shared_ptr<NeighborList> nlist,
const QueryArgs& qargs)
void compute(std::shared_ptr<Filter> filter, std::shared_ptr<NeighborQuery> nq, nb_array<float> query_points,
std::shared_ptr<NeighborList> nlist, const QueryArgs& qargs)
{
const auto num_query_points = query_points.shape(0);
const auto* query_points_data = (vec3<float>*) query_points.data();
Expand Down Expand Up @@ -48,4 +47,3 @@ void export_FilterSANN(nb::module_& m)
}; // namespace detail

}; }; // namespace freud::locality

5 changes: 2 additions & 3 deletions cpp/locality/export_Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ namespace wrap {
template<typename T, typename shape = nanobind::shape<-1, 3>>
using nb_array = nanobind::ndarray<T, shape, nanobind::device::cpu, nanobind::c_contig>;

void compute(std::shared_ptr<Filter> filter, std::shared_ptr<NeighborQuery> nq,
nb_array<float> query_points, std::shared_ptr<NeighborList> nlist,
const QueryArgs& qargs);
void compute(std::shared_ptr<Filter> filter, std::shared_ptr<NeighborQuery> nq, nb_array<float> query_points,
std::shared_ptr<NeighborList> nlist, const QueryArgs& qargs);

}; // namespace wrap

Expand Down
6 changes: 2 additions & 4 deletions cpp/locality/export_NeighborList.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ void ConstructFromArrays(NeighborList* nlist, nb_array<unsigned int, nb::ndim<1>
num_points, vectors_data, weights_data);
}

void ConstructAllPairs(NeighborList* nlist, nb_array<float> points,
nb_array<float> query_points, const box::Box& box,
const bool exclude_ii)
void ConstructAllPairs(NeighborList* nlist, nb_array<float> points, nb_array<float> query_points,
const box::Box& box, const bool exclude_ii)
{
const unsigned int num_points = points.shape(0);
const auto* points_data = (const vec3<float>*) points.data();
Expand Down Expand Up @@ -88,4 +87,3 @@ void export_NeighborBond(nb::module_& m)
}; // namespace detail

}; }; // namespace freud::locality

11 changes: 5 additions & 6 deletions cpp/locality/export_NeighborList.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ template<typename T, typename shape = nanobind::shape<-1, 3>>
using nb_array = nanobind::ndarray<T, shape, nanobind::device::cpu, nanobind::c_contig>;

void ConstructFromArrays(NeighborList* nlist, nb_array<unsigned int, nanobind::ndim<1>> query_point_indices,
unsigned int num_query_points, nb_array<unsigned int, nanobind::ndim<1>> point_indices,
unsigned int num_points, nb_array<float> vectors,
nb_array<float, nanobind::ndim<1>> weights);
unsigned int num_query_points,
nb_array<unsigned int, nanobind::ndim<1>> point_indices, unsigned int num_points,
nb_array<float> vectors, nb_array<float, nanobind::ndim<1>> weights);

void ConstructAllPairs(NeighborList* nlist, nb_array<float> points,
nb_array<float> query_points, const box::Box& box,
const bool exclude_ii);
void ConstructAllPairs(NeighborList* nlist, nb_array<float> points, nb_array<float> query_points,
const box::Box& box, const bool exclude_ii);

unsigned int filter(std::shared_ptr<NeighborList> nlist, nb_array<bool, nanobind::ndim<1>> filter);

Expand Down
7 changes: 2 additions & 5 deletions cpp/locality/export_NeighborQuery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ namespace freud { namespace locality {

namespace wrap {

std::shared_ptr<NeighborQueryIterator> query(std::shared_ptr<NeighborQuery> nq,
nb_array<float> query_points,
std::shared_ptr<NeighborQueryIterator> query(std::shared_ptr<NeighborQuery> nq, nb_array<float> query_points,
const QueryArgs& qargs)
{
unsigned int n_query_points = query_points.shape(0);
Expand All @@ -29,8 +28,7 @@ void AABBQueryConstructor(AABBQuery* nq, const box::Box& box, nb_array<float> po
new (nq) AABBQuery(box, points_data, n_points);
}

void LinkCellConstructor(LinkCell* nq, const box::Box& box, nb_array<float> points,
float cell_width)
void LinkCellConstructor(LinkCell* nq, const box::Box& box, nb_array<float> points, float cell_width)
{
unsigned int n_points = points.shape(0);
vec3<float>* points_data = (vec3<float>*) points.data();
Expand Down Expand Up @@ -98,4 +96,3 @@ void export_NeighborQueryIterator(nb::module_& m)
}; // namespace detail

}; }; // namespace freud::locality

12 changes: 4 additions & 8 deletions cpp/locality/export_NeighborQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ namespace wrap {
template<typename T, typename shape = nanobind::shape<-1, 3>>
using nb_array = nanobind::ndarray<T, shape, nanobind::device::cpu, nanobind::c_contig>;

std::shared_ptr<NeighborQueryIterator> query(std::shared_ptr<NeighborQuery> nq,
nb_array<float> query_points,
std::shared_ptr<NeighborQueryIterator> query(std::shared_ptr<NeighborQuery> nq, nb_array<float> query_points,
const QueryArgs& qargs);

void AABBQueryConstructor(AABBQuery* nq, const box::Box& box,
nb_array<float> points);
void AABBQueryConstructor(AABBQuery* nq, const box::Box& box, nb_array<float> points);

void LinkCellConstructor(LinkCell* nq, const box::Box& box,
nb_array<float> points, float cell_width);
void LinkCellConstructor(LinkCell* nq, const box::Box& box, nb_array<float> points, float cell_width);

void RawPointsConstructor(RawPoints* nq, const box::Box& box,
nb_array<float> points);
void RawPointsConstructor(RawPoints* nq, const box::Box& box, nb_array<float> points);

}; // namespace wrap

Expand Down
9 changes: 3 additions & 6 deletions cpp/locality/export_PeriodicBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

#include "export_PeriodicBuffer.h"

#include <nanobind/stl/shared_ptr.h>
#include <nanobind/stl/array.h>
#include <nanobind/stl/shared_ptr.h>

namespace nb = nanobind;

namespace freud { namespace locality {

namespace detail {
namespace freud { namespace locality { namespace detail {

void export_PeriodicBuffer(nb::module_& m)
{
Expand All @@ -23,5 +21,4 @@ void export_PeriodicBuffer(nb::module_& m)
.def("getBufferIds", &PeriodicBuffer::getBufferIds);
};

}; }; }; // namespace freud::locality::detail

}; }; }; // namespace freud::locality::detail
8 changes: 2 additions & 6 deletions cpp/locality/export_PeriodicBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@

#include <nanobind/nanobind.h>

namespace freud { namespace locality {

namespace detail {
namespace freud { namespace locality { namespace detail {

void export_PeriodicBuffer(nanobind::module_& m);

}; // namespace detail

}; }; // namespace freud::locality
}; }; }; // namespace freud::locality::detail

#endif
3 changes: 1 addition & 2 deletions cpp/locality/export_Voronoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ nb::object getPolytopes(std::shared_ptr<Voronoi> voro)
return polytopes_python;
}

};
}; // namespace wrap

namespace detail {

Expand All @@ -56,4 +56,3 @@ void export_Voronoi(nb::module_& m)
}; // namespace detail

}; }; // namespace freud::locality

4 changes: 2 additions & 2 deletions cpp/locality/export_Voronoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace detail {

void export_Voronoi(nanobind::module_& m);

}; // namespace detail
}; // namespace detail

}; }; // namespace freud::locality
}; }; // namespace freud::locality

#endif
2 changes: 1 addition & 1 deletion cpp/util/export_ManagedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ template<typename T> nanobind::ndarray<nanobind::numpy, const T> toNumpyArrayVec
return nanobind::ndarray<nanobind::numpy, const T>((void*) data_ptr, ndim, &dims[0], self);
}

}; // namespace wrap
}; // namespace wrap

namespace detail {

Expand Down
13 changes: 6 additions & 7 deletions cpp/util/export_Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <vector>
#include <string>
#include <vector>

#include "VectorMath.h"

Expand All @@ -18,7 +18,7 @@ namespace wrap {
template<typename T> nanobind::ndarray<nanobind::numpy, const T> vectorToNumpyArray(nanobind::object self)
{
std::vector<T>* self_cpp = nanobind::cast<std::vector<T>*>(self);
auto dims = { self_cpp->size() };
auto dims = {self_cpp->size()};
auto ndim = 1;
auto data_ptr = self_cpp->data();
return nanobind::ndarray<nanobind::numpy, const T>((void*) data_ptr, dims, self);
Expand All @@ -31,22 +31,21 @@ template<typename T> nanobind::ndarray<nanobind::numpy, const T> vectorToNumpyAr

// get array data like before
size_t size = self_cpp->size();
std::initializer_list<size_t> dims = { size, 3 };
std::initializer_list<size_t> dims = {size, 3};
auto ndim = 2;
auto data_ptr = self_cpp->data();

// now return the array
return nanobind::ndarray<nanobind::numpy, const T>((void*) data_ptr, dims, self);
}

}; // namespace wrap
}; // namespace wrap

namespace detail {

template<typename T> void export_Vector(nanobind::module_& m, const std::string& name)
{
nanobind::class_<std::vector<T>>(m, name.c_str())
.def("toNumpyArray", &wrap::vectorToNumpyArray<T>);
nanobind::class_<std::vector<T>>(m, name.c_str()).def("toNumpyArray", &wrap::vectorToNumpyArray<T>);
}

template<typename T> void export_VectorVec3(nanobind::module_& m, const std::string& name)
Expand All @@ -55,7 +54,7 @@ template<typename T> void export_VectorVec3(nanobind::module_& m, const std::str
.def("toNumpyArray", &wrap::vectorToNumpyArrayVec3<T>);
}

}; // namespace detail
}; // namespace detail

}; }; // namespace freud::util

Expand Down
1 change: 0 additions & 1 deletion cpp/util/module-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ NB_MODULE(_util, m)
export_Vector<double>(m, "Vector_double");
export_Vector<unsigned int>(m, "Vector_unsignedint");
export_VectorVec3<float>(m, "VectorVec3_float");

}
9 changes: 8 additions & 1 deletion freud/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
set(python_files box.py data.py errors.py locality.py parallel.py plot.py util.py)
set(python_files
box.py
data.py
errors.py
locality.py
parallel.py
plot.py
util.py)
# cluster.py density.py diffraction.py environment.py order.py pmft.py)

install(FILES ${python_files} DESTINATION freud)
8 changes: 6 additions & 2 deletions freud/locality.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,9 @@ def from_arrays(

if weights is None:
weights = np.ones(query_point_indices.shape, dtype=np.float32)
weights = freud.util._convert_array(weights, shape=query_point_indices.shape).copy()
weights = freud.util._convert_array(
weights, shape=query_point_indices.shape
).copy()

result = cls()
result._cpp_obj = freud._locality.NeighborList(
Expand Down Expand Up @@ -840,7 +842,9 @@ class _RawPoints(NeighborQuery):
def __init__(self, box, points):
# Assume valid set of arguments is passed
b = freud.util._convert_box(box)
self._points = freud.util._convert_array(points, shape=(None, 3), dtype=np.float32).copy()
self._points = freud.util._convert_array(
points, shape=(None, 3), dtype=np.float32
).copy()
self._cpp_obj = freud._locality.RawPoints(b._cpp_obj, self._points)


Expand Down

0 comments on commit b98a307

Please sign in to comment.