@@ -33,39 +33,29 @@ public override string ToString()
3333 }
3434 else if ( this . ndim == 2 )
3535 {
36- if ( dtype == typeof ( int ) )
37- {
38- output = this . _ToMatrixString < int > ( ) ;
39- }
40- else if ( dtype == typeof ( double ) )
41- {
42- output = this . _ToMatrixString < double > ( ) ;
43- }
44-
36+ output = this . _ToMatrixString ( ) ;
4537 }
4638 else
4739 {
48- if ( dtype == typeof ( int ) )
49- {
50- //output = this._ToVectorString<int>();
51- }
52- else if ( dtype == typeof ( double ) )
53- {
54- //output = this._ToVectorString<double>();
55- }
40+ output = this . _ToVectorString ( ) ;
5641 }
5742
5843 return output ;
5944 }
60- protected string _ToVectorString < T > ( )
45+ protected string _ToVectorString ( )
6146 {
6247 string returnValue = "array([" ;
6348
6449 int digitBefore = 0 ;
6550 int digitAfter = 0 ;
6651
67- var dataParsed = Storage . GetData < T > ( ) . Select ( x => _ParseNumber ( x , ref digitBefore , ref digitAfter ) ) . ToArray ( ) ;
52+ string [ ] dataParsed = new string [ Storage . GetData ( ) . Length ] ;
53+
54+ Array strg = Storage . GetData ( ) ;
6855
56+ for ( int idx = 0 ; idx < dataParsed . Length ; idx ++ )
57+ dataParsed [ idx ] = _ParseNumber ( strg . GetValue ( idx ) , ref digitBefore , ref digitAfter ) ;
58+
6959 string elementFormatStart = "{0:" ;
7060
7161 string elementFormatEnd = "" ;
@@ -83,25 +73,30 @@ protected string _ToVectorString<T>()
8373
8474 elementFormat = elementFormatStart + new string ( Enumerable . Repeat < char > ( ' ' , missingDigits ) . ToArray ( ) ) + "0." + elementFormatEnd ;
8575
86- returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , Storage . GetData < T > ( ) [ idx ] ) + ", " ) ;
76+ returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , strg . GetValue ( idx ) ) + ", " ) ;
8777 }
8878 missingDigits = digitBefore - dataParsed . Last ( ) . Replace ( " " , "" ) . Split ( '.' ) [ 0 ] . Length ;
8979
9080 elementFormat = elementFormatStart + new string ( Enumerable . Repeat < char > ( ' ' , missingDigits ) . ToArray ( ) ) + "." + elementFormatEnd ;
9181
92- returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , Storage . GetData < T > ( ) . Last ( ) ) + "])" ) ;
82+ returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , strg . GetValue ( strg . Length - 1 ) ) + "])" ) ;
9383
9484 return returnValue ;
9585 }
96- protected string _ToMatrixString < T > ( )
86+ protected string _ToMatrixString ( )
9787 {
9888 string returnValue = "array([[" ;
9989
10090 int digitBefore = 0 ;
10191 int digitAfter = 0 ;
10292
103- string [ ] dataParsed = Storage . GetData < T > ( ) . Select ( x => _ParseNumber ( x , ref digitBefore , ref digitAfter ) ) . ToArray ( ) ;
93+ string [ ] dataParsed = new string [ Storage . GetData ( ) . Length ] ;
94+
95+ Array strg = Storage . GetData ( ) ;
10496
97+ for ( int idx = 0 ; idx < dataParsed . Length ; idx ++ )
98+ dataParsed [ idx ] = _ParseNumber ( strg . GetValue ( idx ) , ref digitBefore , ref digitAfter ) ;
99+
105100 string elementFormatStart = "{0:" ;
106101
107102 string elementFormatEnd = "" ;
@@ -113,27 +108,27 @@ protected string _ToMatrixString<T>()
113108 int missingDigits ;
114109 string elementFormat ;
115110
116- for ( int idx = 0 ; idx < this . ndim - 1 ; idx ++ )
111+ for ( int idx = 0 ; idx < dataParsed . Length - 1 ; idx ++ )
117112 {
118113 missingDigits = digitBefore - dataParsed [ idx ] . Replace ( " " , "" ) . Split ( '.' ) [ 0 ] . Length ;
119114
120115 elementFormat = elementFormatStart + new string ( Enumerable . Repeat < char > ( ' ' , missingDigits ) . ToArray ( ) ) + "0." + elementFormatEnd ;
121116
122117 if ( ( ( idx + 1 ) % shape [ 1 ] ) == 0 )
123118 {
124- returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , Storage . GetData < T > ( ) [ idx ] ) + "], \n [" ) ;
119+ returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , strg . GetValue ( idx ) ) + "], \n [" ) ;
125120 }
126121 else
127122 {
128- returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , Storage . GetData < T > ( ) [ idx ] ) + ", " ) ;
123+ returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , strg . GetValue ( idx ) ) + ", " ) ;
129124 }
130125 }
131126
132127 missingDigits = digitBefore - dataParsed . Last ( ) . Replace ( " " , "" ) . Split ( '.' ) [ 0 ] . Length ;
133128
134129 elementFormat = elementFormatStart + new string ( Enumerable . Repeat < char > ( ' ' , missingDigits ) . ToArray ( ) ) + "." + elementFormatEnd ;
135130
136- returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , Storage . GetData < T > ( ) . Last ( ) ) + "]])" ) ;
131+ returnValue += ( String . Format ( new CultureInfo ( "en-us" ) , elementFormat , strg . GetValue ( strg . Length - 1 ) ) + "]])" ) ;
137132
138133 return returnValue ;
139134 }
0 commit comments