Skip to content

Commit

Permalink
Format .jl files (#59)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] authored Apr 24, 2020
1 parent 656516e commit 8b24576
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/register.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ explicitly. The batch size will be `size(raw, 2)` by default.
"""
function ArrayReg{B}(raw::MT) where {B,T,MT<:AbstractMatrix{T}}
ispow2(size(raw, 1)) ||
throw(DimensionMismatch("Expect first dimension size to be power of 2"))
throw(DimensionMismatch("Expect first dimension size to be power of 2"))
if !(ispow2(size(raw, 2) ÷ B) && size(raw, 2) % B == 0)
throw(DimensionMismatch("Expect second dimension size to be an integral multiple of batch size $B"))
end
Expand Down Expand Up @@ -235,7 +235,7 @@ function YaoBase.fidelity(r1::ArrayReg{B1}, r2::ArrayReg{B2}) where {B1,B2}
return B == 1 ? res[] : res
end

function YaoBase.fidelity(r1::ArrayReg{B}, r2::ArrayReg{1}) where B
function YaoBase.fidelity(r1::ArrayReg{B}, r2::ArrayReg{1}) where {B}
state1 = rank3(r1)
state2 = rank3(r2)
nqubits(r1) == nqubits(r2) || throw(DimensionMismatch("Register size not match!"))
Expand All @@ -247,7 +247,7 @@ function YaoBase.fidelity(r1::ArrayReg{B}, r2::ArrayReg{1}) where B
return B == 1 ? res[] : res
end

YaoBase.fidelity(r1::ArrayReg{1}, r2::ArrayReg{B}) where B = YaoBase.fidelity(r2, r1)
YaoBase.fidelity(r1::ArrayReg{1}, r2::ArrayReg{B}) where {B} = YaoBase.fidelity(r2, r1)

function YaoBase.fidelity(r1::ArrayReg{1}, r2::ArrayReg{1})
state1 = state(r1)
Expand Down
10 changes: 7 additions & 3 deletions test/density_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ using Test, YaoArrayRegister
focus!(reg5, 1:3)
@test isapprox(fidelity(reg, reg_), fidelity(reg4, reg5), atol = 1e-5)

@test isapprox.(fidelity(reg, reg_), fidelity(repeat(reg4, 3), repeat(reg5, 3)), atol = 1e-5) |>
all
@test isapprox.(
fidelity(reg, reg_),
fidelity(repeat(reg4, 3), repeat(reg5, 3)),
atol = 1e-5,
) |> all

# batch
st = rand(ComplexF64, 8, 2)
reg1 = ArrayReg(st)
reg2 = rand_state(3)

@test fidelity(reg1, reg2) [fidelity(ArrayReg(st[:, 1]), reg2), fidelity(ArrayReg(st[:, 2]), reg2)]
@test fidelity(reg1, reg2)
[fidelity(ArrayReg(st[:, 1]), reg2), fidelity(ArrayReg(st[:, 2]), reg2)]

@test isapprox.(
fidelity(reg, reg_),
Expand Down

0 comments on commit 8b24576

Please sign in to comment.