@@ -10,14 +10,25 @@ public class NDArrayConverter
1010 public unsafe static T Scalar < T > ( NDArray nd ) where T : unmanaged
1111 => nd . dtype switch
1212 {
13+ TF_DataType . TF_UINT8 => Scalar < T > ( * ( byte * ) nd . data ) ,
1314 TF_DataType. TF_FLOAT => Scalar< T > ( * ( float * ) nd . data ) ,
1415 TF_DataType. TF_INT64 => Scalar< T > ( * ( long * ) nd . data ) ,
1516 _ => throw new NotImplementedException ( "" )
1617 } ;
1718
19+ static T Scalar < T> ( byte input )
20+ => Type . GetTypeCode ( typeof ( T ) ) switch
21+ {
22+ TypeCode . Byte => ( T ) Convert . ChangeType ( input , TypeCode . Byte ) ,
23+ TypeCode . Int32 => ( T ) Convert . ChangeType ( input , TypeCode . Int32 ) ,
24+ TypeCode . Single => ( T ) Convert . ChangeType ( input , TypeCode . Single ) ,
25+ _ => throw new NotImplementedException ( "" )
26+ } ;
27+
1828 static T Scalar< T > ( float input )
1929 => Type . GetTypeCode ( typeof ( T ) ) switch
2030 {
31+ TypeCode . Byte => ( T ) Convert . ChangeType ( input , TypeCode . Byte ) ,
2132 TypeCode . Int32 => ( T ) Convert . ChangeType ( input , TypeCode . Int32 ) ,
2233 TypeCode . Single => ( T ) Convert . ChangeType ( input , TypeCode . Single ) ,
2334 _ => throw new NotImplementedException ( "" )
@@ -26,6 +37,7 @@ static T Scalar<T>(float input)
2637 static T Scalar< T > ( long input )
2738 => Type . GetTypeCode ( typeof ( T ) ) switch
2839 {
40+ TypeCode . Byte => ( T ) Convert . ChangeType ( input , TypeCode . Byte ) ,
2941 TypeCode . Int32 => ( T ) Convert . ChangeType ( input , TypeCode . Int32 ) ,
3042 TypeCode . Single => ( T ) Convert . ChangeType ( input , TypeCode . Single ) ,
3143 _ => throw new NotImplementedException ( "" )
0 commit comments