@@ -36,6 +36,10 @@ private IntPtr Allocate(NDArray nd)
3636 size = ( ulong ) ( nd . size * nd . dtypesize ) ;
3737 }
3838
39+ var dataType = ToTFDataType ( nd . dtype ) ;
40+ // shape
41+ var dims = nd . shape . Select ( x => ( long ) x ) . ToArray ( ) ;
42+
3943 switch ( nd . dtype . Name )
4044 {
4145 case "Int16" :
@@ -51,37 +55,25 @@ private IntPtr Allocate(NDArray nd)
5155 Marshal . Copy ( nd . Data < double > ( ) , 0 , dotHandle , nd . size ) ;
5256 break ;
5357 case "String" :
54- /*var value = nd.Data<string>()[0];
55- var bytes = Encoding.UTF8.GetBytes(value);
56- dotHandle = Marshal.AllocHGlobal(bytes.Length + 1);
57- Marshal.Copy(bytes, 0, dotHandle, bytes.Length);
58- size = (ulong)bytes.Length;*/
59-
6058 var str = nd . Data < string > ( ) [ 0 ] ;
6159 ulong dst_len = c_api . TF_StringEncodedSize ( ( ulong ) str . Length ) ;
62- //dotHandle = Marshal.AllocHGlobal((int)dst_len);
63- //size = c_api.TF_StringEncode(str, (ulong)str.Length, dotHandle, dst_len, status);
64-
6560 var dataType1 = ToTFDataType ( nd . dtype ) ;
6661 // shape
6762 var dims1 = nd . shape . Select ( x => ( long ) x ) . ToArray ( ) ;
6863
6964 var tfHandle1 = c_api . TF_AllocateTensor ( dataType1 ,
7065 dims1 ,
7166 nd . ndim ,
72- dst_len ) ;
67+ dst_len + sizeof ( Int64 ) ) ;
7368
7469 dotHandle = c_api . TF_TensorData ( tfHandle1 ) ;
75- c_api . TF_StringEncode ( str , ( ulong ) str . Length , dotHandle , dst_len , status ) ;
70+ Marshal . WriteInt64 ( dotHandle , 0 ) ;
71+ c_api . TF_StringEncode ( str , ( ulong ) str . Length , dotHandle + sizeof ( Int64 ) , dst_len , status ) ;
7672 return tfHandle1 ;
77- break ;
7873 default :
7974 throw new NotImplementedException ( "Marshal.Copy failed." ) ;
8075 }
81-
82- var dataType = ToTFDataType ( nd . dtype ) ;
83- // shape
84- var dims = nd . shape . Select ( x => ( long ) x ) . ToArray ( ) ;
76+
8577 // Free the original buffer and set flag
8678 Deallocator deallocator = ( IntPtr values , IntPtr len , ref bool closure ) =>
8779 {
0 commit comments