Skip to content

Conversation

@palday
Copy link
Member

@palday palday commented Aug 19, 2025

fixes #326

function StatsAPI.coefnames(C::AbstractContrasts, levels::AbstractVector{Bool}, baseind::Integer)
not_base = [1:(baseind-1); (baseind+1):length(levels)]
# broadcasted DataAPI.unwrap converts Vector{Bool} to BitVector
convert(Vector{Bool}, DataAPI.unwrap.(levels[not_base]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how this compares in terms of performance to something like

Bool[DataAPI.unwrap(level) for (i, level) in pairs(level) if i != baseind]

or perhaps

Bool[DataAPI.unwrap(@inbounds levels[i])
     for i in Iterators.flatten((firstindex(levels):(baseind - 1),
                                 (baseind + 1):lastindex(levels)))]

luv 2 micro-optimize

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is your performance bottleneck ... 😂

@palday palday requested a review from ararslan August 20, 2025 16:58

# We need an explicit method for `AbstractVector{Bool}` to avoid an ambiguity
StatsAPI.coefnames(C::HypothesisCoding, levels::AbstractVector{Bool}, baseind::Int) =
something(C.labels, DataAPI.unwrap.(levels[1:length(levels) .!= baseind]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether it's worth using invoke to avoid duplicating the method body?

Suggested change
something(C.labels, DataAPI.unwrap.(levels[1:length(levels) .!= baseind]))
invoke(coefnames, Tuple{HypothesisCoding,AbstractVector,Int}, C, levels, baseind)

Probably doesn't really matter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I'll consider that next time, going with the "no change" lazy and fast option for now 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very reasonable

@palday palday merged commit ad89c67 into master Aug 20, 2025
7 of 8 checks passed
@palday palday deleted the pa/bitvector branch August 20, 2025 17:04
@ararslan
Copy link
Member

Hmm, is the nightly CI failure related?

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.

Missing methods with v0.7.5 but not on 0.7.4

3 participants