Package io.github.hakkelt.ndarrays.basic
Class BasicComplexFloatNDArray
- java.lang.Object
-
- io.github.hakkelt.ndarrays.internal.AbstractNDArray<org.apache.commons.math3.complex.Complex,T>
-
- io.github.hakkelt.ndarrays.AbstractComplexNDArray<Float>
-
- io.github.hakkelt.ndarrays.basic.BasicComplexFloatNDArray
-
- All Implemented Interfaces:
ComplexNDArray<Float>
,NDArray<org.apache.commons.math3.complex.Complex>
,Iterable<org.apache.commons.math3.complex.Complex>
public class BasicComplexFloatNDArray extends AbstractComplexNDArray<Float>
Reference implementation for the NDArray of complex float (single-precision, 32 bit floating point) values.
-
-
Constructor Summary
Constructors Constructor Description BasicComplexFloatNDArray(int... shape)
Simple constructor that defines only the shape of the NDArray and fills it with zeros.BasicComplexFloatNDArray(NDArray<?> array)
Copy constructor.BasicComplexFloatNDArray(NDArray<? extends Number> real, NDArray<? extends Number> imag)
Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ComplexNDArray<Float>
copyFrom(NDArray<?> array)
Updates this NDArray with the elements of the NDArray given as parameter.boolean
equals(Object other)
Compares the specified object with this NDArray for equality.static Collector<Object,List<Object>,NDArray<org.apache.commons.math3.complex.Complex>>
getCollector(int... shape)
String
getNamePrefix()
Returns a string that identifies the implementation behind this current object.int
hashCode()
This method is unsupported because NDArrays should not be used as keys in hash-based collections.static ComplexNDArray<Float>
of(byte... array)
Factory method that creates a ComplexNDArray from a list or 1D array of byte values.static ComplexNDArray<Float>
of(byte[] real, byte[] imag)
Factory method that creates a ComplexNDArray from two 1D array of byte values.static ComplexNDArray<Float>
of(double... array)
Factory method that creates a ComplexNDArray from a list or 1D array of double values.static ComplexNDArray<Float>
of(double[] real, double[] imag)
Factory method that creates a ComplexNDArray from two 1D array of double values.static ComplexNDArray<Float>
of(float... array)
Factory method that creates a ComplexNDArray from a list or 1D array of float values.static ComplexNDArray<Float>
of(float[] real, float[] imag)
Factory method that creates a ComplexNDArray from two 1D array of float values.static ComplexNDArray<Float>
of(int... array)
Factory method that creates a ComplexNDArray from a list or 1D array of int values.static ComplexNDArray<Float>
of(int[] real, int[] imag)
Factory method that creates a ComplexNDArray from two 1D array of int values.static ComplexNDArray<Float>
of(long... array)
Factory method that creates a ComplexNDArray from a list or 1D array of long values.static ComplexNDArray<Float>
of(long[] real, long[] imag)
Factory method that creates a ComplexNDArray from two 1D array of long values.static ComplexNDArray<Float>
of(short... array)
Factory method that creates a ComplexNDArray from a list or 1D array of short values.static ComplexNDArray<Float>
of(short[] real, short[] imag)
Factory method that creates a ComplexNDArray from two 1D array of short values.static ComplexNDArray<Float>
of(Object[] realOrComplex)
Factory method that creates an NDArray from a multi-dimensional array of numeric values (including Complex type).static ComplexNDArray<Float>
of(Object[] real, Object[] imag)
Factory method that creates a ComplexNDArray from two multi-dimensional arrays of numeric values.static ComplexNDArray<Float>
ofMagnitudePhase(NDArray<? extends Number> magnitude, NDArray<? extends Number> phase)
Factory method that creates a ComplexNDArray from two multi-dimensional arrays of numeric values.static ComplexNDArray<Float>
ofMagnitudePhase(Object[] magnitude, Object[] phase)
Factory method that creates a ComplexNDArray from two multi-dimensional arrays of numeric values.static BasicComplexFloatNDArray
readFromFile(File file)
Load the content of the given file into a new BasicByteNDArray.-
Methods inherited from class io.github.hakkelt.ndarrays.AbstractComplexNDArray
abs, apply, applyOnComplexSlices, applyWithCartesianIndices, applyWithLinearIndices, argument, copy, dataTypeAsString, dtype, dtype2, fillUsingCartesianIndices, fillUsingLinearIndices, imaginary, mapOnComplexSlices, real, set, set, setImag, setImag, setReal, setReal, similar
-
Methods inherited from class io.github.hakkelt.ndarrays.internal.AbstractNDArray
accumulate, applyOnSlices, contains, contentToString, contentToString, forEach, forEachWithCartesianIndices, forEachWithLinearIndices, get, get, getImag, getImag, getReal, getReal, iterator, length, mapOnSlices, maybeParallelStream, ndim, norm, norm, parallelStream, prod, reduceSlices, set, set, shape, shape, spliterator, stream, streamCartesianIndices, streamLinearIndices, sum, toArray, toArray, toArray, toString, writeToFile
-
Methods inherited from interface io.github.hakkelt.ndarrays.ComplexNDArray
accumulate, add, add, add, add, add, add, add, add, addInplace, addInplace, addInplace, addInplace, addInplace, addInplace, addInplace, addInplace, concatenate, contentToString, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, divide, divide, divide, divide, divide, divide, divide, divide, divideInplace, divideInplace, divideInplace, divideInplace, divideInplace, divideInplace, divideInplace, divideInplace, dropDims, fill, fill, fill, getImag, getImag, getReal, getReal, inverseMask, map, mapWithCartesianIndices, mapWithLinearIndices, mask, mask, maskWithCartesianIndices, maskWithLinearIndices, multiply, multiply, multiply, multiply, multiply, multiply, multiply, multiply, multiplyInplace, multiplyInplace, multiplyInplace, multiplyInplace, multiplyInplace, multiplyInplace, multiplyInplace, multiplyInplace, permuteDims, prod, reduceComplexSlices, reshape, selectDims, slice, squeeze, subtract, subtract, subtract, subtract, subtract, subtract, subtract, subtract, subtractInplace, subtractInplace, subtractInplace, subtractInplace, subtractInplace, subtractInplace, subtractInplace, subtractInplace, sum
-
Methods inherited from interface io.github.hakkelt.ndarrays.NDArray
accumulate, applyOnSlices, contains, contentToString, forEach, forEachWithCartesianIndices, forEachWithLinearIndices, get, get, iterator, length, mapOnSlices, ndim, norm, norm, norm, parallelStream, prod, reduceSlices, set, set, shape, shape, spliterator, stream, streamCartesianIndices, streamLinearIndices, sum, toArray, toArray, toArray, toString, writeToFile
-
-
-
-
Constructor Detail
-
BasicComplexFloatNDArray
public BasicComplexFloatNDArray(int... shape)
Simple constructor that defines only the shape of the NDArray and fills it with zeros.- Parameters:
shape
- dimensions / shape of the NDArray
-
BasicComplexFloatNDArray
public BasicComplexFloatNDArray(NDArray<?> array)
Copy constructor.- Parameters:
array
- NDArray from which entries are copied from.
-
-
Method Detail
-
of
public static ComplexNDArray<Float> of(byte... array)
Factory method that creates a ComplexNDArray from a list or 1D array of byte values.- Parameters:
array
- a list or 1D array of byte values from which a BasicComplexFloatNDArray is created.- Returns:
- a ComplexNDArray created from a list or 1D array of byte values
-
of
public static ComplexNDArray<Float> of(short... array)
Factory method that creates a ComplexNDArray from a list or 1D array of short values.- Parameters:
array
- a list or 1D array of short values from which a BasicComplexFloatNDArray is created.- Returns:
- a ComplexNDArray created from a list or 1D array of short values
-
of
public static ComplexNDArray<Float> of(int... array)
Factory method that creates a ComplexNDArray from a list or 1D array of int values.- Parameters:
array
- a list or 1D array of int values from which a BasicComplexFloatNDArray is created.- Returns:
- a ComplexNDArray created from a list or 1D array of int values
-
of
public static ComplexNDArray<Float> of(long... array)
Factory method that creates a ComplexNDArray from a list or 1D array of long values.- Parameters:
array
- a list or 1D array of long values from which a BasicComplexFloatNDArray is created.- Returns:
- a ComplexNDArray created from a list or 1D array of long values
-
of
public static ComplexNDArray<Float> of(float... array)
Factory method that creates a ComplexNDArray from a list or 1D array of float values.- Parameters:
array
- a list or 1D array of float values from which a BasicComplexFloatNDArray is created.- Returns:
- a ComplexNDArray created from a list or 1D array of float values
-
of
public static ComplexNDArray<Float> of(double... array)
Factory method that creates a ComplexNDArray from a list or 1D array of double values.- Parameters:
array
- a list or 1D array of double values from which a BasicComplexFloatNDArray is created.- Returns:
- a ComplexNDArray created from a list or 1D array of double values
-
of
public static ComplexNDArray<Float> of(Object[] realOrComplex)
Factory method that creates an NDArray from a multi-dimensional array of numeric values (including Complex type).- Parameters:
realOrComplex
- a multi-dimensional array of numeric values (including Complex type) from which a BasicComplexFloatNDArray is created.- Returns:
- an NDArray created from a multi-dimensional array of numeric values
-
of
public static ComplexNDArray<Float> of(byte[] real, byte[] imag)
Factory method that creates a ComplexNDArray from two 1D array of byte values.- Parameters:
real
- a 1D array of byte values from which the real part of the created BasicComplexFloatNDArray is read.imag
- a 1D array of byte values from which the imaginary part of the created BasicComplexFloatNDArray is read.- Returns:
- a ComplexNDArray created from the two 1D array of byte values
-
of
public static ComplexNDArray<Float> of(short[] real, short[] imag)
Factory method that creates a ComplexNDArray from two 1D array of short values.- Parameters:
real
- a 1D array of short values from which the real part of the created BasicComplexFloatNDArray is read.imag
- a 1D array of short values from which the imaginary part of the created BasicComplexFloatNDArray is read.- Returns:
- a ComplexNDArray created from the two 1D array of short values
-
of
public static ComplexNDArray<Float> of(int[] real, int[] imag)
Factory method that creates a ComplexNDArray from two 1D array of int values.- Parameters:
real
- a 1D array of int values from which the real part of the created BasicComplexFloatNDArray is read.imag
- a 1D array of int values from which the imaginary part of the created BasicComplexFloatNDArray is read.- Returns:
- a ComplexNDArray created from the two 1D array of int values
-
of
public static ComplexNDArray<Float> of(long[] real, long[] imag)
Factory method that creates a ComplexNDArray from two 1D array of long values.- Parameters:
real
- a 1D array of long values from which the real part of the created BasicComplexFloatNDArray is read.imag
- a 1D array of long values from which the imaginary part of the created BasicComplexFloatNDArray is read.- Returns:
- a ComplexNDArray created from the two 1D array of long values
-
of
public static ComplexNDArray<Float> of(float[] real, float[] imag)
Factory method that creates a ComplexNDArray from two 1D array of float values.- Parameters:
real
- a 1D array of float values from which the real part of the created BasicComplexFloatNDArray is read.imag
- a 1D array of float values from which the imaginary part of the created BasicComplexFloatNDArray is read.- Returns:
- a ComplexNDArray created from the two 1D array of float values
-
of
public static ComplexNDArray<Float> of(double[] real, double[] imag)
Factory method that creates a ComplexNDArray from two 1D array of double values.- Parameters:
real
- a 1D array of double values from which the real part of the created BasicComplexFloatNDArray is read.imag
- a 1D array of double values from which the imaginary part of the created BasicComplexFloatNDArray is read.- Returns:
- a ComplexNDArray created from the two 1D array of double values
-
of
public static ComplexNDArray<Float> of(Object[] real, Object[] imag)
Factory method that creates a ComplexNDArray from two multi-dimensional arrays of numeric values.- Parameters:
real
- a multi-dimensional array of numeric values from which the real part of the created BasicComplexFloatNDArray is read.imag
- a multi-dimensional array of numeric values from which the imaginary part of the created BasicComplexFloatNDArray is read.- Returns:
- a ComplexNDArray created from the two multi-dimensional arrays of numeric values
-
ofMagnitudePhase
public static ComplexNDArray<Float> ofMagnitudePhase(Object[] magnitude, Object[] phase)
Factory method that creates a ComplexNDArray from two multi-dimensional arrays of numeric values.- Parameters:
magnitude
- a multi-dimensional array of numeric values that stores the magnitude of the complex array to be created.phase
- a multi-dimensional array of numeric values that stores the phase of the complex array to be created.- Returns:
- a ComplexNDArray created from the two multi-dimensional arrays of numeric values
-
ofMagnitudePhase
public static ComplexNDArray<Float> ofMagnitudePhase(NDArray<? extends Number> magnitude, NDArray<? extends Number> phase)
Factory method that creates a ComplexNDArray from two multi-dimensional arrays of numeric values.- Parameters:
magnitude
- a real-valued NDArray that stores the magnitude of the complex array to be created.phase
- a real-valued NDArray that stores the phase of the complex array to be created.- Returns:
- a ComplexNDArray created from the two multi-dimensional arrays of numeric values
-
readFromFile
public static BasicComplexFloatNDArray readFromFile(File file) throws IOException
Load the content of the given file into a new BasicByteNDArray.Only the files written by function writeToFile can be loaded by this function.
- Example:
ComplexNDArray<Float> array = new BasicComplexFloatNDArray(128, 128).fill(5); array.writeToFile(new File("array.nda")); ComplexNDArray<Double> array2 = BasicComplexDoubleNDArray.readFromFile(new File("array.nda")); assertEquals(array, array2);
- Parameters:
file
- file from which the content of the NDArray is read (the extension of the file can be arbitrary, but .nda is recommended)- Returns:
- a new BasicByteNDArray whose shape and content is loaded from the given file
- Throws:
IOException
- when the given file cannot be opened for read
-
copyFrom
public ComplexNDArray<Float> copyFrom(NDArray<?> array)
Description copied from interface:NDArray
Updates this NDArray with the elements of the NDArray given as parameter.Note: the parameter NDArray must have the same shape and this NDArray!
- Parameters:
array
- NDArray from which values are copied to this NDArray- Returns:
- this NDArray
-
getNamePrefix
public String getNamePrefix()
Description copied from interface:NDArray
Returns a string that identifies the implementation behind this current object. The output of the toString() function starts with this string.- Returns:
- a string that identifies the implementation
-
getCollector
public static Collector<Object,List<Object>,NDArray<org.apache.commons.math3.complex.Complex>> getCollector(int... shape)
-
equals
public boolean equals(Object other)
Description copied from interface:NDArray
Compares the specified object with this NDArray for equality. Two arrays are equal, if they are both real or both complex, and they are element-wise equal. If the specified object is not NDArray then the function returns false.- Specified by:
equals
in interfaceNDArray<org.apache.commons.math3.complex.Complex>
- Overrides:
equals
in classAbstractNDArray<org.apache.commons.math3.complex.Complex,Float>
- Parameters:
other
- Object to be compared for equality- Returns:
- true if the specified object equals with this NDArray
-
hashCode
@Generated public int hashCode()
Description copied from interface:NDArray
This method is unsupported because NDArrays should not be used as keys in hash-based collections.- Specified by:
hashCode
in interfaceNDArray<org.apache.commons.math3.complex.Complex>
- Overrides:
hashCode
in classAbstractNDArray<org.apache.commons.math3.complex.Complex,Float>
- Returns:
- always throws UnsupportedOperationsException
-
-