-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeParameterAccessors]
similartype
(#1561)
* [TypeParameterAccessors] `similartype` * [NDTensors] Bump to v0.3.50
- Loading branch information
Showing
17 changed files
with
117 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "NDTensors" | ||
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" | ||
authors = ["Matthew Fishman <[email protected]>"] | ||
version = "0.3.49" | ||
version = "0.3.50" | ||
|
||
[deps] | ||
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
using .TypeParameterAccessors: similartype | ||
|
||
# | ||
# BlockSparseTensor (Tensor using BlockSparse storage) | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
NDTensors/src/lib/TypeParameterAccessors/src/base/similartype.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
`set_indstype` should be overloaded for | ||
types with structured dimensions, | ||
like `OffsetArrays` or named indices | ||
(such as ITensors). | ||
""" | ||
function set_indstype(arraytype::Type{<:AbstractArray}, dims::Tuple) | ||
return set_ndims(arraytype, length(dims)) | ||
end | ||
|
||
function similartype(arraytype::Type{<:AbstractArray}, eltype::Type, dims::Tuple) | ||
return similartype(similartype(arraytype, eltype), dims) | ||
end | ||
|
||
@traitfn function similartype( | ||
arraytype::Type{ArrayT}, eltype::Type | ||
) where {ArrayT; !IsWrappedArray{ArrayT}} | ||
return set_eltype(arraytype, eltype) | ||
end | ||
|
||
@traitfn function similartype( | ||
arraytype::Type{ArrayT}, dims::Tuple | ||
) where {ArrayT; !IsWrappedArray{ArrayT}} | ||
return set_indstype(arraytype, dims) | ||
end | ||
|
||
function similartype(arraytype::Type{<:AbstractArray}, dims::Base.DimOrInd...) | ||
return similartype(arraytype, dims) | ||
end | ||
|
||
function similartype(arraytype::Type{<:AbstractArray}) | ||
return similartype(arraytype, eltype(arraytype)) | ||
end | ||
|
||
## Wrapped arrays | ||
@traitfn function similartype( | ||
arraytype::Type{ArrayT}, eltype::Type | ||
) where {ArrayT; IsWrappedArray{ArrayT}} | ||
return similartype(unwrap_array_type(arraytype), eltype) | ||
end | ||
|
||
@traitfn function similartype( | ||
arraytype::Type{ArrayT}, dims::Tuple | ||
) where {ArrayT; IsWrappedArray{ArrayT}} | ||
return similartype(unwrap_array_type(arraytype), dims) | ||
end | ||
|
||
# This is for uniform `Diag` storage which uses | ||
# a Number as the data type. | ||
# TODO: Delete this when we change to using a | ||
# `FillArray` instead. This is a stand-in | ||
# to make things work with the current design. | ||
function similartype(numbertype::Type{<:Number}) | ||
return numbertype | ||
end | ||
|
||
# Instances | ||
function similartype(array::AbstractArray, eltype::Type, dims...) | ||
return similartype(typeof(array), eltype, dims...) | ||
end | ||
similartype(array::AbstractArray, eltype::Type) = similartype(typeof(array), eltype) | ||
similartype(array::AbstractArray, dims...) = similartype(typeof(array), dims...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
NDTensors/src/lib/TypeParameterAccessors/test/test_similartype.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@eval module $(gensym()) | ||
using Test: @test, @test_broken, @testset | ||
using LinearAlgebra: Adjoint | ||
using NDTensors.TypeParameterAccessors: similartype | ||
@testset "TypeParameterAccessors similartype" begin | ||
@test similartype(Array, Float64, (2, 2)) == Matrix{Float64} | ||
# TODO: Is this a good definition? Probably it should be left unspecified. | ||
@test similartype(Array) == Array{Any} | ||
@test similartype(Array, Float64) == Array{Float64} | ||
@test similartype(Array, (2, 2)) == Matrix | ||
@test similartype(Adjoint{Float32,Matrix{Float32}}, Float64, (2, 2, 2)) == | ||
Array{Float64,3} | ||
@test similartype(Adjoint{Float32,Matrix{Float32}}, Float64) == Matrix{Float64} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ad092fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register subdir=NDTensors
ad092fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/118751
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: