Package edu.ucla.sspace.vector

Examples of edu.ucla.sspace.vector.AtomicSparseVector


    /**
     * {@inheritDoc}
     */
    public double addAndGet(int row, int col, double delta) {
        checkIndices(row, col);
        AtomicSparseVector rowEntry = getRow(row, col, true);
        return rowEntry.addAndGet(col, delta);   
    }
View Full Code Here


    /**
     * {@inheritDoc}
     */
    public double get(int row, int col) {
        checkIndices(row, col);
        AtomicSparseVector rowEntry = getRow(row, col, false);
        return (rowEntry == null) ? 0d : rowEntry.get(col);
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public double getAndAdd(int row, int col, double delta) {
        checkIndices(row, col);
        AtomicSparseVector rowEntry = getRow(row, col, true);
        return rowEntry.getAndAdd(col, delta);
    }
View Full Code Here

    public SparseDoubleVector getColumnVector(int column) {
        checkIndices(0, column);
        rowReadLock.lock();
        SparseDoubleVector values = new SparseHashDoubleVector(rows.get());
        for (int row = 0; row < rows.get(); ++row) {
            AtomicSparseVector rowEntry = getRow(row, -1, false);           
            double value = 0;
            if (rowEntry != null && (value = rowEntry.get(column)) != 0)
                values.set(row, value);
        }
        rowReadLock.unlock();
        return values;
    }
View Full Code Here

     */
    public SparseDoubleVector getColumnVectorUnsafe(int column) {
        checkIndices(0, column);
        SparseDoubleVector values = new SparseHashDoubleVector(rows.get());
        for (int row = 0; row < rows.get(); ++row) {
            AtomicSparseVector rowEntry = getRow(row, -1, false);           
            double value = 0;
            if (rowEntry != null && (value = rowEntry.get(column)) != 0)
                values.set(row, value);
        }
        return values;
    }
View Full Code Here

     * at the time of the call, which may be different from earlier calls to
     * {@link #columns()}.
     */
    public double[] getRow(int row) {
        checkIndices(row, 0);
        AtomicSparseVector rowEntry = getRow(row, -1, false);
        return (rowEntry == null)
            ? new double[cols.get()]
            : toArray(rowEntry, cols.get());
    }
View Full Code Here

     */
    private AtomicSparseVector getRow(int row,
                                      int col,
                                      boolean createIfAbsent) {
        rowReadLock.lock();
        AtomicSparseVector rowEntry = sparseMatrix.get(row);

        if (col >= cols.get())
            cols.set(col + 1);
        rowReadLock.unlock();

        // If no row existed, create one
        if (rowEntry == null && createIfAbsent) {
            rowWriteLock.lock();
            // ensure that another thread has not already added this row while
            // this thread was waiting on the lock
            rowEntry = sparseMatrix.get(row);
            if (rowEntry == null) {
                rowEntry = new AtomicSparseVector(new CompactSparseVector());

                // update the bounds as necessary
                if (row >= rows.get()) {
                    rows.set(row + 1);
                }
View Full Code Here

     * @param row the row whose values should be returned
     *
     * @return an unsafe, non-atomic view of the row's data
     */
    public SparseDoubleVector getRowVectorUnsafe(int row) {
        AtomicSparseVector rowEntry = sparseMatrix.get(row);
        return (rowEntry == null)
            ? new CompactSparseVector(cols.get())
            : Vectors.immutable(Vectors.subview(rowEntry.getVector(),
                                                0, cols.get()));
    }
View Full Code Here

     * {@inheritDoc}
     */
    public void set(int row, int col, double val) {
        checkIndices(row, col);

        AtomicSparseVector rowEntry = getRow(row, col, true);
        denseArrayReadLock.lock();
        rowEntry.set(col, val);
        denseArrayReadLock.unlock();
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void setRow(int row, double[] columns) {
        checkIndices(row, 0);
        AtomicSparseVector rowEntry = getRow(row, columns.length - 1, true);
        denseArrayReadLock.lock();
        for (int i = 0; i < columns.length; ++i)
            rowEntry.set(i, columns[i]);
        denseArrayReadLock.unlock();
    }
View Full Code Here

TOP

Related Classes of edu.ucla.sspace.vector.AtomicSparseVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.