Refine search
/** * * @param thisnD * @param filePath */ public static void write(INDArray thisnD, String filePath) { //TO DO: Add precision support in toString //TO DO: Write to file one line at time String lineOne = "{\n"; String lineTwo = "\"filefrom\": \"dl4j\",\n"; String lineThree = "\"ordering\": \"" + thisnD.ordering() + "\",\n"; String lineFour = "\"shape\":\t" + java.util.Arrays.toString(thisnD.shape()) + ",\n"; String lineFive = "\"data\":\n"; String fileData = thisnD.toString(); String fileEnd = "\n}\n"; String fileBegin = lineOne + lineTwo + lineThree + lineFour + lineFive; try { FileUtils.writeStringToFile(new File(filePath), fileBegin + fileData + fileEnd); } catch (IOException e) { throw new RuntimeException("Error writing output", e); } } }
@Override public GradientUpdater instantiate(INDArray viewArray, boolean initializeViewArray) { AdamUpdater u = new AdamUpdater(this); long[] gradientShape = viewArray.shape(); gradientShape = Arrays.copyOf(gradientShape, gradientShape.length); gradientShape[1] /= 2; u.setStateViewArray(viewArray, gradientShape, viewArray.ordering(), initializeViewArray); return u; }
@Override public GradientUpdater instantiate(INDArray viewArray, boolean initializeViewArray) { AdaDeltaUpdater u = new AdaDeltaUpdater(this); long[] gradientShape = viewArray.shape(); gradientShape = Arrays.copyOf(gradientShape, gradientShape.length); gradientShape[1] /= 2; u.setStateViewArray(viewArray, gradientShape, viewArray.ordering(), initializeViewArray); return u; }
@Override public GradientUpdater instantiate(INDArray viewArray, boolean initializeViewArray) { NadamUpdater u = new NadamUpdater(this); long[] gradientShape = viewArray.shape(); gradientShape = Arrays.copyOf(gradientShape, gradientShape.length); gradientShape[1] /= 2; u.setStateViewArray(viewArray, gradientShape, viewArray.ordering(), initializeViewArray); return u; }
private static String writeStringForArray(INDArray write, String format) { if (format.isEmpty()) format = "0.000000000000000000E0"; String lineOne = "{\n"; String lineTwo = "\"filefrom\": \"dl4j\",\n"; String lineThree = "\"ordering\": \"" + write.ordering() + "\",\n"; String lineFour = "\"shape\":\t" + java.util.Arrays.toString(write.shape()) + ",\n"; String lineFive = "\"data\":\n"; String fileData = new NDArrayStrings(",", format).format(write, false); String fileEnd = "\n}\n"; String fileBegin = lineOne + lineTwo + lineThree + lineFour + lineFive; String fileContents = fileBegin + fileData + fileEnd; return fileContents; }
@Override public GradientUpdater instantiate(INDArray viewArray, boolean initializeViewArray) { AMSGradUpdater u = new AMSGradUpdater(this); long[] gradientShape = viewArray.shape(); gradientShape = Arrays.copyOf(gradientShape, gradientShape.length); gradientShape[1] /= 3; u.setStateViewArray(viewArray, gradientShape, viewArray.ordering(), initializeViewArray); return u; }
@Override public GradientUpdater instantiate(INDArray viewArray, boolean initializeViewArray) { AdaMaxUpdater a = new AdaMaxUpdater(this); long[] gradientShape = viewArray.shape(); gradientShape = Arrays.copyOf(gradientShape, gradientShape.length); gradientShape[1] /= 2; a.setStateViewArray(viewArray, gradientShape, viewArray.ordering(), initializeViewArray); return a; }
/** * Atan2 operation, new INDArray instance will be returned * Note the order of x and y parameters is opposite to that of java.lang.Math.atan2 * * @param x the abscissa coordinate * @param y the ordinate coordinate * @return the theta from point (r, theta) when converting (x,y) from to cartesian to polar coordinates */ public static INDArray atan2(@NonNull INDArray x, @NonNull INDArray y) { return Nd4j.getExecutioner() .execAndReturn(new OldAtan2Op(x, y, Nd4j.createUninitialized(x.shape(), x.ordering()))); }
/** * This method sums given arrays and stores them to a new array * * @param arrays * @return */ public static INDArray accumulate(INDArray... arrays) { if (arrays == null|| arrays.length == 0) throw new ND4JIllegalStateException("Input for accumulation is null or empty"); return accumulate(Nd4j.create(arrays[0].shape(), arrays[0].ordering()), arrays); }
public static boolean hasDefaultStridesForShape(INDArray input){ if(!strideDescendingCAscendingF(input)){ return false; } char order = input.ordering(); long[] defaultStrides; if(order == 'f'){ defaultStrides = ArrayUtil.calcStridesFortran(input.shape()); } else { defaultStrides = ArrayUtil.calcStrides(input.shape()); } return Arrays.equals(input.stride(), defaultStrides); } }
/** * Element-wise power function - x^y, performed element-wise * * @param ndArray the ndarray to raise to the power of * @param power the power to raise by * @param dup if true: * @return the ndarray raised to this power */ public static INDArray pow(INDArray ndArray, INDArray power, boolean dup) { INDArray result = (dup ? Nd4j.create(ndArray.shape(), ndArray.ordering()) : ndArray); return exec(new Pow(ndArray, power, result, ndArray.length(), 0)); }
/** * Expand the array dimensions. * This is equivalent to * adding a new axis dimension * @param input the input array * @param dimension the dimension to add the * new axis at * @return the array with the new axis dimension */ public static INDArray expandDims(INDArray input, int dimension) { if (dimension < 0) dimension += input.rank(); long[] shape = input.shape(); long[] indexes = new long[input.rank() + 1]; for (int i = 0; i < indexes.length; i++) indexes[i] = i < dimension ? shape[i] : i == dimension ? 1 : shape[i - 1]; return input.reshape(input.ordering(), indexes); }