Skip to content

Commit cbc4fe8

Browse files
committed
improve javadoc
1 parent 9e84b85 commit cbc4fe8

File tree

2 files changed

+21
-127
lines changed

2 files changed

+21
-127
lines changed

src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/shm/ShmBuilder.java

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.nio.ByteBuffer;
2929
import java.util.Arrays;
3030

31-
import org.tensorflow.Tensor;
3231
import org.tensorflow.types.TFloat32;
3332
import org.tensorflow.types.TFloat64;
3433
import org.tensorflow.types.TInt32;
@@ -43,11 +42,10 @@
4342
import net.imglib2.type.numeric.real.FloatType;
4443

4544
/**
46-
* A {@link RandomAccessibleInterval} builder for TensorFlow {@link Tensor} objects.
47-
* Build ImgLib2 objects (backend of {@link io.bioimage.modelrunner.tensor.Tensor})
48-
* from Tensorflow 2 {@link Tensor}
45+
* A utility class that converts {@link TType} tensors into {@link SharedMemoryArray}s for
46+
* interprocessing communication
4947
*
50-
* @author Carlos Garcia Lopez de Haro and Daniel Felipe Gonzalez Obando
48+
* @author Carlos Garcia Lopez de Haro
5149
*/
5250
public final class ShmBuilder
5351
{
@@ -58,17 +56,15 @@ private ShmBuilder()
5856
{
5957
}
6058

61-
/**
62-
* Creates a {@link RandomAccessibleInterval} from a given {@link TType} tensor
63-
*
64-
* @param <T>
65-
* the possible ImgLib2 datatypes of the image
66-
* @param tensor
67-
* The {@link TType} tensor data is read from.
68-
* @return The {@link RandomAccessibleInterval} built from the {@link TType} tensor.
69-
* @throws IllegalArgumentException If the {@link TType} tensor type is not supported.
70-
* @throws IOException
71-
*/
59+
/**
60+
* Create a {@link SharedMemoryArray} from a {@link TType} tensor
61+
* @param tensor
62+
* the tensor to be passed into the other process through the shared memory
63+
* @param memoryName
64+
* the name of the memory region where the tensor is going to be copied
65+
* @throws IllegalArgumentException if the data type of the tensor is not supported
66+
* @throws IOException if there is any error creating the shared memory array
67+
*/
7268
public static void build(TType tensor, String memoryName) throws IllegalArgumentException, IOException
7369
{
7470
if (tensor instanceof TUint8)
@@ -97,14 +93,6 @@ else if (tensor instanceof TInt64)
9793
}
9894
}
9995

100-
/**
101-
* Builds a {@link RandomAccessibleInterval} from a unsigned byte-typed {@link TUint8} tensor.
102-
*
103-
* @param tensor
104-
* The {@link TUint8} tensor data is read from.
105-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link UnsignedByteType}.
106-
* @throws IOException
107-
*/
10896
private static void buildFromTensorUByte(TUint8 tensor, String memoryName) throws IOException
10997
{
11098
long[] arrayShape = tensor.shape().asArray();
@@ -122,14 +110,6 @@ private static void buildFromTensorUByte(TUint8 tensor, String memoryName) throw
122110
if (PlatformDetection.isWindows()) shma.close();
123111
}
124112

125-
/**
126-
* Builds a {@link RandomAccessibleInterval} from a unsigned int32-typed {@link TInt32} tensor.
127-
*
128-
* @param tensor
129-
* The {@link TInt32} tensor data is read from.
130-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link IntType}.
131-
* @throws IOException
132-
*/
133113
private static void buildFromTensorInt(TInt32 tensor, String memoryName) throws IOException
134114
{
135115
long[] arrayShape = tensor.shape().asArray();
@@ -148,14 +128,6 @@ private static void buildFromTensorInt(TInt32 tensor, String memoryName) throws
148128
if (PlatformDetection.isWindows()) shma.close();
149129
}
150130

