use of org.nd4j.linalg.api.complex.IComplexNDArray in project nd4j by deeplearning4j.
the class Nd4j method diag.
/**
* Creates a new matrix where the values of the given vector are the diagonal values of
* the matrix if a vector is passed in, if a matrix is returns the kth diagonal
* in the matrix
*
* @param x the diagonal values
* @param k the kth diagonal to getDouble
* @return new matrix
*/
public static IComplexNDArray diag(IComplexNDArray x, int k) {
if (x.isScalar())
return x.dup();
if (x.isVector()) {
IComplexNDArray m = Nd4j.createComplex(x.length(), x.length());
IComplexNDArray xLinear = x.linearView();
for (int i = 0; i < x.length(); i++) m.putScalar(i, i, xLinear.getComplex(i));
return m;
} else if (x.isMatrix()) {
int vectorLength = x.rows() - k;
IComplexNDArray ret = Nd4j.createComplex(new int[] { vectorLength, 1 });
for (int i = 0; i < vectorLength; i++) {
ret.putScalar(i, x.getComplex(i, i));
}
return ret;
}
throw new IllegalArgumentException("Illegal input for diagonal of shape " + x.shape().length);
}
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 shape the shape 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[] shape, int[] stride, long offset) {
checkShapeValues(shape);
IComplexNDArray ret = INSTANCE.createComplex(shape, stride, offset);
logCreationIfNecessary(ret);
return ret;
}
use of org.nd4j.linalg.api.complex.IComplexNDArray in project nd4j by deeplearning4j.
the class Nd4j method complexRand.
// //////////////////// RANDOM ///////////////////////////////
/**
* Create a random ndarray with the given shape using
* the current time as the seed
*
* @param shape the shape of the ndarray
* @return the random ndarray with the specified shape
*/
public static IComplexNDArray complexRand(int... shape) {
INDArray based = Nd4j.rand(new int[] { 1, ArrayUtil.prod(shape) * 2 });
IComplexNDArray ret = Nd4j.createComplex(based.data(), shape);
logCreationIfNecessary(ret);
return ret;
}
use of org.nd4j.linalg.api.complex.IComplexNDArray in project nd4j by deeplearning4j.
the class Nd4j method complexZeros.
/**
* Create an ndarray of ones
*
* @param shape the shape of the ndarray
* @return an ndarray with ones filled in
*/
public static IComplexNDArray complexZeros(int... shape) {
checkShapeValues(shape);
IComplexNDArray ret = INSTANCE.complexZeros(shape);
logCreationIfNecessary(ret);
return ret;
}
use of org.nd4j.linalg.api.complex.IComplexNDArray in project nd4j by deeplearning4j.
the class Nd4j method createComplex.
/**
* Create an ndrray with the specified shape
*
* @param data the data to use with tne ndarray
* @param shape the shape of the ndarray
* @return the created ndarray
*/
public static IComplexNDArray createComplex(double[] data, int[] shape) {
shape = getEnsuredShape(shape);
if (shape.length == 1) {
if (shape[0] == data.length) {
shape = new int[] { 1, data.length };
} else
throw new ND4JIllegalStateException("Shape of the new array " + Arrays.toString(shape) + " doesn't match data length: " + data.length);
}
checkShapeValues(shape);
IComplexNDArray ret = INSTANCE.createComplex(data, shape);
logCreationIfNecessary(ret);
return ret;
}
Aggregations