/** * Add a mapping that we have recovered from disk */ public void addMapping(int id, Object object) { // Store the mapping idToObject.put(id, object); objectToID.put(object, id); // increase the next canonical id the recovered id is higher than it. highestID = highestID < id ? id : highestID; }
public Object put(long id, Object v) { Object result; if (id == 0) { throw new IllegalArgumentException(); } else if (id > 0 && id <= 0x00000000FFFFFFFFL) { result = this.ints.put((int) id, v); } else { result = this.longs.put(id, v); } return result; }
public SparseMatrix(int rows, int columns, Map<Integer, Vector> rowVectors, boolean shallow) { // Why this is passing in a map? iterating it is pretty inefficient as opposed to simple lists... super(rows, columns); this.rowVectors = new Int2ObjectOpenHashMap<>(); if (shallow) { for (Map.Entry<Integer, Vector> entry : rowVectors.entrySet()) { this.rowVectors.put(entry.getKey().intValue(), entry.getValue()); } } else { for (Map.Entry<Integer, Vector> entry : rowVectors.entrySet()) { this.rowVectors.put(entry.getKey().intValue(), entry.getValue().clone()); } } }
/** Register the constructor for a fixed ID class. */ public static void registerDSFID(int dsfid, Class dsfidClass) { try { Constructor<?> cons = dsfidClass.getConstructor((Class[]) null); cons.setAccessible(true); if (!cons.isAccessible()) { throw new InternalGemFireError( "default constructor not accessible " + "for DSFID=" + dsfid + ": " + dsfidClass); } if (dsfid >= Byte.MIN_VALUE && dsfid <= Byte.MAX_VALUE) { dsfidMap[dsfid + Byte.MAX_VALUE + 1] = cons; } else { dsfidMap2.put(dsfid, cons); } } catch (NoSuchMethodException nsme) { throw new InternalGemFireError(nsme); } }
/** * Create an id of the given object. * * @return the id generated for this object. */ public int createId(Object object) { assert !objectToID.containsKey(object); int id = ++highestID; objectToID.put(object, id); idToObject.put(id, object); return id; }
try { int id = Integer.parseInt(idAsString); map.put(id, message); } catch (NumberFormatException nfe) {
@Override public void set(int row, int column, double value) { RandomAccessSparseVector r = rowVectors.get(row); if (r == null) { r = new RandomAccessSparseVector(columnSize()); rowVectors.put(row, r); } r.set(column, value); }
@Override public void setQuick(int row, int column, double value) { Vector r = rowVectors.get(row); if (r == null) { r = new RandomAccessSparseVector(columnSize()); rowVectors.put(row, r); } r.setQuick(column, value); }
public void generateDataFrameIndex() { for (int i = 0; i < df.getData().get(index).size(); i++) { if (!dataTable.containsKey((int) df.get(i, index))) { dataTable.put((int) df.get(i, index), new IntArrayList()); } dataTable.get((int) df.get(i, index)).add(index); } }
@Override public Matrix clone() { SparseMatrix clone = new SparseMatrix(numRows(), numCols()); for (MatrixSlice slice : this) { clone.rowVectors.put(slice.index(), slice.clone()); } return clone; }
@Override public Vector row(int row) { if (row < 0 || row >= rowSize()) { throw new IndexException(row, rowSize()); } RandomAccessSparseVector res = rowVectors.get(row); if (res == null) { res = new RandomAccessSparseVector(columnSize()); rowVectors.put(row, res); } return res; }
@Override public Vector viewRow(int row) { if (row < 0 || row >= rowSize()) { throw new IndexException(row, rowSize()); } Vector res = rowVectors.get(row); if (res == null) { res = new RandomAccessSparseVector(columnSize()); rowVectors.put(row, res); } return res; }
@Override public Vector viewRow(int row) { if (row < 0 || row >= rowSize()) { throw new IndexException(row, rowSize()); } RandomAccessSparseVector res = rowVectors.get(row); if (res == null) { res = new RandomAccessSparseVector(columnSize()); rowVectors.put(row, res); } return res.clone(); }
@Override public Matrix assignRow(int row, Vector other) { if (columnSize() != other.size()) { throw new CardinalityException(columnSize(), other.size()); } if (row < 0 || row >= rowSize()) { throw new IndexException(row, rowSize()); } rowVectors.put(row, other); return this; }
if (!messages.containsKey(version)) { Message jmsg = createJGMessage(msg, local, version); messages.put(version, jmsg); if (firstMessage) { theStats.incSentBytes(jmsg.getLength());
@Override public Matrix assignColumn(int column, Vector other) { if (rowSize() != other.size()) { throw new CardinalityException(rowSize(), other.size()); } if (column < 0 || column >= columnSize()) { throw new IndexException(column, columnSize()); } for (int row = 0; row < rowSize(); row++) { double val = other.getQuick(row); if (val != 0.0) { Vector r = rowVectors.get(row); if (r == null) { r = new RandomAccessSparseVector(columnSize()); rowVectors.put(row, r); } r.setQuick(column, val); } } return this; }
@Override public Matrix assign(Matrix other, DoubleDoubleFunction function) { //TODO generalize to other kinds of functions if (Functions.PLUS.equals(function) && other instanceof SparseMatrix) { int rows = rowSize(); if (rows != other.rowSize()) { throw new CardinalityException(rows, other.rowSize()); } int columns = columnSize(); if (columns != other.columnSize()) { throw new CardinalityException(columns, other.columnSize()); } SparseMatrix otherSparse = (SparseMatrix) other; for(ObjectIterator<Entry<Vector>> fastIterator = otherSparse.rowVectors.int2ObjectEntrySet().fastIterator(); fastIterator.hasNext();) { final Entry<Vector> entry = fastIterator.next(); final int rowIndex = entry.getIntKey(); Vector row = rowVectors.get(rowIndex); if (row == null) { rowVectors.put(rowIndex, entry.getValue().clone()); } else { row.assign(entry.getValue(), Functions.PLUS); } } return this; } else { return super.assign(other, function); } }
/** * Set the long vector as the row specified. * * @param i the row * @param vec the vector to set as the row */ void setRow(int i, LongSparseVector vec) { rows.put(i, vec); } }
@Override public void readFieldsForPartition(DataInput in, int partitionId) throws IOException { Basic2ObjectMap<I, M> partitionMap = idTypeOps.create2ObjectOpenHashMap( messageWriter); partitionMap.readFields(in); synchronized (map) { map.put(partitionId, partitionMap); } }