All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.uib.cipr.matrix.DenseVectorSub Maven / Gradle / Ivy

Go to download

Matrix data structures, linear solvers, least squares methods, eigenvalue, and singular value decompositions. For larger random dense matrices (above ~ 350 x 350) matrix-matrix multiplication C = A.B is about 50% faster than MTJ.

There is a newer version: 1.1.0
Show newest version
package no.uib.cipr.matrix;

import java.util.Arrays;

/**
 * Wraps a DenseVector, allowing easy access to a sub array of the original
 * without taking copies.
 * 

* It should be possible to utilise BLAS / LAPACK in various matrix classes. * However, as it would be a mammoth task, it will be done on an as-needed * basis. * * @author Sam Halliday */ public class DenseVectorSub extends AbstractVector { private static final long serialVersionUID = -4686967189822912723L; private DenseVector wrapped; private int offset; public DenseVectorSub(DenseVector wrapped, int offset, int size) { super(size); if (offset + size > wrapped.size) throw new IllegalArgumentException(offset + "+" + size + ">" + wrapped.size); this.offset = offset; this.wrapped = wrapped; } @Override public double get(int index) { check(index); return wrapped.get(offset + index); } @Override public void set(int index, double value) { check(index); wrapped.set(offset + index, value); } @Override public DenseVector copy() { double[] data = Arrays.copyOfRange(wrapped.getData(), offset, offset + size); return new DenseVector(data, false); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy