Skip to content
Snippets Groups Projects
Commit 8263cc73 authored by carlosuc3m's avatar carlosuc3m
Browse files

identify different data types

parent 3a046a7a
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import java.nio.ByteBuffer; ...@@ -4,6 +4,7 @@ import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import org.jcp.xml.dsig.internal.dom.Utils;
import org.tensorflow.Tensor; import org.tensorflow.Tensor;
import net.imglib2.Cursor; import net.imglib2.Cursor;
...@@ -14,6 +15,8 @@ import net.imglib2.type.Type; ...@@ -14,6 +15,8 @@ import net.imglib2.type.Type;
import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.integer.ByteType; import net.imglib2.type.numeric.integer.ByteType;
import net.imglib2.type.numeric.integer.IntType; import net.imglib2.type.numeric.integer.IntType;
import net.imglib2.type.numeric.integer.LongType;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.real.DoubleType; import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.type.numeric.real.FloatType; import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.Util; import net.imglib2.util.Util;
...@@ -186,7 +189,8 @@ public final class MappedFileBuilder ...@@ -186,7 +189,8 @@ public final class MappedFileBuilder
createFileHeader(org.bioimageanalysis.icy.deeplearning.tensor.Tensor<T> tensor) { createFileHeader(org.bioimageanalysis.icy.deeplearning.tensor.Tensor<T> tensor) {
String dimsStr = String dimsStr =
tensor.getData() != null ? Arrays.toString(tensor.getData().dimensionsAsLongArray()) : "[]"; tensor.getData() != null ? Arrays.toString(tensor.getData().dimensionsAsLongArray()) : "[]";
String descriptionStr = "{'dtype':'" + tensor.getDataType() + "','axes':'" String descriptionStr = "{'dtype':'"
+ getDataTypeString(Util.getTypeFromInterval(tensor.getData())) + "','axes':'"
+ tensor.getAxesOrderString() + "','name':'" + tensor.getName() + "','shape':'" + tensor.getAxesOrderString() + "','name':'" + tensor.getName() + "','shape':'"
+ dimsStr + "'}"; + dimsStr + "'}";
...@@ -205,6 +209,32 @@ public final class MappedFileBuilder ...@@ -205,6 +209,32 @@ public final class MappedFileBuilder
return byteHeader; return byteHeader;
} }
/**
* Method that returns a Sting representing the datatype of T
* @param <T>
* @param type
* @return
*/
public static< T extends RealType< T > & NativeType< T > > String getDataTypeString(T type) {
if (type instanceof ByteType) {
return "byte";
} else if (type instanceof IntType) {
return "int32";
} else if (type instanceof FloatType) {
return "float32";
} else if (type instanceof DoubleType) {
return "float64";
} else if (type instanceof LongType) {
return "int64";
} else if (type instanceof UnsignedByteType) {
return "ubyte";
} else {
throw new IllegalArgumentException("Unsupported data type. At the moment the only "
+ "supported dtypes are: " + IntType.class + ", " + FloatType.class + ", "
+ DoubleType.class + ", " + LongType.class + " and " + UnsignedByteType.class);
}
}
/** /**
* Get the total byte size of the temp file that is oging to be created to do interprocess * Get the total byte size of the temp file that is oging to be created to do interprocess
* communication for MacOSX * communication for MacOSX
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment