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

sum and friends with dims error on dims that are not in the DimArray #883

Open
tiemvanderdeure opened this issue Dec 11, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@tiemvanderdeure
Copy link
Contributor

I don't know if the title is so clear but here's the MWE:

da = rand(X(1:10), Y(1:10))
sum(da; dims = (X, Z))
sum(da; dims = (2,3))
sum(parent(da); dims = (2,3))

The first two error, while the third one just ignores the dimension that the array doesn't have. DimArrays should behave the same way, I think.

Stacktrace:

ERROR: MethodError: no method matching name(::Type{Tuple{Val{X}, Val{Z}}})
The function `name` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  name(::DimTable, Any...)
   @ DimensionalData ~/.julia/dev/DimensionalData/src/tables.jl:169
  name(::Tuple{})
   @ DimensionalData ~/.julia/dev/DimensionalData/src/Dimensions/dimension.jl:232
  name(::Type{<:Y})
   @ DimensionalData ~/.julia/dev/DimensionalData/src/Dimensions/dimension.jl:457
  ...

Stacktrace:
  [1] dimsmatch(f::typeof(<:), dim::Type{X{…}}, match::Type{Tuple{…}})
    @ DimensionalData.Dimensions ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:35
  [2] (::DimensionalData.Dimensions.var"#46#47"{DataType, DataType})(s::Type)
    @ DimensionalData.Dimensions ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:101
  [3] findnext(testf::DimensionalData.Dimensions.var"#46#47"{DataType, DataType}, A::Tuple{DataType, DataType}, start::Int64)
    @ Base ./array.jl:2352
  [4] #s120#45
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:100 [inlined]
  [5] var"#s120#45"(::Any, f::Any, tosort::Any, order::Any)
    @ DimensionalData.Dimensions ./none:0
  [6] (::Core.GeneratedFunctionStub)(::UInt64, ::LineNumberNode, ::Any, ::Vararg{Any})
    @ Core ./boot.jl:707
  [7] _sortdims
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:91 [inlined]
  [8] _dims
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:152 [inlined]
  [9] _dim_query1
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:809 [inlined]
 [10] _dim_query
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:781 [inlined]
 [11] _dim_query
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:773 [inlined]
 [12] dims
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:149 [inlined]
 [13] _otherdims(f::Function, ds::Tuple{X{…}, Y{…}}, query::Tuple{Tuple{…}})
    @ DimensionalData.Dimensions ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:300
 [14] _dim_query1(f::typeof(DimensionalData.Dimensions._otherdims), op::typeof(<:), ::DimensionalData.Dimensions.AlwaysTuple, d::Tuple{…}, query::Tuple{…})
    @ DimensionalData.Dimensions ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:809
 [15] _dim_query1
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:788 [inlined]
 [16] _dim_query
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:781 [inlined]
 [17] _dim_query
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:773 [inlined]
 [18] otherdims
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:295 [inlined]
 [19] dimnum
    @ ~/.julia/dev/DimensionalData/src/Dimensions/primitives.jl:216 [inlined]
 [20] _sum
    @ ~/.julia/dev/DimensionalData/src/array/methods.jl:20 [inlined]
 [21] #sum#195
    @ ~/.julia/dev/DimensionalData/src/array/methods.jl:16 [inlined]
 [22] top-level scope
@rafaqz
Copy link
Owner

rafaqz commented Dec 11, 2024

Yep looks like a bug

@tiemvanderdeure
Copy link
Contributor Author

Probably just needs a commondims somewhere but I'm not sure if it should be at the top of the stack or in one of the internal methods

@rafaqz
Copy link
Owner

rafaqz commented Dec 12, 2024

Its actually two minor bugs. I'll fix

@rafaqz rafaqz added the bug Something isn't working label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants