Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type converting errors when loading imdb dataset #1116

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/TensorFlowNET.Core/NumPy/NDArray.Implicit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,15 @@ public void Deconstruct(out byte blue, out byte green, out byte red)
public static implicit operator NDArray(bool value)
=> new NDArray(value);

public static implicit operator NDArray(byte value)
=> new NDArray(value);

public static implicit operator NDArray(int value)
=> new NDArray(value);

public static implicit operator NDArray(long value)
=> new NDArray(value);

public static implicit operator NDArray(float value)
=> new NDArray(value);

Expand Down
11 changes: 11 additions & 0 deletions src/TensorFlowNET.Core/Operations/array_ops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ public static Tensor zeros(Shape shape, TF_DataType dtype = TF_DataType.TF_FLOAT
// var shape_tensor = constant_op._tensor_shape_tensor_conversion_function(shape);
Tensor zeros = dtype switch
{
TF_DataType.TF_BOOL => constant(false),
TF_DataType.TF_DOUBLE => constant(0d),
TF_DataType.TF_FLOAT => constant(0f),
TF_DataType.TF_INT64 => constant(0L),
TF_DataType.TF_UINT64 => constant((ulong)0),
TF_DataType.TF_INT32 => constant(0),
TF_DataType.TF_UINT32 => constant((uint)0),
TF_DataType.TF_INT8 => constant((sbyte)0),
TF_DataType.TF_UINT8 => constant((byte)0),
_ => constant(0)
Expand All @@ -108,9 +113,15 @@ public static Tensor zeros(Shape shape, TF_DataType dtype = TF_DataType.TF_FLOAT
return _constant_if_small(0.0F, shape, dtype, name);
case TF_DataType.TF_INT64:
return _constant_if_small(0L, shape, dtype, name);
case TF_DataType.TF_UINT64:
return _constant_if_small<ulong>(0, shape, dtype, name);
case TF_DataType.TF_INT32:
return _constant_if_small(0, shape, dtype, name);
case TF_DataType.TF_UINT32:
return _constant_if_small<uint>(0, shape, dtype, name);
case TF_DataType.TF_INT8:
return _constant_if_small<sbyte>(0, shape, dtype, name);
case TF_DataType.TF_UINT8:
return _constant_if_small<byte>(0, shape, dtype, name);
default:
throw new TypeError("can't find type for zeros");
Expand Down