Skip to content

Commit

Permalink
un-template managed arraty
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-waltmann committed Jul 18, 2024
1 parent 75de26c commit 3127581
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 190 deletions.
16 changes: 8 additions & 8 deletions cpp/locality/BondHistogramCompute.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace freud { namespace locality {
* of accumulating histograms over many frames, assuming that computations must
* be performed on a per-NeighborBond basis.
*/
template<size_t Ndim> class BondHistogramCompute
class BondHistogramCompute
{
public:
//! Default constructor
Expand Down Expand Up @@ -57,7 +57,7 @@ template<size_t Ndim> class BondHistogramCompute
}

//! Get a reference to the bin counts array
std::shared_ptr<util::ManagedArray<unsigned int, Ndim>> getBinCounts()
std::shared_ptr<util::ManagedArray<unsigned int>> getBinCounts()
{
return reduceAndReturn(m_histogram.getBinCounts());
}
Expand All @@ -73,19 +73,19 @@ template<size_t Ndim> class BondHistogramCompute
//! Return the edges of bins.
/*! This vector will be of size axis.size()+1 for each axis.
*/
std::array<std::vector<float>, Ndim> getBinEdges() const
std::vector<std::vector<float>> getBinEdges() const
{
return m_histogram.getBinEdges();
}

//! Return a vector of tuples (min, max) indicating the bounds of each axis.
std::array<std::pair<float, float>, Ndim> getBounds() const
std::vector<std::pair<float, float>> getBounds() const
{
return m_histogram.getBounds();
}

//! Return a vector indicating the number of bins in each axis.
std::array<size_t, Ndim> getAxisSizes() const
std::vector<size_t> getAxisSizes() const
{
return m_histogram.getAxisSizes();
}
Expand Down Expand Up @@ -120,11 +120,11 @@ template<size_t Ndim> class BondHistogramCompute
unsigned int m_n_query_points {0}; //!< The number of query points.
bool m_reduce {true}; //!< Whether or not the histogram needs to be reduced.

util::Histogram<unsigned int, Ndim> m_histogram; //!< Histogram of interparticle distances (bond lengths).
util::Histogram<unsigned int, Ndim>::ThreadLocalHistogram
util::Histogram<unsigned int> m_histogram; //!< Histogram of interparticle distances (bond lengths).
util::Histogram<unsigned int>::ThreadLocalHistogram
m_local_histograms; //!< Thread local bin counts for TBB parallelism

using BondHistogram = util::Histogram<unsigned int, Ndim>;
using BondHistogram = util::Histogram<unsigned int>;
};

}; }; // namespace freud::locality
Expand Down
8 changes: 4 additions & 4 deletions cpp/locality/LinkCell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void LinkCell::computeCellList(const vec3<float>* points, unsigned int n_points)
{
// determine the number of cells and allocate memory
unsigned int Nc = getNumCells();
m_cell_list = util::ManagedArray<unsigned int, 1>(n_points + Nc);
m_cell_list = util::ManagedArray<unsigned int>(n_points + Nc);
m_n_points = n_points;

// initialize memory
Expand All @@ -329,8 +329,8 @@ void LinkCell::computeCellList(const vec3<float>* points, unsigned int n_points)

vec3<unsigned int> LinkCell::indexToCoord(unsigned int x) const
{
std::array<size_t, 3> coord
= util::ManagedArray<unsigned int, 3>::getMultiIndex({m_celldim.x, m_celldim.y, m_celldim.z}, x);
std::vector<size_t> coord
= util::ManagedArray<unsigned int>::getMultiIndex({m_celldim.x, m_celldim.y, m_celldim.z}, x);
// For backwards compatibility with the Index1D layout, the indices and
// the dimensions are passed in reverse to the indexer. Changing this would
// also require updating the logic in IteratorCellShell.
Expand All @@ -342,7 +342,7 @@ unsigned int LinkCell::coordToIndex(unsigned int x, unsigned int y, unsigned int
// For backwards compatibility with the Index1D layout, the indices and
// the dimensions are passed in reverse to the indexer. Changing this would
// also require updating the logic in IteratorCellShell.
return util::ManagedArray<unsigned int, 3>::getIndex(
return util::ManagedArray<unsigned int>::getIndex(
{m_celldim.z, m_celldim.y, m_celldim.x},
{static_cast<unsigned int>(z), static_cast<unsigned int>(y), static_cast<unsigned int>(x)});
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/locality/LinkCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class IteratorLinkCell
public:
IteratorLinkCell() = default;

IteratorLinkCell(const util::ManagedArray<unsigned int, 1>& cell_list, unsigned int Np, unsigned int Nc,
IteratorLinkCell(const util::ManagedArray<unsigned int>& cell_list, unsigned int Np, unsigned int Nc,
unsigned int cell)
: m_cell_list(cell_list), m_Np(Np), m_Nc(Nc)
{
Expand All @@ -75,7 +75,7 @@ class IteratorLinkCell
unsigned int begin();

private:
util::ManagedArray<unsigned int, 1> m_cell_list; //!< The cell list
util::ManagedArray<unsigned int> m_cell_list; //!< The cell list
unsigned int m_Np {0}; //!< Number of particles in the cell list
unsigned int m_Nc {0}; //!< Number of cells in the cell list
unsigned int m_cur_idx {LINK_CELL_TERMINATOR}; //!< Current index
Expand Down Expand Up @@ -246,7 +246,7 @@ class LinkCell : public NeighborQuery
vec3<unsigned int> m_celldim {0, 0, 0}; //!< Cell dimensions
unsigned int m_size {0}; //!< The size of cell list.

util::ManagedArray<unsigned int, 1> m_cell_list; //!< The cell list last computed
util::ManagedArray<unsigned int> m_cell_list; //!< The cell list last computed
using CellNeighbors = tbb::concurrent_hash_map<unsigned int, std::vector<unsigned int>>;
mutable CellNeighbors m_cell_neighbors; //!< Hash map of cell neighbors for each cell
};
Expand Down
92 changes: 46 additions & 46 deletions cpp/locality/NeighborList.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ namespace freud { namespace locality {

NeighborList::NeighborList() : m_num_query_points(0), m_num_points(0), m_segments_counts_updated(false)
{
m_neighbors = std::make_shared<util::ManagedArray<unsigned int, 2>>();
m_distances = std::make_shared<util::ManagedArray<float, 1>>();
m_weights = std::make_shared<util::ManagedArray<float, 1>>();
m_vectors = std::make_shared<util::ManagedArray<vec3<float>, 1>>();
m_segments = std::make_shared<util::ManagedArray<unsigned int, 1>>();
m_counts = std::make_shared<util::ManagedArray<unsigned int, 1>>();
m_neighbors = std::make_shared<util::ManagedArray<unsigned int>>();
m_distances = std::make_shared<util::ManagedArray<float>>();
m_weights = std::make_shared<util::ManagedArray<float>>();
m_vectors = std::make_shared<util::ManagedArray<vec3<float>>>();
m_segments = std::make_shared<util::ManagedArray<unsigned int>>();
m_counts = std::make_shared<util::ManagedArray<unsigned int>>();
}

NeighborList::NeighborList(unsigned int num_bonds)
: m_num_query_points(0), m_num_points(0), m_segments_counts_updated(false)
{
m_neighbors = std::make_shared<util::ManagedArray<unsigned int, 2>>(std::array<size_t, 2> {num_bonds, 2});
m_distances = std::make_shared<util::ManagedArray<float, 1>>(num_bonds);
m_weights = std::make_shared<util::ManagedArray<float, 1>>(num_bonds);
m_vectors = std::make_shared<util::ManagedArray<vec3<float>, 1>>(num_bonds);
m_segments = std::make_shared<util::ManagedArray<unsigned int, 1>>();
m_counts = std::make_shared<util::ManagedArray<unsigned int, 1>>();
m_neighbors = std::make_shared<util::ManagedArray<unsigned int>>(std::vector<size_t> {num_bonds, 2});
m_distances = std::make_shared<util::ManagedArray<float>>(num_bonds);
m_weights = std::make_shared<util::ManagedArray<float>>(num_bonds);
m_vectors = std::make_shared<util::ManagedArray<vec3<float>>>(num_bonds);
m_segments = std::make_shared<util::ManagedArray<unsigned int>>();
m_counts = std::make_shared<util::ManagedArray<unsigned int>>();
}

NeighborList::NeighborList(const NeighborList& other)
Expand All @@ -44,12 +44,12 @@ NeighborList::NeighborList(unsigned int num_bonds, const unsigned int* query_poi
unsigned int num_points, const vec3<float>* vectors, const float* weights)
: m_num_query_points(num_query_points), m_num_points(num_points), m_segments_counts_updated(false)
{
m_neighbors = std::make_shared<util::ManagedArray<unsigned int, 2>>(std::array<size_t, 2> {num_bonds, 2});
m_distances = std::make_shared<util::ManagedArray<float, 1>>(num_bonds);
m_weights = std::make_shared<util::ManagedArray<float, 1>>(num_bonds);
m_vectors = std::make_shared<util::ManagedArray<vec3<float>, 1>>(num_bonds);
m_segments = std::make_shared<util::ManagedArray<unsigned int, 1>>(num_query_points);
m_counts = std::make_shared<util::ManagedArray<unsigned int, 1>>(num_query_points);
m_neighbors = std::make_shared<util::ManagedArray<unsigned int>>(std::vector<size_t> {num_bonds, 2});
m_distances = std::make_shared<util::ManagedArray<float>>(num_bonds);
m_weights = std::make_shared<util::ManagedArray<float>>(num_bonds);
m_vectors = std::make_shared<util::ManagedArray<vec3<float>>>(num_bonds);
m_segments = std::make_shared<util::ManagedArray<unsigned int>>(num_query_points);
m_counts = std::make_shared<util::ManagedArray<unsigned int>>(num_query_points);
unsigned int last_index(0);
for (unsigned int i = 0; i < num_bonds; i++)
{
Expand Down Expand Up @@ -81,12 +81,12 @@ NeighborList::NeighborList(const vec3<float>* points, const vec3<float>* query_p
const unsigned int num_ii = (exclude_ii ? std::min(num_points, num_query_points) : 0);
const unsigned int num_bonds = num_points * num_query_points - num_ii;

m_neighbors = std::make_shared<util::ManagedArray<unsigned int, 2>>(std::array<size_t, 2> {num_bonds, 2});
m_distances = std::make_shared<util::ManagedArray<float, 1>>(num_bonds);
m_weights = std::make_shared<util::ManagedArray<float, 1>>(num_bonds);
m_vectors = std::make_shared<util::ManagedArray<vec3<float>, 1>>(num_bonds);
m_segments = std::make_shared<util::ManagedArray<unsigned int, 1>>(num_query_points);
m_counts = std::make_shared<util::ManagedArray<unsigned int, 1>>(num_query_points);
m_neighbors = std::make_shared<util::ManagedArray<unsigned int>>(std::vector<size_t> {num_bonds, 2});
m_distances = std::make_shared<util::ManagedArray<float>>(num_bonds);
m_weights = std::make_shared<util::ManagedArray<float>>(num_bonds);
m_vectors = std::make_shared<util::ManagedArray<vec3<float>>>(num_bonds);
m_segments = std::make_shared<util::ManagedArray<unsigned int>>(num_query_points);
m_counts = std::make_shared<util::ManagedArray<unsigned int>>(num_query_points);

util::forLoopWrapper(0, num_query_points, [&](size_t begin, size_t end) {
for (unsigned int i = begin; i < end; ++i)
Expand Down Expand Up @@ -126,11 +126,11 @@ NeighborList::NeighborList(std::vector<NeighborBond> bonds)
MaxIndex max_idx_point = 0;

// prep arrays to populate
m_distances = std::make_shared<util::ManagedArray<float, 1>>(bonds.size());
m_vectors = std::make_shared<util::ManagedArray<vec3<float>, 1>>(bonds.size());
m_weights = std::make_shared<util::ManagedArray<float, 1>>(bonds.size());
m_distances = std::make_shared<util::ManagedArray<float>>(bonds.size());
m_vectors = std::make_shared<util::ManagedArray<vec3<float>>>(bonds.size());
m_weights = std::make_shared<util::ManagedArray<float>>(bonds.size());
m_neighbors
= std::make_shared<util::ManagedArray<unsigned int, 2>>(std::array<size_t, 2> {bonds.size(), 2});
= std::make_shared<util::ManagedArray<unsigned int>>(std::vector<size_t> {bonds.size(), 2});

// fill arrays in parallel
util::forLoopWrapper(0, bonds.size(), [&](size_t begin, size_t end) {
Expand Down Expand Up @@ -162,8 +162,8 @@ NeighborList::NeighborList(std::vector<NeighborBond> bonds)
// set num points, query points as max of thread-local maxes
m_num_points = (*std::max_element(max_idx_point.begin(), max_idx_point.end())) + 1;
m_num_query_points = (*std::max_element(max_idx_query.begin(), max_idx_query.end())) + 1;
m_segments = std::make_shared<util::ManagedArray<unsigned int, 1>>(m_num_query_points);
m_counts = std::make_shared<util::ManagedArray<unsigned int, 1>>(m_num_query_points);
m_segments = std::make_shared<util::ManagedArray<unsigned int>>(m_num_query_points);
m_counts = std::make_shared<util::ManagedArray<unsigned int>>(m_num_query_points);
m_segments_counts_updated = false;
}

Expand Down Expand Up @@ -194,8 +194,8 @@ void NeighborList::updateSegmentCounts() const
{
if (!m_segments_counts_updated)
{
m_counts = std::make_shared<util::ManagedArray<unsigned int, 1>>(m_num_query_points);
m_segments = std::make_shared<util::ManagedArray<unsigned int, 1>>(m_num_query_points);
m_counts = std::make_shared<util::ManagedArray<unsigned int>>(m_num_query_points);
m_segments = std::make_shared<util::ManagedArray<unsigned int>>(m_num_query_points);
const unsigned int INDEX_TERMINATOR(0xffffffff);
unsigned int last_index(INDEX_TERMINATOR);
unsigned int counter(0);
Expand Down Expand Up @@ -241,10 +241,10 @@ template<typename Iterator> unsigned int NeighborList::filter(Iterator begin)
// Arrays to hold filtered data - we use new arrays instead of writing over
// existing data to avoid requiring a second pass in resize().
auto new_neighbors
= std::make_shared<util::ManagedArray<unsigned int, 2>>(std::array<size_t, 2> {new_size, 2});
auto new_distances = std::make_shared<util::ManagedArray<float, 1>>(new_size);
auto new_weights = std::make_shared<util::ManagedArray<float, 1>>(new_size);
auto new_vectors = std::make_shared<util::ManagedArray<vec3<float>, 1>>(new_size);
= std::make_shared<util::ManagedArray<unsigned int>>(std::vector<size_t> {new_size, 2});
auto new_distances = std::make_shared<util::ManagedArray<float>>(new_size);
auto new_weights = std::make_shared<util::ManagedArray<float>>(new_size);
auto new_vectors = std::make_shared<util::ManagedArray<vec3<float>>>(new_size);

auto current_element = begin;
unsigned int num_good(0);
Expand Down Expand Up @@ -312,10 +312,10 @@ unsigned int NeighborList::find_first_index(unsigned int i) const
void NeighborList::resize(unsigned int num_bonds)
{
auto new_neighbors
= std::make_shared<util::ManagedArray<unsigned int, 2>>(std::array<size_t, 2> {num_bonds, 2});
auto new_distances = std::make_shared<util::ManagedArray<float, 1>>(num_bonds);
auto new_weights = std::make_shared<util::ManagedArray<float, 1>>(num_bonds);
auto new_vectors = std::make_shared<util::ManagedArray<vec3<float>, 1>>(num_bonds);
= std::make_shared<util::ManagedArray<unsigned int>>(std::vector<size_t> {num_bonds, 2});
auto new_distances = std::make_shared<util::ManagedArray<float>>(num_bonds);
auto new_weights = std::make_shared<util::ManagedArray<float>>(num_bonds);
auto new_vectors = std::make_shared<util::ManagedArray<vec3<float>>>(num_bonds);

// On shrinking resizes, keep existing data.
if (num_bonds <= getNumBonds())
Expand All @@ -342,12 +342,12 @@ void NeighborList::copy(const NeighborList& other)
m_num_query_points = other.m_num_query_points;
m_num_points = other.m_num_points;
m_segments_counts_updated = other.m_segments_counts_updated;
m_neighbors = std::make_shared<util::ManagedArray<unsigned int, 2>>(*other.m_neighbors);
m_distances = std::make_shared<util::ManagedArray<float, 1>>(*other.m_distances);
m_weights = std::make_shared<util::ManagedArray<float, 1>>(*other.m_weights);
m_vectors = std::make_shared<util::ManagedArray<vec3<float>, 1>>(*other.m_vectors);
m_segments = std::make_shared<util::ManagedArray<unsigned int, 1>>(*other.m_segments);
m_counts = std::make_shared<util::ManagedArray<unsigned int, 1>>(*other.m_counts);
m_neighbors = std::make_shared<util::ManagedArray<unsigned int>>(*other.m_neighbors);
m_distances = std::make_shared<util::ManagedArray<float>>(*other.m_distances);
m_weights = std::make_shared<util::ManagedArray<float>>(*other.m_weights);
m_vectors = std::make_shared<util::ManagedArray<vec3<float>>>(*other.m_vectors);
m_segments = std::make_shared<util::ManagedArray<unsigned int>>(*other.m_segments);
m_counts = std::make_shared<util::ManagedArray<unsigned int>>(*other.m_counts);
}

void NeighborList::validate(unsigned int num_query_points, unsigned int num_points) const
Expand Down
24 changes: 12 additions & 12 deletions cpp/locality/NeighborList.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,37 @@ class NeighborList
void updateSegmentCounts() const;

//! Access the neighbors array for reading
std::shared_ptr<util::ManagedArray<unsigned int, 2>> getNeighbors() const
std::shared_ptr<util::ManagedArray<unsigned int>> getNeighbors() const
{
return m_neighbors;
}

//! Access the distances array for reading
std::shared_ptr<util::ManagedArray<float, 1>> getDistances() const
std::shared_ptr<util::ManagedArray<float>> getDistances() const
{
return m_distances;
}

//! Access the weights array for reading
std::shared_ptr<util::ManagedArray<float, 1>> getWeights() const
std::shared_ptr<util::ManagedArray<float>> getWeights() const
{
return m_weights;
}

//! Access the vectors array for reading
std::shared_ptr<util::ManagedArray<vec3<float>, 1>> getVectors() const
std::shared_ptr<util::ManagedArray<vec3<float>>> getVectors() const
{
return m_vectors;
}

//! Access the counts array for reading
std::shared_ptr<util::ManagedArray<unsigned int, 1>> getCounts() const
std::shared_ptr<util::ManagedArray<unsigned int>> getCounts() const
{
updateSegmentCounts();
return m_counts;
}
//! Access the segments array for reading
std::shared_ptr<util::ManagedArray<unsigned int, 1>> getSegments() const
std::shared_ptr<util::ManagedArray<unsigned int>> getSegments() const
{
updateSegmentCounts();
return m_segments;
Expand Down Expand Up @@ -139,20 +139,20 @@ class NeighborList
//! Number of points
unsigned int m_num_points;
//! Neighbor list indices array
std::shared_ptr<util::ManagedArray<unsigned int, 2>> m_neighbors;
std::shared_ptr<util::ManagedArray<unsigned int>> m_neighbors;
//! Neighbor list per-bond distance array
std::shared_ptr<util::ManagedArray<float, 1>> m_distances;
std::shared_ptr<util::ManagedArray<float>> m_distances;
//! Neighbor list per-bond weight array
std::shared_ptr<util::ManagedArray<float, 1>> m_weights;
std::shared_ptr<util::ManagedArray<float>> m_weights;
//!< Directed vectors per-bond array
std::shared_ptr<util::ManagedArray<vec3<float>, 1>> m_vectors;
std::shared_ptr<util::ManagedArray<vec3<float>>> m_vectors;

//! Track whether segments and counts are up to date
mutable bool m_segments_counts_updated;
//! Neighbor counts for each query point
mutable std::shared_ptr<util::ManagedArray<unsigned int, 1>> m_counts;
mutable std::shared_ptr<util::ManagedArray<unsigned int>> m_counts;
//! Neighbor segments for each query point
mutable std::shared_ptr<util::ManagedArray<unsigned int, 1>> m_segments;
mutable std::shared_ptr<util::ManagedArray<unsigned int>> m_segments;
};

bool compareNeighborBond(const NeighborBond& left, const NeighborBond& right);
Expand Down
2 changes: 1 addition & 1 deletion cpp/locality/Voronoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void Voronoi::compute(std::shared_ptr<freud::locality::NeighborQuery> nq)
const auto n_points = nq->getNPoints();

m_polytopes.resize(n_points);
m_volumes = std::make_shared<util::ManagedArray<double, 1>>(n_points);
m_volumes = std::make_shared<util::ManagedArray<double>>(n_points);

const vec3<float> v1 = m_box.getLatticeVector(0);
const vec3<float> v2 = m_box.getLatticeVector(1);
Expand Down
4 changes: 2 additions & 2 deletions cpp/locality/Voronoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Voronoi
return m_polytopes;
}

std::shared_ptr<util::ManagedArray<double, 1>> getVolumes() const
std::shared_ptr<util::ManagedArray<double>> getVolumes() const
{
return m_volumes;
}
Expand All @@ -45,7 +45,7 @@ class Voronoi
box::Box m_box;
std::shared_ptr<NeighborList> m_neighbor_list; //!< Stored neighbor list
std::vector<std::vector<vec3<double>>> m_polytopes; //!< Voronoi polytopes
std::shared_ptr<util::ManagedArray<double, 1>> m_volumes; //!< Voronoi cell volumes
std::shared_ptr<util::ManagedArray<double>> m_volumes; //!< Voronoi cell volumes
};
}; }; // end namespace freud::locality

Expand Down
Loading

0 comments on commit 3127581

Please sign in to comment.