-
Notifications
You must be signed in to change notification settings - Fork 31
Introduce Space, Dimensions, and GeneralDimensions
#360
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
Merged
+779
−334
Merged
Changes from 18 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
c0b2196
introduce `Space` and `Dimensions`
ytdHuang ff0a997
fix some tests
ytdHuang a5cd9fd
update definition for `AbstractDimensions`
ytdHuang fc8ca49
fix some tests for `AbstractDimensions`
ytdHuang d15696c
minor change
ytdHuang 235b4f0
introduce `Field`
ytdHuang 12e22ab
support `*` for `Compoundimensions`
ytdHuang 0999688
fix `*` for `QobjEvo`
ytdHuang 53f71ac
fix some tests
ytdHuang cc31eeb
fix comments
ytdHuang d15413b
remove duplicate tests
ytdHuang 4c848c1
comment `steadystate` failed type-inference tests
ytdHuang e9df9fb
modify some comments
ytdHuang 8fc9248
format files
ytdHuang 2930089
extend generation methods for `CompoundDimensions`
ytdHuang aa01c99
introduce internal field `_dims`
ytdHuang d3977c6
first try of `Space` and `Dimensions` (#359)
ytdHuang d5ff284
fix tests
ytdHuang dced5d4
minor changes
ytdHuang f18d546
fix type-instability for `prod`
ytdHuang 1684fc7
Fix type-instability for `prod` (#363)
ytdHuang 6e1fe7b
Merge branch 'dev/dimensions' into dev/dims-patch-1
ytdHuang 977b7d3
modify `show` for `AbstractSpace` and `CompoundDimensions`
ytdHuang 51779f2
address the comments from admins discussions in 2025-01-06
ytdHuang 342768c
introduce field `dimensions`, and property `dims` (#361)
ytdHuang 6d12ffb
fix `CUDA` extension
ytdHuang 52af74b
fix `dims` type
ytdHuang bd598aa
minor changes
ytdHuang 65d9879
update changelog
ytdHuang 4bda75d
Merge branch 'main' into dev/dimensions
ytdHuang cb2535f
disable `permute` for arbitrary `GeneralDimensions` and fix it in the…
ytdHuang 2ecd7ef
Merge branch 'dev/dimensions' into dev/dimensions
ytdHuang 309a670
Several updates for `Dimensions` structure (#367)
ytdHuang 507892f
fix typo
ytdHuang c7383ea
fix `permute`
ytdHuang c1fbedd
minor changes
ytdHuang ac6f54c
format files
ytdHuang df53828
improve error message for generating `Qobj`
ytdHuang 442f0a7
fix runtests
ytdHuang 1f88d74
make `Dimensions`-type contains tuple of `Space`
ytdHuang c89e5a2
Merge branch 'main' into dev/dimensions
ytdHuang faacd36
fix docstrings
ytdHuang e6166b8
improve `getproperty`
ytdHuang eeac23c
fix definition of `GeneralDimensions` structure
ytdHuang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,82 @@ | ||
| export AbstractDimensions, Dimensions, CompoundDimensions | ||
|
|
||
| abstract type AbstractDimensions{N} end | ||
|
|
||
| # this show function is for printing AbstractDimensions | ||
| function Base.show(io::IO, svec::SVector{N,AbstractSpace}) where {N} | ||
| print(io, "[") | ||
| join(io, string.(svec), ", ") | ||
| return print(io, "]") | ||
| end | ||
|
|
||
| struct Dimensions{N} <: AbstractDimensions{N} | ||
| to::SVector{N,AbstractSpace} | ||
| end | ||
| function Dimensions(dims::Union{AbstractVector{T},NTuple{N,T}}) where {T<:Integer,N} | ||
ytdHuang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _non_static_array_warning("dims", dims) | ||
| L = length(dims) | ||
| (L > 0) || throw(DomainError(dims, "The argument dims must be of non-zero length")) | ||
|
|
||
| return Dimensions{L}(SVector{L,AbstractSpace}(Space.(dims))) | ||
| end | ||
| Dimensions(dims::Int) = Dimensions(SVector{1,Int}(dims)) | ||
| Dimensions(dims::Any) = throw( | ||
| ArgumentError( | ||
| "The argument dims must be a Tuple or a StaticVector of non-zero length and contain only positive integers.", | ||
| ), | ||
| ) | ||
|
|
||
| Base.show(io::IO, D::Dimensions) = print(io, D.to) | ||
|
|
||
| struct CompoundDimensions{N} <: AbstractDimensions{N} | ||
| # note that the number `N` should be the same for both `to` and `from` | ||
| to::SVector{N,AbstractSpace} # space acting on the left | ||
| from::SVector{N,AbstractSpace} # space acting on the right | ||
| end | ||
| function CompoundDimensions(dims::Union{AbstractVector{T},NTuple{N,T}}) where {T<:Union{AbstractVector,NTuple},N} | ||
| (length(dims) != 2) && throw(ArgumentError("Invalid dims = $dims")) | ||
|
|
||
| _non_static_array_warning("dims[1]", dims[1]) | ||
| _non_static_array_warning("dims[2]", dims[2]) | ||
|
|
||
| L1 = length(dims[1]) | ||
| L2 = length(dims[2]) | ||
| ((L1 > 0) && (L1 == L2)) || throw( | ||
| DomainError( | ||
| (L1, L2), | ||
| "The length of the arguments `dims[1]` and `dims[2]` must be in the same length and have at least one element.", | ||
| ), | ||
| ) | ||
|
|
||
| return CompoundDimensions{L1}( | ||
| SVector{L1,AbstractSpace}(Space.(dims[1])), | ||
| SVector{L1,AbstractSpace}(Space.(dims[2])), | ||
| ) | ||
| end | ||
|
|
||
| Base.show(io::IO, D::CompoundDimensions) = print(io, "[", D.to, ", ", D.from, "]") | ||
|
|
||
| _gen_dims(dims::AbstractDimensions) = dims | ||
| _gen_dims(dims::Union{AbstractVector{T},NTuple{N,T}}) where {T<:Integer,N} = Dimensions(dims) | ||
| _gen_dims(dims::Union{AbstractVector{T},NTuple{N,T}}) where {T<:Union{AbstractVector,NTuple},N} = | ||
| CompoundDimensions(dims) | ||
| _gen_dims(dims::Any) = Dimensions(dims) | ||
|
|
||
| # obtain dims in the type of SVector with integers | ||
| dims_to_list(dimsvec::SVector{N,AbstractSpace}) where {N} = SVector{N,Int}(ntuple(i -> dimsvec[i].size, Val(N))) | ||
| dims_to_list(dims::Dimensions) = dims_to_list(dims.to) | ||
| dims_to_list(dims::CompoundDimensions) = SVector{2}(dims_to_list(dims.to), dims_to_list(dims.from)) | ||
|
|
||
| Base.:(==)(vect::AbstractVector{T}, dims::AbstractDimensions) where {T} = vect == dims_to_list(dims) | ||
| Base.:(==)(dims::AbstractDimensions, vect::AbstractVector{T}) where {T} = vect == dims | ||
|
|
||
| Base.length(::AbstractDimensions{N}) where {N} = N | ||
|
|
||
| # need to specify return type `Int` for `_get_space_size` | ||
| # otherwise the type of `prod(::Dimensions)` will be unstable | ||
| _get_space_size(s::AbstractSpace)::Int = s.size | ||
| Base.prod(dims::Dimensions) = prod(dims.to) | ||
| Base.prod(spaces::SVector{N,AbstractSpace}) where {N} = prod(_get_space_size, spaces) | ||
|
|
||
| LinearAlgebra.transpose(dims::Dimensions) = dims | ||
| LinearAlgebra.transpose(dims::CompoundDimensions) = CompoundDimensions(dims.from, dims.to) # switch `to` and `from` | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.