@Benchmark public void get() { int localSize = this.size; String[] localElements = this.elements; ObjectObjectMap<String, String> localHppcMap = this.hppcMap; for (int i = 0; i < localSize; i++) { if (localHppcMap.get(localElements[i]) == null) { throw new AssertionError(i); } } } }
/** Get back fields that have been previously added with {@link #addWithKey(Object, IndexableField)}. */ public IndexableField getByKey(Object key) { return keyedFields == null ? null : keyedFields.get(key); }
@Override public int test() { int res = 0; for ( int i = 0; i < m_keys.length; ++i ) if ( m_map.get( m_keys[ i ] ) != null ) res ^= 1; return res; } }
@Override public int test() { int res = 0; for ( int i = 0; i < m_keys.length; ++i ) if ( m_map.get( m_keys[ i ] ) != null ) res ^= 1; return res; } }
/** Get back fields that have been previously added with {@link #addWithKey(Object, IndexableField)}. */ public IndexableField getByKey(Object key) { return keyedFields == null ? null : keyedFields.get(key); }
/** Get back fields that have been previously added with {@link #addWithKey(Object, IndexableField)}. */ public IndexableField getByKey(Object key) { return keyedFields == null ? null : keyedFields.get(key); }
/** Get back fields that have been previously added with {@link #addWithKey(Object, IndexableField)}. */ public IndexableField getByKey(Object key) { return keyedFields == null ? null : keyedFields.get(key); }
/** Get back fields that have been previously added with {@link #addWithKey(Object, IndexableField)}. */ public IndexableField getByKey(Object key) { return keyedFields == null ? null : keyedFields.get(key); }
/** * This writes a feature's individual value, using the human readable name if possible, to a StringBuilder */ private void debugFeatureValue(String feature, int index, ConcatVector vector, BufferedWriter bw) throws IOException { bw.write("\t"); if (sparseFeatureIndex.containsKey(feature) && sparseFeatureIndex.get(feature).values().contains(index)) { // we can map this index to an interpretable string, so we do bw.write("SPARSE VALUE \""); bw.write(reverseSparseFeatureIndex.get(feature).get(index)); bw.write("\""); } else { // we can't map this to a useful string, so we default to the number bw.write(Integer.toString(index)); } bw.write(": "); bw.write(Double.toString(vector.getValueAt(featureToIndex.getOrDefault(feature, -1), index))); bw.write("\n"); } }
ObjectIntMap<String> sparseIndex = sparseFeatureIndex.get(featureName); IntObjectMap<String> reverseSparseIndex = reverseSparseFeatureIndex.get(featureName); if (sparseIndex == null || reverseSparseIndex == null) { synchronized (sparseFeatureIndex) { sparseIndex = sparseFeatureIndex.get(featureName); reverseSparseIndex = reverseSparseFeatureIndex.get(featureName); if (sparseIndex == null || reverseSparseIndex == null) { sparseIndex = new ObjectIntHashMap<>();
/** * This constructs a fresh vector that is sized correctly to accommodate all the known sparse values for vectors * that are possibly sparse. * * @param presize a flag for whether or not to create all the dense double arrays for our sparse features * * @return a new, internally correctly sized ConcatVector that will work correctly as weights for features from * this namespace; */ public ConcatVector newWeightsVector(boolean presize) { ConcatVector vector = new ConcatVector(featureToIndex.size()); if (presize) { for (ObjectCursor<String> s : sparseFeatureIndex.keys()) { int size = sparseFeatureIndex.get(s.value).size(); vector.setDenseComponent(ensureFeature(s.value), new double[size]); } } setAlwaysOneFeature(vector, 1); return vector; }
/** * @return a Builder for proto serialization */ public ConcatVectorNamespaceProto.ConcatVectorNamespace.Builder getProtoBuilder() { ConcatVectorNamespaceProto.ConcatVectorNamespace.Builder m = ConcatVectorNamespaceProto.ConcatVectorNamespace.newBuilder(); // Add the outer layer features for (ObjectCursor<String> feature : featureToIndex.keys()) { ConcatVectorNamespaceProto.ConcatVectorNamespace.FeatureToIndexComponent.Builder component = ConcatVectorNamespaceProto.ConcatVectorNamespace.FeatureToIndexComponent.newBuilder(); component.setKey(feature.value); component.setData(featureToIndex.getOrDefault(feature.value, -1)); m.addFeatureToIndex(component); } for (ObjectCursor<String> feature : sparseFeatureIndex.keys()) { ConcatVectorNamespaceProto.ConcatVectorNamespace.SparseFeatureIndex.Builder sparseFeature = ConcatVectorNamespaceProto.ConcatVectorNamespace.SparseFeatureIndex.newBuilder(); sparseFeature.setKey(feature.value); for (ObjectCursor<String> sparseFeatureName : sparseFeatureIndex.get(feature.value).keys()) { ConcatVectorNamespaceProto.ConcatVectorNamespace.FeatureToIndexComponent.Builder component = ConcatVectorNamespaceProto.ConcatVectorNamespace.FeatureToIndexComponent.newBuilder(); component.setKey(sparseFeatureName.value); component.setData(sparseFeatureIndex.get(feature.value).getOrDefault(sparseFeatureName.value, -1)); sparseFeature.addFeatureToIndex(component); } m.addSparseFeatureIndex(sparseFeature); } return m; }