本文整理汇总了Java中javolution.util.Index类的典型用法代码示例。如果您正苦于以下问题:Java Index类的具体用法?Java Index怎么用?Java Index使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Index类属于javolution.util包,在下文中一共展示了Index类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: plus
import javolution.util.Index; //导入依赖的package包/类
private SparseVector<F> plus(SparseVector<F> that) {
if (this._dimension != that._dimension) throw new DimensionException();
SparseVector<F> V = SparseVector.newInstance(_dimension, _zero);
V._elements.putAll(this._elements);
for (FastMap.Entry<Index, F> e = that._elements.head(), n = that._elements.tail();
(e = e.getNext()) != n;) {
Index index = e.getKey();
FastMap.Entry<Index, F> entry = V._elements.getEntry(index);
if (entry == null) {
V._elements.put(index, e.getValue());
} else {
entry.setValue(entry.getValue().plus(e.getValue()));
}
}
return V;
}
示例2: getRow
import javolution.util.Index; //导入依赖的package包/类
@Override
public SparseVector<F> getRow(int i) {
if (!_transposed)
return _rows.get(i);
// Else transposed.
int n = _rows.size();
int m = _n;
if ((i < 0) || (i >= m))
throw new DimensionException();
SparseVector<F> V = SparseVector.newInstance(n, _zero);
for (int j = 0; j < n; j++) {
SparseVector<F> row = _rows.get(j);
F e = row._elements.get(Index.valueOf(i));
if (e != null) {
V._elements.put(Index.valueOf(j), e);
}
}
return V;
}
示例3: getColumn
import javolution.util.Index; //导入依赖的package包/类
@Override
public SparseVector<F> getColumn(int j) {
if (_transposed)
return _rows.get(j);
int m = _rows.size();
if ((j < 0) || (j >= _n))
throw new DimensionException();
SparseVector<F> V = SparseVector.newInstance(_n, _zero);
for (int i = 0; i < m; i++) {
SparseVector<F> row = _rows.get(i);
F e = row._elements.get(Index.valueOf(j));
if (e != null) {
V._elements.put(Index.valueOf(i), e);
}
}
return V;
}
示例4: times
import javolution.util.Index; //导入依赖的package包/类
@Override
public SparseMatrix<F> times(Matrix<F> that) {
final int m = this.getNumberOfRows();
final int n = this.getNumberOfColumns();
final int p = that.getNumberOfColumns();
if (that.getNumberOfRows() != n)
throw new DimensionException();
// Creates a mxp matrix in transposed form (p columns vectors of size m)
FastTable<SparseVector<F>> rows = this.getRows();
SparseMatrix<F> M = SparseMatrix.newInstance(m, _zero, true);
for (int j = 0; j < p; j++) {
Vector<F> thatColj = that.getColumn(j);
SparseVector<F> column = SparseVector.newInstance(m, _zero);
M._rows.add(column); // M is transposed.
for (int i = 0; i < m; i++) {
F e = rows.get(i).times(thatColj);
if (!_zero.equals(e)) {
column._elements.put(Index.valueOf(i), e);
}
}
}
return M;
}
示例5: inverse
import javolution.util.Index; //导入依赖的package包/类
@Override
public SparseMatrix<F> inverse() {
if (!isSquare())
throw new DimensionException("Matrix not square");
F detInv = this.determinant().inverse();
SparseMatrix<F> A = this.adjoint();
// Multiply adjoint elements with 1 / determinant.
for (int i = 0, m = A._rows.size(); i < m; i++) {
SparseVector<F> row = A._rows.get(i);
for (FastMap.Entry<Index, F> e = row._elements.head(), end = row._elements
.tail(); (e = e.getNext()) != end;) {
F element = e.getValue();
e.setValue(detInv.times(element));
}
}
return A;
}
示例6: determinant
import javolution.util.Index; //导入依赖的package包/类
@Override
public F determinant() {
if (!isSquare())
throw new DimensionException("Matrix not square");
if (_n == 1)
return this.get(0, 0);
// Expansion by minors (also known as Laplacian)
// This algorithm is division free but too slow for dense matrix.
SparseVector<F> row0 = this.getRow(0);
F det = null;
for (FastMap.Entry<Index, F> e = row0._elements.head(), end = row0._elements
.tail(); (e = e.getNext()) != end;) {
int i = e.getKey().intValue();
F d = e.getValue().times(cofactor(0, i));
if (i % 2 != 0) {
d = d.opposite();
}
det = (det == null) ? d : det.plus(d);
}
return det == null ? _zero : det;
}
示例7: adjoint
import javolution.util.Index; //导入依赖的package包/类
@Override
public SparseMatrix<F> adjoint() {
SparseMatrix<F> M = SparseMatrix.newInstance(_n, _zero, _transposed);
int m = _rows.size();
for (int i = 0; i < m; i++) {
SparseVector<F> row = SparseVector.newInstance(_n, _zero);
M._rows.add(row);
for (int j = 0; j < _n; j++) {
F cofactor = _transposed ? cofactor(j, i) : cofactor(i, j);
if (!_zero.equals(cofactor)) {
row._elements
.put(Index.valueOf(j),
((i + j) % 2 == 0) ? cofactor : cofactor
.opposite());
}
}
}
return M.transpose();
}
示例8: vectorization
import javolution.util.Index; //导入依赖的package包/类
@Override
public SparseVector<F> vectorization() {
SparseVector<F> V = SparseVector.newInstance(_n
* this.getNumberOfRows(), _zero);
int offset = 0;
for (int j = 0, n = this.getNumberOfColumns(); j < n; j++) {
SparseVector<F> column = this.getColumn(j);
for (FastMap.Entry<Index, F> e = column._elements.head(), end = column._elements
.tail(); (e = e.getNext()) != end;) {
V._elements.put(Index.valueOf(e.getKey().intValue() + offset),
e.getValue());
}
offset += this.getNumberOfRows();
}
return V;
}
示例9: initializeRealtimeClasses
import javolution.util.Index; //导入依赖的package包/类
/** Initializes all real-time classes. */
public static synchronized boolean initializeRealtimeClasses() {
Initializer initializer = new Initializer(OSGiServices.class.getClassLoader());
initializer.loadClass(MathLib.class);
initializer.loadClass(Text.class);
initializer.loadClass(TypeFormat.class);
initializer.loadClass(Struct.class);
initializer.loadClass(FastBitSet.class);
initializer.loadClass(FastSortedMap.class);
initializer.loadClass(FastSortedSet.class);
initializer.loadClass(FastSortedTable.class);
initializer.loadClass(Index.class); // Preallocates.
initializer.loadClass(Reducers.class);
initializer.loadClass(Equalities.class);
initializer.loadClass(XMLStreamReaderImpl.class);
initializer.loadClass(XMLStreamWriterImpl.class);
return initializer.initializeLoadedClasses();
}
示例10: writeReference
import javolution.util.Index; //导入依赖的package包/类
/**
* Writes a reference to the specified object into the specified XML
* element. The default implementation writes the reference into the
* reference attribute and for the first occurences an identifier
* (counter starting at 1) is written into the identifier attribute.
*
* @param obj the object for which the reference is written.
* @param xml the output XML element.
* @return <code>true</code> if a reference is written;
* <code>false</code> if a new identifier is written.
*/
public boolean writeReference(Object obj, XMLFormat.OutputElement xml)
throws XMLStreamException {
Index id = (Index) _objectToId.get(obj);
if (id == null) { // New identifier.
id = Index.of(_counter++);
_objectToId.put(obj, id);
_tmp.clear().append(id.intValue());
if (_idURI == null) {
xml.getStreamWriter().writeAttribute(_idName, _tmp);
} else {
xml.getStreamWriter().writeAttribute(_idURI, _idName, _tmp);
}
return false;
}
_tmp.clear().append(id.intValue());
if (_refURI == null) {
xml._writer.writeAttribute(_refName, _tmp);
} else {
xml._writer.writeAttribute(_refURI, _refName, _tmp);
}
return true;
}
示例11: valueOf
import javolution.util.Index; //导入依赖的package包/类
/**
* Returns a sparse vector equivalent to the specified vector but with
* the zero elements removed using the specified object equality comparator.
* This method can be used to clean up sparse vectors (to remove elements
* close to zero).
*
* @param that the vector to convert.
* @param zero the zero element for the sparse vector to return.
* @param comparator the comparator used to determinate zero equality.
* @return a sparse vector with zero elements removed.
*/
public static <F extends Field<F>> SparseVector<F> valueOf(
Vector<F> that, F zero, FastComparator<? super F> comparator) {
if (that instanceof SparseVector)
return SparseVector.valueOf((SparseVector<F>) that, zero, comparator);
int n = that.getDimension();
SparseVector<F> V = SparseVector.newInstance(n, zero);
for (int i=0; i < n; i++) {
F element = that.get(i);
if (!comparator.areEqual(zero, element)) {
V._elements.put(Index.valueOf(i), element);
}
}
return V;
}
示例12: get
import javolution.util.Index; //导入依赖的package包/类
@Override
public F get(int i) {
if ((i < 0) || (i >= _dimension))
throw new IndexOutOfBoundsException();
F element = _elements.get(Index.valueOf(i));
return (element == null) ? _zero : element;
}
示例13: opposite
import javolution.util.Index; //导入依赖的package包/类
@Override
public SparseVector<F> opposite() {
SparseVector<F> V = SparseVector.newInstance(_dimension, _zero);
for (FastMap.Entry<Index, F> e = _elements.head(), n = _elements.tail(); (e = e
.getNext()) != n;) {
V._elements.put(e.getKey(), e.getValue().opposite());
}
return V;
}
示例14: times
import javolution.util.Index; //导入依赖的package包/类
@Override
public SparseVector<F> times(F k) {
SparseVector<F> V = SparseVector.newInstance(_dimension, _zero);
for (FastMap.Entry<Index, F> e = _elements.head(), n = _elements.tail(); (e = e
.getNext()) != n;) {
V._elements.put(e.getKey(), e.getValue().times(k));
}
return V;
}
示例15: copy
import javolution.util.Index; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public SparseVector<F> copy() {
SparseVector<F> V = SparseVector.newInstance(_dimension, (F)_zero.copy());
for (Map.Entry<Index, F> e : _elements.entrySet()) {
V._elements.put(e.getKey(), (F) e.getValue().copy());
}
return V;
}