JuliaArrays / JuliaArrays/StaticArrays.jl

Wrong results of matrix inverse multiplication with Float16 static arrays

Open
#1,328 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This is my configuration (using StaticArrays v1.9.15):

julia> versioninfo()
Julia Version 1.10.10
Commit 95f30e51f4 (2025-06-27 09:51 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 24 × Intel(R) Core(TM) Ultra 9 275HX
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, goldmont)
Threads: 24 default, 0 interactive, 12 GC (on 24 virtual cores)
Environment:
  JULIA_DEPOT_PATH = D:\.julia
  JULIA_EDITOR = code
  JULIA_VSCODE_REPL = 1

And this is a working example:

using StaticArrays

A = [0.0517 0.05106 0.05518;
     0.8870 0.88000 0.88040;
     1.0    1.0     1.0]

b = [0.04922, 0.889, 1.0]

x = A \ b     # correct

## Using StaticArrays:
Astatic = SMatrix{3,3}(A)
bstatic = SVector{3}(b)
xstatic = Astatic \ bstatic     # correct: xstatic ≈ x

## Changing to Float32 everything is still right:
A32 = Matrix{Float32}(A)
b32 = Vector{Float32}(b)
x32 = A32 \ b32     # correct

A32static = SMatrix{3,3,Float32}(A)
b32static = SVector{3,Float32}(b)
x32static = A32static \ b32static     # correct

## But things go wrong with Float16 and StaticArrays:
A16 = Matrix{Float16}(A)
b16 = Vector{Float16}(b)
x16 = A16 \ b16     # correct

A16static = SMatrix{3,3,Float16}(A)
b16static = SVector{3,Float16}(b)
x16static = A16static \ b16static     # WRONG: x ≈ [1.32, 0.33, -0.65]; x16static ≈ [1.33, 0.6665, 0.15]

The discrepancy of the last result is way beyond rounding errors.

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 by running the provided Julia reproduction with StaticArrays v1.9.15 and compare the Float16 static-array solve with the dynamic Float16 result. The issue is done when Float16 static-array matrix inversion or multiplication produces a result consistent with the dynamic solve, within expected precision.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.