protected INDArray create(DataBuffer data, int[] shape, long offset) { if (this instanceof IComplexNDArray) return Nd4j.createComplex(data, shape, offset); else return Nd4j.create(data, shape, offset); }
/** * * @param shape * @param stride * @param ordering * @return */ public static INDArray zeros(int[] shape, int[] stride, char ordering) { return create(shape, stride, ordering); }
/** * Creates a row vector with the specified number of columns * * @param columns the columns of the ndarray * @return the created ndarray */ public static INDArray create(int columns) { return create(columns, order()); }
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); }
/** * Creates an 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 * @return the instance */ public static INDArray create(int rows, int columns, int[] stride) { return create(rows, columns, stride, order()); }
protected INDArray create(DataBuffer data, int[] newShape, int[] newStrides, long offset) { if (this instanceof IComplexNDArray) return Nd4j.createComplex(data, newShape, newStrides, offset); else return Nd4j.create(data, newShape, newStrides, offset); }
/** * Creates an ndarray with the specified shape * * @param rows the rows of the ndarray * @param columns the columns of the ndarray * @return the instance */ public static INDArray create(int rows, int columns) { return create(rows, columns, order()); }
/** * Computes the eigenvalues of a general matrix. */ public static IComplexNDArray eigenvalues(INDArray A) { assert A.rows() == A.columns(); INDArray WR = Nd4j.create(A.rows(), A.rows()); INDArray WI = WR.dup(); Nd4j.getBlasWrapper().geev('N', 'N', A.dup(), WR, WI, dummy, dummy); return Nd4j.createComplex(WR, WI); }
@Override public INDArray sample(long[] shape) { INDArray ret = Nd4j.create(shape); return sample(ret); }
/** * Creates a row vector with the data * * @param data the columns of the ndarray * @return the created ndarray */ public static INDArray create(float[] data) { return create(data, order()); }
/** * Creates a row vector with the data * * @param data the columns of the ndarray * @return the created ndarray */ public static INDArray create(double[] data) { return create(data, order()); }
/** * Creates an ndarray with the specified shape * * @param shape the shape of the ndarray * @return the instance */ public static INDArray create(long... shape) { return create(shape, order()); }
@Override public INDArray sample(int[] shape) { INDArray ret = Nd4j.create(shape); return sample(ret); }
public static INDArray toNDArray(int[][] nums) { if (Nd4j.dataType() == DataBuffer.Type.DOUBLE) { double[] doubles = ArrayUtil.toDoubles(nums); INDArray create = Nd4j.create(doubles, new int[] {nums[0].length, nums.length}); return create; } else { float[] doubles = ArrayUtil.toFloats(nums); INDArray create = Nd4j.create(doubles, new int[] {nums[0].length, nums.length}); return create; } }
private void growCapacity(int idx) { if(container == null) { container = Nd4j.create(10); } else if(idx >= container.length()) { val max = Math.max(container.length() * 2,idx); INDArray newContainer = Nd4j.create(max); newContainer.put(new INDArrayIndex[]{NDArrayIndex.interval(0,container.length())},container); container = newContainer; } }
protected INDArray createScalarForIndex(long i, boolean applyOffset) { if(isVector()) return getScalar(i); return Nd4j.create(data(), new long[] {1, 1}, new long[] {1, 1}, i); }
@Override public INDArray nextFloat(char order, long[] shape) { long length = ArrayUtil.prodLong(shape); INDArray ret = Nd4j.create(shape, order); DataBuffer data = ret.data(); for (long i = 0; i < length; i++) { data.put(i, nextFloat()); } return ret; }
public static INDArray convertFromApacheMatrix(RealMatrix matrix) { int[] shape = new int[] {matrix.getRowDimension(), matrix.getColumnDimension()}; INDArray out = Nd4j.create(shape); for (int i = 0; i < shape[0]; i++) { for (int j = 0; j < shape[1]; j++) { double value = matrix.getEntry(i, j); out.putScalar(new int[] {i, j}, value); } } return out; }
@Override public INDArray getReal() { INDArray result = Nd4j.create(shape()); IComplexNDArray linearView = linearView(); INDArray linearRet = result.linearView(); for (int i = 0; i < linearView.length(); i++) { linearRet.putScalar(i, linearView.getReal(i)); } return result; }
public static INDArray im2col(INDArray img, int kh, int kw, int sy, int sx, int ph, int pw, int dh, int dw, boolean isSameMode) { Nd4j.getCompressor().autoDecompress(img); //Input: NCHW format // FIXME: int cast int outH = outputSize((int) img.size(2), kh, sy, ph, dh, isSameMode); int outW = outputSize((int) img.size(3), kw, sx, pw, dw, isSameMode); //[miniBatch,depth,kH,kW,outH,outW] INDArray out = Nd4j.create(new long[]{img.size(0), img.size(1), kh, kw, outH, outW}, 'c'); return im2col(img, kh, kw, sy, sx, ph, pw, dh, dw, isSameMode, out); }