JuliaArrays / JuliaArrays/StaticArrays.jl

Some operations do not ignore trailing dimensions equal to 1

Open
#779 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
844
Forks
159
Avg merge
3d 21h
Merged PRs (30d)
3

Description

As in the title. Here is a small example:
addition in Base Julia arrays ignores trailing dimensions equal to 1:

julia> [1 2][:,1:1] + [1]
1×1 Array{Int64,2}:
 2

but in StaticArrays it does not:

julia> [1 2][:,1:1] +  SA[1]
ERROR: DimensionMismatch("Sizes ((1, 1), Size(1,)) of input arrays do not match")
Stacktrace:
 [1] _throw_size_mismatch(::Array{Int64,2}, ::Vararg{Any,N} where N) at /home/mateusz/.julia/dev/StaticArrays/src/traits.jl:198
 [2] same_size at /home/mateusz/.julia/dev/StaticArrays/src/traits.jl:192 [inlined]
 [3] macro expansion at /home/mateusz/.julia/dev/StaticArrays/src/mapreduce.jl:74 [inlined]
 [4] _map at /home/mateusz/.julia/dev/StaticArrays/src/mapreduce.jl:41 [inlined]
 [5] map at /home/mateusz/.julia/dev/StaticArrays/src/mapreduce.jl:34 [inlined]
 [6] +(::Array{Int64,2}, ::SArray{Tuple{1},Int64,1,1}) at /home/mateusz/.julia/dev/StaticArrays/src/linalg.jl:12
 [7] top-level scope at none:0

Do you think StaticArrays should have same_size modified to follow the behavior of Base?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/traits.jl at same_size and _throw_size_mismatch, then read the callers shown in src/mapreduce.jl and src/linalg.jl. Compare the reported StaticArrays behavior with the Base Julia example and determine whether trailing dimensions equal to 1 should be accepted; done means the operation follows the intended behavior without the reported DimensionMismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.