-
Notifications
You must be signed in to change notification settings - Fork 0
Add ndims
type parameter to AbstractArrayInterface
#42
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
Changes from 6 commits
fbb9192
3011bfc
741c75c
70f82e1
ecd8379
d9faf8c
1942bdd
51fbbb1
2c34966
a2ab28d
8c3705b
ce0ee30
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "DerivableInterfaces" | ||
uuid = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f" | ||
authors = ["ITensor developers <[email protected]> and contributors"] | ||
version = "0.4.5" | ||
version = "0.5.0" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,16 @@ export concatenate | |
|
||
using Base: promote_eltypeof | ||
using ..DerivableInterfaces: | ||
DerivableInterfaces, AbstractInterface, interface, zero!, arraytype | ||
DerivableInterfaces, AbstractArrayInterface, interface, zero!, arraytype | ||
|
||
unval(x) = x | ||
unval(::Val{x}) where {x} = x | ||
|
||
set_interface_ndims(::Type{Nothing}, ::Val{N}) where {N} = nothing | ||
function set_interface_ndims(Interface::Type{<:AbstractArrayInterface}, ::Val{N}) where {N} | ||
return Interface(Val(N)) | ||
end | ||
|
||
function _Concatenated end | ||
|
||
""" | ||
|
@@ -42,25 +47,31 @@ function _Concatenated end | |
Lazy representation of the concatenation of various `Args` along `Dims`, in order to provide | ||
hooks to customize the implementation. | ||
""" | ||
struct Concatenated{Interface,Dims,Args<:Tuple} | ||
struct Concatenated{Interface<:Union{AbstractArrayInterface,Nothing},Dims,Args<:Tuple} | ||
interface::Interface | ||
dims::Val{Dims} | ||
args::Args | ||
global @inline function _Concatenated( | ||
interface::Interface, dims::Val{Dims}, args::Args | ||
) where {Interface,Dims,Args<:Tuple} | ||
) where {Interface<:Union{AbstractArrayInterface,Nothing},Dims,Args<:Tuple} | ||
return new{Interface,Dims,Args}(interface, dims, args) | ||
end | ||
end | ||
|
||
function Concatenated(interface::Union{Nothing,AbstractInterface}, dims::Val, args::Tuple) | ||
function Concatenated(interface::Nothing, dims::Val, args::Tuple) | ||
return _Concatenated(interface, dims, args) | ||
end | ||
function Concatenated(interface::AbstractArrayInterface, dims::Val, args::Tuple) | ||
N = cat_ndims(dims, args...) | ||
return _Concatenated(typeof(interface)(Val(N)), dims, args) | ||
end | ||
function Concatenated(dims::Val, args::Tuple) | ||
return Concatenated(interface(args...), dims, args) | ||
N = cat_ndims(dims, args...) | ||
return _Concatenated(typeof(interface(args...))(Val(N)), dims, args) | ||
end | ||
function Concatenated{Interface}(dims::Val, args::Tuple) where {Interface} | ||
return Concatenated(Interface(), dims, args) | ||
N = cat_ndims(dims, args...) | ||
return _Concatenated(set_interface_ndims(Interface, Val(N)), dims, args) | ||
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. With this new call to 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. That's true, when you call I suppose what this does is catch cases where a user specifies an interface but it actually has the wrong But also thinking about this particular constructor, it should change the 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. In the latest commits I propose a compromise. If the interface object is passed explicitly, it is taken "as is" and isn't modified, even if the That matches the behavior of julia> using Base.Broadcast: DefaultArrayStyle, Broadcasted
julia> bc = Broadcasted(DefaultArrayStyle{1}(), +, (randn(2, 2), randn(2, 2)))
Broadcasted(+, ([0.095430782012298 0.4338409876936397; -0.2285907590132556 2.0739880112106475], [-0.6626604337472756 0.5369654075753642; 0.2681815713554777 -0.7930248596990674]))
julia> bc.style
DefaultArrayStyle{1}()
julia> bc = Broadcasted(+, (randn(2, 2), randn(2, 2)))
Broadcasted(+, ([-0.08113666651442918 -0.11158415095613558; -0.5031937898445847 -1.1018574952687241], [-1.595659893181313 0.12746978522353117; 0.026558187695457296 -0.22363363427492086]))
julia> bc.style
DefaultArrayStyle{2}() That seems reasonable, since the interface is meant to be something where you can specify it to decide on the dispatch, I think we shouldn't be too opinionated about modifying what the user input since it may have been deliberate. |
||
end | ||
|
||
dims(::Concatenated{<:Any,D}) where {D} = D | ||
|
Uh oh!
There was an error while loading. Please reload this page.