Skip to content

Commit

Permalink
improve javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 12, 2023
1 parent d5b7910 commit 26e15ab
Show file tree
Hide file tree
Showing 5 changed files with 325 additions and 356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ public void validate(int[] tileSize) throws Exception {
* please use {@link #setTileSizeForTensorAndImageSize(int[], int[])}
* @param tileSize
* the patch array size to validate, it has to be in the axes order of the tensor
* @param tileAxesOrder
* the axes order of the 'tileSize' argument
* @throws Exception if the patch does not comply with the constraints specified
*/
public void validate(int[] tileSize, String tileAxesOrder) throws Exception {
Expand Down Expand Up @@ -414,6 +416,8 @@ public void setTileSizeForTensorAndImageSize(int[] tileSize, int[] tensorImageSi
* axes order of the tile provided
* @param tensorImageSize
* size of the image that is used for the tensor.
* @param imageAxesOrder
* the axes order of the image size provided
* @throws Exception if the patch size is not able to
* fulfill the requirements of the tensor
*/
Expand Down
90 changes: 34 additions & 56 deletions src/main/java/io/bioimage/modelrunner/tensor/ImgLib2ToArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*/
package io.bioimage.modelrunner.tensor;

import java.nio.ByteBuffer;

import net.imglib2.Cursor;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.type.NativeType;
Expand All @@ -40,9 +38,7 @@
import net.imglib2.view.Views;

/**
* Class that maps {@link Tensor} objects to {@link ByteBuffer} objects.
* This is done to modify the files that are used to communicate between process
* to avoid the TF2-TF1/Pytorch incompatibility that happens in these systems
* Class that maps {@link Tensor} objects to an array of the corresponding primitive type.
*
* @author Carlos Garcia Lopez de Haro
*/
Expand Down Expand Up @@ -76,18 +72,18 @@ public static < T extends RealType< T > & NativeType< T > > Object build(Tensor<
}

/**
* Adds the {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
* Gets the {@link RandomAccessibleInterval} data into a Java flat array of the corresponding
* primitive type with C-ordering
*
* @param <T>
* the type of the {@link RandomAccessibleInterval}
* @param rai
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
* {@link RandomAccessibleInterval} to be flattened into a Java array
* @return a Java flat array of the corresponding primitive type that contains the data of the {@link RandomAccessibleInterval}
* in C-order
* @throws IllegalArgumentException If the {@link RandomAccessibleInterval} type is not supported.
*/
public static <T extends Type<T>> Object build(RandomAccessibleInterval<T> rai)
public static < T extends RealType< T > & NativeType< T > > Object build(RandomAccessibleInterval<T> rai)
{
if (Util.getTypeFromInterval(rai) instanceof ByteType) {
return buildInt8((RandomAccessibleInterval<ByteType>) rai);
Expand All @@ -113,13 +109,11 @@ public static <T extends Type<T>> Object build(RandomAccessibleInterval<T> rai)
}

/**
* Adds the ByteType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
* Gets the {@link ByteType} {@link RandomAccessibleInterval} data into a Java flat byte array with C-ordering
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
* {@link RandomAccessibleInterval} to be flattened into a Java array
* @return a Java flat byte array that contains the data of the {@link RandomAccessibleInterval} in C-order
*/
private static byte[] buildInt8(RandomAccessibleInterval<ByteType> tensor)
{
Expand All @@ -142,13 +136,11 @@ private static byte[] buildInt8(RandomAccessibleInterval<ByteType> tensor)
}

/**
* Adds the ByteType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
* Gets the {@link UnsignedByteType} {@link RandomAccessibleInterval} data into a Java flat byte array with C-ordering
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
* {@link RandomAccessibleInterval} to be flattened into a Java array
* @return a Java flat byte array that contains the data of the {@link RandomAccessibleInterval} in C-order
*/
private static byte[] buildUint8(RandomAccessibleInterval<UnsignedByteType> tensor)
{
Expand All @@ -171,13 +163,11 @@ private static byte[] buildUint8(RandomAccessibleInterval<UnsignedByteType> tens
}

/**
* Adds the ByteType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
* Gets the {@link ShortType} {@link RandomAccessibleInterval} data into a Java flat short array with C-ordering
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
* {@link RandomAccessibleInterval} to be flattened into a Java array
* @return a Java flat short array that contains the data of the {@link RandomAccessibleInterval} in C-order
*/
private static short[] buildInt16(RandomAccessibleInterval<ShortType> tensor)
{
Expand All @@ -200,13 +190,11 @@ private static short[] buildInt16(RandomAccessibleInterval<ShortType> tensor)
}

/**
* Adds the ByteType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
* Gets the {@link UnsignedShortType} {@link RandomAccessibleInterval} data into a Java flat short array with C-ordering
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
* {@link RandomAccessibleInterval} to be flattened into a Java array
* @return a Java flat short array that contains the data of the {@link RandomAccessibleInterval} in C-order
*/
private static short[] buildUint16(RandomAccessibleInterval<UnsignedShortType> tensor)
{
Expand All @@ -229,13 +217,11 @@ private static short[] buildUint16(RandomAccessibleInterval<UnsignedShortType> t
}

/**
* Adds the IntType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
* Gets the {@link IntType} {@link RandomAccessibleInterval} data into a Java flat int array with C-ordering
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
* {@link RandomAccessibleInterval} to be flattened into a Java array
* @return a Java flat int array that contains the data of the {@link RandomAccessibleInterval} in C-order
*/
private static int[] buildInt32(RandomAccessibleInterval<IntType> tensor)
{
Expand All @@ -258,13 +244,11 @@ private static int[] buildInt32(RandomAccessibleInterval<IntType> tensor)
}

/**
* Adds the IntType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
* Gets the {@link UnsignedIntType} {@link RandomAccessibleInterval} data into a Java flat int array with C-ordering
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
* {@link RandomAccessibleInterval} to be flattened into a Java array
* @return a Java flat int array that contains the data of the {@link RandomAccessibleInterval} in C-order
*/
private static int[] buildUint32(RandomAccessibleInterval<UnsignedIntType> tensor)
{
Expand All @@ -287,13 +271,11 @@ private static int[] buildUint32(RandomAccessibleInterval<UnsignedIntType> tenso
}

/**
* Adds the IntType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
* Gets the {@link LongType} {@link RandomAccessibleInterval} data into a Java flat long array with C-ordering
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
* {@link RandomAccessibleInterval} to be flattened into a Java array
* @return a Java flat long array that contains the data of the {@link RandomAccessibleInterval} in C-order
*/
private static long[] buildInt64(RandomAccessibleInterval<LongType> tensor)
{
Expand All @@ -316,13 +298,11 @@ private static long[] buildInt64(RandomAccessibleInterval<LongType> tensor)
}

/**
* Adds the FloatType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
* Gets the {@link FloatType} {@link RandomAccessibleInterval} data into a Java flat float array with C-ordering
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
* {@link RandomAccessibleInterval} to be flattened into a Java array
* @return a Java flat float array that contains the data of the {@link RandomAccessibleInterval} in C-order
*/
private static float[] buildFloat32(RandomAccessibleInterval<FloatType> tensor)
{
Expand All @@ -345,13 +325,11 @@ private static float[] buildFloat32(RandomAccessibleInterval<FloatType> tensor)
}

/**
* Adds the DoubleType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
* Gets the {@link DoubleType} {@link RandomAccessibleInterval} data into a Java flat double array with C-ordering
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
* {@link RandomAccessibleInterval} to be flattened into a Java array
* @return a Java flat double array that contains the data of the {@link RandomAccessibleInterval} in C-order
*/
private static double[] buildFloat64(RandomAccessibleInterval<DoubleType> tensor)
{
Expand Down
Loading

0 comments on commit 26e15ab

Please sign in to comment.