Skip to content

Commit

Permalink
Merge pull request #14293 from JuliaLang/teh/matmul_types
Browse files Browse the repository at this point in the history
matmul: don't assume the existence of type-conversions
  • Loading branch information
jakebolewski committed Dec 8, 2015
2 parents 14bb60a + 709c867 commit f5f3b57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 7 additions & 4 deletions base/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,15 @@ function generic_matmatmul!{T,S,R}(C::AbstractVecOrMat{R}, tA, tB, A::AbstractVe
return matmul3x3!(C, tA, tB, A, B)
end

tile_size = 0
if isbits(R) && isbits(T) && isbits(S)
tile_size = floor(Int,sqrt(tilebufsize/max(sizeof(R),sizeof(S),sizeof(T))))
end
@inbounds begin
if isbits(R)
tile_size = floor(Int,sqrt(tilebufsize/sizeof(R)))
if tile_size > 0
sz = (tile_size, tile_size)
Atile = pointer_to_array(convert(Ptr{R}, pointer(Abuf)), sz)
Btile = pointer_to_array(convert(Ptr{R}, pointer(Bbuf)), sz)
Atile = pointer_to_array(convert(Ptr{T}, pointer(Abuf)), sz)
Btile = pointer_to_array(convert(Ptr{S}, pointer(Bbuf)), sz)

z = zero(R)

Expand Down
17 changes: 17 additions & 0 deletions test/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,20 @@ b = rand(3,3)
@test_throws ArgumentError A_mul_B!(a, a, b)
@test_throws ArgumentError A_mul_B!(a, b, a)
@test_throws ArgumentError A_mul_B!(a, a, a)

# Number types that lack conversion to the destination type (#14293)
immutable RootInt
i::Int
end
import Base: *, promote_op
(*)(x::RootInt, y::RootInt) = x.i*y.i
promote_op(::Base.MulFun, ::Type{RootInt}, ::Type{RootInt}) = Int

a = [RootInt(3)]
C = [0]
A_mul_Bt!(C, a, a)
@test C[1] == 9
a = [RootInt(2),RootInt(10)]
@test a*a' == [4 20; 20 100]
A = [RootInt(3) RootInt(5)]
@test A*a == [56]

0 comments on commit f5f3b57

Please sign in to comment.