@@ -70,7 +70,7 @@ public static partial class BinaryRelations
70
70
}
71
71
72
72
/// <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
74
74
/// </summary>
75
75
/// <param name="matrix1">binary matrix</param>
76
76
/// <param name="x">index [1..n]</param>
@@ -80,7 +80,7 @@ public static partial class BinaryRelations
80
80
if ( x == null ) throw new ArgumentNullException ( nameof ( x ) ) ;
81
81
ThrowIfNull_NotQuad ( matrix1 ) ;
82
82
var length = matrix1 . GetLength ( 0 ) ;
83
- var set = x . Select ( p => -- p ) . ToList ( ) ;
83
+ var set = x . Select ( p => -- p ) . OrderBy ( a => a ) . ToList ( ) ;
84
84
var result = new bool [ x . Length , x . Length ] ;
85
85
86
86
for ( int i = 0 ; i < length ; i ++ )
@@ -92,7 +92,33 @@ public static partial class BinaryRelations
92
92
}
93
93
}
94
94
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 ;
96
122
}
97
123
98
124
#endregion
0 commit comments