Skip to content

Commit

Permalink
remove type piracy
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoms committed Aug 4, 2024
1 parent 7e926ba commit 4cef65b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 3 additions & 8 deletions src/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/multilinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4cef65b

Please sign in to comment.