From 3a42d80acafdc63c8944d97a7a4847868c3545bf Mon Sep 17 00:00:00 2001 From: Eli Belash Date: Wed, 28 Aug 2019 00:00:31 +0300 Subject: [PATCH] Tensor.StringData: Changed to public. --- src/TensorFlowNET.Core/Tensors/Tensor.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.cs b/src/TensorFlowNET.Core/Tensors/Tensor.cs index aaf8ddad..75cba69e 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.cs @@ -221,15 +221,6 @@ namespace Tensorflow /// When is string public T[] ToArray() where T : unmanaged { - //when T is string - if (typeof(T) == typeof(string)) - { - if (dtype != TF_DataType.TF_STRING) - throw new ArgumentException($"Given <{typeof(T).Name}> can't be converted to string."); - - return (T[]) (object) StringData(); - } - //Are the types matching? if (typeof(T).as_dtype() == dtype) { @@ -376,9 +367,15 @@ namespace Tensorflow } } - /// Used internally in ToArray<T> - private unsafe string[] StringData() + /// + /// Extracts string array from current Tensor. + /// + /// When != TF_DataType.TF_STRING + public unsafe string[] StringData() { + if (dtype != TF_DataType.TF_STRING) + throw new InvalidOperationException($"Unable to call StringData when dtype != TF_DataType.TF_STRING (dtype is {dtype})"); + // // TF_STRING tensors are encoded with a table of 8-byte offsets followed by TF_StringEncode-encoded bytes. // [offset1, offset2,...,offsetn, s1size, s1bytes, s2size, s2bytes,...,snsize,snbytes]