|
68 | 68 |
|
69 | 69 | # This helps to support diagonals where the elements are known |
70 | 70 | # from the types, for example diagonals that are `Zeros` and `Ones`. |
71 | | -function DiagonalArray{T,N,D}( |
72 | | - init::ShapeInitializer, unstored::Unstored |
73 | | -) where {T,N,D<:AbstractVector{T}} |
74 | | - return DiagonalArray{T,N,D}( |
| 71 | +function DiagonalArray{T,N,D,U}( |
| 72 | + init::ShapeInitializer, unstored::Unstored{T,N,U} |
| 73 | +) where {T,N,D<:AbstractVector{T},U<:AbstractArray{T,N}} |
| 74 | + return DiagonalArray{T,N,D,U}( |
75 | 75 | construct(D, init, diaglength_from_shape(axes(unstored))), unstored |
76 | 76 | ) |
77 | 77 | end |
| 78 | +function DiagonalArray{T,N,D}( |
| 79 | + init::ShapeInitializer, unstored::Unstored{T,N,U} |
| 80 | +) where {T,N,D<:AbstractVector{T},U<:AbstractArray{T,N}} |
| 81 | + return DiagonalArray{T,N,D,U}(init, unstored) |
| 82 | +end |
78 | 83 |
|
79 | 84 | # This helps to support diagonals where the elements are known |
80 | 85 | # from the types, for example diagonals that are `Zeros` and `Ones`. |
81 | 86 | # These versions use the default unstored type `Zeros{T,N}`. |
| 87 | +function DiagonalArray{T,N,D,U}( |
| 88 | + init::ShapeInitializer, ax::Tuple{Vararg{AbstractUnitRange{<:Integer}}} |
| 89 | +) where {T,N,D<:AbstractVector{T},U<:AbstractArray{T,N}} |
| 90 | + return DiagonalArray{T,N,D,U}(init, Unstored(U(ax))) |
| 91 | +end |
82 | 92 | function DiagonalArray{T,N,D}( |
83 | 93 | init::ShapeInitializer, ax::Tuple{Vararg{AbstractUnitRange{<:Integer}}} |
84 | 94 | ) where {T,N,D<:AbstractVector{T}} |
85 | 95 | return DiagonalArray{T,N,D}(init, Unstored(Zeros{T,N}(ax))) |
86 | 96 | end |
| 97 | +function DiagonalArray{T,N,D,U}( |
| 98 | + init::ShapeInitializer, ax::AbstractUnitRange{<:Integer}... |
| 99 | +) where {T,N,D<:AbstractVector{T},U<:AbstractArray{T,N}} |
| 100 | + return DiagonalArray{T,N,D,U}(init, ax) |
| 101 | +end |
87 | 102 | function DiagonalArray{T,N,D}( |
88 | 103 | init::ShapeInitializer, ax::AbstractUnitRange{<:Integer}... |
89 | 104 | ) where {T,N,D<:AbstractVector{T}} |
90 | 105 | return DiagonalArray{T,N,D}(init, ax) |
91 | 106 | end |
| 107 | +function DiagonalArray{T,N,D,U}( |
| 108 | + init::ShapeInitializer, sz::Tuple{Integer,Vararg{Integer}} |
| 109 | +) where {T,N,D<:AbstractVector{T},U<:AbstractArray{T,N}} |
| 110 | + return DiagonalArray{T,N,D,U}(init, Base.OneTo.(sz)) |
| 111 | +end |
92 | 112 | function DiagonalArray{T,N,D}( |
93 | 113 | init::ShapeInitializer, sz::Tuple{Integer,Vararg{Integer}} |
94 | 114 | ) where {T,N,D<:AbstractVector{T}} |
95 | 115 | return DiagonalArray{T,N,D}(init, Base.OneTo.(sz)) |
96 | 116 | end |
| 117 | +function DiagonalArray{T,N,D,U}( |
| 118 | + init::ShapeInitializer, sz1::Integer, sz_rest::Integer... |
| 119 | +) where {T,N,D<:AbstractVector{T},U<:AbstractArray{T,N}} |
| 120 | + return DiagonalArray{T,N,D,U}(init, (sz1, sz_rest...)) |
| 121 | +end |
97 | 122 | function DiagonalArray{T,N,D}( |
98 | 123 | init::ShapeInitializer, sz1::Integer, sz_rest::Integer... |
99 | 124 | ) where {T,N,D<:AbstractVector{T}} |
|
0 commit comments