@@ -105,17 +105,17 @@ internal static MatlabMatrix FormatMatrix<T>(Matrix<T> matrix, string name)
105105 {
106106 if ( matrix == null )
107107 {
108- throw new ArgumentNullException ( " matrix" ) ;
108+ throw new ArgumentNullException ( nameof ( matrix ) ) ;
109109 }
110110
111111 if ( string . IsNullOrEmpty ( name ) )
112112 {
113- throw new ArgumentException ( "String parameter cannot be empty or null." , " name" ) ;
113+ throw new ArgumentException ( "String parameter cannot be empty or null." , nameof ( name ) ) ;
114114 }
115115
116116 if ( name . IndexOf ( ' ' ) > - 1 )
117117 {
118- throw new ArgumentException ( string . Format ( "Name cannot contain a space.name: {0 }" , name ) , "name" ) ;
118+ throw new ArgumentException ( $ "Name cannot contain a space.name: { name } ", nameof ( name ) ) ;
119119 }
120120
121121 var dataType = typeof ( T ) ;
@@ -167,7 +167,7 @@ internal static MatlabMatrix FormatMatrix<T>(Matrix<T> matrix, string name)
167167 writer . Write ( ( byte ) ( sparse ? ArrayClass . Sparse : doublePrecision ? ArrayClass . Double : ArrayClass . Single ) ) ;
168168 writer . Write ( ( byte ) ( complex ? ArrayFlags . Complex : 0 ) ) ;
169169 writer . Write ( ( short ) 0 ) ;
170- writer . Write ( ( int ) sparseNonZeroValues ) ;
170+ writer . Write ( sparseNonZeroValues ) ;
171171
172172 // Dimensions Array tag: data type + size (8 bytes)
173173 writer . Write ( ( int ) DataType . Int32 ) ;
@@ -178,11 +178,10 @@ internal static MatlabMatrix FormatMatrix<T>(Matrix<T> matrix, string name)
178178 writer . Write ( matrix . ColumnCount ) ;
179179
180180 // Array Name:
181- bool smallBlock ;
182181 var nameBytes = Encoding . ASCII . GetBytes ( name ) ;
183- WriteElementTag ( writer , DataType . Int8 , nameBytes . Length , out smallBlock ) ;
182+ WriteElementTag ( writer , DataType . Int8 , nameBytes . Length , out var isSmallBlock ) ;
184183 writer . Write ( nameBytes ) ;
185- PadElement ( writer , nameBytes . Length , smallBlock ) ;
184+ PadElement ( writer , nameBytes . Length , isSmallBlock ) ;
186185
187186 if ( sparse )
188187 {
@@ -203,9 +202,8 @@ static void WriteDenseMatrix<T>(BinaryWriter writer, Matrix<T> matrix, bool comp
203202 {
204203 int count = matrix . RowCount * matrix . ColumnCount ;
205204
206- bool smallBlock ;
207205 int size = doublePrecision ? count * 8 : count * 4 ;
208- WriteElementTag ( writer , doublePrecision ? DataType . Double : DataType . Single , size , out smallBlock ) ;
206+ WriteElementTag ( writer , doublePrecision ? DataType . Double : DataType . Single , size , out var isSmallBlock ) ;
209207
210208 var data = ( ( DenseColumnMajorMatrixStorage < T > ) matrix . Storage ) . Data ;
211209
@@ -219,14 +217,14 @@ static void WriteDenseMatrix<T>(BinaryWriter writer, Matrix<T> matrix, bool comp
219217 }
220218 else if ( doublePrecision )
221219 {
222- WriteComplexArray ( writer , ( Complex [ ] ) ( object ) data , data . Length , size , ref smallBlock ) ;
220+ WriteComplexArray ( writer , ( Complex [ ] ) ( object ) data , data . Length , size , ref isSmallBlock ) ;
223221 }
224222 else
225223 {
226- WriteComplex32Array ( writer , ( Complex32 [ ] ) ( object ) data , data . Length , size , ref smallBlock ) ;
224+ WriteComplex32Array ( writer , ( Complex32 [ ] ) ( object ) data , data . Length , size , ref isSmallBlock ) ;
227225 }
228226
229- PadElement ( writer , size , smallBlock ) ;
227+ PadElement ( writer , size , isSmallBlock ) ;
230228 }
231229
232230 static void WriteSparseMatrix < T > ( BinaryWriter writer , Matrix < T > matrix , bool complex , bool doublePrecision )
@@ -235,32 +233,31 @@ static void WriteSparseMatrix<T>(BinaryWriter writer, Matrix<T> matrix, bool com
235233 var transposed = matrix . Transpose ( ) ;
236234 var storage = ( SparseCompressedRowMatrixStorage < T > ) transposed . Storage ;
237235
238- bool smallBlock ;
239236 int nzcount = storage . ValueCount ;
240237
241238 // row data array
242239 var ir = storage . ColumnIndices ;
243- WriteElementTag ( writer , DataType . Int32 , nzcount * 4 , out smallBlock ) ;
240+ WriteElementTag ( writer , DataType . Int32 , nzcount * 4 , out var isSmallBlock ) ;
244241 for ( var i = 0 ; i < nzcount ; i ++ )
245242 {
246243 writer . Write ( ir [ i ] ) ;
247244 }
248245
249- PadElement ( writer , nzcount * 4 , smallBlock ) ;
246+ PadElement ( writer , nzcount * 4 , isSmallBlock ) ;
250247
251248 // column data array
252249 var jc = storage . RowPointers ;
253- WriteElementTag ( writer , DataType . Int32 , jc . Length * 4 , out smallBlock ) ;
250+ WriteElementTag ( writer , DataType . Int32 , jc . Length * 4 , out isSmallBlock ) ;
254251 for ( var i = 0 ; i < jc . Length ; i ++ )
255252 {
256253 writer . Write ( jc [ i ] ) ;
257254 }
258255
259- PadElement ( writer , jc . Length * 4 , smallBlock ) ;
256+ PadElement ( writer , jc . Length * 4 , isSmallBlock ) ;
260257
261258 // values
262259 int size = doublePrecision ? nzcount * 8 : nzcount * 4 ;
263- WriteElementTag ( writer , doublePrecision ? DataType . Double : DataType . Single , size , out smallBlock ) ;
260+ WriteElementTag ( writer , doublePrecision ? DataType . Double : DataType . Single , size , out isSmallBlock ) ;
264261
265262 if ( doublePrecision && ! complex )
266263 {
@@ -272,14 +269,14 @@ static void WriteSparseMatrix<T>(BinaryWriter writer, Matrix<T> matrix, bool com
272269 }
273270 else if ( doublePrecision )
274271 {
275- WriteComplexArray ( writer , ( Complex [ ] ) ( object ) storage . Values , nzcount , size , ref smallBlock ) ;
272+ WriteComplexArray ( writer , ( Complex [ ] ) ( object ) storage . Values , nzcount , size , ref isSmallBlock ) ;
276273 }
277274 else
278275 {
279- WriteComplex32Array ( writer , ( Complex32 [ ] ) ( object ) storage . Values , nzcount , size , ref smallBlock ) ;
276+ WriteComplex32Array ( writer , ( Complex32 [ ] ) ( object ) storage . Values , nzcount , size , ref isSmallBlock ) ;
280277 }
281278
282- PadElement ( writer , size , smallBlock ) ;
279+ PadElement ( writer , size , isSmallBlock ) ;
283280 }
284281
285282 static void WriteDoubleArray ( BinaryWriter writer , double [ ] data , int count )
@@ -348,7 +345,7 @@ static void WriteElementTag(BinaryWriter writer, DataType dataType, int size, ou
348345 }
349346 }
350347
351- static void PadElement ( BinaryWriter writer , int size , bool smallBlock , byte padValue = ( byte ) 0 )
348+ static void PadElement ( BinaryWriter writer , int size , bool smallBlock , byte padValue = 0 )
352349 {
353350 var blockSize = smallBlock ? SmallBlockSize : LargeBlockSize ;
354351 var offset = 0 ;
@@ -364,7 +361,7 @@ static void PadElement(BinaryWriter writer, int size, bool smallBlock, byte padV
364361 }
365362 }
366363
367- static void Pad ( BinaryWriter writer , int count , byte padValue = ( byte ) 0 )
364+ static void Pad ( BinaryWriter writer , int count , byte padValue = 0 )
368365 {
369366 for ( var i = 0 ; i < count ; i ++ )
370367 {
0 commit comments