public double dotProduct ( ConcatVector other ) { if ( loadedNative ) { return dotProductNative ( other ) ; } else { double sum = 0.0f ; for ( int i = 0 ; i < Math . min ( pointers . length , other . pointers . length ) ; i ++ ) { if ( pointers [ i ] == null || other . pointers [ i ] == null ) continue ; if ( sparse [ i ] && other . sparse [ i ] ) { outer : for ( int j = 0 ; j < pointers [ i ] . length / 2 ; j ++ ) { int sparseIndex = ( int ) pointers [ i ] [ j * 2 ] ; for ( int k = 0 ; k < other . pointers [ i ] . length / 2 ; k ++ ) { int otherSparseIndex = ( int ) other . pointers [ i ] [ k * 2 ] ; if ( sparseIndex == otherSparseIndex ) { sum += pointers [ i ] [ ( j * 2 ) + 1 ] * other . pointers [ i ] [ ( k * 2 ) + 1 ] ; continue outer ; } } } } else if ( sparse [ i ] && ! other . sparse [ i ] ) { for ( int j = 0 ; j < pointers [ i ] . length / 2 ; j ++ ) { int sparseIndex = ( int ) pointers [ i ] [ j * 2 ] ; if ( sparseIndex >= 0 && sparseIndex < other . pointers [ i ] . length ) { sum += other . pointers [ i ] [ sparseIndex ] * pointers [ i ] [ ( j * 2 ) + 1 ] ; } } } else if ( ! sparse [ i ] && other . sparse [ i ] ) { for ( int j = 0 ; j < other . pointers [ i ] . length / 2 ; j ++ ) { int sparseIndex = ( int ) other . pointers [ i ] [ j * 2 ] ; if ( sparseIndex >= 0 && sparseIndex < pointers [ i ] . length ) { sum += pointers [ i ] [ sparseIndex ] * other . pointers [ i ] [ ( j * 2 ) + 1 ] ; } } } else { for ( int j = 0 ; j < Math . min ( pointers [ i ] . length , other . pointers [ i ] . length ) ; j ++ ) { sum += pointers [ i ] [ j ] * other . pointers [ i ] [ j ] ; } } } return sum ; } }
This function assumes both vectors are infinitely padded with 0s so it won t complain if there s a dim mismatch . There are no side effects .