From 27dab96fb0071800e9fe74dc47b9614215e95db3 Mon Sep 17 00:00:00 2001 From: Thomas Christensen Date: Mon, 21 Feb 2022 11:53:43 -0500 Subject: [PATCH] don't be a type-pirate --- Project.toml | 2 +- src/GellMannMatrices.jl | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index 3ffc6a5..161feca 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GellMannMatrices" uuid = "ab9ec009-2876-46ab-95e9-a984e5637243" authors = ["Thomas Christensen and contributors"] -version = "0.1.0" +version = "0.1.1" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/GellMannMatrices.jl b/src/GellMannMatrices.jl index b2ba44e..809a507 100644 --- a/src/GellMannMatrices.jl +++ b/src/GellMannMatrices.jl @@ -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)