@@ -70,7 +70,7 @@ public static partial class BinaryRelations
7070 }
7171
7272 /// <summary>
73- /// Narrows matrix to region defined by the set of X..Xi..Xn. Indexes are starting from 1
73+ /// Narrows matrix to the region defined by the set of X..Xi..Xn. Indexes are starting from 1 and will be sorted
7474 /// </summary>
7575 /// <param name="matrix1">binary matrix</param>
7676 /// <param name="x">index [1..n]</param>
@@ -80,7 +80,7 @@ public static partial class BinaryRelations
8080 if ( x == null ) throw new ArgumentNullException ( nameof ( x ) ) ;
8181 ThrowIfNull_NotQuad ( matrix1 ) ;
8282 var length = matrix1 . GetLength ( 0 ) ;
83- var set = x . Select ( p => -- p ) . ToList ( ) ;
83+ var set = x . Select ( p => -- p ) . OrderBy ( a => a ) . ToList ( ) ;
8484 var result = new bool [ x . Length , x . Length ] ;
8585
8686 for ( int i = 0 ; i < length ; i ++ )
@@ -92,7 +92,33 @@ public static partial class BinaryRelations
9292 }
9393 }
9494
95- return result ;
95+ return result ;
96+ }
97+
98+ /// <summary>
99+ /// Narrows matrix to the region defined by the set of X..Xi..Xn, but preserves it's original size. Indexes are starting from 1 and will be sorted
100+ /// </summary>
101+ /// <param name="matrix1">binary matrix</param>
102+ /// <param name="x">index [1..n]</param>
103+ /// <returns>binary matrix</returns>
104+ public static bool [ , ] NarrowingPreserveSize ( this bool [ , ] matrix1 , params int [ ] x )
105+ {
106+ if ( x == null ) throw new ArgumentNullException ( nameof ( x ) ) ;
107+ ThrowIfNull_NotQuad ( matrix1 ) ;
108+ var length = matrix1 . GetLength ( 0 ) ;
109+ var result = ( bool [ , ] ) matrix1 . Clone ( ) ;
110+ x = x . Select ( p => -- p ) . OrderBy ( a => a ) . ToArray ( ) ;
111+
112+ for ( int i = 0 ; i < length ; i ++ )
113+ {
114+ for ( int j = 0 ; j < length ; j ++ )
115+ {
116+ if ( ! x . Contains ( i ) || ! x . Contains ( j ) )
117+ result [ i , j ] = false ;
118+ }
119+ }
120+
121+ return result ;
96122 }
97123
98124 #endregion
0 commit comments