Skip to content

Commit

Permalink
don't be a type-pirate
Browse files Browse the repository at this point in the history
  • Loading branch information
thchr committed Feb 21, 2022
1 parent c1abac5 commit 27dab96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GellMannMatrices"
uuid = "ab9ec009-2876-46ab-95e9-a984e5637243"
authors = ["Thomas Christensen <[email protected]> and contributors"]
version = "0.1.0"
version = "0.1.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
17 changes: 6 additions & 11 deletions src/GellMannMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ using LinearAlgebra, SparseArrays
export gellmann

# ---------------------------------------------------------------------------------------- #
# until we have https://github.com/JuliaLang/julia/pull/44211, we need to extend `dims2cat`
# to ensure type-stability of `cat(..., dims=(1,2))`
# ... we probably shouldn't do this, piracy and all that :(
function Base.dims2cat(::Val{dims}) where dims
any((0), dims) && throw(ArgumentError("All cat dimensions must be positive integers, but got $dims"))
ntuple(in(dims), maximum(dims))
end

# ---------------------------------------------------------------------------------------- #

# direct sum (i.e., block-diagonalization of matrices As)
@inline (As...) = cat(As..., dims=Val((1,2)))
if VERSION < v"1.8"
# work around for https://github.com/JuliaLang/julia/pull/44211 for Julia ≤ v1.7
@inline (As...) = cat(As..., dims=(1,2))::typeof((.+)(As...))
else
@inline (As...) = cat(As..., dims=Val((1,2)))
end

# https://en.wikipedia.org/wiki/Matrix_unit
unit(::Type{<:SparseMatrixCSC}, i, j, n, m) = sparse([i], [j], [1], n, m)
Expand Down

0 comments on commit 27dab96

Please sign in to comment.