chakravala / chakravala/DirectSum.jl

Submanifold index arrays should be typed

Open
#7 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Julia
Stars
50
Forks
4
PR merge metrics
No merged PRs in 30d

Description

I received this error:
```Julia
Linear operators for D=1: Error During Test at /Users/eschnett/src/jl/RayTraceGR/test/runtests.jl:52
Got exception outside of a @test
MethodError: no method matching one(::Type{Any})
Closest candidates are:
one(::Type{Union{Missing, T}}) where T at missing.jl:105
one(!Matched::Type{Missing}) at missing.jl:103
one(!Matched::BitArray{2}) at bitarray.jl:422
...
Stacktrace:
[1] one(::Type{Any}) at ./missing.jl:105
[2] reduce_empty(::typeof(*), ::Type{T} where T) at ./reduce.jl:308
[3] reduce_empty(::typeof(Base.mul_prod), ::Type{T} where T) at ./reduce.jl:316
[4] mapreduce_empty(::typeof(identity), ::Function, ::Type{T} where T) at ./reduce.jl:335
[5] _mapreduce(::typeof(identity), ::typeof(Base.mul_prod), ::IndexLinear, ::Array{Any,1}) at ./reduce.jl:392
[6] _mapreduce_dim at ./reducedim.jl:312 [inlined]
[7] #mapreduce#580 at ./reducedim.jl:307 [inlined]
[8] mapreduce at ./reducedim.jl:307 [inlined]
[9] _prod at ./reducedim.jl:657 [inlined]
[10] _prod(::Array{Any,1}, ::Colon) at ./reducedim.jl:656
[11] #prod#585 at ./reducedim.jl:652 [inlined]
[12] prod at ./reducedim.jl:652 [inlined]
[13] parityinterior(::SubManifold{⟨+⟩,1,0x0000000000000001}, ::UInt64, ::UInt64) at /Users/eschnett/.julia/dev/Grassmann/src/parity.jl:77
[14] interior(::UInt64, ::UInt64, ::SubManifold{⟨+⟩,1,0x0000000000000001}) at /Users/eschnett/.julia/dev/Grassmann/src/parity.jl:168
[15] skewaddblade!_pre(::SubManifold{⟨+⟩,1,0x0000000000000001}, ::SizedArray{Tuple{1},Any,1,1}, ::UInt64, ::UInt64, ::Expr) at /Users/eschnett/.julia/dev/Grassmann/src/algebra.jl:258
[16] #s335#570 at /Users/eschnett/.julia/dev/Grassmann/src/products.jl:373 [inlined]
[17] #s335#570(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) at ./none:0
[18] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:526
[19] dot(::Chain{v₁,1,Chain{v₁,1,Rational{Int128},1},1}, ::Chain{v₁,1,Rational{Int128},1}) at /Users/eschnett/.julia/packages/AbstractTensors/6BQWx/src/AbstractTensors.jl:132
[20] top-level scope at /Users/eschnett/src/jl/RayTraceGR/test/runtests.jl:64
[21] top-level scope at /Users/eschnett/src/julia-1.4/usr/share/julia/stdlib/v1.4/Test/src/Test.jl:1186
[22] include(::String) at ./client.jl:439
[23] top-level scope at none:6
[24] eval(::Module, ::Any) at ./boot.jl:331
[25] exec_options(::Base.JLOptions) at ./client.jl:264
[26] _start() at ./client.jl:484
```

Tracking things down, the problem comes from an empty list of indices used in `parity.jl` line 77:
```Julia
ind = indices(B,N); g = prod(V[ind])
```
`V[ind]` is an empty array of type `Vector{Any}`, so `prod` cannot determine the neutral element. (I am using 1-dimensional manifolds, which is probably a bit of a special case.)

I believe the solution is to add explicit `Int` declarations to the array comprehensions in lines 198, 199 of `DirectSum.jl` in `DirectSum`:
```Julia
@inline getindex(vs::SubManifold,i::Vector) = [getindex(vs,j) for j ∈ i]
@inline getindex(vs::SubManifold,i::UnitRange{Int}) = [getindex(vs,j) for j ∈ i]
```

This change resolves the problem for me.

Contributor guide

No contributing guide indexed for this repository

Research direction

Inspect DirectSum.jl lines 198-199 and parity.jl line 77, then reproduce the reported one-dimensional case using the RayTraceGR test at test/runtests.jl:52-64. Verify that submanifold index arrays have a concrete integer element type and that the empty-index path no longer raises the reported prod error.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.