brenhinkeller / NaNStatistics.jl

Fast summary statistics, histograms, and binning – ignoring NaNs
MIT License
48 stars 2 forks source link

Error when using dim or dims keywords #23

Closed astrobc1 closed 2 years ago

astrobc1 commented 2 years ago

I am receiving the following error when using the dim or dims keyword.

Such functionality was working fine this morning before I updated several packages; I haven't yet tracked down which packages (besides possibly NaNStatistics) have changed.

Steps to reproduce below. This happens on all nanfunctions I've tried as well as dim vs. dims.

julia> using NaNStatistics

julia> x = ones(3, 3)
3×3 Matrix{Float64}:
 1.0  1.0  1.0
 1.0  1.0  1.0
 1.0  1.0  1.0

julia> nanmedian(x, dim=1)
ERROR: MethodError: no method matching _nanmedian!(::Matrix{Float64}, ::Matrix{Float64}, ::Tuple{Static.StaticInt{1}})
Closest candidates are:
  _nanmedian!(::AbstractArray{Tₒ, N}, ::AbstractArray{T, N}, ::Tuple{}) where {Tₒ, T, N} at ~/.julia/packages/NaNStatistics/P1OCn/src/Sorting/nanmedian.jl:229
  _nanmedian!(::AbstractArray{Tₒ, N}, ::AbstractArray{T, N}, ::D) where {Tₒ, T, N, M, D<:Tuple{Vararg{Integer, M}}} at ~/.julia/packages/NaNStatistics/P1OCn/src/Sorting/nanmedian.jl:226
  _nanmedian!(::AbstractArray{T, N}, ::Tuple) where {T, N} at ~/.julia/packages/NaNStatistics/P1OCn/src/Sorting/nanmedian.jl:86
  ...
