Skip to content

Wrong answers from dot with a SubArray that reverts the order of elements on Julia v1.6 and before #984

@junyuan-chen

Description

@junyuan-chen

I am surprised by some wrong answers from dot that are illustrated below:

julia> using LinearAlgebra

julia> v1 = [1.0, 2.0, 3.0]
3-element Vector{Float64}:
 1.0
 2.0
 3.0

julia> dot([1.0, 2.0], view(v1, 2:-1:1))
7.0

The 7.0 returned above seems like coming from a bug that computes what I would expect for dot([1.0, 2.0], view(v1, 3:-1:2)).

Such behavior is not present if the parent vector contains integers:

julia> v2 = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> dot([1.0, 2.0], view(v2, 2:-1:1))
4.0

I noticed the above unexpected results when I was trying to figure out why the CI for a package fails on Julia v1.6 for all platforms. It seems that the above behavior happens on Julia v1.6.7 and older versions but not v1.7 or later.

I am posting my local version info here but I don't think this is platform-specific:

julia> versioninfo()
Julia Version 1.6.7
Commit 3b76b25b64 (2022-07-19 15:11 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin21.4.0)
  CPU: Apple M1 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, westmere)
Environment:
  JULIA_NUM_THREADS = 8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions