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

use axes() and eachindex() to better support arbitrary AbstractArray #1550

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

palday
Copy link
Member

@palday palday commented May 16, 2022

Starts the process of fixing #1265.

Other things that I saw while doing this:

  • There are times where there is a constraint on the eltype but not on the container type AbstractMatrix{Float64} or AbstractArray{Float64}.
  • I did start changing some AbstractArray to AbstractVector when it was clear that there was an implicit assumption of one dimension.
  • There are times where the container type is specified but not the eltype: Matrix{T}.

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

In general, I think it would be good to

  • not try to fix all array indexing in one PR, and
  • not to mix functional changes (new features or breaking changes) with these bug fixes.

By not trying to go through all of Distributions in one go, fixes and reviews, and hence releases, will be much quicker. Even more so since for every fix we should add a test with e.g. OffsetArrays to make sure we don't accidentally break stuff again at some point in the future.

Keeping the PR focused to these bug fixes will also make reviewing easier and avoid accidentally breaking downstream code.

src/mixtures/mixturemodel.jl Show resolved Hide resolved
src/mixtures/mixturemodel.jl Outdated Show resolved Hide resolved
src/mixtures/mixturemodel.jl Outdated Show resolved Hide resolved
src/mixtures/mixturemodel.jl Outdated Show resolved Hide resolved
src/mixtures/mixturemodel.jl Outdated Show resolved Hide resolved
src/multivariate/dirichlet.jl Outdated Show resolved Hide resolved
src/multivariate/dirichlet.jl Outdated Show resolved Hide resolved
src/multivariate/dirichlet.jl Outdated Show resolved Hide resolved
src/multivariate/dirichletmultinomial.jl Outdated Show resolved Hide resolved
src/multivariates.jl Outdated Show resolved Hide resolved
@nalimilan
Copy link
Member

@palday Any plans to finish this PR? ;-)

@palday
Copy link
Member Author

palday commented Aug 17, 2023

@nalimilan I started working on this again while other stuff was compiling and running today, but the tests -- even on master -- have both failures and errors on Julia 1.9.2 on Apple silicon.

@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2023

Codecov Report

Patch coverage: 50.00% and project coverage change: -0.01% ⚠️

Comparison is base (c664d25) 85.91% compared to head (ea1be91) 85.91%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1550      +/-   ##
==========================================
- Coverage   85.91%   85.91%   -0.01%     
==========================================
  Files         142      142              
  Lines        8579     8574       -5     
==========================================
- Hits         7371     7366       -5     
  Misses       1208     1208              
Files Changed Coverage Δ
src/multivariate/dirichlet.jl 73.00% <20.00%> (-0.31%) ⬇️
src/mixtures/mixturemodel.jl 69.74% <62.50%> (-0.30%) ⬇️
src/multivariates.jl 44.82% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nalimilan
Copy link
Member

Thanks. CI passes on x86 though so looks like we can move ahead.

src/mixtures/mixturemodel.jl Show resolved Hide resolved
@@ -334,7 +335,7 @@ function _mixlogpdf!(r::AbstractArray, d::AbstractMixtureModel, x)

# in the mean time, add log(prior) to lp and
# update the maximum for each sample
for j = 1:n
for j in eachindex(r)
Copy link
Member

Choose a reason for hiding this comment

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

This seems problematic as j is used to index into lp_i which is a view of a Matrix column. We should use two different indices or for (j, lp_ij) in zip(eachindex(m), lp_i) as below. r isn't relevant here anyway.

end
end
end

@inbounds for j = 1:n
@inbounds for j in eachindex(r)
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Comment on lines +263 to 266
for k in axes(P, 1)
pk = P[k, iP]
@inbounds μ[k] += pk * wi
@inbounds γ[k] += pk * pk * wi
Copy link
Member

Choose a reason for hiding this comment

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

Should use a different index for μ and γ as these may not have the same indices as P.

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.

4 participants