@Override public INDArray toFlattened(char order, INDArray... matrices) { return toFlattened(order, Arrays.asList(matrices)); }
@Override public INDArray toFlattened(int length, Iterator<? extends INDArray>... matrices) { List<INDArray> arr = new ArrayList<>(); for (Iterator<? extends INDArray> arrs : matrices) { while (arrs.hasNext()) arr.add(arrs.next()); } return toFlattened(arr); }
/** * Merge the vectors and append a bias. * Each vector must be either row or column vectors. * An exception is thrown for inconsistency (mixed row and column vectors) * * @param vectors the vectors to merge * @return the merged ndarray appended with the bias */ @Override public INDArray appendBias(INDArray... vectors) { int size = 0; for (INDArray vector : vectors) { size += vector.rows(); } INDArray result = Nd4j.create(size + 1, vectors[0].columns()); int index = 0; for (INDArray vector : vectors) { INDArray put = toFlattened(vector, Nd4j.ones(1)); result.put(new INDArrayIndex[] {NDArrayIndex.interval(index, index + vector.rows() + 1), NDArrayIndex.interval(0, vectors[0].columns())}, put); index += vector.rows(); } return result; }
@Override public INDArray toFlattened(char order, INDArray... matrices) { return toFlattened(order, Arrays.asList(matrices)); }
@Override public INDArray toFlattened(int length, Iterator<? extends INDArray>... matrices) { List<INDArray> arr = new ArrayList<>(); for (Iterator<? extends INDArray> arrs : matrices) { while (arrs.hasNext()) arr.add(arrs.next()); } return toFlattened(arr); }
/** * Merge the vectors and append a bias. * Each vector must be either row or column vectors. * An exception is thrown for inconsistency (mixed row and column vectors) * * @param vectors the vectors to merge * @return the merged ndarray appended with the bias */ @Override public INDArray appendBias(INDArray... vectors) { int size = 0; for (INDArray vector : vectors) { size += vector.rows(); } INDArray result = Nd4j.create(size + 1, vectors[0].columns()); int index = 0; for (INDArray vector : vectors) { INDArray put = toFlattened(vector, Nd4j.ones(1)); result.put(new INDArrayIndex[] {NDArrayIndex.interval(index, index + vector.rows() + 1), NDArrayIndex.interval(0, vectors[0].columns())}, put); index += vector.rows(); } return result; }