@@ -43,38 +43,6 @@ internal class MatrixBuilder : MatrixBuilder<double>
4343
4444 public override double One => 1d ;
4545
46-
47-
48-
49-
50-
51-
52-
53-
54-
55-
56-
57-
58-
59-
60-
61-
62-
63-
64-
65-
66-
67-
68-
69-
70-
71-
72-
73-
74-
75-
76-
77-
7846 public override Matrix < double > Dense ( DenseColumnMajorMatrixStorage < double > storage )
7947 {
8048 return new DenseMatrix ( storage ) ;
@@ -341,6 +309,76 @@ internal class VectorBuilder : VectorBuilder<Numerics.Complex32>
341309 }
342310}
343311
312+ namespace MathNet . Numerics . LinearAlgebra . Int
313+ {
314+ internal class MatrixBuilder : MatrixBuilder < int >
315+ {
316+ public override int Zero => 0 ;
317+
318+ public override int One => 1 ;
319+
320+ public override Matrix < int > Dense ( DenseColumnMajorMatrixStorage < int > storage )
321+ {
322+ return new DenseMatrix ( storage ) ;
323+ }
324+
325+ public override Matrix < int > Sparse ( SparseCompressedRowMatrixStorage < int > storage )
326+ {
327+ throw new NotSupportedException ( ) ;
328+ //return new SparseMatrix(storage);
329+ }
330+
331+ public override Matrix < int > Diagonal ( DiagonalMatrixStorage < int > storage )
332+ {
333+ throw new NotSupportedException ( ) ;
334+ //return new DiagonalMatrix(storage);
335+ }
336+
337+ public override Matrix < int > Random ( int rows , int columns , IContinuousDistribution distribution )
338+ {
339+ return Dense ( rows , columns , Generate . Random ( rows * columns , distribution ) . Select ( x => ( int ) x ) . ToArray ( ) ) ;
340+ }
341+
342+ public override IIterationStopCriterion < int > [ ] IterativeSolverStopCriteria ( int maxIterations = 1000 )
343+ {
344+ return new IIterationStopCriterion < int > [ ]
345+ {
346+ new FailureStopCriterion < int > ( ) ,
347+ new DivergenceStopCriterion < int > ( ) ,
348+ new IterationCountStopCriterion < int > ( maxIterations ) ,
349+ new ResidualStopCriterion < int > ( 1e-12 )
350+ } ;
351+ }
352+
353+ internal override int Add ( int x , int y )
354+ {
355+ return x + y ;
356+ }
357+ }
358+
359+ internal class VectorBuilder : VectorBuilder < int >
360+ {
361+ public override int Zero => 0 ;
362+
363+ public override int One => 1 ;
364+
365+ public override Vector < int > Dense ( DenseVectorStorage < int > storage )
366+ {
367+ return new DenseVector ( storage ) ;
368+ }
369+
370+ public override Vector < int > Sparse ( SparseVectorStorage < int > storage )
371+ {
372+ throw new NotSupportedException ( ) ;
373+ //return new SparseVector(storage);
374+ }
375+
376+ public override Vector < int > Random ( int length , IContinuousDistribution distribution )
377+ {
378+ return Dense ( Generate . Random ( length , distribution ) . Select ( x => ( int ) x ) . ToArray ( ) ) ;
379+ }
380+ }
381+ }
344382namespace MathNet . Numerics . LinearAlgebra
345383{
346384 /// <summary>
@@ -1722,7 +1760,12 @@ static Tuple<MatrixBuilder<T>, VectorBuilder<T>> Create()
17221760 ( MatrixBuilder < T > ) ( object ) new Single . MatrixBuilder ( ) ,
17231761 ( VectorBuilder < T > ) ( object ) new Single . VectorBuilder ( ) ) ;
17241762 }
1725-
1763+ if ( typeof ( T ) == typeof ( int ) )
1764+ {
1765+ return new Tuple < MatrixBuilder < T > , VectorBuilder < T > > (
1766+ ( MatrixBuilder < T > ) ( object ) new Int . MatrixBuilder ( ) ,
1767+ ( VectorBuilder < T > ) ( object ) new Int . VectorBuilder ( ) ) ;
1768+ }
17261769 throw new NotSupportedException ( FormattableString . Invariant ( $ "Matrices and vectors of type '{ typeof ( T ) . Name } ' are not supported. Only Double, Single, Complex or Complex32 are supported at this point.") ) ;
17271770 }
17281771
0 commit comments