@@ -292,6 +292,14 @@ pub fn inplace_row_normalize_64(x: &mut [Vec<I64F64>]) {
292292
293293/// Returns x / y for input vectors x and y, if y == 0 return 0.
294294pub fn vecdiv ( x : & [ I32F32 ] , y : & [ I32F32 ] ) -> Vec < I32F32 > {
295+ if x. len ( ) != y. len ( ) {
296+ log:: error!(
297+ "vecdiv input lengths are not equal: {:?} != {:?}" ,
298+ x. len( ) ,
299+ y. len( )
300+ ) ;
301+ }
302+
295303 let zero = I32F32 :: saturating_from_num ( 0 ) ;
296304
297305 let mut out = Vec :: with_capacity ( x. len ( ) ) ;
@@ -477,6 +485,14 @@ pub fn inplace_col_max_upscale(x: &mut [Vec<I32F32>]) {
477485
478486// Apply mask to vector, mask=true will mask out, i.e. set to 0.
479487pub fn inplace_mask_vector ( mask : & [ bool ] , vector : & mut [ I32F32 ] ) {
488+ if mask. len ( ) != vector. len ( ) {
489+ log:: error!(
490+ "inplace_mask_vector input lengths are not equal: {:?} != {:?}" ,
491+ mask. len( ) ,
492+ vector. len( )
493+ ) ;
494+ }
495+
480496 if mask. is_empty ( ) {
481497 return ;
482498 }
@@ -490,6 +506,13 @@ pub fn inplace_mask_vector(mask: &[bool], vector: &mut [I32F32]) {
490506
491507// Apply mask to matrix, mask=true will mask out, i.e. set to 0.
492508pub fn inplace_mask_matrix ( mask : & [ Vec < bool > ] , matrix : & mut [ Vec < I32F32 > ] ) {
509+ if mask. len ( ) != matrix. len ( ) {
510+ log:: error!(
511+ "inplace_mask_matrix input sizes are not equal: {:?} != {:?}" ,
512+ mask. len( ) ,
513+ matrix. len( )
514+ ) ;
515+ }
493516 let Some ( first_row) = mask. first ( ) else {
494517 return ;
495518 } ;
@@ -513,6 +536,13 @@ pub fn inplace_mask_matrix(mask: &[Vec<bool>], matrix: &mut [Vec<I32F32>]) {
513536
514537// Apply row mask to matrix, mask=true will mask out, i.e. set to 0.
515538pub fn inplace_mask_rows ( mask : & [ bool ] , matrix : & mut [ Vec < I32F32 > ] ) {
539+ if mask. len ( ) != matrix. len ( ) {
540+ log:: error!(
541+ "inplace_mask_rows input sizes are not equal: {:?} != {:?}" ,
542+ mask. len( ) ,
543+ matrix. len( )
544+ ) ;
545+ }
516546 let Some ( first_row) = matrix. first ( ) else {
517547 return ;
518548 } ;
@@ -528,6 +558,13 @@ pub fn inplace_mask_rows(mask: &[bool], matrix: &mut [Vec<I32F32>]) {
528558// Apply column mask to matrix, mask=true will mask out, i.e. set to 0.
529559// Assumes each column has the same length.
530560pub fn inplace_mask_cols ( mask : & [ bool ] , matrix : & mut [ Vec < I32F32 > ] ) {
561+ if mask. len ( ) != matrix. len ( ) {
562+ log:: error!(
563+ "inplace_mask_cols input sizes are not equal: {:?} != {:?}" ,
564+ mask. len( ) ,
565+ matrix. len( )
566+ ) ;
567+ }
531568 if matrix. is_empty ( ) {
532569 return ;
533570 } ;
@@ -603,10 +640,13 @@ pub fn inplace_mask_diag_except_index(matrix: &mut [Vec<I32F32>], except_index:
603640 return ;
604641 }
605642 if matrix. len ( ) != first_row. len ( ) {
606- log:: error!( "inplace_mask_diag_except_index: input matrix is not square" ) ;
643+ log:: error!(
644+ "inplace_mask_diag input matrix is now square: {:?} != {:?}" ,
645+ matrix. len( ) ,
646+ first_row. len( )
647+ ) ;
607648 return ;
608649 }
609-
610650 let diag_at_index = matrix
611651 . get ( except_index as usize )
612652 . and_then ( |row| row. get ( except_index as usize ) )
@@ -752,6 +792,13 @@ pub fn matmul(matrix: &[Vec<I32F32>], vector: &[I32F32]) -> Vec<I32F32> {
752792 if cols == 0 {
753793 return vec ! [ ] ;
754794 }
795+ if matrix. len ( ) != vector. len ( ) {
796+ log:: error!(
797+ "matmul input sizes are not equal: {:?} != {:?}" ,
798+ matrix. len( ) ,
799+ vector. len( )
800+ ) ;
801+ }
755802
756803 let zero = I32F32 :: saturating_from_num ( 0.0 ) ;
757804 let mut acc = vec ! [ zero; cols] ;
@@ -783,6 +830,13 @@ pub fn matmul_transpose(matrix: &[Vec<I32F32>], vector: &[I32F32]) -> Vec<I32F32
783830 if first_row. is_empty ( ) {
784831 return vec ! [ ] ;
785832 }
833+ if matrix. len ( ) != first_row. len ( ) {
834+ log:: error!(
835+ "matmul_transpose matrix is not square: {:?} != {:?}" ,
836+ matrix. len( ) ,
837+ first_row. len( )
838+ ) ;
839+ }
786840
787841 let zero = I32F32 :: saturating_from_num ( 0.0 ) ;
788842 let mut out = Vec :: with_capacity ( matrix. len ( ) ) ;
@@ -1027,6 +1081,11 @@ pub fn weighted_median_col(
10271081 } else {
10281082 use_stake. push ( zero) ;
10291083 use_score. push ( zero) ;
1084+ log:: error!(
1085+ "weighted_median_col row.len() != columns: {:?} != {:?}" ,
1086+ row. len( ) ,
1087+ columns
1088+ ) ;
10301089 }
10311090 } else {
10321091 // Missing row: insert zeroes.
@@ -1128,6 +1187,13 @@ pub fn interpolate(mat1: &[Vec<I32F32>], mat2: &[Vec<I32F32>], ratio: I32F32) ->
11281187 if mat1. is_empty ( ) || mat1. first ( ) . map ( |r| r. is_empty ( ) ) . unwrap_or ( true ) {
11291188 return vec ! [ vec![ ] ] ;
11301189 }
1190+ if mat1. len ( ) != mat2. len ( ) {
1191+ log:: error!(
1192+ "interpolate mat1.len() != mat2.len(): {:?} != {:?}" ,
1193+ mat1. len( ) ,
1194+ mat2. len( )
1195+ ) ;
1196+ }
11311197
11321198 let zero = I32F32 :: saturating_from_num ( 0.0 ) ;
11331199 let cols = mat1. first ( ) . map ( |r| r. len ( ) ) . unwrap_or ( 0 ) ;
@@ -1147,8 +1213,16 @@ pub fn interpolate(mat1: &[Vec<I32F32>], mat2: &[Vec<I32F32>], ratio: I32F32) ->
11471213
11481214 for row1 in mat1. iter ( ) {
11491215 let ( Some ( row2) , Some ( out_row) ) = ( m2_it. next ( ) , out_it. next ( ) ) else {
1216+ log:: error!( "interpolate: No more rows in mat2" ) ;
11501217 break ;
11511218 } ;
1219+ if row1. len ( ) != row2. len ( ) {
1220+ log:: error!(
1221+ "interpolate row1.len() != row2.len(): {:?} != {:?}" ,
1222+ row1. len( ) ,
1223+ row2. len( )
1224+ ) ;
1225+ }
11521226
11531227 // Walk elements of row1, row2, and out_row in lockstep; stop at the shortest.
11541228 let mut r1_it = row1. iter ( ) ;
@@ -1184,6 +1258,11 @@ pub fn interpolate_sparse(
11841258 }
11851259 if mat1. len ( ) != mat2. len ( ) {
11861260 // In case if sizes mismatch, return clipped weights
1261+ log:: error!(
1262+ "interpolate_sparse: mat1.len() != mat2.len(): {:?} != {:?}" ,
1263+ mat1. len( ) ,
1264+ mat2. len( )
1265+ ) ;
11871266 return mat2. to_owned ( ) ;
11881267 }
11891268 let rows = mat1. len ( ) ;
@@ -1329,6 +1408,14 @@ pub fn mat_ema_sparse(
13291408 old : & [ Vec < ( u16 , I32F32 ) > ] ,
13301409 alpha : I32F32 ,
13311410) -> Vec < Vec < ( u16 , I32F32 ) > > {
1411+ if new. len ( ) != old. len ( ) {
1412+ log:: error!(
1413+ "mat_ema_sparse: new.len() == old.len(): {:?} != {:?}" ,
1414+ new. len( ) ,
1415+ old. len( )
1416+ ) ;
1417+ }
1418+
13321419 let zero = I32F32 :: saturating_from_num ( 0.0 ) ;
13331420 let one_minus_alpha = I32F32 :: saturating_from_num ( 1.0 ) . saturating_sub ( alpha) ;
13341421
@@ -1381,6 +1468,12 @@ pub fn mat_ema_alpha_sparse(
13811468) -> Vec < Vec < ( u16 , I32F32 ) > > {
13821469 // If shapes don't match, just return `new`
13831470 if new. len ( ) != old. len ( ) || new. len ( ) != alpha. len ( ) {
1471+ log:: error!(
1472+ "mat_ema_alpha_sparse shapes don't match: {:?} vs. {:?} vs. {:?}" ,
1473+ old. len( ) ,
1474+ new. len( ) ,
1475+ alpha. len( )
1476+ ) ;
13841477 return new. to_owned ( ) ;
13851478 }
13861479
@@ -1397,6 +1490,15 @@ pub fn mat_ema_alpha_sparse(
13971490 break ;
13981491 } ;
13991492
1493+ if new_row. len ( ) != old_row. len ( ) || new_row. len ( ) != alpha_row. len ( ) {
1494+ log:: error!(
1495+ "mat_ema_alpha_sparse row shapes don't match: {:?} vs. {:?} vs. {:?}" ,
1496+ old_row. len( ) ,
1497+ new_row. len( ) ,
1498+ alpha_row. len( )
1499+ ) ;
1500+ }
1501+
14001502 // Densified accumulator sized to alpha_row length (columns outside are ignored).
14011503 let mut decayed_values = vec ! [ zero; alpha_row. len( ) ] ;
14021504
@@ -1443,6 +1545,12 @@ pub fn mat_ema_alpha(
14431545
14441546 // If outer dimensions don't match, return bonds unchanged
14451547 if new. len ( ) != old. len ( ) || new. len ( ) != alpha. len ( ) {
1548+ log:: error!(
1549+ "mat_ema_alpha shapes don't match: {:?} vs. {:?} vs. {:?}" ,
1550+ old. len( ) ,
1551+ new. len( ) ,
1552+ alpha. len( )
1553+ ) ;
14461554 return old. to_owned ( ) ;
14471555 }
14481556
0 commit comments