You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- New methods for * for combinations of OffsetArray and AbstractArray
Unfortunately this introduces method ambiguities with Base.
- As an alternative, tried defining a new promote_rule, but somehow it doesn't get invoked.
New convenience constructors
- Wrap any (non-offset) array as an OffsetArray with standard indices
- Remove layer of indirection when constructing with explicit offsets
Cosmetic edits to constructor section for improved readability
# Ideally, one would instead improve LinearAlgebra's support of custom indexing.
300
+
function (*)(A::OffsetMatrix, B::OffsetMatrix)
301
+
matmult_check_axes(A, B)
302
+
C =OffsetArray(parent(A) *parent(B), (axes(A,1), axes(B,2)))
303
+
end
304
+
305
+
function (*)(A::OffsetMatrix, B::OffsetVector)
306
+
matmult_check_axes(A, B)
307
+
C =OffsetArray(parent(A) *parent(B), axes(A,1))
308
+
end
309
+
matmult_check_axes(A, B) =axes(A, 2) ==axes(B, 1) ||error("axes(A,2) must equal axes(B,1)")
310
+
311
+
(*)(A::OffsetMatrix, B::AbstractMatrix) = A *OffsetArray(B)
312
+
(*)(A::OffsetMatrix, B::AbstractVector) = A *OffsetArray(B)
313
+
(*)(A::AbstractMatrix, B::OffsetArray) =OffsetArray(A) * B
314
+
(*)(A::AbstractVector, B::OffsetArray) =OffsetArray(A) * B
315
+
316
+
# An alternative to the above four methods would be to use promote_rule, but it doesn't get invoked
317
+
# promote_rule(::Type{A1}, ::Type{A2}) where A1<:AbstractArray{<:Any,N} where A2<:OffsetArray{<:Any,N,A3} where {N,A3} = OffsetArray{eltype(promote_type(A1, A3)), N, promote_type(A1, A3)}
0 commit comments