151-
/**
152-
* Builds a {@link RandomAccessibleInterval} from a unsigned float32-typed {@link TFloat32} tensor.
153-
*
154-
* @param tensor
155-
* The {@link TFloat32} tensor data is read from.
156-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link FloatType}.
157-
* @throws IOException
158-
*/
159131
private static void buildFromTensorFloat(TFloat32 tensor, String memoryName) throws IOException
160132
{
161133
long[] arrayShape = tensor.shape().asArray();
@@ -174,14 +146,6 @@ private static void buildFromTensorFloat(TFloat32 tensor, String memoryName) thr
174146
if (PlatformDetection.isWindows()) shma.close();
175147
}
176148

177-
/**
178-
* Builds a {@link RandomAccessibleInterval} from a unsigned float64-typed {@link TFloat64} tensor.
179-
*
180-
* @param tensor
181-
* The {@link TFloat64} tensor data is read from.
182-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link DoubleType}.
183-
* @throws IOException
184-
*/
185149
private static void buildFromTensorDouble(TFloat64 tensor, String memoryName) throws IOException
186150
{
187151
long[] arrayShape = tensor.shape().asArray();
@@ -200,14 +164,6 @@ private static void buildFromTensorDouble(TFloat64 tensor, String memoryName) th
200164
if (PlatformDetection.isWindows()) shma.close();
201165
}
202166

