@@ -11,40 +11,31 @@ public NDArray vstack(params NDArray[] nps)
1111 {
1212 if ( nps == null || nps . Length == 0 )
1313 throw new Exception ( "Input arrays can not be empty" ) ;
14+
15+ List < object > list = this . Storage . GetData < object > ( ) . ToList ( ) ;
1416
15- int dataLength = this . Storage . Length ;
16-
17- for ( int idx = 0 ; idx < nps . Length ; idx ++ )
18- dataLength += nps [ idx ] . Storage . Length ;
19-
20- Array dataSysArr = Array . CreateInstance ( this . dtype , dataLength ) ;
21- NDArray np = new NDArray ( this . dtype ) ;
22-
23- this . Storage . GetData ( this . dtype ) . CopyTo ( dataSysArr , 0 ) ;
24-
25- int idxOfLastCopyiedElement = this . Storage . Length ;
17+ NDArray np = new NDArray ( dtype ) ;
2618
27- for ( int idx = 0 ; idx < nps . Length ; idx ++ )
19+ foreach ( NDArray ele in nps )
2820 {
29- nps [ idx ] . Storage . GetData ( this . dtype ) . CopyTo ( dataSysArr , idxOfLastCopyiedElement ) ;
30- idxOfLastCopyiedElement += nps [ idx ] . Storage . Length ;
21+ if ( nps [ 0 ] . shape != ele . shape )
22+ throw new Exception ( "Arrays mush have same shapes" ) ;
23+
24+ list . AddRange ( ele . Storage . GetData < object > ( ) ) ;
3125 }
32-
33- var check = dataSysArr . GetValue ( idxOfLastCopyiedElement - 1 ) ;
3426
35- if ( ndim == 1 )
27+ np . Storage . SetData ( list . ToArray ( ) ) ;
28+
29+ if ( nps [ 0 ] . shape . Shapes . Count == 1 )
3630 {
37- np . Storage . Shape = new Shape ( new int [ ] { nps . Length + 1 , shape . Shapes [ 0 ] } ) ;
31+ np . Storage . Shape = new Shape ( new int [ ] { nps . Length + 1 , nps [ 0 ] . shape . Shapes [ 0 ] } ) ;
3832 }
3933 else
4034 {
4135 int [ ] shapes = nps [ 0 ] . shape . Shapes . ToArray ( ) ;
42- shapes [ 0 ] *= nps . Length ;
43- np . Storage . Shape = new Shape ( shapes ) ;
36+ shapes [ 0 ] *= nps . Length + 1 ;
37+ np . Storage . Shape = new Shape ( shapes ) ;
4438 }
45-
46- np . Storage . SetData ( dataSysArr ) ;
47-
4839 return np ;
4940 }
5041 }
0 commit comments