use of de.lmu.ifi.dbs.elki.data.type.VectorTypeInformation in project elki by elki-project.
the class FilterUtil method guessFactory.
/**
* Try to guess the appropriate factory.
*
* @param in Input type
* @param <V> Vector type
* @return Factory
*/
@SuppressWarnings("unchecked")
public static <V extends NumberVector> NumberVector.Factory<V> guessFactory(SimpleTypeInformation<V> in) {
NumberVector.Factory<V> factory = null;
if (in instanceof VectorTypeInformation) {
factory = (NumberVector.Factory<V>) ((VectorTypeInformation<V>) in).getFactory();
}
if (factory == null) {
// FIXME: hack. Add factories to simple type information, too?
try {
Field f = in.getRestrictionClass().getField("FACTORY");
factory = (NumberVector.Factory<V>) f.get(null);
} catch (Exception e) {
LoggingUtil.warning("Cannot determine factory for type " + in.getRestrictionClass(), e);
}
}
return factory;
}
use of de.lmu.ifi.dbs.elki.data.type.VectorTypeInformation in project elki by elki-project.
the class VectorDimensionalityFilter method updateMeta.
/**
* Update metadata.
*/
private void updateMeta() {
meta = new BundleMeta();
BundleMeta origmeta = source.getMeta();
for (int i = 0; i < origmeta.size(); i++) {
SimpleTypeInformation<?> type = origmeta.get(i);
if (column < 0) {
// Test whether this type matches
if (TypeUtil.NUMBER_VECTOR_VARIABLE_LENGTH.isAssignableFromType(type)) {
if (type instanceof VectorFieldTypeInformation) {
@SuppressWarnings("unchecked") final VectorFieldTypeInformation<V> castType = (VectorFieldTypeInformation<V>) type;
if (dim != -1 && castType.mindim() > dim) {
throw new AbortException("Would filter all vectors: minimum dimensionality " + castType.mindim() + " > desired dimensionality " + dim);
}
if (dim != -1 && castType.maxdim() < dim) {
throw new AbortException("Would filter all vectors: maximum dimensionality " + castType.maxdim() + " < desired dimensionality " + dim);
}
if (dim == -1) {
dim = castType.mindim();
}
if (castType.mindim() == castType.maxdim()) {
meta.add(castType);
column = i;
continue;
}
}
@SuppressWarnings("unchecked") final VectorTypeInformation<V> castType = (VectorTypeInformation<V>) type;
if (dim != -1) {
meta.add(new VectorFieldTypeInformation<>(FilterUtil.guessFactory(castType), dim, dim, castType.getSerializer()));
} else {
LOG.warning("No dimensionality yet for column " + i);
meta.add(castType);
}
column = i;
continue;
}
}
meta.add(type);
}
}
Aggregations