|  | 
| 1 | 1 | module OffsetArrays | 
| 2 | 2 | 
 | 
| 3 | 3 | using Base: Indices, tail, @propagate_inbounds | 
| 4 |  | -import Base: (*), convert, promote_rule | 
| 5 | 4 | 
 | 
| 6 | 5 | @static if !isdefined(Base, :IdentityUnitRange) | 
| 7 | 6 |     const IdentityUnitRange = Base.Slice | 
| @@ -406,28 +405,23 @@ end | 
| 406 | 405 | 
 | 
| 407 | 406 | no_offset_view(A::OffsetArray) = no_offset_view(parent(A)) | 
| 408 | 407 | 
 | 
| 409 |  | - | 
| 410 | 408 | # Quick hack for matrix multiplication. | 
| 411 | 409 | # Ideally, one would instead improve LinearAlgebra's support of custom indexing. | 
| 412 |  | -function (*)(A::OffsetMatrix, B::OffsetMatrix) | 
|  | 410 | +function Base.:(*)(A::OffsetMatrix, B::OffsetMatrix) | 
| 413 | 411 |     matmult_check_axes(A, B) | 
| 414 |  | -    C = OffsetArray(parent(A) * parent(B), (axes(A,1), axes(B,2))) | 
|  | 412 | +    C = parent(A) * parent(B) | 
|  | 413 | +    OffsetArray{eltype(C), 2, typeof(C)}(C, (A.offsets[1], B.offsets[2])) | 
| 415 | 414 | end | 
| 416 | 415 | 
 | 
| 417 |  | -function (*)(A::OffsetMatrix, B::OffsetVector) | 
|  | 416 | +function Base.:(*)(A::OffsetMatrix, B::OffsetVector) | 
| 418 | 417 |     matmult_check_axes(A, B) | 
| 419 |  | -    C = OffsetArray(parent(A) * parent(B), axes(A,1)) | 
|  | 418 | +    C = parent(A) * parent(B) | 
|  | 419 | +    OffsetArray{eltype(C), 1, typeof(C)}(C, (A.offsets[1], )) | 
|  | 420 | +end | 
|  | 421 | +function matmult_check_axes(A, B) | 
|  | 422 | +    axes(A, 2) === axes(B, 1) || axes(A, 2) == axes(B, 1) ||  | 
|  | 423 | +        error("axes(A,2) = $(UnitRange(axes(A,2))) does not equal axes(B,1) = $(UnitRange(axes(B,1)))") | 
| 420 | 424 | end | 
| 421 |  | -matmult_check_axes(A, B) = axes(A, 2) == axes(B, 1) || error("axes(A,2) must equal axes(B,1)") | 
| 422 |  | - | 
| 423 |  | -(*)(A::OffsetMatrix, B::AbstractMatrix) = A * OffsetArray(B) | 
| 424 |  | -(*)(A::OffsetMatrix, B::AbstractVector) = A * OffsetArray(B) | 
| 425 |  | -(*)(A::AbstractMatrix, B::OffsetArray) = OffsetArray(A) * B | 
| 426 |  | -(*)(A::AbstractVector, B::OffsetArray) = OffsetArray(A) * B | 
| 427 |  | - | 
| 428 |  | -# An alternative to the above four methods would be to use promote_rule, but it doesn't get invoked | 
| 429 |  | -# 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)} | 
| 430 |  | - | 
| 431 | 425 | 
 | 
| 432 | 426 | #### | 
| 433 | 427 | # work around for segfault in searchsorted* | 
|  | 
0 commit comments