Skip to content

Commit afb79d6

Browse files
committed
define norm p
1 parent ebceda7 commit afb79d6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/fusiontensor/linear_algebra_interface.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ function LinearAlgebra.mul!(
3333
return C
3434
end
3535

36-
function LinearAlgebra.norm(ft::FusionTensor)
36+
function LinearAlgebra.norm(ft::FusionTensor, p::Real=2)
3737
m = data_matrix(ft)
3838
row_sectors = sectors(codomain_axis(ft))
3939
n2 = sum(eachblockstoredindex(m); init=zero(real(eltype(ft)))) do b
40-
return quantum_dimension(row_sectors[Int(first(Tuple(b)))]) * norm(m[b])^2
40+
return quantum_dimension(row_sectors[Int(first(Tuple(b)))]) * norm(m[b], p)^p
4141
end
42-
return sqrt(n2)
42+
return n2^(1 / p)
4343
end
4444

4545
LinearAlgebra.normalize(ft::FusionTensor, p::Real=2) = ft / norm(ft, p)

test/test_linear_algebra.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ include("setup.jl")
2626
ft = to_fusiontensor(sdst, (g, g), (dual(g), dual(g)))
2727
@test isnothing(check_sanity(ft))
2828
@test norm(ft) 3 / 2
29+
@test norm(ft, 2) 3 / 2
30+
@test norm(ft, 2.0) 3 / 2
31+
@test norm(ft, 1) 1.5
2932
@test isapprox(tr(ft), 0; atol=eps(Float64))
3033

3134
ft2 = normalize(ft)

0 commit comments

Comments
 (0)