code
stringlengths
73
34.1k
label
stringclasses
1 value
private void setup() { st = new StreamTokenizer(this); st.resetSyntax(); st.eolIsSignificant(false); st.lowerCaseMode(true); // Parse numbers as words st.wordChars('0', '9'); st.wordChars('-', '.'); // Characters as words st.wordChars('\u0000', '...
java
public void add(int num, int[] indices) { for (int i = 0; i < indices.length; ++i) indices[i] += num; }
java
private String readTrimmedLine() throws IOException { String line = readLine(); if (line != null) return line.trim(); else throw new EOFException(); }
java
public MatrixInfo readMatrixInfo() throws IOException { String[] component = readTrimmedLine().split(" +"); if (component.length != 5) throw new IOException( "Current line unparsable. It must consist of 5 tokens"); // Read header if (!component[0].equalsI...
java
public VectorInfo readVectorInfo() throws IOException { String[] component = readTrimmedLine().split(" +"); if (component.length != 4) throw new IOException( "Current line unparsable. It must consist of 4 tokens"); // Read header if (!component[0].equalsI...
java
public MatrixSize readMatrixSize(MatrixInfo info) throws IOException { // Always read the matrix size int numRows = getInt(), numColumns = getInt(); // For coordinate matrices we also read the number of entries if (info.isDense()) return new MatrixSize(numRows, numColumns, i...
java
public MatrixSize readArraySize() throws IOException { int numRows = getInt(), numColumns = getInt(); return new MatrixSize(numRows, numColumns, numRows * numColumns); }
java
public MatrixSize readCoordinateSize() throws IOException { int numRows = getInt(), numColumns = getInt(), numEntries = getInt(); return new MatrixSize(numRows, numColumns, numEntries); }
java
public VectorSize readVectorSize(VectorInfo info) throws IOException { // Always read the vector size int size = getInt(); // For coordinate vectors we also read the number of entries if (info.isDense()) return new VectorSize(size); else { int numEntries ...
java
public VectorSize readVectorCoordinateSize() throws IOException { int size = getInt(), numEntries = getInt(); return new VectorSize(size, numEntries); }
java
public void readArray(double[] dataR, double[] dataI) throws IOException { int size = dataR.length; if (size != dataI.length) throw new IllegalArgumentException( "All arrays must be of the same size"); for (int i = 0; i < size; ++i) { dataR[i] = getDou...
java
public void readCoordinate(int[] index, double[] data) throws IOException { int size = index.length; if (size != data.length) throw new IllegalArgumentException( "All arrays must be of the same size"); for (int i = 0; i < size; ++i) { index[i] = getInt...
java
public void readCoordinate(int[] index, float[] dataR, float[] dataI) throws IOException { int size = index.length; if (size != dataR.length || size != dataI.length) throw new IllegalArgumentException( "All arrays must be of the same size"); for (int i...
java
public void readPattern(int[] index) throws IOException { int size = index.length; for (int i = 0; i < size; ++i) index[i] = getInt(); }
java
public void readCoordinate(int[] row, int[] column, double[] data) throws IOException { int size = row.length; if (size != column.length || size != data.length) throw new IllegalArgumentException( "All arrays must be of the same size"); for (int i = 0;...
java
public void readPattern(int[] row, int[] column) throws IOException { int size = row.length; if (size != column.length) throw new IllegalArgumentException( "All arrays must be of the same size"); for (int i = 0; i < size; ++i) { row[i] = getInt(); ...
java
public void readCoordinate(int[] row, int[] column, double[] dataR, double[] dataI) throws IOException { int size = row.length; if (size != column.length || size != dataR.length || size != dataI.length) throw new IllegalArgumentException( "All ...
java
private float getFloat() throws IOException { st.nextToken(); if (st.ttype == StreamTokenizer.TT_WORD) return Float.parseFloat(st.sval); else if (st.ttype == StreamTokenizer.TT_EOF) throw new EOFException("End-of-File encountered during parsing"); else ...
java
private int getDiagSize(int diagonal) { if (diagonal < 0) return Math.min(numRows + diagonal, numColumns); else return Math.min(numRows, numColumns - diagonal); }
java
public PermutationMatrix getP() { PermutationMatrix perm = PermutationMatrix.fromPartialPivots(piv); perm.transpose(); return perm; }
java
public QRP factor(Matrix A) { if (Q.numRows() != A.numRows()) throw new IllegalArgumentException("Q.numRows() != A.numRows()"); else if (R.numColumns() != A.numColumns()) throw new IllegalArgumentException( "R.numColumns() != A.numColumns()"); // copy...
java
public void apply(Matrix H, int column, int i1, int i2) { double temp = c * H.get(i1, column) + s * H.get(i2, column); H.set(i2, column, -s * H.get(i1, column) + c * H.get(i2, column)); H.set(i1, column, temp); }
java
public void apply(Vector x, int i1, int i2) { double temp = c * x.get(i1) + s * x.get(i2); x.set(i2, -s * x.get(i1) + c * x.get(i2)); x.set(i1, temp); }
java
public static LQ factorize(Matrix A) { return new LQ(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
java
private void validate() { if (isDense() && isPattern()) throw new IllegalArgumentException( "Matrix cannot be dense with pattern storage"); if (isReal() && isHermitian()) throw new IllegalArgumentException( "Data cannot be real with hermiti...
java
public static RQ factorize(Matrix A) { return new RQ(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
java
public void setRestart(int restart) { this.restart = restart; if (restart <= 0) throw new IllegalArgumentException( "restart must be a positive integer"); s = new DenseVector(restart + 1); H = new DenseMatrix(restart + 1, restart); rotation = new ...
java
private static void scatter(SparseVector v, double[] z) { int[] index = v.getIndex(); int used = v.getUsed(); double[] data = v.getData(); Arrays.fill(z, 0); for (int i = 0; i < used; ++i) z[index[i]] = data[i]; }
java
private void gather(double[] z, SparseVector v, double taui, int d) { // Number of entries in the lower and upper part of the original matrix int nl = 0, nu = 0; for (VectorEntry e : v) { if (e.index() < d) nl++; else if (e.index() > d) nu+...
java
public void setEigenvalues(double eigmin, double eigmax) { this.eigmin = eigmin; this.eigmax = eigmax; if (eigmin <= 0) throw new IllegalArgumentException("eigmin <= 0"); if (eigmax <= 0) throw new IllegalArgumentException("eigmax <= 0"); if (eigmin > eig...
java
private static void checkKhatriRaoArguments(Matrix A, Matrix B) { if (A.numColumns() != B.numColumns()) throw new IndexOutOfBoundsException( "A.numColumns != B.numColumns (" + A.numColumns() + " != " + B.numColumns() + ")"); }
java
public void printMatrixSize(MatrixSize size, MatrixInfo info) { format(Locale.ENGLISH, "%10d %10d", size.numRows(), size.numColumns()); if (info.isCoordinate()) format(Locale.ENGLISH, " %19d", size.numEntries()); println(); }
java
public void printMatrixSize(MatrixSize size) { format(Locale.ENGLISH, "%10d %10d %19d%n", size.numRows(), size.numColumns(), size.numEntries()); }
java
public void printVectorSize(VectorSize size, VectorInfo info) { format(Locale.ENGLISH, "%10d", size.size()); if (info.isCoordinate()) format(Locale.ENGLISH, " %19d", size.numEntries()); println(); }
java
public void printVectorSize(VectorSize size) { format(Locale.ENGLISH, "%10d %19d%n", size.size(), size.numEntries()); }
java
public void printArray(double[] data) { for (int i = 0; i < data.length; ++i) format(Locale.ENGLISH, "% .12e%n", data[i]); }
java
public void printArray(float[] dataR, float[] dataI) { int size = dataR.length; if (size != dataI.length) throw new IllegalArgumentException( "All arrays must be of the same size"); for (int i = 0; i < size; ++i) format(Locale.ENGLISH, "% .12e % .12e%n...
java
public void printCoordinate(int[] index, long[] data, int offset) { int size = index.length; if (size != data.length) throw new IllegalArgumentException( "All arrays must be of the same size"); for (int i = 0; i < size; ++i) format(Locale.ENGLISH, "%10...
java
public void printCoordinate(int[] index, float[] dataR, float[] dataI, int offset) { int size = index.length; if (size != dataR.length || size != dataI.length) throw new IllegalArgumentException( "All arrays must be of the same size"); for (int i = 0; ...
java
public void printCoordinate(int[] row, int[] column, float[] dataR, float[] dataI, int offset) { int size = row.length; if (size != column.length || size != dataR.length || size != dataI.length) throw new IllegalArgumentException( "All arrays m...
java
public void printCoordinate(int[] row, int[] column, long[] data, int offset) { int size = row.length; if (size != column.length || size != data.length) throw new IllegalArgumentException( "All arrays must be of the same size"); for (int i = 0; i < size; ++i) ...
java
public void printPattern(int[] row, int[] column, int offset) { int size = row.length; if (size != column.length) throw new IllegalArgumentException( "All arrays must be of the same size"); for (int i = 0; i < size; ++i) format(Locale.ENGLISH, "%10d %1...
java
public void printPattern(int[] index, int offset) { int size = index.length; for (int i = 0; i < size; ++i) format(Locale.ENGLISH, "%10d%n", index[i] + offset); }
java
public void printCoordinate(int[] row, int[] column, float[] dataR, float[] dataI) { printCoordinate(row, column, dataR, dataI, 0); }
java
public static QL factorize(Matrix A) { return new QL(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
java
private static int[] findDiagonalIndices(CompRowMatrix A) { int[] rowptr = A.getRowPointers(); int[] colind = A.getColumnIndices(); int[] diagIndices = new int[A.numRows()]; for (int i = 0; i < A.numRows(); ++i) { diagIndices[i] = no.uib.cipr.matrix.spar...
java
private List<Set<Integer>> findNodeNeighborhood(CompRowMatrix A, int[] diagind, double eps) { N = new ArrayList<Set<Integer>>(A.numRows()); int[] rowptr = A.getRowPointers(); int[] colind = A.getColumnIndices(); double[] data = A.getData(); ...
java
private static boolean[] createInitialR(CompRowMatrix A) { boolean[] R = new boolean[A.numRows()]; int[] rowptr = A.getRowPointers(); int[] colind = A.getColumnIndices(); double[] data = A.getData(); for (int i = 0; i < A.numRows(); ++i) { bo...
java
private List<Set<Integer>> createInitialAggregates( List<Set<Integer>> N, boolean[] R) { C = new ArrayList<Set<Integer>>(); for (int i = 0; i < R.length; ++i) { // Skip non-free nodes if (!R[i]) continue; // S...
java
private static List<Set<Integer>> enlargeAggregates( List<Set<Integer>> C, List<Set<Integer>> N, boolean[] R) { // Contains the aggregates each node is coupled to List<List<Integer>> belong = new ArrayList<List<Integer>>(R.length); for (int i = 0; i < R.length; ++i) ...
java
private static List<Set<Integer>> createFinalAggregates( List<Set<Integer>> C, List<Set<Integer>> N, boolean[] R) { for (int i = 0; i < R.length; ++i) { // Skip non-free nodes if (!R[i]) continue; // Create new aggregate ...
java
public static SVD factorize(Matrix A) throws NotConvergedException { return new SVD(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
java
public SVD factor(DenseMatrix A) throws NotConvergedException { if (A.numRows() != m) throw new IllegalArgumentException("A.numRows() != m"); else if (A.numColumns() != n) throw new IllegalArgumentException("A.numColumns() != n"); intW info = new intW(0); LAPACK....
java
public static int binarySearchGreater(int[] index, int key, int begin, int end) { return binarySearchInterval(index, key, begin, end, true); }
java
public static int binarySearchSmaller(int[] index, int key, int begin, int end) { return binarySearchInterval(index, key, begin, end, false); }
java
public static int binarySearch(int[] index, int key, int begin, int end) { return java.util.Arrays.binarySearch(index, begin, end, key); }
java
public static int[] bandwidth(int num, int[] ind) { int[] nz = new int[num]; for (int i = 0; i < ind.length; ++i) nz[ind[i]]++; return nz; }
java
public void setColumn(int i, SparseVector x) { if (x.size() != numRows) throw new IllegalArgumentException( "New column must be of the same size as existing column"); colD[i] = x; }
java
public void setRow(int i, SparseVector x) { if (x.size() != numColumns) throw new IllegalArgumentException( "New row must be of the same size as existing row"); rowD[i] = x; }
java
public double rcond(Matrix A) { if (n != A.numRows()) throw new IllegalArgumentException("n != A.numRows()"); if (!A.isSquare()) throw new IllegalArgumentException("!A.isSquare()"); double anorm = A.norm(Norm.One); double[] work = new double[3 * n]; int[...
java
public static EVD factorize(Matrix A) throws NotConvergedException { return new EVD(A.numRows()).factor(new DenseMatrix(A)); }
java
public Matrix calcOrig() { if (!Coordinates.equals(getSource().getSize(), getSize())) { throw new RuntimeException( "Cannot change Matrix size. Use calc(Ret.NEW) or calc(Ret.LINK) instead."); } long[] newCoordinates = new long[position.length]; for (long[] c : newContent.allCoordinates()) { Co...
java
public Rectangle getCellRect(int row, int column, boolean includeSpacing) { Rectangle r = new Rectangle(); boolean valid = true; if (row < 0) { // y = height = 0; valid = false; } else if (row >= getRowCount()) { r.y = getHeight(); valid = false; } else { r.height = getRowHeight(row);...
java
public void addEvents(Matrix events) { int seriesCount = getSeriesCount(); for (int r = 0; r < events.getRowCount(); r++) { long timestamp = events.getAsLong(r, 0); for (int c = 1; c < events.getColumnCount(); c++) { double value = events.getAsDouble(r, c); addEvent(timestamp, seriesCount + c - ...
java
public void fill(final double[][] data, final int startRow, final int startCol) { final int rows = data.length; final int cols = data[0].length; verifyTrue(startRow < rows && startRow < getRowCount(), "illegal startRow: %s", startRow); verifyTrue(startCol < cols && startCol < getColumnCount(), "illegal st...
java
double[] getBlockData(int row, int column) { int blockNumber = layout.getBlockNumber(row, column); double[] block = data[blockNumber]; if (null == block) { block = new double[layout.getBlockSize(row, column)]; data[blockNumber] = block; } return data[blockNumber]; }
java
public Matrix mtimes(Matrix m2) { if (m2 instanceof DenseDoubleMatrix2D) { final DenseDoubleMatrix2D result = new BlockDenseDoubleMatrix2D((int) getRowCount(), (int) m2.getColumnCount(), layout.blockStripe, BlockOrder.ROWMAJOR); Mtimes.DENSEDOUBLEMATRIX2D.calc(this, (DenseDoubleMatrix2D) m2, result); ...
java
public static final int nextInteger(int min, int max) { return min == max ? min : min + getRandom().nextInt(max - min); }
java
public final <V> SynchronizedGenericMatrix<V> synchronizedMatrix(GenericMatrix<V> matrix) { return new SynchronizedGenericMatrix<V>(matrix); }
java
public static boolean canSwapRows(Matrix matrix, int row1, int row2, int col1) { boolean response = true; for (int col = 0; col < col1; ++col) { if (0 == matrix.getAsDouble(row1, col)) { if (0 != matrix.getAsDouble(row2, col)) { response = false; break; } } } return response; }
java
public static boolean canSwapCols(Matrix matrix, int col1, int col2, int row1) { boolean response = true; for (int row = row1 + 1; row < matrix.getRowCount(); ++row) { if (0 == matrix.getAsDouble(row, col1)) { if (0 != matrix.getAsDouble(row, col2)) { response = false; break; } } } retur...
java
public static Matrix reduce(Matrix source) { Matrix response = Matrix.Factory.zeros(source.getRowCount(), 1); for (int row = 0; row < source.getRowCount(); ++row) { response.setAsDouble(row, row, 0); } return source.getRowCount() == source.getColumnCount() ? Ginv.reduce(source, response) : response; }
java
public Matrix[] svd() { GMatrix m = (GMatrix) matrix.clone(); int nrows = (int) getRowCount(); int ncols = (int) getColumnCount(); GMatrix u = new GMatrix(nrows, nrows); GMatrix s = new GMatrix(nrows, ncols); GMatrix v = new GMatrix(ncols, ncols); m.SVD(u, s, v); Matrix U = new VecMathDenseDoubleMatrix2...
java
public Matrix[] lu() { if (isSquare()) { GMatrix m = (GMatrix) matrix.clone(); GMatrix lu = (GMatrix) matrix.clone(); GVector piv = new GVector(matrix.getNumCol()); m.LUD(lu, piv); Matrix l = new VecMathDenseDoubleMatrix2D(lu).tril(Ret.NEW, 0); for (int i = (int) l.getRowCount() - 1; i != -1; i--) {...
java
private int selectBlocksPerTaskDimJ(int blockStripe, int iMax, int jMax, int kMax) { int adjust = (jMax % blockStripe > 0) ? 1 : 0; if (jMax < (5 * blockStripe) || jMax <= iMax) { // do not break this dimension into parallel tasks return jMax / blockStripe + adjust; } else { // assume 2 parallel ta...
java
public String initializedGroupStatus() throws Exception { String status = null; if (clusteringEnabled) { initClusterNodeStatus(); status = updateNodeStatus(); } return status; }
java
@Override @SuppressWarnings("unchecked") protected void restoreState(Object[] objects) { if (objects != null && objects.length != 0) { variable = (Variable) objects[0]; constants = (List<Variable>) objects[1]; lastObjectHash = (Map<String, Object>) objects[2]; ...
java
private static final long gatherLongLE(final byte[] data, final int index) { int i1 = gatherIntLE(data, index); long l2 = gatherIntLE(data, index + 4); return uintToLong(i1) | (l2 << 32); }
java
private static final long gatherPartialLongLE(final byte[] data, final int index, final int available) { if(available >= 4) { int i = gatherIntLE(data, index); long l = uintToLong(i); int left = available - 4; if(left == 0) { return l; ...
java
private static final int gatherIntLE(final byte[] data, final int index) { int i = data[index] & 0xFF; i |= (data[index + 1] & 0xFF) << 8; i |= (data[index + 2] & 0xFF) << 16; i |= (data[index + 3] << 24); return i; }
java
private static final int gatherPartialIntLE(final byte[] data, final int index, final int available) { int i = data[index] & 0xFF; if(available > 1) { i |= (data[index + 1] & 0xFF) << 8; if(available > 2) { i |= (data[index + 2] & 0xFF) << 16; } ...
java
public static Map<Method, Method> findManagedMethods(Class<?> clazz) { Map<Method, Method> result = new HashMap<>(); // gather all publicly available methods // this returns everything, even if it's declared in a parent for (Method method : clazz.getMethods()) { // skip ...
java
public Map<String, Exception> unexportAllAndReportMissing() { Map<String, Exception> errors = new HashMap<>(); synchronized(exportedObjects) { List<ObjectName> toRemove = new ArrayList<>(exportedObjects.size()); for (ObjectName objectName : exportedObjects.keySet()) { ...
java
public static int byteArrayToInt(final byte[] byteArray, final int startPos, final int length) { if (byteArray == null) { throw new IllegalArgumentException("Parameter 'byteArray' cannot be null"); } if (length <= 0 || length > 4) { throw new IllegalArgumentException("Length must be between 1 and 4. Le...
java
private static String formatByte(final byte[] pByte, final boolean pSpace, final boolean pTruncate) { String result; if (pByte == null) { result = ""; } else { int i = 0; if (pTruncate) { while (i < pByte.length && pByte[i] == 0) { i++; } } if (i < pByte.length) { int s...
java
public static byte[] fromString(final String pData) { if (pData == null) { throw new IllegalArgumentException("Argument can't be null"); } StringBuilder sb = new StringBuilder(pData); int j = 0; for (int i = 0; i < sb.length(); i++) { if (!Character.isWhitespace(sb.charAt(i))) { sb.setCharAt...
java
public static boolean matchBitByBitIndex(final int pVal, final int pBitIndex) { if (pBitIndex < 0 || pBitIndex > MAX_BIT_INTEGER) { throw new IllegalArgumentException( "parameter 'pBitIndex' must be between 0 and 31. pBitIndex=" + pBitIndex); } return (pVal & 1 << pBitIndex) != 0; }
java
public static byte setBit(final byte pData, final int pBitIndex, final boolean pOn) { if (pBitIndex < 0 || pBitIndex > 7) { throw new IllegalArgumentException("parameter 'pBitIndex' must be between 0 and 7. pBitIndex=" + pBitIndex); } byte ret = pData; if (pOn) { // Set bit ret |= 1 << pBitIndex; ...
java
public static String toBinary(final byte[] pBytes) { String ret = null; if (pBytes != null && pBytes.length > 0) { BigInteger val = new BigInteger(bytesToStringNoSpace(pBytes), HEXA); StringBuilder build = new StringBuilder(val.toString(2)); // left pad with 0 to fit byte size for (int i = build.l...
java
public byte[] getData() { byte[] ret = new byte[byteTab.length]; System.arraycopy(byteTab, 0, ret, 0, byteTab.length); return ret; }
java
public byte getMask(final int pIndex, final int pLength) { byte ret = (byte) DEFAULT_VALUE; // Add X 0 to the left ret = (byte) (ret << pIndex); ret = (byte) ((ret & DEFAULT_VALUE) >> pIndex); // Add X 0 to the right int dec = BYTE_SIZE - (pLength + pIndex); if (dec > 0) { ret = (byte) (ret >> ...
java
public byte[] getNextByte(final int pSize, final boolean pShift) { byte[] tab = new byte[(int) Math.ceil(pSize / BYTE_SIZE_F)]; if (currentBitIndex % BYTE_SIZE != 0) { int index = 0; int max = currentBitIndex + pSize; while (currentBitIndex < max) { int mod = currentBitIndex % BYTE_SIZE; i...
java
public Date getNextDate(final int pSize, final String pPattern, final boolean pUseBcd) { Date date = null; // create date formatter SimpleDateFormat sdf = new SimpleDateFormat(pPattern); // get String String dateTxt = null; if (pUseBcd) { dateTxt = getNextHexaString(pSize); } else { dateTxt...
java
public long getNextLongSigned(final int pLength) { if (pLength > Long.SIZE) { throw new IllegalArgumentException("Long overflow with length > 64"); } long decimal = getNextLong(pLength); long signMask = 1 << pLength - 1; if ( (decimal & signMask) != 0) { return - (signMask - (signMask ^ decimal...
java
public long getNextLong(final int pLength) { // allocate Size of Integer ByteBuffer buffer = ByteBuffer.allocate(BYTE_SIZE * 2); // final value long finalValue = 0; // Incremental value long currentValue = 0; // Size to read int readSize = pLength; // length max of the index int max = curr...
java
public String getNextString(final int pSize, final Charset pCharset) { return new String(getNextByte(pSize, true), pCharset); }
java
public void resetNextBits(final int pLength) { int max = currentBitIndex + pLength; while (currentBitIndex < max) { int mod = currentBitIndex % BYTE_SIZE; int length = Math.min(max - currentBitIndex, BYTE_SIZE - mod); byteTab[currentBitIndex / BYTE_SIZE] &= ~getMask(mod, length); currentBitIndex +...
java
public void setNextByte(final byte[] pValue, final int pLength, final boolean pPadBefore) { int totalSize = (int) Math.ceil(pLength / BYTE_SIZE_F); ByteBuffer buffer = ByteBuffer.allocate(totalSize); int size = Math.max(totalSize - pValue.length, 0); if (pPadBefore) { for (int i = 0; i < size; i++) { ...
java
public void setNextDate(final Date pValue, final String pPattern, final boolean pUseBcd) { // create date formatter SimpleDateFormat sdf = new SimpleDateFormat(pPattern); String value = sdf.format(pValue); if (pUseBcd) { setNextHexaString(value, value.length() * 4); } else { setNextString(value...
java
public void setNextLong(final long pValue, final int pLength) { if (pLength > Long.SIZE) { throw new IllegalArgumentException("Long overflow with length > 64"); } setNextValue(pValue, pLength, Long.SIZE - 1); }
java