JuliaArrays / JuliaArrays/StaticArrays.jl

Make matrix algebra (`zero`,`one`,`*`,`+`, ...) work with special matrix types

Open
#765 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The correct general behavior for zero and one is to construct a StaticArrays type which can represent the additive and multiplicative identities. Currently this doesn't always work for the reasons described in JuliaLang/LinearAlgebra.jl#1516: for example, zero(Rotations.RotMatrix) should not return a RotMatrix.

One fix would be to make operations always call similar_type and refine the documentation for similar_type to specify that it should return the type of a "general full matrix". "Full" for the purposes of array ops like broadcasting which don't preserve "structural zeros", and full for algebraic purposes because we need a member of GL(n,R) as generic output. This seems consistent(ish?) with similar in Base. Note that changing to use similar_type like this is slightly breaking and led to JuliaLang/julia#700, so this will technically be a breaking change. However we need to do something like this for correctness so we should do it in the next major release. Generally I don't think it will be very breaking...

Perhaps there's some more general option where similar_type can somehow be aware of the algebraic operation... eg, for multiply to call similar_type(m, *, sz, ty)... but I'm not sure that would be any better than simply overriding *.

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

Begin with the existing implementations of zero, one, *, +, and similar_type, then read JuliaLang/LinearAlgebra.jl#1516 and JuliaLang/julia#700 for the correctness and breaking-change context. Done means the chosen design makes identity and algebra operations work for special matrix types and documents the resulting similar_type contract; no specific file or test is named here.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend-api-design
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.