File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ limitations under the License.
2121using System . ComponentModel ;
2222using System . Diagnostics ;
2323using System . Linq ;
24+ using NumSharp . Utilities ;
2425
2526namespace Tensorflow
2627{
@@ -29,9 +30,37 @@ namespace Tensorflow
2930 /// </summary>
3031 public static partial class Binding
3132 {
33+ private static string _tostring ( object obj )
34+ {
35+ switch ( obj )
36+ {
37+ case NDArray nd :
38+ return nd . ToString ( false ) ;
39+ case Array arr :
40+ if ( arr . Rank != 1 || arr . GetType ( ) . GetElementType ( ) ? . IsArray == true )
41+ arr = Arrays . Flatten ( arr ) ;
42+ var objs = toObjectArray ( arr ) ;
43+ return $ "[{ string . Join ( ", " , objs . Select ( _tostring ) ) } ]";
44+ default :
45+ return obj ? . ToString ( ) ?? "null" ;
46+ }
47+
48+ object [ ] toObjectArray ( Array arr )
49+ {
50+ var len = arr . LongLength ;
51+ var ret = new object [ len ] ;
52+ for ( long i = 0 ; i < len ; i ++ )
53+ {
54+ ret [ i ] = arr . GetValue ( i ) ;
55+ }
56+
57+ return ret ;
58+ }
59+ }
60+
3261 public static void print ( object obj )
3362 {
34- Console . WriteLine ( obj . ToString ( ) ) ;
63+ Console . WriteLine ( _tostring ( obj ) ) ;
3564 }
3665
3766 public static int len ( object a )
You can’t perform that action at this time.
0 commit comments