@@ -14,39 +14,29 @@ public override string ToString()
1414
1515 if ( this . ndim == 2 )
1616 {
17- if ( dtype == typeof ( int ) )
18- {
19- output = this . _ToMatrixString < int > ( ) ;
20- }
21- else if ( dtype == typeof ( double ) )
22- {
23- output = this . _ToMatrixString < double > ( ) ;
24- }
25-
17+ output = this . _ToMatrixString ( ) ;
2618 }
2719 else
2820 {
29- if ( dtype == typeof ( int ) )
30- {
31- //output = this._ToVectorString<int>();
32- }
33- else if ( dtype == typeof ( double ) )
34- {
35- //output = this._ToVectorString<double>();
36- }
21+ output = this . _ToVectorString ( ) ;
3722 }
3823
3924 return output ;
4025 }
41- protected string _ToVectorString < T > ( )
26+ protected string _ToVectorString ( )
4227 {
4328 string returnValue = "array([" ;
4429
4530 int digitBefore = 0 ;
4631 int digitAfter = 0 ;
4732
48- var dataParsed = Storage . GetData < T > ( ) . Select ( x => _ParseNumber ( x , ref digitBefore , ref digitAfter ) ) . ToArray ( ) ;
33+ string [ ] dataParsed = new string [ Storage . GetData ( ) . Length ] ;
34+
35+ Array strg = Storage . GetData ( ) ;
4936
37+ for ( int idx = 0 ; idx < dataParsed . Length ; idx ++ )
38+ dataParsed [ idx ] = _ParseNumber ( strg . GetValue ( idx ) , ref digitBefore , ref digitAfter ) ;
39+
5040 string elementFormatStart = "{0:" ;
5141
5242 string elementFormatEnd = "" ;
@@ -64,25 +54,30 @@ protected string _ToVectorString<T>()
6454
6555 elementFormat = elementFormatStart + new string ( Enumerable . Repeat < char > ( ' ' , missingDigits ) . ToArray ( ) ) + "0." + elementFormatEnd ;
6656
67- returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , Storage . GetData < T > ( ) [ idx ] ) + ", " ) ;
57+ returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , strg . GetValue ( idx ) ) + ", " ) ;
6858 }
6959 missingDigits = digitBefore - dataParsed . Last ( ) . Replace ( " " , "" ) . Split ( '.' ) [ 0 ] . Length ;
7060
7161 elementFormat = elementFormatStart + new string ( Enumerable . Repeat < char > ( ' ' , missingDigits ) . ToArray ( ) ) + "." + elementFormatEnd ;
7262
73- returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , Storage . GetData < T > ( ) . Last ( ) ) + "])" ) ;
63+ returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , strg . GetValue ( strg . Length - 1 ) ) + "])" ) ;
7464
7565 return returnValue ;
7666 }
77- protected string _ToMatrixString < T > ( )
67+ protected string _ToMatrixString ( )
7868 {
7969 string returnValue = "array([[" ;
8070
8171 int digitBefore = 0 ;
8272 int digitAfter = 0 ;
8373
84- string [ ] dataParsed = Storage . GetData < T > ( ) . Select ( x => _ParseNumber ( x , ref digitBefore , ref digitAfter ) ) . ToArray ( ) ;
74+ string [ ] dataParsed = new string [ Storage . GetData ( ) . Length ] ;
75+
76+ Array strg = Storage . GetData ( ) ;
8577
78+ for ( int idx = 0 ; idx < dataParsed . Length ; idx ++ )
79+ dataParsed [ idx ] = _ParseNumber ( strg . GetValue ( idx ) , ref digitBefore , ref digitAfter ) ;
80+
8681 string elementFormatStart = "{0:" ;
8782
8883 string elementFormatEnd = "" ;
@@ -94,27 +89,27 @@ protected string _ToMatrixString<T>()
9489 int missingDigits ;
9590 string elementFormat ;
9691
97- for ( int idx = 0 ; idx < this . ndim - 1 ; idx ++ )
92+ for ( int idx = 0 ; idx < dataParsed . Length - 1 ; idx ++ )
9893 {
9994 missingDigits = digitBefore - dataParsed [ idx ] . Replace ( " " , "" ) . Split ( '.' ) [ 0 ] . Length ;
10095
10196 elementFormat = elementFormatStart + new string ( Enumerable . Repeat < char > ( ' ' , missingDigits ) . ToArray ( ) ) + "0." + elementFormatEnd ;
10297
10398 if ( ( ( idx + 1 ) % shape [ 1 ] ) == 0 )
10499 {
105- returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , Storage . GetData < T > ( ) [ idx ] ) + "], \n [" ) ;
100+ returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , strg . GetValue ( idx ) ) + "], \n [" ) ;
106101 }
107102 else
108103 {
109- returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , Storage . GetData < T > ( ) [ idx ] ) + ", " ) ;
104+ returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , strg . GetValue ( idx ) ) + ", " ) ;
110105 }
111106 }
112107
113108 missingDigits = digitBefore - dataParsed . Last ( ) . Replace ( " " , "" ) . Split ( '.' ) [ 0 ] . Length ;
114109
115110 elementFormat = elementFormatStart + new string ( Enumerable . Repeat < char > ( ' ' , missingDigits ) . ToArray ( ) ) + "." + elementFormatEnd ;
116111
117- returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , Storage . GetData < T > ( ) . Last ( ) ) + "]])" ) ;
112+ returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , strg . GetValue ( strg . Length - 1 ) ) + "]])" ) ;
118113
119114 return returnValue ;
120115 }
0 commit comments