/** * Check whether an entry is set. * * @param entry The entry. * @return {@code true} if the entry is set in this vector. * @throws IllegalArgumentException if the entry is not from this vector or another vector sharing * the same key domain. Only vectors and their side channels share key domains for the * purposes of this check. */ public boolean isSet(VectorEntry entry) { final SparseVector evec = entry.getVector(); final int eind = entry.getIndex(); if (evec == null) { throw new IllegalArgumentException("entry is not associated with a vector"); } else if (!keys.isCompatibleWith(evec.keys)) { throw new IllegalArgumentException("entry does not have safe key domain"); } assert entry.getKey() == keys.getKey(eind); return keys.indexIsActive(eind); }
/** * Creates a new square matrix whose number of rows and columns match the dimensionality of the * given vector. It also places the values of the vector on the diagonal of the matrix. * * @param diagonal The vector of diagonal values. * @return A new, square matrix with the diagonal elements equal to the elements of the given * vector. */ public MatrixType createDiagonal(final Vectorizable diagonal) { final Vector vector = diagonal.convertToVector(); final int dimensionality = vector.getDimensionality(); // Create the matrix. final MatrixType result = this.createMatrix(dimensionality, dimensionality); // Set the diagonal values. for (VectorEntry entry : vector) { final int i = entry.getIndex(); result.setElement(i, i, entry.getValue()); } return result; }
/** * Get the value for the entry's key. * * @param entry A {@code VectorEntry} with the key to look up * @return the key's value * @throws IllegalArgumentException if the entry is unset, or if it is not from this vector or * another vector sharing the same key domain. Only vectors and their side channels share key * domains for the purposes of this check. */ public double get(VectorEntry entry) { final SparseVector evec = entry.getVector(); final int eind = entry.getIndex(); if (evec == null) { throw new IllegalArgumentException("entry is not associated with a vector"); } else if (!evec.keys.isCompatibleWith(keys)) { throw new IllegalArgumentException("entry does not have safe key domain"); } assert entry.getKey() == keys.getKey(eind); if (keys.indexIsActive(eind)) { return values[eind]; } else { throw new IllegalArgumentException("Key " + entry.getKey() + " is not set"); } }