Skip to content

Commit

Permalink
Try to decouple transpose! from LinearAlgebra.
Browse files Browse the repository at this point in the history
  • Loading branch information
orenbenkiki committed Jun 1, 2024
1 parent 86ad201 commit 25579ec
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/v0.1.0/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-06-01T18:28:22","documenter_version":"1.4.1"}}
{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-06-01T20:18:31","documenter_version":"1.4.1"}}
12 changes: 6 additions & 6 deletions docs/v0.1.0/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,12 @@ <h1 id="Index">
</a>
</li>
<li>
<a href="matrix_layouts.html#Daf.MatrixLayouts.transpose!">
<code>Daf.MatrixLayouts.transpose!
</code>
</a>
</li>
<li>
<a href="messages.html#Daf.Messages.depict_percent">
<code>Daf.Messages.depict_percent
</code>
Expand Down Expand Up @@ -2162,12 +2168,6 @@ <h1 id="Index">
</a>
</li>
<li>
<a href="matrix_layouts.html#LinearAlgebra.transpose!">
<code>LinearAlgebra.transpose!
</code>
</a>
</li>
<li>
<a href="computations.html#Daf.Computations.@computation">
<code>Daf.Computations.@computation
</code>
Expand Down
10 changes: 5 additions & 5 deletions docs/v0.1.0/matrix_layouts.html
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ <h2 id="Changing-layout">
</strong>, summing the UMIs of a gene is fast, and summing the UMIs of a cell is slow.
</p>
<p>In contrast,
<a href="matrix_layouts.html#LinearAlgebra.transpose!">
<a href="matrix_layouts.html#Daf.MatrixLayouts.transpose!">
<code>transpose!
</code>
</a> (with a
Expand Down Expand Up @@ -656,8 +656,8 @@ <h2 id="Changing-layout">
<header>
<a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring">
</a>
<a class="docstring-binding" id="LinearAlgebra.transpose!" href="#LinearAlgebra.transpose!">
<code>LinearAlgebra.transpose!
<a class="docstring-binding" id="Daf.MatrixLayouts.transpose!" href="#Daf.MatrixLayouts.transpose!">
<code>Daf.MatrixLayouts.transpose!
</code>
</a>
<span class="docstring-category">Function
Expand Down Expand Up @@ -922,8 +922,8 @@ <h2 id="Index">
</a>
</li>
<li>
<a href="matrix_layouts.html#LinearAlgebra.transpose!">
<code>LinearAlgebra.transpose!
<a href="matrix_layouts.html#Daf.MatrixLayouts.transpose!">
<code>Daf.MatrixLayouts.transpose!
</code>
</a>
</li>
Expand Down
Binary file modified docs/v0.1.0/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/v0.1.0/search_index.js

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions src/matrix_layouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export relayout!
export require_major_axis
export require_minor_axis
export Rows
export transpose!

using ..GenericFunctions
using ..GenericTypes
Expand Down Expand Up @@ -267,7 +268,7 @@ basically what `relayout!` does for you. In addition, `relayout!` will work for
`NamedMatrix` with the same axes. If `destination` is also a `NamedMatrix`, then its axes must match `source`.
"""
function relayout!(matrix::AbstractMatrix)::AbstractMatrix
return transpose(LinearAlgebra.transpose!(matrix))
return transpose(transpose!(matrix))
end

function relayout!(destination::AbstractMatrix, source::NamedMatrix)::NamedArray # untested
Expand Down Expand Up @@ -354,40 +355,40 @@ end
This is a shorthand for `LinearAlgebra.transpose!(similar(transpose(m)), m)`. That is, this will return a transpose of a
matrix, but instead of simply using a zero-copy wrapper, it actually rearranges the data. See [`relayout!`](@ref).
"""
function LinearAlgebra.transpose!(matrix::AbstractMatrix)::AbstractMatrix
function transpose!(matrix::AbstractMatrix)::AbstractMatrix
@debug "transpose! $(depict(matrix)) {" # NOLINT
result = LinearAlgebra.transpose!(similar(transpose(matrix)), matrix)
@debug "transpose! $(depict(result)) }" # NOLINT
return result
end

function LinearAlgebra.transpose!(matrix::AbstractSparseMatrix)::AbstractMatrix
function transpose!(matrix::AbstractSparseMatrix)::AbstractMatrix
@assert require_major_axis(matrix) == Columns
@debug "transpose! $(depict(matrix)) {" # NOLINT
result = SparseMatrixCSC(transpose(matrix))
@debug "transpose! $(depict(result)) }" # NOLINT
return result
end

function LinearAlgebra.transpose!(matrix::NamedMatrix)::NamedArray
return NamedArray(LinearAlgebra.transpose!(matrix.array), flip_tuple(matrix.dicts), flip_tuple(matrix.dimnames))
function transpose!(matrix::NamedMatrix)::NamedArray
return NamedArray(transpose!(matrix.array), flip_tuple(matrix.dicts), flip_tuple(matrix.dimnames))
end

function flip_tuple(tuple::Tuple{T1, T2})::Tuple{T2, T1} where {T1, T2}
value1, value2 = tuple
return (value2, value1)
end

function LinearAlgebra.transpose!(matrix::SparseArrays.ReadOnly)::AbstractMatrix
return LinearAlgebra.transpose!(parent(matrix))
function transpose!(matrix::SparseArrays.ReadOnly)::AbstractMatrix
return transpose!(parent(matrix))
end

function LinearAlgebra.transpose!(matrix::Transpose)::AbstractMatrix
return transpose(LinearAlgebra.transpose!(parent(matrix)))
function transpose!(matrix::Transpose)::AbstractMatrix
return transpose(transpose!(parent(matrix)))
end

function LinearAlgebra.transpose!(matrix::Adjoint)::AbstractMatrix
return adjoint(LinearAlgebra.transpose!(parent(matrix)))
function transpose!(matrix::Adjoint)::AbstractMatrix
return adjoint(transpose!(parent(matrix)))
end

"""
Expand Down

0 comments on commit 25579ec

Please sign in to comment.