Skip to content

Use default getindex for vector[face] when no Polytope is generated #246

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

Merged
merged 7 commits into from
Mar 24, 2025

Conversation

ffreyer
Copy link
Collaborator

@ffreyer ffreyer commented Mar 7, 2025

This allows things like f[f .== 1]

@SimonDanisch
Copy link
Member

That seems pretty breaking to me!

@ffreyer
Copy link
Collaborator Author

ffreyer commented Mar 10, 2025

The only thing that changes is that a tuple becomes a Vector

@ffreyer ffreyer changed the title Use default getindex when not generating Polytopes Use default getindex for vector[face] when no Polytope is generated Mar 10, 2025
@SimonDanisch
Copy link
Member

But that code path is usually used in high performance situations (e.g. iterating over all face indices)...
I think this could have quite the impact to use vectors there...
Maybe we can return a FixedVector{Bool} instead? I guess that should have the same indexing behaviour as vector.

@SimonDanisch
Copy link
Member

Ok, I think this is the right approach to fix #249 and #247
We also need to remove:

@propagate_inbounds function Base.getindex(points::AbstractVector{P}, face::F) where {P<: Point, F <: AbstractFace}
    return Polytope(P, F)(map(i-> points[i], face.data))
end

@propagate_inbounds function Base.getindex(elements::AbstractVector, face::F) where {F <: AbstractFace}
    return map(i-> elements[i], face.data)
end

Looks like that was the behaviour before, and I dont see a good reason why whe should deviate from the previous behavior.

@SimonDanisch
Copy link
Member

I guess the tests should be:

f = QuadFace{Int64}(1,2,3,4) # Some face
@test f[f.!=3]  isa AbstractVector{Int} # [email protected] had Vector, but maybe SVector would be better here
V = Point{3, Float64}[[-1.0, -1.0, -1.0], [-1.0, 1.0, -1.0], [1.0, 1.0, -1.0], [1.0, -1.0, -1.0]]
@test V[f] isa typeof(V) # 0.4 returned Vector

@Kevin-Mattheus-Moerman
Copy link
Contributor

@ffreyer yep this seems to fix those issues, thanks!

  • Using faces to index into point vectors no longer produces point vectors #247 is fully fixed.
  • The core issue in Breaking behaviour change relating to using Boolean operations on faces #249 i.e. allowing for f[f.!=3] on faces, is fixed.
    A side note is that if we have f = QuadFace{Int64}(1,2,3,4) then f.!=3 still returns the odd creature that is a QuadFace{Bool}. Similarly for a Point{3,Float} by the name of v this v.<0.5 returns a Point3{Bool}. Both these face/point types seem to never actually represent a valid face or point in any way. For my projects this is not breaking anything but it does seem like perhaps these things should return some kind of static vector containing Bools? Again this doesn't break anything, and perhaps you have good reasons for keeping it.

@SimonDanisch
Copy link
Member

We decided to keep it like this for now to just recover the old behaviour as quickly as possible..
I agree, that this should in the future rather return an SVector, but we didn't like to get into a bigger refactor, this may entail.
Although since QuadFace is an SVector in disguise, it probably would be relatively quick to change.

@ffreyer ffreyer merged commit dc103e8 into master Mar 24, 2025
14 checks passed
@ffreyer ffreyer deleted the ff/face-getindex branch March 24, 2025 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Breaking behaviour change relating to using Boolean operations on faces Using faces to index into point vectors no longer produces point vectors
3 participants