Skip to content

Commit

Permalink
update transform_reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
elalish committed Jun 18, 2024
1 parent a86ebaa commit 934e9c5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
19 changes: 9 additions & 10 deletions src/manifold/src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,8 @@ void Manifold::Impl::CalculateBBox() {
*/
bool Manifold::Impl::IsFinite() const {
auto policy = autoPolicy(NumVert());
return transform_reduce<bool>(policy, vertPos_.begin(), vertPos_.end(),
FiniteVert(), true,
thrust::logical_and<bool>());
return transform_reduce<bool>(policy, vertPos_.begin(), vertPos_.end(), true,
thrust::logical_and<bool>(), FiniteVert());
}

/**
Expand All @@ -408,11 +407,11 @@ bool Manifold::Impl::IsFinite() const {
*/
bool Manifold::Impl::IsIndexInBounds(VecView<const glm::ivec3> triVerts) const {
auto policy = autoPolicy(triVerts.size());
glm::ivec2 minmax = transform_reduce<glm::ivec2>(
policy, triVerts.begin(), triVerts.end(), MakeMinMax(),
glm::ivec2(std::numeric_limits<int>::max(),
std::numeric_limits<int>::min()),
MinMax());
glm::ivec2 minmax =
transform_reduce<glm::ivec2>(policy, triVerts.begin(), triVerts.end(),
glm::ivec2(std::numeric_limits<int>::max(),
std::numeric_limits<int>::min()),
MinMax(), MakeMinMax());

return minmax[0] >= 0 && minmax[1] < NumVert();
}
Expand Down Expand Up @@ -441,6 +440,7 @@ float Manifold::Impl::MinGap(const Manifold::Impl& other,
float minDistanceSquared = transform_reduce<float>(
autoPolicy(collisions.size()), thrust::counting_iterator<int>(0),
thrust::counting_iterator<int>(collisions.size()),
searchLength * searchLength, thrust::minimum<float>(),
[&collisions, this, &other](int i) {
const int tri = collisions.Get(i, 1);
const int triOther = collisions.Get(i, 0);
Expand All @@ -454,8 +454,7 @@ float Manifold::Impl::MinGap(const Manifold::Impl& other,
}

return DistanceTriangleTriangleSquared(p, q);
},
searchLength * searchLength, thrust::minimum<float>());
});

return sqrt(minDistanceSquared);
};
Expand Down
4 changes: 2 additions & 2 deletions src/manifold/src/sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,10 @@ bool MeshGL::Merge() {
strided_range<Vec<float>::Iter> iPos(vertPropD.begin() + i, vertPropD.end(),
numProp);
auto minMax = transform_reduce<thrust::pair<float, float>>(
autoPolicy(numVert), iPos.begin(), iPos.end(), Duplicate(),
autoPolicy(numVert), iPos.begin(), iPos.end(),
thrust::make_pair(std::numeric_limits<float>::infinity(),
-std::numeric_limits<float>::infinity()),
MinMax());
MinMax(), Duplicate());
bBox.min[i] = minMax.first;
bBox.max[i] = minMax.second;
}
Expand Down
5 changes: 2 additions & 3 deletions src/polygon/src/polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ bool IsConvex(const PolygonsIdx &polys, float precision) {
*/
std::vector<glm::ivec3> TriangulateConvex(const PolygonsIdx &polys) {
const int numTri = transform_reduce<int>(
autoPolicy(polys.size()), polys.begin(), polys.end(),
[](const SimplePolygonIdx &poly) { return poly.size() - 2; }, 0,
thrust::plus<int>());
autoPolicy(polys.size()), polys.begin(), polys.end(), 0, std::plus(),
[](const SimplePolygonIdx &poly) { return poly.size() - 2; });
std::vector<glm::ivec3> triangles;
triangles.reserve(numTri);
for (const SimplePolygonIdx &poly : polys) {
Expand Down
17 changes: 9 additions & 8 deletions src/utilities/include/par.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,15 @@ template <typename DerivedPolicy, typename InputIterator1,
OutputIterator copy_if(ExecutionPolicy policy, InputIterator1 first,
InputIterator1 last, OutputIterator result,
Predicate pred) {
#if MANIFOLD_PAR == 'T'
if (policy == ExecutionPolicy::Seq)
return std::copy_if(first, last, result, pred);
else
return std::copy_if(std::execution::par_unseq, first, last, result, pred);
#else
// #if MANIFOLD_PAR == 'T'
// if (policy == ExecutionPolicy::Seq)
// return std::copy_if(first, last, result, pred);
// else
// return std::copy_if(std::execution::par_unseq, first, last, result,
// pred);
// #else
return std::copy_if(first, last, result, pred);
#endif
// #endif
}

template <typename T>
Expand Down Expand Up @@ -197,7 +198,7 @@ STL_DYNAMIC_BACKEND_VOID(copy_n)

// void implies that the user have to specify the return type in the template
// argument, as we are unable to deduce it
THRUST_DYNAMIC_BACKEND(transform_reduce, void)
STL_DYNAMIC_BACKEND(transform_reduce, void)
THRUST_DYNAMIC_BACKEND(reduce_by_key, void)
STL_DYNAMIC_BACKEND(remove, void)
STL_DYNAMIC_BACKEND(find, void)
Expand Down

0 comments on commit 934e9c5

Please sign in to comment.