Java Code Examples for org.nd4j.linalg.factory.Nd4j#createComplex()

The following examples show how to use org.nd4j.linalg.factory.Nd4j#createComplex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
public IComplexNDArray hermitian() {
    IComplexNDArray result = Nd4j.createComplex(shape());

    IComplexDouble c = Nd4j.createDouble(0, 0);

    for (int i = 0; i < slices(); i++)
        for (int j = 0; j < columns(); j++)
            result.putScalar(j, i, getComplex(i, j, c).conji());
    return result;
}
 
Example 2
Source File: ComplexNDArrayUtil.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Center an array
 *
 * @param arr   the arr to center
 * @param shape the shape of the array
 * @return the center portion of the array based on the
 * specified shape
 */
public static IComplexNDArray center(IComplexNDArray arr, long[] shape) {
    if (arr.length() < ArrayUtil.prod(shape))
        return arr;
    for (int i = 0; i < shape.length; i++)
        if (shape[i] < 1)
            shape[i] = 1;

    INDArray shapeMatrix = NDArrayUtil.toNDArray(shape);
    INDArray currShape = NDArrayUtil.toNDArray(arr.shape());

    INDArray startIndex = Transforms.floor(currShape.sub(shapeMatrix).divi(Nd4j.scalar(2)));
    INDArray endIndex = startIndex.add(shapeMatrix);
    INDArrayIndex[] indexes = Indices.createFromStartAndEnd(startIndex, endIndex);

    if (shapeMatrix.length() > 1)
        return arr.get(indexes);


    else {
        IComplexNDArray ret = Nd4j.createComplex(new int[] {(int) shapeMatrix.getDouble(0)});
        int start = (int) startIndex.getDouble(0);
        int end = (int) endIndex.getDouble(0);
        int count = 0;
        for (int i = start; i < end; i++) {
            ret.putScalar(count++, arr.getComplex(i));
        }

        return ret;
    }


}
 
Example 3
Source File: ComplexNDArrayUtil.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Pads an ndarray with zeros
 *
 * @param nd          the ndarray to pad
 * @param targetShape the the new shape
 * @return the padded ndarray
 */
public static IComplexNDArray padWithZeros(IComplexNDArray nd, long[] targetShape) {
    if (Arrays.equals(nd.shape(), targetShape))
        return nd;
    //no padding required
    if (ArrayUtil.prod(nd.shape()) >= ArrayUtil.prod(targetShape))
        return nd;

    IComplexNDArray ret = Nd4j.createComplex(targetShape);
    INDArrayIndex[] targetShapeIndex = NDArrayIndex.createCoveringShape(nd.shape());
    ret.put(targetShapeIndex, nd);
    return ret;

}
 
Example 4
Source File: JCublasNDArrayFactory.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
public IComplexNDArray createComplex(float[] dim) {
    if (dim.length % 2 != 0)
        throw new IllegalArgumentException("Complex nd array buffers must have an even number of elements");
    IComplexNDArray ret = Nd4j.createComplex(dim.length / 2);
    int count = 0;
    for (int i = 0; i < dim.length - 1; i += 2) {
        ret.putScalar(count++, Nd4j.createDouble(dim[i], dim[i + 1]));
    }
    return ret;
}
 
Example 5
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public IComplexNDArray linearViewColumnOrder() {
    if (length() >= Integer.MAX_VALUE)
        throw new IllegalArgumentException("Length can not be >= Integer.MAX_VALUE");
    return Nd4j.createComplex(data, new int[] {(int) length(), 1}, offset());
}
 
Example 6
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public IComplexNDArray norm1(int... dimension) {
    return Nd4j.createComplex(super.norm1(dimension));
}
 
Example 7
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public IComplexNDArray min(int... dimension) {
    return Nd4j.createComplex(super.min(dimension));
}
 
Example 8
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
protected IComplexNDArray create(DataBuffer data, int[] shape, long offset) {
    return Nd4j.createComplex(data, shape, offset);
}
 
Example 9
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
protected INDArray create(int[] shape, char ordering) {
    return Nd4j.createComplex(shape, ordering);
}
 
Example 10
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
protected IComplexNDArray create(int[] shape) {
    return Nd4j.createComplex(shape, Nd4j.getComplexStrides(shape, ordering()), 0);
}
 
Example 11
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public IComplexNDArray mean(int... dimension) {
    return Nd4j.createComplex(super.mean(dimension));
}
 
Example 12
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public IComplexNDArray prod(int... dimension) {
    return Nd4j.createComplex(super.prod(dimension));
}
 
Example 13
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public IComplexNDArray normmax(int... dimension) {
    return Nd4j.createComplex(super.normmax(dimension));
}
 
Example 14
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
protected INDArray createScalarForIndex(int i, boolean applyOffset) {
    return Nd4j.createComplex(data(), new int[] {1, 1}, new int[] {1, 1}, applyOffset ? offset() + i : i);
}
 
Example 15
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
protected INDArray create(DataBuffer data, int[] shape, int[] strides) {
    if (this instanceof IComplexNDArray)
        return Nd4j.createComplex(data, shape, strides, 0, ordering());
    else
        return Nd4j.create(data, shape, strides, 0, ordering());
}
 
Example 16
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
protected INDArray create(int[] shape, char ordering) {
    if (this instanceof IComplexNDArray)
        return Nd4j.createComplex(shape, ordering);
    else
        return Nd4j.create(shape, ordering);
}
 
Example 17
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
protected IComplexNDArray create(DataBuffer data, int[] newShape, int[] newStrides, long offset, char ordering) {
    return Nd4j.createComplex(data, newShape, newStrides, offset, ordering);
}
 
Example 18
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
protected IComplexNDArray create(INDArray baseNDArray) {
    return Nd4j.createComplex(baseNDArray);
}
 
Example 19
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
protected INDArray create(DataBuffer data, int[] newShape, int[] newStrides, long offset, char ordering) {
    if (this instanceof IComplexNDArray)
        return Nd4j.createComplex(data, newShape, newStrides, offset, ordering);
    else
        return Nd4j.create(data, newShape, newStrides, offset, ordering);
}
 
Example 20
Source File: BaseComplexNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
/**
 * Return transposed copy of this matrix.
 */
@Override
public IComplexNDArray transposei() {
    return Nd4j.createComplex(super.transposei());
}