/** {@inheritDoc} */ @Override public BlockRealMatrix createMatrix(final int rowDimension, final int columnDimension) throws NotStrictlyPositiveException { return new BlockRealMatrix(rowDimension, columnDimension); }
/** {@inheritDoc} */ @Override public void setRowVector(final int row, final RealVector vector) throws OutOfRangeException, MatrixDimensionMismatchException { try { setRow(row, ((ArrayRealVector) vector).getDataRef()); } catch (ClassCastException cce) { super.setRowVector(row, vector); } }
throws MatrixDimensionMismatchException { try { return add((BlockRealMatrix) m); } catch (ClassCastException cce) { final BlockRealMatrix out = new BlockRealMatrix(rows, columns);
/** {@inheritDoc} */ @Override public BlockRealMatrix getColumnMatrix(final int column) throws OutOfRangeException { MatrixUtils.checkColumnIndex(this, column); final BlockRealMatrix out = new BlockRealMatrix(rows, 1); // perform copy block-wise, to ensure good cache behavior final int jBlock = column / BLOCK_SIZE; final int jColumn = column - jBlock * BLOCK_SIZE; final int jWidth = blockWidth(jBlock); int outBlockIndex = 0; int outIndex = 0; double[] outBlock = out.blocks[outBlockIndex]; for (int iBlock = 0; iBlock < blockRows; ++iBlock) { final int iHeight = blockHeight(iBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; for (int i = 0; i < iHeight; ++i) { if (outIndex >= outBlock.length) { outBlock = out.blocks[++outBlockIndex]; outIndex = 0; } outBlock[outIndex++] = block[i * jWidth + jColumn]; } } return out; }
new BlockRealMatrix(endRow - startRow + 1, endColumn - startColumn + 1); final int iHeight = out.blockHeight(iBlock); int qBlock = blockStartColumn; for (int jBlock = 0; jBlock < out.blockColumns; ++jBlock) { final int jWidth = out.blockWidth(jBlock); final double[] outBlock = out.blocks[outIndex]; final int index = pBlock * blockColumns + qBlock; final int width = blockWidth(qBlock); final int width2 = blockWidth(qBlock + 1); copyBlockPart(blocks[index], width, rowsShift, BLOCK_SIZE, columnsShift, BLOCK_SIZE, outBlock, jWidth, 0, 0); copyBlockPart(blocks[index + 1], width2, rowsShift, BLOCK_SIZE, 0, widthExcess, outBlock, jWidth, 0, jWidth - widthExcess); copyBlockPart(blocks[index + blockColumns], width, 0, heightExcess, columnsShift, BLOCK_SIZE, outBlock, jWidth, iHeight - heightExcess, 0); copyBlockPart(blocks[index + blockColumns + 1], width2, 0, heightExcess, 0, widthExcess, copyBlockPart(blocks[index], width,
/** {@inheritDoc} */ @Override public BlockRealMatrix getRowMatrix(final int row) throws OutOfRangeException { MatrixUtils.checkRowIndex(this, row); final BlockRealMatrix out = new BlockRealMatrix(1, columns); // perform copy block-wise, to ensure good cache behavior final int iBlock = row / BLOCK_SIZE; final int iRow = row - iBlock * BLOCK_SIZE; int outBlockIndex = 0; int outIndex = 0; double[] outBlock = out.blocks[outBlockIndex]; for (int jBlock = 0; jBlock < blockColumns; ++jBlock) { final int jWidth = blockWidth(jBlock); final double[] block = blocks[iBlock * blockColumns + jBlock]; final int available = outBlock.length - outIndex; if (jWidth > available) { System.arraycopy(block, iRow * jWidth, outBlock, outIndex, available); outBlock = out.blocks[++outBlockIndex]; System.arraycopy(block, iRow * jWidth, outBlock, 0, jWidth - available); outIndex = jWidth - available; } else { System.arraycopy(block, iRow * jWidth, outBlock, outIndex, jWidth); outIndex += jWidth; } } return out; }
throws DimensionMismatchException { try { return multiply((BlockRealMatrix) m); } catch (ClassCastException cce) { final BlockRealMatrix out = new BlockRealMatrix(rows, m.getColumnDimension()); final int kWidth = blockWidth(kBlock); final double[] tBlock = blocks[iBlock * blockColumns + kBlock]; final int rStart = kBlock * BLOCK_SIZE;
public class Literal<T> { private final T literal; private Literal(T literal) { this.literal = literal; } public T get(){ return literal; } public static Literal<Complex> createComplexLiteral(Complex complex){ return new Literal<>(complex); } public static Literal<BlockRealMatrix> createBlockRealMatrixLiteral(BlockRealMatrix complex){ int m = realMatrix.getData().length; int n = realMatrix.getData()[0].length; BlockRealMatrix mat = new BlockRealMatrix(m, n); for (int i = 0; i < m; i++)mat.setRow(i, realMatrix.getRow(i)); return new Literal<>(mat); } // all the other create methods }
/** * {@inheritDoc} * * @throws NumberIsTooLargeException if {@code m} is an * {@code OpenMapRealMatrix}, and the total number of entries of the product * is larger than {@code Integer.MAX_VALUE}. */ @Override public RealMatrix multiply(final RealMatrix m) throws DimensionMismatchException, NumberIsTooLargeException { try { return multiply((OpenMapRealMatrix) m); } catch (ClassCastException cce) { MatrixUtils.checkMultiplicationCompatible(this, m); final int outCols = m.getColumnDimension(); final BlockRealMatrix out = new BlockRealMatrix(rows, outCols); for (OpenIntToDoubleHashMap.Iterator iterator = entries.iterator(); iterator.hasNext();) { iterator.advance(); final double value = iterator.value(); final int key = iterator.key(); final int i = key / columns; final int k = key % columns; for (int j = 0; j < outCols; ++j) { out.addToEntry(i, j, value * m.getEntry(k, j)); } } return out; } }
final int nRows = getRowDimension(); final int nCols = getColumnDimension(); final BlockRealMatrix out = new BlockRealMatrix(nCols, nRows);
public static RealMatrix convertToApacheMatrix(INDArray matrix) { if (matrix.rank() != 2) throw new IllegalArgumentException("Input rank is not 2 (not matrix)"); long[] shape = matrix.shape(); if (matrix.columns() > Integer.MAX_VALUE || matrix.rows() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); BlockRealMatrix out = new BlockRealMatrix((int) shape[0], (int) shape[1]); for (int i = 0; i < shape[0]; i++) { for (int j = 0; j < shape[1]; j++) { double value = matrix.getDouble(i, j); out.setEntry(i, j, value); } } return out; }
throws MatrixDimensionMismatchException { try { return subtract((BlockRealMatrix) m); } catch (ClassCastException cce) { final BlockRealMatrix out = new BlockRealMatrix(rows, columns);
final int blockSize = BlockRealMatrix.BLOCK_SIZE; final int cBlocks = (columns + blockSize - 1) / blockSize; final double[][] xBlocks = BlockRealMatrix.createBlocksLayout(n, columns); final double[][] y = new double[b.getRowDimension()][blockSize]; final double[] alpha = new double[blockSize]; return new BlockRealMatrix(n, columns, xBlocks, false);
double[] f = new double[n]; double[] f1 = new double[n]; BlockRealMatrix prt = new BlockRealMatrix(m, n); // initializes to zeros prt.setColumn(j,(new ArrayRealVector(f1)).subtract(new ArrayRealVector(f)).mapDivideToSelf(del[j]).toArray()); // one sided diff else { prt.setColumn(j,(new ArrayRealVector(f1)).subtract(new ArrayRealVector(feval(p))).mapDivideToSelf(2*del[j]).toArray()); // central diff return prt.getData(); //jacobian, dimension is (m x n)
Arrays.fill(d, 1.0); RealMatrix xs = new BlockRealMatrix(scores); // N x n .multiply(new BlockRealMatrix(ones)) .scalarMultiply(1.0 / N); RealMatrix delts = xs.subtract(new BlockRealMatrix(ones).multiply(mus)); // N x n
public double[] CanCor(int[] iA, int[] iB, double[][] cov) { this.iA = iA; this.iB = iB; this.cov = cov; RealMatrix covA = new BlockRealMatrix(cov).getSubMatrix(iA, iA); RealMatrix covB = new BlockRealMatrix(cov).getSubMatrix(iB, iB); RealMatrix covAB = new BlockRealMatrix(cov).getSubMatrix(iA, iB); RealMatrix covBA = new BlockRealMatrix(cov).getSubMatrix(iB, iA); RealMatrix S = getInverse(covA).multiply(covAB).multiply(getInverse(covB)).multiply(covBA); double[] rtCors = new EigenDecomposition(S).getRealEigenvalues(); Arrays.sort(rtCors); double[] Cors = new double[rtCors.length]; for (int i = rtCors.length; i > 0; i--) { Cors[rtCors.length - i] = Math.pow(rtCors[i - 1], .5); } return Cors; }
/** {@inheritDoc} */ @Override public void setColumnVector(final int column, final RealVector vector) throws OutOfRangeException, MatrixDimensionMismatchException { try { setColumn(column, ((ArrayRealVector) vector).getDataRef()); } catch (ClassCastException cce) { super.setColumnVector(column, vector); } }
throws DimensionMismatchException { if (m instanceof BlockRealMatrix) { return multiply((BlockRealMatrix) m); } else { final BlockRealMatrix out = new BlockRealMatrix(rows, m.getColumnDimension()); final int kWidth = blockWidth(kBlock); final double[] tBlock = blocks[iBlock * blockColumns + kBlock]; final int rStart = kBlock * BLOCK_SIZE;
/ 120.0; final BlockRealMatrix t = new BlockRealMatrix(3, 3); t.setRow(0, new double[] { a, -bb, -cc }); t.setRow(1, new double[] { -bb, b, -aa }); t.setRow(2, new double[] { -cc, -aa, c });
/** * {@inheritDoc} * * @throws NumberIsTooLargeException if {@code m} is an * {@code OpenMapRealMatrix}, and the total number of entries of the product * is larger than {@code Integer.MAX_VALUE}. */ @Override public RealMatrix multiply(final RealMatrix m) throws DimensionMismatchException, NumberIsTooLargeException { if (m instanceof OpenMapRealMatrix) { return multiply((OpenMapRealMatrix) m); } else { MatrixUtils.checkMultiplicationCompatible(this, m); final int outCols = m.getColumnDimension(); final BlockRealMatrix out = new BlockRealMatrix(rows, outCols); for (OpenIntToDoubleHashMap.Iterator iterator = entries.iterator(); iterator.hasNext();) { iterator.advance(); final double value = iterator.value(); final int key = iterator.key(); final int i = key / columns; final int k = key % columns; for (int j = 0; j < outCols; ++j) { out.addToEntry(i, j, value * m.getEntry(k, j)); } } return out; } }