Skip to content

Commit

Permalink
keep adding javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 12, 2023
1 parent 50689b3 commit c341b20
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public interface SharedMemoryArray extends Closeable {
* The name is assigned automatically.
*
* @param <T>
* possible ImgLib2 data types of the retrieved {@link RandomAccessibleInterval}
* possible ImgLib2 data types of the provided {@link RandomAccessibleInterval}
* @param rai
* the {@link RandomAccessibleInterval} that is going to be written into a shared memory region
* @return a {@link SharedMemoryArray} instance that helps handling the data written to the shared memory region
Expand All @@ -95,7 +95,7 @@ SharedMemoryArray buildSHMA(RandomAccessibleInterval<T> rai) {
* An instance of {@link SharedMemoryArray} is created that helps managing the shared memory data.
*
* @param <T>
* possible ImgLib2 data types of the retrieved {@link RandomAccessibleInterval}
* possible ImgLib2 data types of the provided {@link RandomAccessibleInterval}
* @param name
* name of the shared memory region where the {@link RandomAccessibleInterval} data has been copied
* @param rai
Expand All @@ -108,15 +108,69 @@ SharedMemoryArray buildSHMA(String name, RandomAccessibleInterval<T> rai) {
else if (PlatformDetection.isLinux()) return SharedMemoryArrayLinux.build(name, rai);
else return SharedMemoryArrayMacOS.build(name, rai);
}


/**
* This method copies the data from a {@link RandomAccessibleInterval} into a shared memory region
* to be able to shared it with other processes.
* This method copies the data into the shared memory region following the Numpy .npy format. This means
* that the header of the region will contain info about the shape, the byte order, the column order (whether
* is fortran or not) and the data type.
* This way, the underlying nd array can be reconstructed just with the shared memory region name.
*
* An instance of {@link SharedMemoryArray} is created that helps managing the shared memory data.
* The name is assigned automatically.
*
* @param <T>
* possible ImgLib2 data types of the provided {@link RandomAccessibleInterval}
* @param rai
* the {@link RandomAccessibleInterval} that is going to be written into a shared memory region
* @return a {@link SharedMemoryArray} instance that helps handling the data written to the shared memory region
*/
static <T extends RealType<T> & NativeType<T>>
SharedMemoryArray buildNumpyLikeSHMA(RandomAccessibleInterval<T> rai) {
if (PlatformDetection.isWindows()) return SharedMemoryArrayWin.buildNumpyFormat(rai);
else if (PlatformDetection.isLinux()) return SharedMemoryArrayLinux.buildNumpyFormat(rai);
else return SharedMemoryArrayMacOS.buildNumpyFormat(rai);
}

/**
* This method copies the data from a {@link RandomAccessibleInterval} into a shared memory region
* to be able to shared it with other processes.
* This method copies the data into the shared memory region following the Numpy .npy format. This means
* that the header of the region will contain info about the shape, the byte order, the column order (whether
* is fortran or not) and the data type.
* This way, the underlying nd array can be reconstructed just with the shared memory region name.
*
* An instance of {@link SharedMemoryArray} is created that helps managing the shared memory data.
*
* @param <T>
* possible ImgLib2 data types of the provided {@link RandomAccessibleInterval}
* @param name
* name of the shared memory region where the {@link RandomAccessibleInterval} data has been copied
* @param rai
* the {@link RandomAccessibleInterval} that is going to be written into a shared memory region
* @return a {@link SharedMemoryArray} instance that helps handling the data written to the shared memory region
*/
static <T extends RealType<T> & NativeType<T>>
SharedMemoryArray buildNumpyLikeSHMA(String name, RandomAccessibleInterval<T> rai) {
if (PlatformDetection.isWindows()) return SharedMemoryArrayWin.buildNumpyFormat(name, rai);
else if (PlatformDetection.isLinux()) return SharedMemoryArrayLinux.buildNumpyFormat(name, rai);
else return SharedMemoryArrayMacOS.buildNumpyFormat(name, rai);
}

/**
* Build a {@link RandomAccessibleInterval} from the data stored in an existing shared memory segment.
* @param <T>
* possible ImgLib2 data types of the retrieved {@link RandomAccessibleInterval}
* @param memoryName
* name of the region where the shared memory segment is located
* @param shape
* shape (array dimensions) into which the flat array of the shared memory segment will be reconstructed
* @param isFortran
* whether converting the falt array into a ndarray is done using Fortran ordering or not (C-ordering)
* @param dataType
* @return
* the data type into which the bytes in the shared memory region will be converted
* @return the {@link RandomAccessibleInterval} defined by the arguments and the shared memory segment
*/
static <T extends RealType<T> & NativeType<T>>
RandomAccessibleInterval<T> buildImgLib2FromSHMA(String memoryName, long[] shape, boolean isFortran, String dataType) {
Expand All @@ -127,12 +181,19 @@ else if (PlatformDetection.isLinux())
else
return SharedMemoryArrayMacOS.createImgLib2RaiFromSharedMemoryBlock(memoryName, shape, isFortran, dataType);
}

/**
*
* Build a {@link RandomAccessibleInterval} from the data stored in an existing shared memory segment.
* The shared memory segment should contain an array of bytes that can be read using the .npy format.
* That is an array of bytes which specifies the characteristics of the nd array (shape, data type, byte order...)
* followed by the flattened data converted into bytes.
* If the shared memory region follows that convention, only the name of the shared memory region is needed to
* reconstruct the underlying nd array
* @param <T>
* possible ImgLib2 data types of the retrieved {@link RandomAccessibleInterval}
* @param memoryName
* @return
* name of the region where the shared memory segment is located
* @return the {@link RandomAccessibleInterval} defined exclusively by the shared memory region following the .npy format
*/
static <T extends RealType<T> & NativeType<T>>
RandomAccessibleInterval<T> buildImgLib2FromNumpyLikeSHMA(String memoryName) {
Expand All @@ -143,10 +204,24 @@ else if (PlatformDetection.isLinux())
else
return SharedMemoryArrayMacOS.buildImgLib2FromNumpyLikeSHMA(memoryName);
}

/**
* Build a {@link HashMap} from the data stored in an existing shared memory segment.
* The returned {@link HashMap} contains one entry for the data type, another for the shape (array dimensions),
* byte ordering, column order (whether it is Fortran ordering or C ordering) and another for the actual byte
* data (a flat array with the byte values of the array).
*
* The shared memory segment should contain an array of bytes that can be read using the .npy format.
* That is an array of bytes which specifies the characteristics of the nd array (shape, data type, byte order...)
* followed by the flattened data converted into bytes.
* If the shared memory region follows that convention, only the name of the shared memory region is needed to
* reconstruct the underlying nd array.
*
* @param <T>
* possible ImgLib2 data types of the retrieved {@link RandomAccessibleInterval}
* @param memoryName
* @return
* name of the region where the shared memory segment is located
* @return the {@link RandomAccessibleInterval} defined exclusively by the shared memory region following the .npy format
*/
static HashMap<String, Object> buildMapFromNumpyLikeSHMA(String memoryName) {
if (PlatformDetection.isWindows())
Expand All @@ -157,33 +232,6 @@ else if (PlatformDetection.isLinux())
return SharedMemoryArrayMacOS.buildMapFromNumpyLikeSHMA(memoryName);
}

/**
*
* @param <T>
* @param rai
* @return
*/
static <T extends RealType<T> & NativeType<T>>
SharedMemoryArray buildNumpyLikeSHMA(RandomAccessibleInterval<T> rai) {
if (PlatformDetection.isWindows()) return SharedMemoryArrayWin.buildNumpyFormat(rai);
else if (PlatformDetection.isLinux()) return SharedMemoryArrayLinux.buildNumpyFormat(rai);
else return SharedMemoryArrayMacOS.buildNumpyFormat(rai);
}

/**
*
* @param <T>
* @param name
* @param rai
* @return
*/
static <T extends RealType<T> & NativeType<T>>
SharedMemoryArray buildNumpyLikeSHMA(String name, RandomAccessibleInterval<T> rai) {
if (PlatformDetection.isWindows()) return SharedMemoryArrayWin.buildNumpyFormat(name, rai);
else if (PlatformDetection.isLinux()) return SharedMemoryArrayLinux.buildNumpyFormat(name, rai);
else return SharedMemoryArrayMacOS.buildNumpyFormat(name, rai);
}

/**
* Checks whether the String provided can be used as the name given to a shared memory segment
* @param name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* in LINUX based systems
* @author Carlos Garcia Lopez de Haro
*/
public final class SharedMemoryArrayLinux implements SharedMemoryArray
public class SharedMemoryArrayLinux implements SharedMemoryArray
{
/**
* Instance of the CLibrary JNI containing the methods to interact with the Shared memory segments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* in POSIX based systems (LINUX, MACOS...)
* @author Carlos Garcia Lopez de Haro
*/
public final class SharedMemoryArrayMacOS implements SharedMemoryArray
public class SharedMemoryArrayMacOS implements SharedMemoryArray
{
private static final CLibrary INSTANCE = CLibrary.INSTANCE;
private static final MacosHelpers macosInstance = MacosHelpers.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* in Windows
* @author Carlos Garcia Lopez de Haro
*/
public final class SharedMemoryArrayWin implements SharedMemoryArray
public class SharedMemoryArrayWin implements SharedMemoryArray
{
/**
* file mapping for shared memory
Expand Down

0 comments on commit c341b20

Please sign in to comment.