Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace reduce(hcat, ...) by stack(...) #1159

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace reduce(hcat, ...) by stack(...)
juliohm committed Jan 14, 2025
commit 4e1c3642c6901457a9414a1e623431be9f613841
2 changes: 1 addition & 1 deletion src/transforms/smoothing.jl
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ function _smooth(mesh, L, n, λ, μ; revert=false)
points = eachvertex(mesh)

# matrix with coordinates (nvertices x ndims)
X = reduce(hcat, to.(points)) |> transpose
X = stack(to, points, dims=1)

# choose between apply and revert mode
λ₁, λ₂ = revert ? (-μ, -λ) : (λ, μ)
2 changes: 1 addition & 1 deletion src/utils/misc.jl
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ See <https://math.stackexchange.com/a/99317>.
function svdbasis(p::AbstractVector{<:Point})
checkdim(first(p), 3)
ℒ = lentype(eltype(p))
X = reduce(hcat, to.(p))
X = stack(to, p)
μ = sum(X, dims=2) / size(X, 2)
Z = X .- μ
U = usvd(Z).U
8 changes: 4 additions & 4 deletions test/partitioning.jl
Original file line number Diff line number Diff line change
@@ -152,8 +152,8 @@ end
# all points in p1 are below those in p2
pts1 = [centroid(p1, i) for i in 1:nelements(p1)]
pts2 = [centroid(p2, i) for i in 1:nelements(p2)]
X1 = reduce(hcat, to.(pts1))
X2 = reduce(hcat, to.(pts2))
X1 = stack(to, pts1)
X2 = stack(to, pts2)
M1 = maximum(X1, dims=2)
m2 = minimum(X2, dims=2)
@test all(X1[2, j] < m2[2] for j in 1:size(X1, 2))
@@ -185,8 +185,8 @@ end
# all points in p1 are to the left of p2
pts1 = [centroid(p1, i) for i in 1:nelements(p1)]
pts2 = [centroid(p2, i) for i in 1:nelements(p2)]
X1 = reduce(hcat, to.(pts1))
X2 = reduce(hcat, to.(pts2))
X1 = stack(to, pts1)
X2 = stack(to, pts2)
M1 = maximum(X1, dims=2)
m2 = minimum(X2, dims=2)
@test all(X1[1, j] < m2[1] for j in 1:size(X1, 2))