Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
19 changes: 14 additions & 5 deletions src/ndarray/binary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,20 @@ function Base.:(*)(rhs1::NDArray{Bool,2}, rhs2::NDArray{Bool,2})
)
end

function Base.:(*)(rhs1::NDArray{<:Integer,2}, rhs2::NDArray{<:Integer,2})
#* this is a stupid.....
throw(
ArgumentError("cuNumeric.jl does not support matrix multiplication of two Integer arrays")
)
function Base.:(*)(rhs1::NDArray{T,2}, rhs2::NDArray{T,2}) where {T<:Integer}

size(rhs1, 2) == size(rhs2, 1) || throw(DimensionMismatch("Matrix dimensions incompatible: $(size(rhs1)) × $(size(rhs2))"))

IntermediateType = Float64

A_float = cuNumeric.as_type(rhs1, IntermediateType)
B_float = cuNumeric.as_type(rhs2, IntermediateType)

C_float = A_float * B_float
C_int = cuNumeric.as_type(C_float, T)
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

Converting through Float64 may cause precision loss or overflow for large integer values. For Int32 values, Float64 has 53 bits of mantissa precision, which can represent all Int32 values exactly. However, for Int64, values larger than 2^53 will lose precision. Consider documenting this limitation or adding a check for Int64 matrices with large values.

Copilot uses AI. Check for mistakes.

return C_int

end

@doc"""
Expand Down
7 changes: 3 additions & 4 deletions test/tests/gemm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ function gemm(N, M, T, max_diff)
if T <: Integer
a = cuNumeric.ones(Int32, 5, 5)
a_jl = ones(Int32, 5, 5)
b = cuNumeric.ones(Float32, 5, 5)
b_jl = ones(Float32, 5, 5)
@test_throws ArgumentError a * a
@test @allowscalar cuNumeric.compare(a_jl * b_jl, a * b, 0.0, max_diff)
b = a * a
b_jl = a_jl * a_jl
@test @allowscalar cuNumeric.compare(b_jl, b, 0.0, max_diff)
return
end

Expand Down
Loading