Unity-Technologies/ml-agents · error · NotImplementedException
Only float data types are currently supported
Error message
Only float data types are currently supported
What it means
FillTensorWithRandomNormal only supports float tensors; it throws NotImplementedException if the TensorProxy's DataType is anything else. Random-normal filling (used to generate random inputs, e.g. for testing) has no implementation for other dtypes.
Source
Thrown at com.unity.ml-agents/Runtime/Inference/TensorProxy.cs:189
}
/// <summary>
/// Fill a pre-allocated Tensor with random numbers
/// </summary>
/// <param name="tensorProxy">The pre-allocated Tensor to fill</param>
/// <param name="randomNormal">RandomNormal object used to populate tensor</param>
/// <exception cref="NotImplementedException">
/// Throws when trying to fill a Tensor of type other than float
/// </exception>
/// <exception cref="ArgumentNullException">
/// Throws when the Tensor is not allocated
/// </exception>
public static void FillTensorWithRandomNormal(
TensorProxy tensorProxy, RandomNormal randomNormal)
{
if (tensorProxy.DataType != typeof(float))
{
throw new NotImplementedException("Only float data types are currently supported");
}
if (tensorProxy.data == null)
{
throw new ArgumentNullException();
}
tensorProxy.data.CompleteAllPendingOperations();
for (var i = 0; i < tensorProxy.data.Length(); i++)
{
((Tensor<float>)tensorProxy.data)[i] = (float)randomNormal.NextDouble();
}
}
}
}
View on GitHub (pinned to 3ecb446f75)
Solutions
- Ensure the TensorProxy.DataType is typeof(float) before calling FillTensorWithRandomNormal
- Write a custom fill routine for non-float dtypes
- Convert the tensor data to float before filling
Example fix
// before
var proxy = new TensorProxy { DataType = typeof(int), shape = ... };
TensorUtils.FillTensorWithRandomNormal(proxy, randomNormal);
// after
var proxy = new TensorProxy { DataType = typeof(float), data = new TensorFloat(...) };
TensorUtils.FillTensorWithRandomNormal(proxy, randomNormal); Defensive patterns
Strategy: type-guard
Validate before calling
if (tensorProxy.DataType != typeof(float))
throw new InvalidOperationException("FillTensorWithRandomNormal requires a float tensor"); Type guard
bool IsFloatTensor(TensorProxy t) => t.DataType == typeof(float);
Try / catch
try { TensorProxy.FillTensorWithRandomNormal(proxy, randomNormal); }
catch (NotImplementedException)
{ /* fall back to a custom dtype-specific fill routine */ } Prevention
- Always create TensorProxy instances with DataType = typeof(float) for random fill helpers
- Write dedicated fill helpers for int/other dtypes
- Check DataType before invoking shared tensor utilities
When it happens
Trigger: Calling TensorProxy.FillTensorWithRandomNormal with a tensorProxy whose DataType is not typeof(float) (e.g. int, double).
Common situations: Custom inference/utility code building non-float tensors and reusing the random-fill helper; test-generation code for quantized or integer-input models.
Related errors
- Unknown tensorProxy expected as output : {tensor.name}
- Unknown tensorProxy expected as input : {tensor.name}
- Index out of bounds, expected a number between 0 and {Length
- Enumerator not started.
- Enumerator has reached the end already.
AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02).
Data as JSON: /api/errors/7d64b06968ec9b04.
Report an issue: GitHub.