Search in sources :

Example 26 with IComplexNDArray

use of org.nd4j.linalg.api.complex.IComplexNDArray in project nd4j by deeplearning4j.

the class Nd4j method createComplex.

/**
 * Creates a complex ndarray with the specified shape
 *
 * @param data    the data to use with the ndarray
 * @param rows    the rows of the ndarray
 * @param columns the columns of the ndarray
 * @param stride  the stride for the ndarray
 * @param offset  the offset of the ndarray
 * @return the instance
 */
public static IComplexNDArray createComplex(float[] data, int rows, int columns, int[] stride, long offset, char ordering) {
    int[] shape = new int[] { rows, columns };
    shape = getEnsuredShape(shape);
    checkShapeValues(shape);
    IComplexNDArray ret = INSTANCE.createComplex(data, shape, stride, offset, ordering);
    logCreationIfNecessary(ret);
    return ret;
}
Also used : IComplexNDArray(org.nd4j.linalg.api.complex.IComplexNDArray)

Example 27 with IComplexNDArray

use of org.nd4j.linalg.api.complex.IComplexNDArray in project nd4j by deeplearning4j.

the class Nd4j method scalar.

/**
 * Create a scalar nd array with the specified value and offset
 *
 * @param value the value of the scalar
 * @return the scalar nd array
 */
public static IComplexNDArray scalar(IComplexFloat value) {
    IComplexNDArray ret = INSTANCE.scalar(value);
    logCreationIfNecessary(ret);
    return ret;
}
Also used : IComplexNDArray(org.nd4j.linalg.api.complex.IComplexNDArray)

Example 28 with IComplexNDArray

use of org.nd4j.linalg.api.complex.IComplexNDArray in project nd4j by deeplearning4j.

the class Nd4j method createComplex.

/**
 * Creates a complex ndarray with the specified shape
 *
 * @param rows    the rows of the ndarray
 * @param columns the columns of the ndarray
 * @param stride  the stride for the ndarray
 * @param offset  the offset of the ndarray
 * @return the instance
 */
public static IComplexNDArray createComplex(int rows, int columns, int[] stride, long offset) {
    if (rows < 1 || columns < 1)
        throw new ND4JIllegalStateException("Number of rows and columns should be positive for new INDArray");
    IComplexNDArray ret = INSTANCE.createComplex(rows, columns, stride, offset);
    logCreationIfNecessary(ret);
    return ret;
}
Also used : ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException) IComplexNDArray(org.nd4j.linalg.api.complex.IComplexNDArray)

Example 29 with IComplexNDArray

use of org.nd4j.linalg.api.complex.IComplexNDArray in project nd4j by deeplearning4j.

the class Nd4j method createComplex.

/**
 * Creates a complex ndarray with the specified shape
 *
 * @param rows    the rows of the ndarray
 * @param columns the columns of the ndarray
 * @param stride  the stride for the ndarray
 * @param offset  the offset of the ndarray
 * @return the instance
 */
public static IComplexNDArray createComplex(double[] data, int rows, int columns, int[] stride, long offset, char ordering) {
    int[] shape = getEnsuredShape(rows, columns);
    checkShapeValues(shape);
    IComplexNDArray ret = INSTANCE.createComplex(data, shape, stride, offset, ordering);
    logCreationIfNecessary(ret);
    return ret;
}
Also used : IComplexNDArray(org.nd4j.linalg.api.complex.IComplexNDArray)

Example 30 with IComplexNDArray

use of org.nd4j.linalg.api.complex.IComplexNDArray in project nd4j by deeplearning4j.

the class Nd4j method sortWithIndices.

/**
 * Sort an ndarray along a particular dimension
 *
 * @param ndarray   the ndarray to sort
 * @param dimension the dimension to sort
 * @return an array with indices and the sorted ndarray
 */
public static INDArray[] sortWithIndices(IComplexNDArray ndarray, int dimension, boolean ascending) {
    INDArray indices = Nd4j.create(ndarray.shape());
    INDArray[] ret = new INDArray[2];
    for (int i = 0; i < ndarray.vectorsAlongDimension(dimension); i++) {
        IComplexNDArray vec = ndarray.vectorAlongDimension(i, dimension);
        INDArray indexVector = indices.vectorAlongDimension(i, dimension);
        final IComplexNumber[] data = new IComplexNumber[vec.length()];
        final Double[] index = new Double[vec.length()];
        for (int j = 0; j < vec.length(); j++) {
            data[j] = vec.getComplex(j);
            index[j] = (double) j;
        }
        if (ascending)
            Arrays.sort(index, new Comparator<Double>() {

                @Override
                public int compare(Double o1, Double o2) {
                    int idx1 = (int) o1.doubleValue();
                    int idx2 = (int) o2.doubleValue();
                    return Double.compare(data[idx1].absoluteValue().doubleValue(), data[idx2].absoluteValue().doubleValue());
                }
            });
        else
            Arrays.sort(index, new Comparator<Double>() {

                @Override
                public int compare(Double o1, Double o2) {
                    int idx1 = (int) o1.doubleValue();
                    int idx2 = (int) o2.doubleValue();
                    return -Double.compare(data[idx1].absoluteValue().doubleValue(), data[idx2].absoluteValue().doubleValue());
                }
            });
        for (int j = 0; j < vec.length(); j++) {
            vec.putScalar(j, data[(int) index[j].doubleValue()]);
            indexVector.putScalar(j, index[j]);
        }
    }
    ret[0] = indices;
    ret[1] = ndarray;
    return ret;
}
Also used : IComplexNumber(org.nd4j.linalg.api.complex.IComplexNumber) IComplexNDArray(org.nd4j.linalg.api.complex.IComplexNDArray) IComplexDouble(org.nd4j.linalg.api.complex.IComplexDouble)

Aggregations

IComplexNDArray (org.nd4j.linalg.api.complex.IComplexNDArray)74 ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)6 INDArray (org.nd4j.linalg.api.ndarray.INDArray)5 IComplexNumber (org.nd4j.linalg.api.complex.IComplexNumber)3 DecimalFormat (java.text.DecimalFormat)2 INDArrayIndex (org.nd4j.linalg.indexing.INDArrayIndex)2 AllocationPoint (org.nd4j.jita.allocator.impl.AllocationPoint)1 DataBuffer (org.nd4j.linalg.api.buffer.DataBuffer)1 IComplexDouble (org.nd4j.linalg.api.complex.IComplexDouble)1