ManyRestraintsBase::ManyRestraintsBase(const ActionOptions& ao): Action(ao), ActionWithValue(ao), ActionPilot(ao), ActionWithVessel(ao), ActionWithInputVessel(ao) { // Read in the vessel we are action on readArgument("bridge"); aves=dynamic_cast<ActionWithVessel*>( getDependencies()[0] ); plumed_assert( getDependencies().size()==1 && aves ); log.printf(" adding restraints on variables calculated by %s action with label %s\n", aves->getName().c_str(),aves->getLabel().c_str()); // Add a task list in order to avoid problems for(unsigned i=0; i<aves->getFullNumberOfTasks(); ++i) addTaskToList( aves->getTaskCode(i) ); // And turn on the derivatives (note problems here because of ActionWithValue) turnOnDerivatives(); needsDerivatives(); // Now create the vessel std::string fake_input="LABEL=bias"; addVessel( "SUM", fake_input, 0 ); readVesselKeywords(); }
void ActionWithValue::turnOnDerivatives() { // Turn on the derivatives noderiv=false; // Resize the derivatives for(unsigned i=0; i<values.size(); ++i) values[i]->resizeDerivatives( getNumberOfDerivatives() ); // And turn on the derivatives in all actions on which we are dependent for(unsigned i=0; i<getDependencies().size(); ++i) { ActionWithValue* vv=dynamic_cast<ActionWithValue*>( getDependencies()[i] ); if(vv) vv->turnOnDerivatives(); } }
void ActionWithVessel::needsDerivatives(){ // Turn on the derivatives and resize noderiv=false; resizeFunctions(); // Setting contributors unlocked here ensures that link cells are ignored contributorsAreUnlocked=true; finishTaskListUpdate(); contributorsAreUnlocked=false; // And turn on the derivatives in all actions on which we are dependent for(unsigned i=0;i<getDependencies().size();++i){ ActionWithVessel* vv=dynamic_cast<ActionWithVessel*>( getDependencies()[i] ); if(vv) vv->needsDerivatives(); } }
TEST_F(DocumentSourceMatchTest, TextSearchShouldRequireWholeDocumentAndTextScore) { auto match = DocumentSourceMatch::create(fromjson("{$text: {$search: 'hello'} }"), getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DocumentSource::EXHAUSTIVE_ALL, match->getDependencies(&dependencies)); ASSERT_EQUALS(true, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedTextScore()); }
TEST_F(DocumentSourceMatchTest, TextSearchShouldRequireWholeDocumentAndTextScore) { auto match = DocumentSourceMatch::create(fromjson("{$text: {$search: 'hello'} }"), getExpCtx()); DepsTracker dependencies(DepsTracker::MetadataAvailable::kTextScore); ASSERT_EQUALS(DepsTracker::State::EXHAUSTIVE_FIELDS, match->getDependencies(&dependencies)); ASSERT_EQUALS(true, dependencies.needWholeDocument); ASSERT_EQUALS(true, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
//---------------------------------------------computeTransitiveHull void ModuleDependencies::computeTransitiveHull(Module* pModule, tModuleDep* pDst, std::set<Module*>* pVisitedModules) { if(!pModule) { tDepCollection::iterator it = m_collDependencies.begin(); tDepCollection::iterator end = m_collDependencies.end(); for(; it!=end; ++it) { std::set<Module*> collVisitedModules; computeTransitiveHull(it->first, &it->second, &collVisitedModules); //recursive call } } else { CLAY_ASSERT(pDst); CLAY_ASSERT(pVisitedModules); pVisitedModules->insert(pModule); const tModuleDep* pDep = getDependencies(pModule); if(pDep) { tModuleDep::const_iterator ti = pDep->begin(); tModuleDep::const_iterator dne = pDep->end(); for(; ti!=dne; ++ti) { pDst->insert(*ti); if(pVisitedModules->find(*ti) == pVisitedModules->end()) //avoid cycles ... { computeTransitiveHull(*ti, pDst, pVisitedModules); //... on recursive call } } } } }
static void getDependencies (Project& project, const String& moduleID, StringArray& dependencies) { ModuleDescription info (project.getModules().getModuleInfo (moduleID)); if (info.isValid()) { const var depsArray (info.moduleInfo ["dependencies"]); if (const Array<var>* const deps = depsArray.getArray()) { for (int i = 0; i < deps->size(); ++i) { const var& d = deps->getReference(i); String uid (d [Ids::ID].toString()); String version (d [Ids::version].toString()); if (! dependencies.contains (uid, true)) { dependencies.add (uid); getDependencies (project, uid, dependencies); } } } } }
TEST_F(DocumentSourceMatchTest, CommentShouldNotAddAnyDependencies) { auto match = DocumentSourceMatch::create(fromjson("{$comment: 'misleading?'}"), getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(0U, dependencies.fields.size()); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
//---------------------------------------------getNumDependencies ModuleDependencies::tDepCollection::size_type ModuleDependencies::getNumDependencies(Module* pModule) const { const ModuleDependencies::tModuleDep* pDep = getDependencies(pModule); if(pDep) { return pDep->size(); } return 0; }
TEST_F(DocumentSourceMatchTest, ShouldAddNotClausesFieldAsDependency) { auto match = DocumentSourceMatch::create(fromjson("{b: {$not: {$gte: 4}}}}"), getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(1U, dependencies.fields.count("b")); ASSERT_EQUALS(1U, dependencies.fields.size()); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
TEST_F(DocumentSourceMatchTest, ShouldAddCorrectDependenciesForClausesWithEmptyJSONSchema) { DepsTracker dependencies; auto query = fromjson("{$jsonSchema: {}}"); auto match = DocumentSourceMatch::create(query, getExpCtx()); ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(0U, dependencies.fields.size()); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
TEST_F(DocumentSourceMatchTest, ShouldOnlyAddOuterFieldAsDependencyOfImplicitEqualityPredicate) { // Parses to {a: {$eq: {notAField: {$gte: 4}}}}. auto match = DocumentSourceMatch::create(fromjson("{a: {notAField: {$gte: 4}}}"), getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(1U, dependencies.fields.count("a")); ASSERT_EQUALS(1U, dependencies.fields.size()); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
TEST_F(DocumentSourceMatchTest, ShouldAddOuterFieldToDependenciesIfElemMatchContainsNoFieldNames) { auto match = DocumentSourceMatch::create(fromjson("{a: {$elemMatch: {$gt: 1, $lt: 5}}}"), getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(1U, dependencies.fields.count("a")); ASSERT_EQUALS(1U, dependencies.fields.size()); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
TEST_F(DocumentSourceMatchTest, ShouldAddCorrectDependenciesForClausesWithInternalSchemaType) { auto query = fromjson("{a: {$_internalSchemaType: 1}}"); auto match = DocumentSourceMatch::create(query, getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(1U, dependencies.fields.size()); ASSERT_EQUALS(1U, dependencies.fields.count("a")); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
TEST_F(DocumentSourceMatchTest, ClauseAndedWithCommentShouldAddDependencies) { auto match = DocumentSourceMatch::create(fromjson("{a: 4, $comment: 'irrelevant'}"), getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(1U, dependencies.fields.count("a")); ASSERT_EQUALS(1U, dependencies.fields.size()); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
TEST_F(DocumentSourceMatchTest, ShouldOnlyAddOuterFieldAsDependencyOfClausesWithinElemMatch) { auto match = DocumentSourceMatch::create(fromjson("{a: {$elemMatch: {c: {$gte: 4}}}}"), getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(1U, dependencies.fields.count("a")); ASSERT_EQUALS(1U, dependencies.fields.size()); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
TEST_F(DocumentSourceMatchTest, ShouldAddWholeDocumentAsDependencyOfClausesWithInternalSchemaRootDocEq) { auto query = fromjson("{$_internalSchemaRootDocEq: {a: 1}}"); auto match = DocumentSourceMatch::create(query, getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(0U, dependencies.fields.size()); ASSERT_EQUALS(true, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
TEST_F(DocumentSourceMatchTest, ShouldAddWholeDocumentAsDependencyOfClausesWithinInternalSchemaMaxProperties) { auto query = fromjson("{$_internalSchemaMaxProperties: 1}"); auto match = DocumentSourceMatch::create(query, getExpCtx()); DepsTracker dependencies1; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies1)); ASSERT_EQUALS(0U, dependencies1.fields.size()); ASSERT_EQUALS(true, dependencies1.needWholeDocument); ASSERT_EQUALS(false, dependencies1.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); query = fromjson("{a: {$_internalSchemaObjectMatch: {$_internalSchemaMaxProperties: 1}}}"); match = DocumentSourceMatch::create(query, getExpCtx()); DepsTracker dependencies2; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies2)); ASSERT_EQUALS(1U, dependencies2.fields.size()); ASSERT_EQUALS(1U, dependencies2.fields.count("a")); ASSERT_EQUALS(false, dependencies2.needWholeDocument); ASSERT_EQUALS(false, dependencies2.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
TEST_F(DocumentSourceMatchTest, ShouldAddCorrectDependenciesForMultiplePredicatesWithJSONSchema) { DepsTracker dependencies; auto query = fromjson("{$jsonSchema: {properties: {a: {type: 'number'}}}, b: 1}"); auto match = DocumentSourceMatch::create(query, getExpCtx()); ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(2U, dependencies.fields.size()); ASSERT_EQUALS(1U, dependencies.fields.count("a")); ASSERT_EQUALS(1U, dependencies.fields.count("b")); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
StringArray EnabledModuleList::getExtraDependenciesNeeded (const String& moduleID) const { StringArray dependencies, extraDepsNeeded; getDependencies (project, moduleID, dependencies); for (auto dep : dependencies) if (dep != moduleID && ! isModuleEnabled (dep)) extraDepsNeeded.add (dep); return extraDepsNeeded; }
TEST_F(DocumentSourceMatchTest, ShouldAddDependenciesOfEachNorClause) { auto match = DocumentSourceMatch::create( fromjson("{$nor: [{'a.b': {$gte: 4}}, {'b.c': {$in: [1, 2]}}]}"), getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(1U, dependencies.fields.count("a.b")); ASSERT_EQUALS(1U, dependencies.fields.count("b.c")); ASSERT_EQUALS(2U, dependencies.fields.size()); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
StringArray EnabledModuleList::getExtraDependenciesNeeded (const String& moduleID) const { StringArray dependencies, extraDepsNeeded; getDependencies (project, moduleID, dependencies); for (int i = 0; i < dependencies.size(); ++i) if ((! isModuleEnabled (dependencies[i])) && dependencies[i] != moduleID) extraDepsNeeded.add (dependencies[i]); return extraDepsNeeded; }
TEST_F(DocumentSourceMatchTest, ShouldAddDependenciesOfClausesWithinElemMatchAsDottedPaths) { auto match = DocumentSourceMatch::create(fromjson("{a: {$elemMatch: {c: {$gte: 4}}}}"), getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DocumentSource::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(1U, dependencies.fields.count("a.c")); ASSERT_EQUALS(1U, dependencies.fields.count("a")); ASSERT_EQUALS(2U, dependencies.fields.size()); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedTextScore()); }
Eigen::Vector2f QS::ExitFlee::evaluate(const Actor *theActor) { const FindExitSensor *exitSensor = dynamic_cast<const QS::FindExitSensor*>(getDependencies()[0].myEntity); const Exit *exit = exitSensor->getExit(); Eigen::Vector2f steeringForce = BasicBehaviors::flee( theActor, exit->getPosition(), theActor->getMaximumSpeed()); return steeringForce; }
TEST_F(DocumentSourceMatchTest, ShouldAddWholeDocumentAsDependencyOfClausesWithinInternalSchemaAllowedProperties) { auto query = fromjson( "{$_internalSchemaAllowedProperties: {properties: ['a', 'b']," "namePlaceholder: 'i', patternProperties: [], otherwise: {i: 0}}}"); auto match = DocumentSourceMatch::create(query, getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(1U, dependencies.fields.size()); ASSERT_EQUALS(true, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
void MetadataItem::getDependencies(std::vector<Dependency>& list, bool ofObject, const wxString& field) { std::vector<Dependency> tmp; getDependencies(tmp, ofObject); for (std::vector<Dependency>::iterator it = tmp.begin(); it != tmp.end(); ++it) { if ((*it).hasField(field)) list.push_back(*it); } }
static void getDependencies (Project& project, const String& moduleID, StringArray& dependencies) { ModuleDescription info (project.getModules().getModuleInfo (moduleID)); for (auto uid : info.getDependencies()) { if (! dependencies.contains (uid, true)) { dependencies.add (uid); getDependencies (project, uid, dependencies); } } }
void VolumeGradientBase::requestAtoms( const std::vector<AtomNumber>& atoms ) { ActionAtomistic::requestAtoms(atoms); bridgeVariable=3*atoms.size(); std::map<std::string,bool> checklabs; for(const auto & p : getDependencies() ) checklabs.insert(std::pair<std::string,bool>(p->getLabel(),false)); for(const auto & p : plumed.getActionSet() ) { if( p->getLabel()==getPntrToMultiColvar()->getLabel() ) break; if( checklabs.count(p->getLabel()) ) checklabs[p->getLabel()]=true; } for(const auto & p : checklabs ) { if( !p.second ) error("the input for the virtual atoms used in the input for this action must appear in the input file before the input multicolvar"); } addDependency( getPntrToMultiColvar() ); tmpforces.resize( 3*atoms.size()+9 ); }
TEST_F(DocumentSourceMatchTest, ShouldOnlyAddOuterFieldAsDependencyOfClausesWithinInternalSchemaObjectMatch) { auto query = fromjson( " {a: {$_internalSchemaObjectMatch: {" " b: {$_internalSchemaObjectMatch: {" " $or: [{c: {$type: 'string'}}, {c: {$gt: 0}}]" " }}}" " }}}"); auto match = DocumentSourceMatch::create(query, getExpCtx()); DepsTracker dependencies; ASSERT_EQUALS(DepsTracker::State::SEE_NEXT, match->getDependencies(&dependencies)); ASSERT_EQUALS(1U, dependencies.fields.count("a")); ASSERT_EQUALS(1U, dependencies.fields.size()); ASSERT_EQUALS(false, dependencies.needWholeDocument); ASSERT_EQUALS(false, dependencies.getNeedsMetadata(DepsTracker::MetadataType::TEXT_SCORE)); }
void ProcessorRouter::reorder(Processor* processor) { (*global_changes_)++; local_changes_++; // Get all the dependencies inside this router. std::set<const Processor*> dependencies = getDependencies(processor); // Stably reorder putting dependencies first. std::vector<const Processor*> new_order; new_order.reserve(global_order_->size()); int num_processors = processors_.size(); // First put the dependencies. for (int i = 0; i < num_processors; ++i) { if (global_order_->at(i) != processor && dependencies.find(global_order_->at(i)) != dependencies.end()) { new_order.push_back(global_order_->at(i)); } } // Then the processor if it is in this router. if (processors_.find(processor) != processors_.end()) new_order.push_back(processor); // Then the remaining processors. for (int i = 0; i < num_processors; ++i) { if (global_order_->at(i) != processor && dependencies.find(global_order_->at(i)) == dependencies.end()) { new_order.push_back(global_order_->at(i)); } } TWYTCH_MOPO_ASSERT(new_order.size() == processors_.size()); (*global_order_) = new_order; // Make sure our parent is ordered as well. if (router_) router_->reorder(processor); }