diff --git a/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/tensor/ImgLib2Builder.java b/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/tensor/ImgLib2Builder.java index 1d42be7..fe613f2 100644 --- a/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/tensor/ImgLib2Builder.java +++ b/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/tensor/ImgLib2Builder.java @@ -67,7 +67,8 @@ private ImgLib2Builder() * @return The {@link RandomAccessibleInterval} built from the {@link TType} tensor. * @throws IllegalArgumentException If the {@link TType} tensor type is not supported. */ - public static > RandomAccessibleInterval build(TType tensor) throws IllegalArgumentException + @SuppressWarnings("unchecked") + public static > RandomAccessibleInterval build(TType tensor) throws IllegalArgumentException { if (tensor instanceof TUint8) { @@ -95,13 +96,6 @@ else if (tensor instanceof TInt64) } } - /** - * Builds a {@link RandomAccessibleInterval} from a unsigned byte-typed {@link TUint8} tensor. - * - * @param tensor - * The {@link TUint8} tensor data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link UnsignedByteType}. - */ private static RandomAccessibleInterval buildFromTensorUByte(TUint8 tensor) { long[] arrayShape = tensor.shape().asArray(); @@ -118,13 +112,6 @@ private static RandomAccessibleInterval buildFromTensorUByte(T return Utils.transpose(rai); } - /** - * Builds a {@link RandomAccessibleInterval} from a unsigned int32-typed {@link TInt32} tensor. - * - * @param tensor - * The {@link TInt32} tensor data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link IntType}. - */ private static RandomAccessibleInterval buildFromTensorInt(TInt32 tensor) { long[] arrayShape = tensor.shape().asArray(); @@ -141,13 +128,6 @@ private static RandomAccessibleInterval buildFromTensorInt(TInt32 tenso return Utils.transpose(rai); } - /** - * Builds a {@link RandomAccessibleInterval} from a unsigned float32-typed {@link TFloat32} tensor. - * - * @param tensor - * The {@link TFloat32} tensor data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link FloatType}. - */ private static RandomAccessibleInterval buildFromTensorFloat(TFloat32 tensor) { long[] arrayShape = tensor.shape().asArray(); @@ -164,13 +144,6 @@ private static RandomAccessibleInterval buildFromTensorFloat(TFloat32 return Utils.transpose(rai); } - /** - * Builds a {@link RandomAccessibleInterval} from a unsigned float64-typed {@link TFloat64} tensor. - * - * @param tensor - * The {@link TFloat64} tensor data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link DoubleType}. - */ private static RandomAccessibleInterval buildFromTensorDouble(TFloat64 tensor) { long[] arrayShape = tensor.shape().asArray(); @@ -187,13 +160,6 @@ private static RandomAccessibleInterval buildFromTensorDouble(TFloat return Utils.transpose(rai); } - /** - * Builds a {@link RandomAccessibleInterval} from a unsigned int64-typed {@link TInt64} tensor. - * - * @param tensor - * The {@link TInt64} tensor data is read from. - * @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link LongType}. - */ private static RandomAccessibleInterval buildFromTensorLong(TInt64 tensor) { long[] arrayShape = tensor.shape().asArray(); diff --git a/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/tensor/TensorBuilder.java b/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/tensor/TensorBuilder.java index fd24f75..453c034 100644 --- a/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/tensor/TensorBuilder.java +++ b/src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/tensor/TensorBuilder.java @@ -78,7 +78,7 @@ private TensorBuilder() {} * @throws IllegalArgumentException If the type of the {@link io.bioimage.modelrunner.tensor.Tensor} * is not supported */ - public static TType build(io.bioimage.modelrunner.tensor.Tensor tensor) + public static & NativeType> TType build(io.bioimage.modelrunner.tensor.Tensor tensor) throws IllegalArgumentException { return build(tensor.getData()); @@ -122,17 +122,7 @@ else if (Util.getTypeFromInterval(array) instanceof LongType) { } } - /** - * Creates a {@link TType} tensor of type {@link TUint8} from an - * {@link RandomAccessibleInterval} of type {@link UnsignedByteType} - * - * @param tensor - * The {@link RandomAccessibleInterval} to fill the tensor with. - * @return The {@link TType} tensor filled with the {@link RandomAccessibleInterval} data. - * @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is - * not compatible - */ - public static TUint8 buildUByte(RandomAccessibleInterval tensor) + private static TUint8 buildUByte(RandomAccessibleInterval tensor) throws IllegalArgumentException { long[] ogShape = tensor.dimensionsAsLongArray(); @@ -159,17 +149,7 @@ public static TUint8 buildUByte(RandomAccessibleInterval tenso return ndarray; } - /** - * Creates a {@link TInt32} tensor of type {@link TInt32} from an - * {@link RandomAccessibleInterval} of type {@link IntType} - * - * @param tensor - * The {@link RandomAccessibleInterval} to fill the tensor with. - * @return The {@link TInt32} tensor filled with the {@link RandomAccessibleInterval} data. - * @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is - * not compatible - */ - public static TInt32 buildInt(RandomAccessibleInterval tensor) + private static TInt32 buildInt(RandomAccessibleInterval tensor) throws IllegalArgumentException { long[] ogShape = tensor.dimensionsAsLongArray(); @@ -197,16 +177,6 @@ public static TInt32 buildInt(RandomAccessibleInterval tensor) return ndarray; } - /** - * Creates a {@link TInt64} tensor of type {@link TInt64} from an - * {@link RandomAccessibleInterval} of type {@link LongType} - * - * @param tensor - * The {@link RandomAccessibleInterval} to fill the tensor with. - * @return The {@link TInt64} tensor filled with the {@link RandomAccessibleInterval} data. - * @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is - * not compatible - */ private static TInt64 buildLong(RandomAccessibleInterval tensor) throws IllegalArgumentException { @@ -235,17 +205,7 @@ private static TInt64 buildLong(RandomAccessibleInterval tensor) return ndarray; } - /** - * Creates a {@link TFloat32} tensor of type {@link TFloat32} from an - * {@link RandomAccessibleInterval} of type {@link FloatType} - * - * @param tensor - * The {@link RandomAccessibleInterval} to fill the tensor with. - * @return The {@link TFloat32} tensor filled with the {@link RandomAccessibleInterval} data. - * @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is - * not compatible - */ - public static TFloat32 buildFloat( + private static TFloat32 buildFloat( RandomAccessibleInterval tensor) throws IllegalArgumentException { @@ -273,16 +233,6 @@ public static TFloat32 buildFloat( return ndarray; } - /** - * Creates a {@link TFloat64} tensor of type {@link TFloat64} from an - * {@link RandomAccessibleInterval} of type {@link DoubleType} - * - * @param tensor - * The {@link RandomAccessibleInterval} to fill the tensor with. - * @return The {@link TFloat64} tensor filled with the {@link RandomAccessibleInterval} data. - * @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is - * not compatible - */ private static TFloat64 buildDouble( RandomAccessibleInterval tensor) throws IllegalArgumentException