Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matmul: don't assume the existence of type-conversions #14293

Merged
merged 1 commit into from
Dec 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put these in a let or give them issue-number-specific names

nevermind guess it isn't necessary here, the same file is already using these names above

C = [0]
A_mul_Bt!(C, a, a)
@test C[1] == 9
a = [RootInt(2),RootInt(10)]
@test a*a' == [4 20; 20 100]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how this passed without defining zero(::Type{RootInt}) ?

oh right this also depends on #13803

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to backport this, we could add that method (for use by the test).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the promote_op changes I don't think this will work?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A = [RootInt(3) RootInt(5)]
@test A*a == [56]