Browse Source

1. fix miss type value.

2. fix type conver performance bug
pull/519/head
dogvane 5 years ago
parent
commit
5511362d64
2 changed files with 26 additions and 13 deletions
  1. +20
    -1
      src/TensorFlowNET.Core/Tensors/TF_DataType.cs
  2. +6
    -12
      src/TensorFlowNET.Core/Tensors/dtypes.cs

+ 20
- 1
src/TensorFlowNET.Core/Tensors/TF_DataType.cs View File

@@ -35,6 +35,25 @@
DtFloatRef = 101, // DT_FLOAT_REF
DtDoubleRef = 102, // DT_DOUBLE_REF
DtInt32Ref = 103, // DT_INT32_REF
DtInt64Ref = 109 // DT_INT64_REF
DtUint8Ref = 104,
DtInt16Ref = 105,
DtInt8Ref = 106,
DtStringRef = 107,
DtComplex64Ref = 108,
DtInt64Ref = 109, // DT_INT64_REF
DtBoolRef = 110,
DtQint8Ref = 111,
DtQuint8Ref = 112,
DtQint32Ref = 113,
DtBfloat16Ref = 114,
DtQint16Ref = 115,
DtQuint16Ref = 116,
DtUint16Ref = 117,
DtComplex128Ref = 118,
DtHalfRef = 119,
DtResourceRef = 120,
DtVariantRef = 121,
DtUint32Ref = 122,
DtUint64Ref = 123,
}
}

+ 6
- 12
src/TensorFlowNET.Core/Tensors/dtypes.cs View File

@@ -46,7 +46,7 @@ namespace Tensorflow
/// <returns><see cref="System.Type"/> equivalent to <paramref name="type"/>, if none exists, returns null.</returns>
public static Type as_numpy_dtype(this TF_DataType type)
{
switch (type)
switch (type.as_base_dtype())
{
case TF_DataType.TF_BOOL:
return typeof(bool);
@@ -182,14 +182,12 @@ namespace Tensorflow

public static DataType as_datatype_enum(this TF_DataType type)
{
return Enum.TryParse(((int) type).ToString(), out DataType dtype) ? dtype : DataType.DtInvalid;
return (DataType)type;
}

public static TF_DataType as_base_dtype(this TF_DataType type)
{
return (int)type > 100 ?
(TF_DataType)Enum.Parse(typeof(TF_DataType), ((int)type - 100).ToString()) :
type;
return (int)type > 100 ? (TF_DataType)((int)type - 100) : type;
}

public static int name(this TF_DataType type)
@@ -204,21 +202,17 @@ namespace Tensorflow

public static DataType as_base_dtype(this DataType type)
{
return (int)type > 100 ?
(DataType)Enum.Parse(typeof(DataType), ((int)type - 100).ToString()) :
type;
return (int)type > 100 ? (DataType)((int)type - 100) : type;
}

public static TF_DataType as_tf_dtype(this DataType type)
{
return Enum.TryParse(((int) type).ToString(), out TF_DataType dtype) ? dtype : TF_DataType.DtInvalid;
return (TF_DataType)type;
}

public static TF_DataType as_ref(this TF_DataType type)
{
return (int)type < 100 ?
(TF_DataType)Enum.Parse(typeof(TF_DataType), ((int)type + 100).ToString()) :
type;
return (int)type < 100 ? (TF_DataType)((int)type + 100) : type;
}

public static long max(this TF_DataType type)


Loading…
Cancel
Save