Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TypeParameterAccessors"
uuid = "7e5a90cf-f82e-492e-a09b-e3e26432c138"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.2.2"
version = "0.3.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
12 changes: 0 additions & 12 deletions src/base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,6 @@ end
return set_type_parameters(type, eltype, param)
end

# These are generic fallback definitions. By convention,
# this is very commonly true of `AbstractArray` subtypes
# but it may not be correct, but it is very convenient
# to define this to make more operations "just work"
# on most AbstractArrays.
# TODO: evaluate if this is actually the case, and weigh up the benefits of ease of use
# against not having a helpful error thrown
position(type::Type{<:AbstractArray}, ::typeof(eltype)) = Position(1)
position(type::Type{<:AbstractArray}, ::typeof(ndims)) = Position(2)

default_type_parameters(::Type{<:AbstractArray}) = (Float64, 1)

for wrapper in [:PermutedDimsArray, :(Base.ReshapedArray), :SubArray]
@eval begin
position(type::Type{<:$wrapper}, ::typeof(eltype)) = Position(1)
Expand Down
22 changes: 22 additions & 0 deletions src/base/array.jl
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# TODO: Is this the best way to handle this?
# The idea is to be able to write functions that accept inputs of the form:
# ```julia
# f(AbstractArray)
# f(AbstractArray{Float64})
# f(AbstractMatrix{Float64})
# ```
# etc.
const AbstractArrayType{T,N} = Union{
Type{AbstractArray},
Type{AbstractArray{T}},
Type{AbstractArray{<:Any,N}},
Type{AbstractArray{T,N}},
}
position(::AbstractArrayType, ::typeof(eltype)) = Position(1)
position(::AbstractArrayType, ::typeof(ndims)) = Position(2)
default_type_parameters(::AbstractArrayType) = (Float64, 1)

Check warning on line 17 in src/base/array.jl

View check run for this annotation

Codecov / codecov/patch

src/base/array.jl#L17

Added line #L17 was not covered by tests

position(::Type{<:Array}, ::typeof(eltype)) = Position(1)
position(::Type{<:Array}, ::typeof(ndims)) = Position(2)
default_type_parameters(::Type{<:Array}) = (Float64, 1)

position(::Type{<:BitArray}, ::typeof(ndims)) = Position(1)
default_type_parameters(::Type{<:BitArray}) = (1,)

Check warning on line 24 in src/base/array.jl

View check run for this annotation

Codecov / codecov/patch

src/base/array.jl#L23-L24

Added lines #L23 - L24 were not covered by tests