Skip to content

Commit f2b7ce3

Browse files
committed
improve javadoc
1 parent 4dfa7d3 commit f2b7ce3

File tree

3 files changed

+11
-100
lines changed

3 files changed

+11
-100
lines changed

src/main/java/io/bioimage/modelrunner/pytorch/javacpp/JavaWorker.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public class JavaWorker {
2222

2323
private boolean cancelRequested = false;
2424

25+
/**
26+
* Method in the child process that is in charge of keeping the process open and calling the model load,
27+
* model inference and model closing
28+
* @param args
29+
* args of the parent process
30+
*/
2531
public static void main(String[] args) {
2632

2733
try(Scanner scanner = new Scanner(System.in)){

src/main/java/io/bioimage/modelrunner/pytorch/javacpp/tensor/ImgLib2Builder.java

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@
2525

2626
import io.bioimage.modelrunner.tensor.Utils;
2727
import io.bioimage.modelrunner.utils.CommonUtils;
28-
import io.bioimage.modelrunner.utils.IndexingUtils;
29-
import net.imglib2.Cursor;
3028
import net.imglib2.RandomAccessibleInterval;
31-
import net.imglib2.img.Img;
32-
import net.imglib2.img.array.ArrayImgFactory;
3329
import net.imglib2.img.array.ArrayImgs;
3430
import net.imglib2.type.Type;
3531
import net.imglib2.type.numeric.integer.ByteType;
3632
import net.imglib2.type.numeric.integer.IntType;
3733
import net.imglib2.type.numeric.integer.LongType;
38-
import net.imglib2.type.numeric.integer.UnsignedByteType;
3934
import net.imglib2.type.numeric.real.DoubleType;
4035
import net.imglib2.type.numeric.real.FloatType;
4136

@@ -78,37 +73,7 @@ public static <T extends Type<T>> RandomAccessibleInterval<T> build(org.bytedeco
7873
}
7974
}
8075

81-
/**
82-
* Builds a {@link RandomAccessibleInterval} from a unsigned byte-typed {@link org.bytedeco.pytorch.Tensor}.
83-
*
84-
* @param tensor
85-
* The {@link org.bytedeco.pytorch.Tensor} data is read from.
86-
* @return The {@link RandomAccessibleInterval} built from the tensor of type {@link UnsignedByteType}.
87-
*/
88-
public static RandomAccessibleInterval<UnsignedByteType> buildFromTensorUByte(org.bytedeco.pytorch.Tensor tensor) {
89-
long[] arrayShape = tensor.shape();
90-
if (CommonUtils.int32Overflows(arrayShape, 1))
91-
throw new IllegalArgumentException("Model output tensor with shape " + Arrays.toString(arrayShape)
92-
+ " is too big. Max number of elements per ubyte output tensor supported: " + Integer.MAX_VALUE / 1);
93-
long[] tensorShape = new long[arrayShape.length];
94-
for (int i = 0; i < arrayShape.length; i ++) tensorShape[i] = arrayShape[arrayShape.length - 1 - i];
95-
long flatSize = 1;
96-
for (long l : tensorShape) {flatSize *= l;}
97-
byte[] flatArr = new byte[(int) flatSize];
98-
tensor.data_ptr_byte().get(flatArr);
99-
RandomAccessibleInterval<UnsignedByteType> rai = ArrayImgs.unsignedBytes(flatArr, tensorShape);
100-
return Utils.transpose(rai);
101-
}
102-
103-
104-
/**
105-
* Builds a {@link RandomAccessibleInterval} from a signed byte-typed {@link org.bytedeco.pytorch.Tensor}.
106-
*
107-
* @param tensor
108-
* The {@link org.bytedeco.pytorch.Tensor} data is read from.
109-
* @return The {@link RandomAccessibleInterval} built from the tensor of type {@link ByteType}.
110-
*/
111-
public static RandomAccessibleInterval<ByteType> buildFromTensorByte(org.bytedeco.pytorch.Tensor tensor)
76+
private static RandomAccessibleInterval<ByteType> buildFromTensorByte(org.bytedeco.pytorch.Tensor tensor)
11277
{
11378
long[] arrayShape = tensor.shape();
11479
if (CommonUtils.int32Overflows(arrayShape, 1))
@@ -124,14 +89,7 @@ public static RandomAccessibleInterval<ByteType> buildFromTensorByte(org.bytedec
12489
return Utils.transpose(rai);
12590
}
12691

127-
/**
128-
* Builds a {@link RandomAccessibleInterval} from a signed integer-typed {@link org.bytedeco.pytorch.Tensor}.
129-
*
130-
* @param tensor
131-
* The {@link org.bytedeco.pytorch.Tensor} data is read from.
132-
* @return The {@link RandomAccessibleInterval} built from the tensor of type {@link IntType}.
133-
*/
134-
public static RandomAccessibleInterval<IntType> buildFromTensorInt(org.bytedeco.pytorch.Tensor tensor)
92+
private static RandomAccessibleInterval<IntType> buildFromTensorInt(org.bytedeco.pytorch.Tensor tensor)
13593
{
13694
long[] arrayShape = tensor.shape();
13795
if (CommonUtils.int32Overflows(arrayShape, 4))
@@ -147,14 +105,7 @@ public static RandomAccessibleInterval<IntType> buildFromTensorInt(org.bytedeco.
147105
return Utils.transpose(rai);
148106
}
149107

150-
/**
151-
* Builds a {@link RandomAccessibleInterval} from a signed float-typed {@link org.bytedeco.pytorch.Tensor}.
152-
*
153-
* @param tensor
154-
* The {@link org.bytedeco.pytorch.Tensor} data is read from.
155-
* @return The {@link RandomAccessibleInterval} built from the tensor of type {@link FloatType}.
156-
*/
157-
public static RandomAccessibleInterval<FloatType> buildFromTensorFloat(org.bytedeco.pytorch.Tensor tensor)
108+
private static RandomAccessibleInterval<FloatType> buildFromTensorFloat(org.bytedeco.pytorch.Tensor tensor)
158109
{
159110
long[] arrayShape = tensor.shape();
160111
if (CommonUtils.int32Overflows(arrayShape, 4))
@@ -170,14 +121,7 @@ public static RandomAccessibleInterval<FloatType> buildFromTensorFloat(org.byted
170121
return Utils.transpose(rai);
171122
}
172123

173-
/**
174-
* Builds a {@link RandomAccessibleInterval} from a signed double-typed {@link org.bytedeco.pytorch.Tensor}.
175-
*
176-
* @param tensor
177-
* The {@link org.bytedeco.pytorch.Tensor} data is read from.
178-
* @return The {@link RandomAccessibleInterval} built from the tensor of type {@link DoubleType}.
179-
*/
180-
public static RandomAccessibleInterval<DoubleType> buildFromTensorDouble(org.bytedeco.pytorch.Tensor tensor)
124+
private static RandomAccessibleInterval<DoubleType> buildFromTensorDouble(org.bytedeco.pytorch.Tensor tensor)
181125
{
182126
long[] arrayShape = tensor.shape();
183127
if (CommonUtils.int32Overflows(arrayShape, 8))
@@ -193,14 +137,7 @@ public static RandomAccessibleInterval<DoubleType> buildFromTensorDouble(org.byt
193137
return Utils.transpose(rai);
194138
}
195139

196-
/**
197-
* Builds a {@link RandomAccessibleInterval} from a signed long-typed {@link org.bytedeco.pytorch.Tensor}.
198-
*
199-
* @param tensor
200-
* The {@link org.bytedeco.pytorch.Tensor} data is read from.
201-
* @return The {@link RandomAccessibleInterval} built from the tensor of type {@link LongType}.
202-
*/
203-
public static RandomAccessibleInterval<LongType> buildFromTensorLong(org.bytedeco.pytorch.Tensor tensor)
140+
private static RandomAccessibleInterval<LongType> buildFromTensorLong(org.bytedeco.pytorch.Tensor tensor)
204141
{
205142
long[] arrayShape = tensor.shape();
206143
if (CommonUtils.int32Overflows(arrayShape, 8))

src/main/java/io/bioimage/modelrunner/pytorch/javacpp/tensor/JavaCPPTensorBuilder.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ public static < T extends RealType< T > & NativeType< T > > org.bytedeco.pytorch
8888
}
8989
}
9090

91-
/**
92-
* Builds a {@link org.bytedeco.pytorch.Tensor} from a signed byte-typed
93-
* {@link RandomAccessibleInterval}.
94-
*
95-
* @param tensor
96-
* the {@link RandomAccessibleInterval} that will be copied into an {@link org.bytedeco.pytorch.Tensor}
97-
* @return The {@link org.bytedeco.pytorch.Tensor} built from the tensor of type {@link ByteType}.
98-
*/
9991
private static org.bytedeco.pytorch.Tensor buildFromTensorByte(RandomAccessibleInterval<ByteType> tensor)
10092
{
10193
long[] ogShape = tensor.dimensionsAsLongArray();
@@ -121,14 +113,6 @@ private static org.bytedeco.pytorch.Tensor buildFromTensorByte(RandomAccessibleI
121113
return ndarray;
122114
}
123115

124-
/**
125-
* Builds a {@link org.bytedeco.pytorch.Tensor} from a signed integer-typed
126-
* {@link RandomAccessibleInterval}.
127-
*
128-
* @param tensor
129-
* the {@link RandomAccessibleInterval} that will be copied into an {@link org.bytedeco.pytorch.Tensor}
130-
* @return The {@link org.bytedeco.pytorch.Tensor} built from the tensor of type {@link IntType}.
131-
*/
132116
private static org.bytedeco.pytorch.Tensor buildFromTensorInt(RandomAccessibleInterval<IntType> tensor)
133117
{
134118
long[] ogShape = tensor.dimensionsAsLongArray();
@@ -154,14 +138,6 @@ private static org.bytedeco.pytorch.Tensor buildFromTensorInt(RandomAccessibleIn
154138
return ndarray;
155139
}
156140

157-
/**
158-
* Builds a {@link org.bytedeco.pytorch.Tensor} from a signed float-typed
159-
* {@link RandomAccessibleInterval}.
160-
*
161-
* @param tensor
162-
* the {@link RandomAccessibleInterval} that will be copied into an {@link org.bytedeco.pytorch.Tensor}
163-
* @return The {@link org.bytedeco.pytorch.Tensor} built from the tensor of type {@link FloatType}.
164-
*/
165141
private static org.bytedeco.pytorch.Tensor buildFromTensorFloat(RandomAccessibleInterval<FloatType> tensor)
166142
{
167143
long[] ogShape = tensor.dimensionsAsLongArray();
@@ -187,14 +163,6 @@ private static org.bytedeco.pytorch.Tensor buildFromTensorFloat(RandomAccessible
187163
return ndarray;
188164
}
189165

190-
/**
191-
* Builds a {@link org.bytedeco.pytorch.Tensor} from a signed double-typed
192-
* {@link RandomAccessibleInterval}.
193-
*
194-
* @param tensor
195-
* the {@link RandomAccessibleInterval} that will be copied into an {@link NDArray}
196-
* @return The {@link org.bytedeco.pytorch.Tensor} built from the tensor of type {@link DoubleType}.
197-
*/
198166
private static org.bytedeco.pytorch.Tensor buildFromTensorDouble(RandomAccessibleInterval<DoubleType> tensor)
199167
{
200168
long[] ogShape = tensor.dimensionsAsLongArray();

0 commit comments

Comments
 (0)