File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 5
5
6
6
// Function to broadcast two matrices
7
7
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
+
8
12
size_t rowsA = A.size ();
9
13
size_t colsA = A[0 ].size ();
10
14
size_t rowsB = B.size ();
11
15
size_t colsB = B[0 ].size ();
12
16
13
17
if (rowsA != rowsB && rowsB != 1 ) {
14
- throw std::invalid_argument (" Incompatible dimensions for broadcasting" );
18
+ throw std::invalid_argument (" Incompatible dimensions for broadcasting (rows) " );
15
19
}
16
20
if (colsA != colsB && colsB != 1 ) {
17
- throw std::invalid_argument (" Incompatible dimensions for broadcasting" );
21
+ throw std::invalid_argument (" Incompatible dimensions for broadcasting (columns) " );
18
22
}
19
23
20
24
if (rowsB == 1 ) {
You can’t perform that action at this time.
0 commit comments