/** * This method effectively resets counter to empty state */ public void clear() { map.clear(); totalCount.set(0.0); dirty.set(false); }
public INDArray yetAnotherExecMethod(@NonNull Map<String, INDArray> inputs) { if (!wasRegistered.get()) { synchronized (this) { if (!wasRegistered.get()) { val bb = asFlatBuffers(); val ptr = new BytePointer(bb); Nd4j.getExecutioner().registerGraph(this.hashCode(), ptr); wasRegistered.set(true); } } } val newMap = new LinkedHashMap<String, INDArray>(); val keySet = inputs.keySet(); for (val key : keySet) { val vx = variableMap.get(key); newMap.put(vx.getVarName(), inputs.get(key)); } val result = Nd4j.getExecutioner().executeGraph(this.hashCode(), newMap); if (result.size() == 0) throw new ND4JIllegalStateException("Execution failed"); val list = new ArrayList<INDArray>(result.values()); return list.get(list.size() - 1); }
@Override public AtomicBoolean deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); boolean value = node.asBoolean(); return new AtomicBoolean(value); } }
@Override public int hashCode(){ return get() ? 1 : 0; }
/** * This method removes given key from counter * * @param element * @return counter value */ public double removeKey(T element) { AtomicDouble v = map.remove(element); dirty.set(true); if (v != null) return v.get(); else return 0.0; }
@Override public void serialize(AtomicBoolean atomicDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeBoolean(atomicDouble.get()); } }
@Override public AtomicBoolean deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); boolean value = node.asBoolean(); return new AtomicBoolean(value); } }
/** * This method will remove all elements with counts below given threshold from counter * @param threshold */ public void dropElementsBelowThreshold(double threshold) { Iterator<T> iterator = keySet().iterator(); while (iterator.hasNext()) { T element = iterator.next(); double val = map.get(element).get(); if (val < threshold) { iterator.remove(); dirty.set(true); } } }
/** * This method returns total sum of counter values * @return */ public double totalCount() { if (dirty.get()) rebuildTotals(); return totalCount.get(); }
/** * This method sets new counter value for given element * * @param element element to be updated * @param count new counter value * @return previous value */ public double setCount(T element, double count) { AtomicDouble t = map.get(element); if (t != null) { double val = t.getAndSet(count); dirty.set(true); return val; } else { map.put(element, new AtomicDouble(count)); totalCount.addAndGet(count); return 0; } }
protected void rebuildTotals() { totalCount.set(0); for (T key : keySet()) { totalCount.addAndGet(getCount(key)); } dirty.set(false); }
@Override public int hashCode(){ return get() ? 1 : 0; }
/** * This method effectively resets counter to empty state */ public void clear() { map.clear(); totalCount.set(0.0); dirty.set(false); }
@Override public void serialize(AtomicBoolean atomicDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeBoolean(atomicDouble.get()); } }
@Override public void enableDebugMode(boolean reallyEnable) { debug.set(reallyEnable); nativeOps.enableDebugMode(reallyEnable); }
/** * This method returns total sum of counter values * @return */ public double totalCount() { if (dirty.get()) rebuildTotals(); return totalCount.get(); }
@Override public void enableVerboseMode(boolean reallyEnable) { verbose.set(reallyEnable); nativeOps.enableVerboseMode(reallyEnable); }
/** * This method removes given key from counter * * @param element * @return counter value */ public double removeKey(T element) { AtomicDouble v = map.remove(element); dirty.set(true); if (v != null) return v.get(); else return 0.0; }