Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
Add zeros,ones methods to Product
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Jun 2, 2024
1 parent 5f78657 commit dd2cfd7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Ansatz/Product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ function Product(::Operator, ::Open, arrays)
Product(TensorNetwork(_tensors), sitemap)
end

function Base.zeros(::Type{Product}, n; p::Int = 2, eltype = Bool)
Product(State(), Open(), fill(append!([one(eltype)], Iterators.repeated(zero(eltype), p - 1)), n))
end

function Base.ones(::Type{Product}, n; p::Int = 2, eltype = Bool)
Product(State(), Open(), fill(append!([zero(eltype), one(eltype)], Iterators.repeated(zero(eltype), p - 2)), n))
end

LinearAlgebra.norm(tn::Product, p::Real = 2) = LinearAlgebra.norm(socket(tn), tn, p)
function LinearAlgebra.norm(::Union{State,Operator}, tn::Product, p::Real)
mapreduce(*, tensors(tn)) do tensor
Expand Down

0 comments on commit dd2cfd7

Please sign in to comment.