Skip to content

Commit 37e6f7b

Browse files
authored
Merge pull request #30 from vaibhavsiingh/issue11
fixed the edge case
2 parents 4aa04aa + 56ae65a commit 37e6f7b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/broadcast.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55

66
// Function to broadcast two matrices
77
void broadcast(const std::vector<std::vector<int>>& A, std::vector<std::vector<int>>& B) {
8+
if (A.empty() || B.empty()) {
9+
throw std::invalid_argument("Matrix A or B cannot be empty");
10+
}
11+
812
size_t rowsA = A.size();
913
size_t colsA = A[0].size();
1014
size_t rowsB = B.size();
1115
size_t colsB = B[0].size();
1216

1317
if (rowsA != rowsB && rowsB != 1) {
14-
throw std::invalid_argument("Incompatible dimensions for broadcasting");
18+
throw std::invalid_argument("Incompatible dimensions for broadcasting (rows)");
1519
}
1620
if (colsA != colsB && colsB != 1) {
17-
throw std::invalid_argument("Incompatible dimensions for broadcasting");
21+
throw std::invalid_argument("Incompatible dimensions for broadcasting (columns)");
1822
}
1923

2024
if (rowsB == 1) {

0 commit comments

Comments
 (0)