Stacktrace:
 [1] macro expansion
   @ ~/.julia/packages/NaNStatistics/P1OCn/src/Sorting/nanmedian.jl:226 [inlined]
 [2] _nanmedian!
   @ ~/.julia/packages/NaNStatistics/P1OCn/src/Sorting/nanmedian.jl:226 [inlined]
 [3] _nanmedian!
   @ ~/.julia/packages/NaNStatistics/P1OCn/src/Sorting/nanmedian.jl:93 [inlined]
 [4] _nanmedian!
   @ ~/.julia/packages/NaNStatistics/P1OCn/src/Sorting/nanmedian.jl:83 [inlined]
 [5] __nanmedian!(A::Matrix{Float64}, #unused#::Colon, region::Int64)
   @ NaNStatistics ~/.julia/packages/NaNStatistics/P1OCn/src/Sorting/nanmedian.jl:79
 [6] __nanmedian(A::Matrix{Float64}, dims::Function, dim::Int64)
   @ NaNStatistics ~/.julia/packages/NaNStatistics/P1OCn/src/Sorting/nanmedian.jl:20
 [7] #nanmedian#43
   @ ~/.julia/packages/NaNStatistics/P1OCn/src/Sorting/nanmedian.jl:17 [inlined]
 [8] top-level scope
   @ REPL[4]:1

julia> 

Package Status:

(@v1.7) pkg> st
      Status `~/.julia/environments/v1.7/Project.toml`
  [0bf59076] AdvancedHMC v0.3.5
  [7d9fca2a] Arpack v0.5.3
  [5c4adb95] AstroAngles v0.1.3
  [c7932e45] AstroLib v0.4.1
  [c61b5328] AstroTime v0.7.0
  [488c2830] BSplines v0.3.3
  [4c5d9882] BasicBSpline v0.6.3
  [6e4b80f9] BenchmarkTools v1.3.1
  [a134a8b2] BlackBoxOptim v0.6.1
  [c4b4474d] Bokeh v0.4.0
  [c7d4f63d] BokehBlink v0.1.0
  [336ed68f] CSV v0.10.4
  [49dc2e85] Calculus v0.5.1
  [8f4d0f93] Conda v1.7.0
  [9c784101] CubicSplines v0.2.1
  [75b670ed] CurveFitParameters v0.1.0 `https://github.com/astrobc1/CurveFitParameters.jl#master`
  [717857b8] DSP v0.7.6
  [a93c6f00] DataFrames v1.3.4
  [82cc6244] DataInterpolations v3.9.2
  [864edb3b] DataStructures v0.18.13
  [39dd38d3] Dierckx v0.5.2
  [2b5f629d] DiffEqBase v6.92.0
  [0c46a032] DifferentialEquations v7.1.0
  [e30172f5] Documenter v0.27.19
  [35a29f4d] DocumenterTools v0.1.14
  [8f9489d3] Echelle v0.1.0 `https://github.com/astrobc1/Echelle.jl#master`
  [fb2f92b1] EchelleBase v0.1.0 `https://github.com/astrobc1/EchelleBase.jl#master`
  [6e4c0b07] EchelleReduce v0.1.0 `https://github.com/astrobc1/EchelleReduce.jl#master`
  [21191324] EchelleSpectralModeling v0.1.0 `https://github.com/astrobc1/EchelleSpectralModeling.jl#master`
  [cfc395e8] ExtendableGrids v0.9.12
  [7a1cc6ca] FFTW v1.5.0
  [525bcba6] FITSIO v0.16.12
  [5789e2e9] FileIO v1.14.0
  [587475ba] Flux v0.13.3
  [f6369f11] ForwardDiff v0.10.30
  [713c75ef] Franklin v0.10.75
  [e9467ef8] GLMakie v0.6.8
  [c91e804a] Gadfly v1.3.4
  [08766a1d] GalacticFlux v0.1.0
  [792012fa] GalacticNLopt v0.1.0
  [a75be94c] GalacticOptim v3.4.0
  [9d3c5eb1] GalacticOptimJL v0.1.0
  [c27321d9] Glob v1.3.0
  [7073ff75] IJulia v1.23.3
  [916415d5] Images v0.25.2
  [5903a43b] Infiltrator v1.5.0
  [a98d9a8b] Interpolations v0.13.6
  [b6b21f68] Ipopt v1.0.2
  [c4497e51] IterativeNelderMead v0.1.1 `https://github.com/astrobc1/IterativeNelderMead.jl#master`
  [033835bb] JLD2 v0.4.22
  [4076af6c] JuMP v1.1.1
  [fc60dff9] LombScargle v1.0.3
  [bdcacae8] LoopVectorization v0.12.119
  [2fda8390] LsqFit v0.12.1
  [33e6dc65] MKL v0.5.0
  [ee78f7c6] Makie v0.17.8
  [961ee093] ModelingToolkit v8.14.1
  [6f286f6a] MultivariateStats v0.9.1
  [76087f3c] NLopt v0.6.5
  [15e1cf62] NPZ v0.4.2
  [77ba4419] NaNMath v0.3.7
  [b946abbf] NaNStatistics v0.6.12
  [429524aa] Optim v1.7.0
  [18e31ff7] Peaks v0.4.0
  [58dd65bb] Plotly v0.4.1
  [f0f68f2c] PlotlyJS v0.18.8
  [91a5bcdd] Plots v1.31.1
  [c3e4b0f8] Pluto v0.19.9
  [f27b6e38] Polynomials v2.0.25
  [438e738f] PyCall v1.93.1
  [d330b81b] PyPlot v2.10.0
  [189a3867] Reexport v1.2.2
  [ae029012] Requires v1.3.0
  [295af30f] Revise v3.3.3
  [ebc72ef8] SciPy v0.1.1
  [fc659fc5] SkyCoords v1.0.1
  [928aab9d] SpecialMatrices v2.0.0
  [90137ffa] StaticArrays v1.5.0
  [2913bbd2] StatsBase v0.33.17
  [0c5d862f] Symbolics v4.8.2
  [bc48ee85] Tullio v0.3.4
  [b8865327] UnicodePlots v2.12.4
  [1986cc42] Unitful v1.11.0
  [6112ee07] UnitfulAstro v1.1.1
  [276b4fcb] WGLMakie v0.6.8
  [bd07be1c] Winston v0.15.2
  [e88e6eb3] Zygote v0.6.40
  [8ba89e20] Distributed
  [37e2e46d] LinearAlgebra
  [44cfe95a] Pkg
astrobc1 commented 2 years ago

Update: I downgraded back to v0.6.11 and it's working again. Here's what changed:

(EchelleEnvCale) pkg> add NaNStatistics@0.6.11
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `~/EchelleEnvCale/Project.toml`
  [b946abbf] + NaNStatistics v0.6.11
    Updating `~/EchelleEnvCale/Manifest.toml`
  [4fba245c] ↓ ArrayInterface v6.0.18 ⇒ v6.0.17
  [015c0d05] ↓ ArrayInterfaceOffsetArrays v0.1.6 ⇒ v0.1.5
  [b0d46f97] ↓ ArrayInterfaceStaticArrays v0.1.4 ⇒ v0.1.2
  [dd5226c6] - ArrayInterfaceStaticArraysCore v0.1.0
  [bdcacae8] ↓ LoopVectorization v0.12.119 ⇒ v0.12.118
  [b946abbf] ↓ NaNStatistics v0.6.12 ⇒ v0.6.11
  [aedffcd0] ↓ Static v0.7.3 ⇒ v0.6.6
brenhinkeller commented 2 years ago

Thanks for the report! Looks like the problem is that StaticInts are no longer a subtype of Integer in Static v 0.7. I'll have a fix momentarily and will make a patch release

astrobc1 commented 2 years ago

Great! Indeed, looks like:

StaticInt{N} <: StaticInteger{N} <: StaticNumber{N} <: Number

I suppose there may be a good reason for this decision within Static.jl, but why StaticInteger is not a subtype of Integer is interesting.

brenhinkeller commented 2 years ago

Yeah, I guess this is a case where it would be nice to be able to have both StaticInteger{N} < StaticNumber{N} and also StaticInteger < Integer if we could subtype more things at once

brenhinkeller commented 2 years ago

v0.6.13 registered: https://github.com/JuliaRegistries/General/pull/63114