diff --git a/src/basic.jl b/src/basic.jl index 4916651..aba657a 100644 --- a/src/basic.jl +++ b/src/basic.jl @@ -265,8 +265,6 @@ function applykraus(K, M) end export applykraus -LA.I(dim::Integer, sp::Bool) = sp ? SA.sparse(LA.I(dim)) : LA.I(dim) - function _orthonormal_range_svd!( A::AbstractMatrix{T}; tol::Union{Real,Nothing} = nothing, @@ -317,14 +315,11 @@ returns the actual projection `V * V'`. Reference: [Watrous' book](https://cs.uwaterloo.ca/~watrous/TQI/), Sec. 7.1.1 """ function symmetric_projection(::Type{T}, dim::Integer, n::Integer; partial::Bool = true) where {T} - if T <: SA.CHOLMOD.VTypes #sparse qr decomposition fails for anything other than Float64 or ComplexF64 - P = SA.spzeros(T, dim^n, dim^n) - else - P = zeros(T, dim^n, dim^n) - end + is_sparse = T <: SA.CHOLMOD.VTypes #sparse qr decomposition fails for anything other than Float64 or ComplexF64 + P = is_sparse ? SA.spzeros(T, dim^n, dim^n) : zeros(T, dim^n, dim^n) perms = Combinatorics.permutations(1:n) for perm in perms - P .+= permutation_matrix(dim, perm; sp = true) + P .+= permutation_matrix(dim, perm; is_sparse) end P ./= length(perms) if partial diff --git a/src/multilinear.jl b/src/multilinear.jl index cf25621..c89c7fe 100644 --- a/src/multilinear.jl +++ b/src/multilinear.jl @@ -292,9 +292,11 @@ If `dims` is an Integer, assumes there are `length(perm)` subsystems of equal di function permutation_matrix( dims::Union{Integer,AbstractVector{<:Integer}}, perm::AbstractVector{<:Integer}; - sp::Bool = true + is_sparse::Bool = true ) dims = dims isa Integer ? fill(dims, length(perm)) : dims - permute_systems(LA.I(prod(dims), sp), perm, dims; rows_only = true) + d = prod(dims) + id = is_sparse ? SA.sparse(LA.I, (d, d)) : LA.I(d) + permute_systems(id, perm, dims; rows_only = true) end export permutation_matrix