-
Notifications
You must be signed in to change notification settings - Fork 60
More tweaks #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
More tweaks #375
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,9 +53,7 @@ storagetype(t) = storagetype(typeof(t)) | |
| function storagetype(::Type{T}) where {T <: AbstractTensorMap} | ||
| if T isa Union | ||
| # attempt to be slightly more specific by promoting unions | ||
| Ma = storagetype(T.a) | ||
| Mb = storagetype(T.b) | ||
| return promote_storagetype(Ma, Mb) | ||
| return promote_storagetype(T.a, T.b) | ||
| else | ||
| # fallback definition by using scalartype | ||
| return similarstoragetype(scalartype(T)) | ||
|
|
@@ -103,11 +101,19 @@ similarstoragetype(X::Type, ::Type{T}) where {T <: Number} = | |
|
|
||
| # implement on tensors | ||
| similarstoragetype(::Type{TT}) where {TT <: AbstractTensorMap} = similarstoragetype(storagetype(TT)) | ||
| similarstoragetype(::Type{TT}, ::Type{T}) where {TT <: AbstractTensorMap, T <: Number} = | ||
| similarstoragetype(storagetype(TT), T) | ||
| function similarstoragetype(::Type{TT}, ::Type{T}) where {TT <: AbstractTensorMap, T <: Number} | ||
| return similarstoragetype(storagetype(TT), T) | ||
| end | ||
| function similarstoragetype(::Type{<:AbstractTensorMap{T, S, N₁, N₂}}, ::Type{TA}) where {T <: Number, TA <: DenseVector, S, N₁, N₂} | ||
| return similarstoragetype(TA, T) | ||
| end | ||
| function similarstoragetype(t::AbstractTensorMap{T, S, N₁, N₂}, ::Type{TA}) where {T <: Number, TA <: DenseVector, S, N₁, N₂} | ||
| return similarstoragetype(typeof(t), TA) | ||
| end | ||
|
|
||
| # implement on arrays | ||
| similarstoragetype(::Type{A}) where {A <: DenseVector{<:Number}} = A | ||
| similarstoragetype(::Type{A}, ::Type{A}) where {A <: DenseVector{<:Number}} = A | ||
|
Comment on lines
+107
to
+116
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we using these somewhere? I'm slightly confused about the meaning of these functions with last argument |
||
| Base.@assume_effects :foldable similarstoragetype(::Type{A}) where {A <: AbstractArray{<:Number}} = | ||
| Core.Compiler.return_type(similar, Tuple{A, Int}) | ||
| Base.@assume_effects :foldable similarstoragetype(::Type{A}, ::Type{T}) where {A <: AbstractArray, T <: Number} = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ Base.adjoint(t::AbstractTensorMap) = AdjointTensorMap(t) | |
| space(t::AdjointTensorMap) = adjoint(space(parent(t))) | ||
| dim(t::AdjointTensorMap) = dim(parent(t)) | ||
| storagetype(::Type{AdjointTensorMap{T, S, N₁, N₂, TT}}) where {T, S, N₁, N₂, TT} = storagetype(TT) | ||
| similarstoragetype(::AdjointTensorMap{T, S, N₁, N₂, TT}, ::Type{T′}) where {T, S, N₁, N₂, TT, T′ <: Number} = similarstoragetype(TT, T′) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this also automatic from the definition of |
||
| similarstoragetype(::AdjointTensorMap{T, S, N₁, N₂, TT}, ::Type{TA}) where {T, S, N₁, N₂, TT, TA <: DenseVector} = similarstoragetype(TT, TA) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here about why the second argument would already be a |
||
|
|
||
| # Blocks and subblocks | ||
| #---------------------- | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the changes here are no longer necessary since
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm checking this now with |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ for (operation, manipulation) in ( | |
| $promote_op(::Type{T}, ::Type{I}) where {T <: Number, I <: Sector} = | ||
| sectorscalartype(I) <: Integer ? T : | ||
| sectorscalartype(I) <: Real ? float(T) : complex(T) | ||
| $promote_op(::Type{TA}, ::Type{I}) where {TA <: DenseVector, I <: Sector} = | ||
| similarstoragetype(TA, $promote_op(eltype(TA), I)) | ||
|
Comment on lines
+20
to
+21
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also not really used I guess? |
||
| # TODO: currently the manipulations all use sectorscalartype, change to: | ||
| # $manipulation_scalartype(I) <: Integer ? T : | ||
| # $manipulation_scalartype(I) <: Real ? float(T) : complex(T) | ||
|
|
@@ -342,11 +344,11 @@ See also [`insertrightunit`](@ref insertrightunit(::AbstractTensorMap, ::Val{i}) | |
| """ | ||
| function insertleftunit( | ||
| t::AbstractTensorMap, ::Val{i} = Val(numind(t) + 1); | ||
| copy::Bool = false, conj::Bool = false, dual::Bool = false | ||
| copy::Bool = false, conj::Bool = false, dual::Bool = false, | ||
| ) where {i} | ||
| W = insertleftunit(space(t), Val(i); conj, dual) | ||
| if t isa TensorMap | ||
| return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W) | ||
| return TensorMapWithStorage{scalartype(t), storagetype(t)}(copy ? Base.copy(t.data) : t.data, W) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look necessary, isn't the storagetype automatically deduced from the provided |
||
| else | ||
| tdst = similar(t, W) | ||
| for (c, b) in blocks(t) | ||
|
|
@@ -371,11 +373,11 @@ See also [`insertleftunit`](@ref insertleftunit(::AbstractTensorMap, ::Val{i}) w | |
| """ | ||
| function insertrightunit( | ||
| t::AbstractTensorMap, ::Val{i} = Val(numind(t)); | ||
| copy::Bool = false, conj::Bool = false, dual::Bool = false | ||
| copy::Bool = false, conj::Bool = false, dual::Bool = false, | ||
| ) where {i} | ||
| W = insertrightunit(space(t), Val(i); conj, dual) | ||
| if t isa TensorMap | ||
| return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W) | ||
| return TensorMapWithStorage{scalartype(t), storagetype(t)}(copy ? Base.copy(t.data) : t.data, W) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here |
||
| else | ||
| tdst = similar(t, W) | ||
| for (c, b) in blocks(t) | ||
|
|
@@ -400,7 +402,7 @@ and [`insertrightunit`](@ref insertrightunit(::AbstractTensorMap, ::Val{i}) wher | |
| function removeunit(t::AbstractTensorMap, ::Val{i}; copy::Bool = false) where {i} | ||
| W = removeunit(space(t), Val(i)) | ||
| if t isa TensorMap | ||
| return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W) | ||
| return TensorMapWithStorage{scalartype(t), storagetype(t)}(copy ? Base.copy(t.data) : t.data, W) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here |
||
| else | ||
| tdst = similar(t, W) | ||
| for (c, b) in blocks(t) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.