203-
/**
204-
* Builds a {@link RandomAccessibleInterval} from a unsigned int64-typed {@link TInt64} tensor.
205-
*
206-
* @param tensor
207-
* The {@link TInt64} tensor data is read from.
208-
* @return The {@link RandomAccessibleInterval} built from the tensor, of type {@link LongType}.
209-
* @throws IOException
210-
*/
211167
private static void buildFromTensorLong(TInt64 tensor, String memoryName) throws IOException
212168
{
213169
long[] arrayShape = tensor.shape().asArray();

src/main/java/io/bioimage/modelrunner/tensorflow/v2/api030/shm/TensorBuilder.java

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323

2424
import io.bioimage.modelrunner.tensor.shm.SharedMemoryArray;
2525
import io.bioimage.modelrunner.utils.CommonUtils;
26-
import net.imglib2.RandomAccessibleInterval;
27-
import net.imglib2.img.Img;
28-
import net.imglib2.type.numeric.integer.IntType;
29-
import net.imglib2.type.numeric.integer.LongType;
30-
import net.imglib2.type.numeric.integer.UnsignedByteType;
31-
import net.imglib2.type.numeric.real.DoubleType;
32-
import net.imglib2.type.numeric.real.FloatType;
3326
import net.imglib2.util.Cast;
3427

3528
import java.nio.ByteBuffer;
@@ -55,10 +48,9 @@
5548
import org.tensorflow.types.family.TType;
5649

5750
/**
58-
* A TensorFlow 2 {@link Tensor} builder from {@link Img} and
59-
* {@link io.bioimage.modelrunner.tensor.Tensor} objects.
51+
* Utility class to build Pytorch Bytedeco tensors from shm segments using {@link SharedMemoryArray}
6052
*
61-
* @author Carlos Garcia Lopez de Haro and Daniel Felipe Gonzalez Obando
53+
* @author Carlos Garcia Lopez de Haro
6254
*/
6355
public final class TensorBuilder {
6456

@@ -68,21 +60,17 @@ public final class TensorBuilder {
6860
private TensorBuilder() {}
6961

7062
/**
71-
* Creates {@link TType} instance with the same size and information as the
72-
* given {@link RandomAccessibleInterval}.
63+
* Creates {@link TType} instance from a {@link SharedMemoryArray}
7364
*
74-
* @param <T>
75-
* the ImgLib2 data types the {@link RandomAccessibleInterval} can be
7665
* @param array
77-
* the {@link RandomAccessibleInterval} that is going to be converted into
66+
* the {@link SharedMemoryArray} that is going to be converted into
7867
* a {@link TType} tensor
79-
* @return a {@link TType} tensor
80-
* @throws IllegalArgumentException if the type of the {@link RandomAccessibleInterval}
68+
* @return the Pytorch {@link TType} as the one stored in the shared memory segment
69+
* @throws IllegalArgumentException if the type of the {@link SharedMemoryArray}
8170
* is not supported
8271
*/
8372
public static TType build(SharedMemoryArray array) throws IllegalArgumentException
8473
{
85-
// Create an Icy sequence of the same type of the tensor
8674
if (array.getOriginalDataType().equals("uint8")) {
8775
return buildUByte(Cast.unchecked(array));
8876
}
@@ -103,17 +91,7 @@ else if (array.getOriginalDataType().equals("int64")) {
10391
}
10492
}
10593

106-
/**
107-
* Creates a {@link TType} tensor of type {@link TUint8} from an
108-
* {@link RandomAccessibleInterval} of type {@link UnsignedByteType}
109-
*
110-
* @param tensor
111-
* The {@link RandomAccessibleInterval} to fill the tensor with.
112-
* @return The {@link TType} tensor filled with the {@link RandomAccessibleInterval} data.
113-
* @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is
114-
* not compatible
115-
*/
116-
public static TUint8 buildUByte(SharedMemoryArray tensor)
94+
private static TUint8 buildUByte(SharedMemoryArray tensor)
11795
throws IllegalArgumentException
11896
{
11997
long[] ogShape = tensor.getOriginalShape();
@@ -128,17 +106,7 @@ public static TUint8 buildUByte(SharedMemoryArray tensor)
128106
return ndarray;
129107
}
130108

131-
/**
132-
* Creates a {@link TInt32} tensor of type {@link TInt32} from an
133-
* {@link RandomAccessibleInterval} of type {@link IntType}
134-
*
135-
* @param tensor
136-
* The {@link RandomAccessibleInterval} to fill the tensor with.
137-
* @return The {@link TInt32} tensor filled with the {@link RandomAccessibleInterval} data.
138-
* @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is
139-
* not compatible
140-
*/
141-
public static TInt32 buildInt(SharedMemoryArray tensor)
109+
private static TInt32 buildInt(SharedMemoryArray tensor)
142110
throws IllegalArgumentException
143111
{
144112
long[] ogShape = tensor.getOriginalShape();
@@ -157,16 +125,6 @@ public static TInt32 buildInt(SharedMemoryArray tensor)
157125
return ndarray;
158126
}
159127

160-
/**
161-
* Creates a {@link TInt64} tensor of type {@link TInt64} from an
162-
* {@link RandomAccessibleInterval} of type {@link LongType}
163-
*
164-
* @param tensor
165-
* The {@link RandomAccessibleInterval} to fill the tensor with.
166-
* @return The {@link TInt64} tensor filled with the {@link RandomAccessibleInterval} data.
167-
* @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is
168-
* not compatible
169-
*/
170128
private static TInt64 buildLong(SharedMemoryArray tensor)
171129
throws IllegalArgumentException
172130
{
@@ -186,17 +144,7 @@ private static TInt64 buildLong(SharedMemoryArray tensor)
186144
return ndarray;
187145
}
188146

189-
/**
190-
* Creates a {@link TFloat32} tensor of type {@link TFloat32} from an
191-
* {@link RandomAccessibleInterval} of type {@link FloatType}
192-
*
193-
* @param tensor
194-
* The {@link RandomAccessibleInterval} to fill the tensor with.
195-
* @return The {@link TFloat32} tensor filled with the {@link RandomAccessibleInterval} data.
196-
* @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is
197-
* not compatible
198-
*/
199-
public static TFloat32 buildFloat(SharedMemoryArray tensor)
147+
private static TFloat32 buildFloat(SharedMemoryArray tensor)
200148
throws IllegalArgumentException
201149
{
202150
long[] ogShape = tensor.getOriginalShape();
@@ -214,16 +162,6 @@ public static TFloat32 buildFloat(SharedMemoryArray tensor)
214162
return ndarray;
215163
}
216164

217-
/**
218-
* Creates a {@link TFloat64} tensor of type {@link TFloat64} from an
219-
* {@link RandomAccessibleInterval} of type {@link DoubleType}
220-
*
221-
* @param tensor
222-
* The {@link RandomAccessibleInterval} to fill the tensor with.
223-
* @return The {@link TFloat64} tensor filled with the {@link RandomAccessibleInterval} data.
224-
* @throws IllegalArgumentException if the input {@link RandomAccessibleInterval} type is
225-
* not compatible
226-
*/
227165
private static TFloat64 buildDouble(SharedMemoryArray tensor)
228166
throws IllegalArgumentException
229167
{

0 commit comments

Comments
 (0)