Skip to content

Commit 7733b94

Browse files
committed
Check multiplication when making out array in kron
1 parent 455d5e0 commit 7733b94

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/linalg/impl_linalg.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use crate::OwnedRepr;
109
use crate::imp_prelude::*;
1110
use crate::numeric_util;
1211
#[cfg(feature = "blas")]
@@ -717,16 +716,22 @@ where
717716
let dimac = a.shape()[1];
718717
let dimbr = b.shape()[0];
719718
let dimbc = b.shape()[1];
720-
let mut out: Array2<MaybeUninit<A>> = Array2::uninit((dimar * dimbr, dimac * dimbc));
719+
let mut out: Array2<MaybeUninit<A>> = Array2::uninit((
720+
dimar
721+
.checked_mul(dimbr)
722+
.expect("Dimensions of kronecker product output array overflows usize."),
723+
dimac
724+
.checked_mul(dimbc)
725+
.expect("Dimensions of kronecker product output array overflows usize."),
726+
));
721727
Zip::from(out.exact_chunks_mut((dimbr, dimbc)))
722728
.and(a)
723-
.for_each(|out, a| {
724-
(*a * b).assign_to(out);
729+
.for_each(|out, &a| {
730+
(a * b).assign_to(out);
725731
});
726732
unsafe { out.assume_init() }
727733
}
728734

729-
730735
#[inline(always)]
731736
/// Return `true` if `A` and `B` are the same type
732737
fn same_type<A: 'static, B: 'static>() -> bool {

0 commit comments

Comments
 (0)