Skip to content

Should copy_transpose! also transpose elements? #1033

@maltezfaria

Description

@maltezfaria

A while back I ran into this issue with StaticArrays:

using StaticArrays

A = @SMatrix rand(3, 3)
B = @SMatrix rand(3, 3)

blockA = fill(A, 3, 2)
blockB = fill(B, 3, 2)

val1 = blockA * transpose(blockB)
val2 = blockA * collect(transpose(blockB))

val1  val2 # false, by a lot

Recently, this came back to bite me again, and I managed to narrow down the issue to this chunk in the transpose.jl file.

for jsrc in jr_src
    jdest = first(jr_dest)
    for isrc in ir_src
        B[idest,jdest] = A[isrc,jsrc]
        jdest += step(jr_dest)
    end
    idest += step(ir_dest)
end

Replacing B[idest,jdest] = A[isrc,jsrc] by B[idest,jdest] = transpose(A[isrc,jsrc]) seems to fix the StaticArray bug, which is related to the copy_transpose! not transposing its elements. Since the transpose(x::Number) = x, this change should not break the scalar version, but I am not sure if there are further implications of such a change.

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