|
|
@@ -65,6 +65,93 @@ namespace Tensorflow |
|
|
|
IEnumerator IEnumerable.GetEnumerator() |
|
|
|
=> GetEnumerator(); |
|
|
|
|
|
|
|
public NDArray numpy() |
|
|
|
{ |
|
|
|
EnsureSingleTensor(this, "nnumpy"); |
|
|
|
return this[0].numpy(); |
|
|
|
} |
|
|
|
|
|
|
|
public T[] ToArray<T>() where T: unmanaged |
|
|
|
{ |
|
|
|
EnsureSingleTensor(this, $"ToArray<{typeof(T)}>"); |
|
|
|
return this[0].ToArray<T>(); |
|
|
|
} |
|
|
|
|
|
|
|
#region Explicit Conversions |
|
|
|
public unsafe static explicit operator bool(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to bool"); |
|
|
|
return (bool)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator sbyte(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to sbyte"); |
|
|
|
return (sbyte)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator byte(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to byte"); |
|
|
|
return (byte)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator ushort(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to ushort"); |
|
|
|
return (ushort)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator short(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to short"); |
|
|
|
return (short)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator int(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to int"); |
|
|
|
return (int)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator uint(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to uint"); |
|
|
|
return (uint)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator long(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to long"); |
|
|
|
return (long)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator ulong(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to ulong"); |
|
|
|
return (ulong)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator float(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to byte"); |
|
|
|
return (byte)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator double(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to double"); |
|
|
|
return (double)tensor[0]; |
|
|
|
} |
|
|
|
|
|
|
|
public unsafe static explicit operator string(Tensors tensor) |
|
|
|
{ |
|
|
|
EnsureSingleTensor(tensor, "explicit conversion to string"); |
|
|
|
return (string)tensor[0]; |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region Implicit Conversions |
|
|
|
public static implicit operator Tensors(Tensor tensor) |
|
|
|
=> new Tensors(tensor); |
|
|
|
|
|
|
@@ -87,12 +174,26 @@ namespace Tensorflow |
|
|
|
public static implicit operator Tensor[](Tensors tensors) |
|
|
|
=> tensors.items.ToArray(); |
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
public void Deconstruct(out Tensor a, out Tensor b) |
|
|
|
{ |
|
|
|
a = items[0]; |
|
|
|
b = items[1]; |
|
|
|
} |
|
|
|
|
|
|
|
private static void EnsureSingleTensor(Tensors tensors, string methodnName) |
|
|
|
{ |
|
|
|
if(tensors.Length == 0) |
|
|
|
{ |
|
|
|
throw new ValueError($"Method `{methodnName}` of `Tensors` cannot be used when `Tensors` contains no Tensor."); |
|
|
|
} |
|
|
|
else if(tensors.Length > 1) |
|
|
|
{ |
|
|
|
throw new ValueError($"Method `{methodnName}` of `Tensors` cannot be used when `Tensors` contains more than one Tensor."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
=> items.Count() == 1 |
|
|
|
? items.First().ToString() |
|
|
|