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

Consistently check matrix sizes in matmul #1152

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jishnub
Copy link
Collaborator

@jishnub jishnub commented Dec 21, 2024

Fixes #1147, and makes the error messages more verbose.

Before

julia> zeros(0,4) * zeros(1)
ERROR: DimensionMismatch: second dimension of matrix, 4, does not match length of input vector, 1
[...]

julia> mul!(zeros(0), zeros(2,2), zeros(2))
ERROR: DimensionMismatch: first dimension of matrix, 2, does not match length of output vector, 0
[...]

After

julia> zeros(0,4) * zeros(1)
ERROR: DimensionMismatch: incompatible dimensions for matrix multiplication: tried to multiply a matrix of size (0, 4) with a vector of length 1. The second dimension of the matrix: 4, does not match the length of the vector: 1.
[...]

julia> zeros(0,4) * zeros(1,1)
ERROR: DimensionMismatch: incompatible dimensions for matrix multiplication: tried to multiply a matrix of size (0, 4) with a matrix of size (1, 1). The second dimension of the first matrix: 4, does not match the first dimension of the second matrix: 1.
[...]

julia> mul!(zeros(0), zeros(2,2), zeros(2))
ERROR: DimensionMismatch: incompatible destination size: the destination vector of length 0 is incomatible with the product of a matrix of size (2, 2) and a vector of length 2. The destination must be of length 2.
[...]

julia> mul!(zeros(0,1), zeros(3,2), zeros(2,3))
ERROR: DimensionMismatch: incompatible destination size: the destination matrix of size (0, 1) is incomatible with the product of a matrix of size (3, 2) and a matrix of size (2, 3). The destination must be of size (3, 3).
[...]

Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

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

Beautiful! Are these all size checks in matmul? I'd expect it in every matrix type file, like triangular etc.

Copy link

codecov bot commented Dec 22, 2024

Codecov Report

Attention: Patch coverage is 94.73684% with 4 lines in your changes missing coverage. Please review.

Project coverage is 91.87%. Comparing base (6e5ea12) to head (9f1edba).

Files with missing lines Patch % Lines
src/matmul.jl 93.33% 3 Missing ⚠️
src/triangular.jl 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1152      +/-   ##
==========================================
+ Coverage   91.83%   91.87%   +0.04%     
==========================================
  Files          34       34              
  Lines       15363    15355       -8     
==========================================
  Hits        14108    14108              
+ Misses       1255     1247       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jishnub jishnub force-pushed the jishnub/matmul_error branch from 55cb3ff to 6d86546 Compare December 23, 2024 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure to check dimensions when multiplying an empty array
2 participants