Skip to content

Commit

Permalink
RAn astyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed Aug 26, 2024
1 parent b978c66 commit 59b2212
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 72 deletions.
8 changes: 4 additions & 4 deletions src/core/ActionWithMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ void ActionWithMatrix::setupMatrixStore() {
}

int ActionWithMatrix::checkTaskIsActive( const unsigned& itask ) const {
int nm = getNumberOfMasks(); if( nm<0 ) return 1;
int nm = getNumberOfMasks(); if( nm<0 ) return 1;

// This checks for matrices that are masking some elements
unsigned nargs = getNumberOfArguments();
unsigned nargs = getNumberOfArguments();
if( nm==1 && getPntrToArgument(nargs-1)->getRank()==2 ) return 1;

for(unsigned j=nargs-nm; j<nargs; ++j) {
plumed_assert( getPntrToArgument(j)->getRank()==1 );
if( fabs(getPntrToArgument(j)->get(itask))>0 ) return 1;
plumed_assert( getPntrToArgument(j)->getRank()==1 );
if( fabs(getPntrToArgument(j)->get(itask))>0 ) return 1;
}
return 0;
}
Expand Down
76 changes: 38 additions & 38 deletions src/core/ActionWithVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,29 @@ ActionWithVector::ActionWithVector(const ActionOptions&ao):
std::vector<Value*> mask; parseArgumentList("MASK",mask);
if( mask.size()>0 ) {
if( nmask>=0 && getNumberOfArguments()==1 ) {
ActionWithVector* av=dynamic_cast<ActionWithVector*>( getPntrToArgument(0)->getPntrToAction() );
plumed_massert( av, "input should be a vector from ActionWithVector" ); unsigned j=0, nargs = av->getNumberOfArguments();
for(unsigned i=nargs-av->nmask; i<nargs; ++i) {
if( av->getPntrToArgument(i)!=mask[j] ) error("the masks in subsequent actions do not match");
j++;
}
ActionWithVector* av=dynamic_cast<ActionWithVector*>( getPntrToArgument(0)->getPntrToAction() );
plumed_massert( av, "input should be a vector from ActionWithVector" ); unsigned j=0, nargs = av->getNumberOfArguments();
for(unsigned i=nargs-av->nmask; i<nargs; ++i) {
if( av->getPntrToArgument(i)!=mask[j] ) error("the masks in subsequent actions do not match");
j++;
}
} else if( nmask>=0 ) error("should not have a mask if you have read the mask keyword");
if( getNumberOfArguments()>0 && getPntrToArgument(0)->hasDerivatives() ) error("input for mask should be vector or matrix");
else if( mask[0]->getRank()==2 ) {
if( mask.size()>1 ) error("MASK should only have one argument");
log.printf(" only computing elements of matrix that correspond to non-zero elements of matrix %s \n", mask[0]->getName().c_str() );
if( mask.size()>1 ) error("MASK should only have one argument");
log.printf(" only computing elements of matrix that correspond to non-zero elements of matrix %s \n", mask[0]->getName().c_str() );
} else if( mask[0]->getRank()==1 ) {
log.printf(" only computing elements of vector that correspond to non-zero elements of vectors %s", mask[0]->getName().c_str() );
for(unsigned i=1; i<mask.size();++i) {
if( mask[i]->getRank()!=1 ) { log.printf("\n"); error("input to mask should be vector"); }
log.printf(", %s", mask[i]->getName().c_str() );
}
log.printf("\n");
log.printf(" only computing elements of vector that correspond to non-zero elements of vectors %s", mask[0]->getName().c_str() );
for(unsigned i=1; i<mask.size(); ++i) {
if( mask[i]->getRank()!=1 ) { log.printf("\n"); error("input to mask should be vector"); }
log.printf(", %s", mask[i]->getName().c_str() );
}
log.printf("\n");
}
std::vector<Value*> allargs( getArguments() ); nmask=mask.size();
for(unsigned i=0; i<mask.size(); ++i) allargs.push_back( mask[i] );
for(unsigned i=0; i<mask.size(); ++i) allargs.push_back( mask[i] );
requestArguments( allargs );
}
}
}
}

Expand Down Expand Up @@ -437,11 +437,11 @@ void ActionWithVector::prepare() {

int ActionWithVector::checkTaskIsActive( const unsigned& itask ) const {
for(unsigned i=0; i<getNumberOfArguments(); ++i) {
Value* myarg = getPntrToArgument(i);
if( myarg->getRank()==0 ) continue;
else if( myarg->getRank()==1 && !myarg->hasDerivatives() ) {
if( fabs(myarg->get(itask))>0 ) return 1;
} else plumed_merror("should not be in action " + getName() );
Value* myarg = getPntrToArgument(i);
if( myarg->getRank()==0 ) continue;
else if( myarg->getRank()==1 && !myarg->hasDerivatives() ) {
if( fabs(myarg->get(itask))>0 ) return 1;
} else plumed_merror("should not be in action " + getName() );
}
return -1;
}
Expand All @@ -451,24 +451,24 @@ std::vector<unsigned>& ActionWithVector::getListOfActiveTasks( ActionWithVector*
unsigned ntasks=0; getNumberOfTasks( ntasks );

if( getenvChainForbidden()==Option::yes ) {
if( getNumberOfArguments()==0 ) {
active_tasks.resize( ntasks );
for(unsigned i=0; i<ntasks; ++i) active_tasks[i]=i;
return active_tasks;
}

std::vector<int> taskFlags( ntasks, -1 );
for(unsigned i=0; i<ntasks; ++i) taskFlags[i] = checkTaskIsActive(i);
unsigned nt=0;
for(unsigned i=0; i<ntasks; ++i) {
if( taskFlags[i]>0 ) nt++;
}
active_tasks.resize(nt); nt=0;
for(unsigned i=0; i<ntasks; ++i) {
if( taskFlags[i]>0 ) { active_tasks[nt]=i; nt++; }
}
if( getNumberOfArguments()==0 ) {
active_tasks.resize( ntasks );
for(unsigned i=0; i<ntasks; ++i) active_tasks[i]=i;
return active_tasks;
}
}

std::vector<int> taskFlags( ntasks, -1 );
for(unsigned i=0; i<ntasks; ++i) taskFlags[i] = checkTaskIsActive(i);
unsigned nt=0;
for(unsigned i=0; i<ntasks; ++i) {
if( taskFlags[i]>0 ) nt++;
}
active_tasks.resize(nt); nt=0;
for(unsigned i=0; i<ntasks; ++i) {
if( taskFlags[i]>0 ) { active_tasks[nt]=i; nt++; }
}
return active_tasks;
}

unsigned stride=comm.Get_size();
unsigned rank=comm.Get_rank();
Expand Down
4 changes: 2 additions & 2 deletions src/function/Bessel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ void Bessel::registerKeywords(Keywords& keys) {

void Bessel::read( ActionWithArguments* action ) {
if( action->getNumberOfArguments()!=1 ) {
ActionWithVector* av = dynamic_cast<ActionWithVector*>( action );
if( !av || (av && action->getNumberOfArguments()-av->getNumberOfMasks()!=1) ) action->error("should only be one argument to less_than actions");
ActionWithVector* av = dynamic_cast<ActionWithVector*>( action );
if( !av || (av && action->getNumberOfArguments()-av->getNumberOfMasks()!=1) ) action->error("should only be one argument to less_than actions");
}
if( action->getPntrToArgument(0)->isPeriodic() ) action->error("cannot use this function on periodic functions");
action->parse("ORDER",order); action->log.printf(" computing %dth order bessel function \n", order );
Expand Down
4 changes: 2 additions & 2 deletions src/function/Between.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ void Between::registerKeywords(Keywords& keys) {

void Between::read( ActionWithArguments* action ) {
if( action->getNumberOfArguments()!=1 ) {
ActionWithVector* av = dynamic_cast<ActionWithVector*>( action );
if( !av || (av && action->getNumberOfArguments()-av->getNumberOfMasks()!=1) ) action->error("should only be one argument to less_than actions");
ActionWithVector* av = dynamic_cast<ActionWithVector*>( action );
if( !av || (av && action->getNumberOfArguments()-av->getNumberOfMasks()!=1) ) action->error("should only be one argument to less_than actions");
}
if( action->getNumberOfArguments()!=1 ) action->error("should only be one argument to between actions");

Expand Down
8 changes: 4 additions & 4 deletions src/function/Custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ bool Custom::checkIfMaskAllowed( const std::vector<Value*>& args ) const {
if( av && av->getNumberOfMasks()>=0 ) {
unsigned nargs = av->getNumberOfArguments(), nm = av->getNumberOfMasks();
for(unsigned k=nargs-nm; k<nargs; ++k ) {
nomask=false; Value* maskarg = av->getPntrToArgument( k );
for(unsigned j=0; j<check_multiplication_vars.size(); ++j) {
if( maskarg==args[check_multiplication_vars[j]] ) return true;
}
nomask=false; Value* maskarg = av->getPntrToArgument( k );
for(unsigned j=0; j<check_multiplication_vars.size(); ++j) {
if( maskarg==args[check_multiplication_vars[j]] ) return true;
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/function/FunctionOfMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FunctionOfMatrix : public ActionWithMatrix {
void turnOnDerivatives() override;
/// Get the number of derivatives for this action
unsigned getNumberOfDerivatives() override ;
/// Check if the task is active
/// Check if the task is active
int checkTaskIsActive( const unsigned& itask ) const override ;
/// Resize the matrices
void prepare() override ;
Expand Down Expand Up @@ -234,12 +234,12 @@ unsigned FunctionOfMatrix<T>::getNumberOfColumns() const {

template <class T>
int FunctionOfMatrix<T>::checkTaskIsActive( const unsigned& itask ) const {
const ActionWithVector* av=dynamic_cast<const ActionWithVector*>( getPntrToArgument(0)->getPntrToAction() );
const ActionWithVector* av=dynamic_cast<const ActionWithVector*>( getPntrToArgument(0)->getPntrToAction() );
unsigned status=1; if( av ) status = av->checkTaskIsActive( itask );
for(unsigned i=1; i<getNumberOfArguments(); ++i) {
const ActionWithVector* av=dynamic_cast<const ActionWithVector*>( getPntrToArgument(i)->getPntrToAction() );
if( av && status!=av->checkTaskIsActive( itask ) ) plumed_merror("this doesn't work");
}
const ActionWithVector* av=dynamic_cast<const ActionWithVector*>( getPntrToArgument(i)->getPntrToAction() );

Check notice

Code scanning / CodeQL

Declaration hides variable Note

Variable av hides another variable of the same name (on
line 237
).
if( av && status!=av->checkTaskIsActive( itask ) ) plumed_merror("this doesn't work");
}
return status;
}

Expand Down
4 changes: 2 additions & 2 deletions src/function/LessThan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ void LessThan::registerKeywords(Keywords& keys) {

void LessThan::read( ActionWithArguments* action ) {
if( action->getNumberOfArguments()!=1 ) {
ActionWithVector* av = dynamic_cast<ActionWithVector*>( action );
if( !av || (av && action->getNumberOfArguments()-av->getNumberOfMasks()!=1) ) action->error("should only be one argument to less_than actions");
ActionWithVector* av = dynamic_cast<ActionWithVector*>( action );
if( !av || (av && action->getNumberOfArguments()-av->getNumberOfMasks()!=1) ) action->error("should only be one argument to less_than actions");
}
if( action->getPntrToArgument(0)->isPeriodic() ) action->error("cannot use this function on periodic functions");

Expand Down
4 changes: 2 additions & 2 deletions src/function/MoreThan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ void MoreThan::registerKeywords(Keywords& keys) {

void MoreThan::read( ActionWithArguments* action ) {
if( action->getNumberOfArguments()!=1 ) {
ActionWithVector* av = dynamic_cast<ActionWithVector*>( action );
if( !av || (av && action->getNumberOfArguments()-av->getNumberOfMasks()!=1) ) action->error("should only be one argument to less_than actions");
ActionWithVector* av = dynamic_cast<ActionWithVector*>( action );
if( !av || (av && action->getNumberOfArguments()-av->getNumberOfMasks()!=1) ) action->error("should only be one argument to less_than actions");
}
if( action->getPntrToArgument(0)->isPeriodic() ) action->error("cannot use this function on periodic functions");

Expand Down
2 changes: 1 addition & 1 deletion src/function/MoreThan.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MoreThan : public FunctionTemplateBase {
public:
void registerKeywords( Keywords& keys ) override;
void read( ActionWithArguments* action ) override;
bool checkIfMaskAllowed( const std::vector<Value*>& args ) const override { return args.size()>1; }
bool checkIfMaskAllowed( const std::vector<Value*>& args ) const override { return args.size()>1; }
bool getDerivativeZeroIfValueIsZero() const override { return true; }
void calc( const ActionWithArguments* action, const std::vector<double>& args, std::vector<double>& vals, Matrix<double>& derivatives ) const override;
};
Expand Down
14 changes: 7 additions & 7 deletions src/matrixtools/MatrixTimesVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ void MatrixTimesVector::prepare() {

int MatrixTimesVector::checkTaskIsActive( const unsigned& itask ) const {
if( getPntrToArgument(1)->getRank()==1 ) {
ActionWithMatrix* am=dynamic_cast<ActionWithMatrix*>( getPntrToArgument(0)->getPntrToAction() );
plumed_assert( am ); return am->checkTaskIsActive(itask);
ActionWithMatrix* am=dynamic_cast<ActionWithMatrix*>( getPntrToArgument(0)->getPntrToAction() );
plumed_assert( am ); return am->checkTaskIsActive(itask);
} else {
unsigned n=getNumberOfArguments()-1;
for(unsigned i=0; i<n; ++i) {
ActionWithMatrix* am=dynamic_cast<ActionWithMatrix*>( getPntrToArgument(i)->getPntrToAction() );
plumed_assert( am ); if( am->checkTaskIsActive(itask)>0 ) return 1;
}
unsigned n=getNumberOfArguments()-1;
for(unsigned i=0; i<n; ++i) {
ActionWithMatrix* am=dynamic_cast<ActionWithMatrix*>( getPntrToArgument(i)->getPntrToAction() );
plumed_assert( am ); if( am->checkTaskIsActive(itask)>0 ) return 1;
}
}
}

Check failure

Code scanning / CodeQL

Missing return statement Error

Function checkTaskIsActive should return a value of type int but does not return a value here

Expand Down
10 changes: 5 additions & 5 deletions src/symfunc/CoordinationNumbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ CoordinationNumbers::CoordinationNumbers(const ActionOptions& ao):
readInputLine( getShortcutLabel() + ": MATRIX_VECTOR_PRODUCT ARG=" + matlab + "," + getShortcutLabel() + "_ones");
std::vector<std::string> moments; parseVector("MOMENTS",moments); Tools::interpretRanges( moments );
if( moments.size()>0 ) {
readInputLine( getShortcutLabel() + "_caverage: MEAN ARG=" + getShortcutLabel() + " PERIODIC=NO");
for(unsigned i=0; i<moments.size(); ++i) {
readInputLine( getShortcutLabel() + "_diffpow-" + moments[i] + ": CUSTOM ARG=" + getShortcutLabel() + "," + getShortcutLabel() + "_caverage PERIODIC=NO FUNC=(x-y)^" + moments[i] );
readInputLine( getShortcutLabel() + "_moment-" + moments[i] + ": MEAN ARG=" + getShortcutLabel() + "_diffpow-" + moments[i] + " PERIODIC=NO");
}
readInputLine( getShortcutLabel() + "_caverage: MEAN ARG=" + getShortcutLabel() + " PERIODIC=NO");
for(unsigned i=0; i<moments.size(); ++i) {
readInputLine( getShortcutLabel() + "_diffpow-" + moments[i] + ": CUSTOM ARG=" + getShortcutLabel() + "," + getShortcutLabel() + "_caverage PERIODIC=NO FUNC=(x-y)^" + moments[i] );
readInputLine( getShortcutLabel() + "_moment-" + moments[i] + ": MEAN ARG=" + getShortcutLabel() + "_diffpow-" + moments[i] + " PERIODIC=NO");
}
}
// Read in all the shortcut stuff
std::map<std::string,std::string> keymap; multicolvar::MultiColvarShortcuts::readShortcutKeywords( keymap, this );
Expand Down

1 comment on commit 59b2212

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/ANGLES.tmp
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/CAVITY.tmp
Found broken examples in automatic/CLASSICAL_MDS.tmp
Found broken examples in automatic/CLUSTER_DIAMETER.tmp
Found broken examples in automatic/CLUSTER_DISTRIBUTION.tmp
Found broken examples in automatic/CLUSTER_PROPERTIES.tmp
Found broken examples in automatic/CONSTANT.tmp
Found broken examples in automatic/CONTACT_MATRIX.tmp
Found broken examples in automatic/CONTACT_MATRIX_PROPER.tmp
Found broken examples in automatic/COORDINATIONNUMBER.tmp
Found broken examples in automatic/DFSCLUSTERING.tmp
Found broken examples in automatic/DISTANCE_FROM_CONTOUR.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FIND_CONTOUR.tmp
Found broken examples in automatic/FIND_CONTOUR_SURFACE.tmp
Found broken examples in automatic/FIND_SPHERICAL_CONTOUR.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/GPROPERTYMAP.tmp
Found broken examples in automatic/HBOND_MATRIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/INCYLINDER.tmp
Found broken examples in automatic/INENVELOPE.tmp
Found broken examples in automatic/INTERPOLATE_GRID.tmp
Found broken examples in automatic/LOCAL_AVERAGE.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/METATENSOR.tmp
Found broken examples in automatic/MULTICOLVARDENS.tmp
Found broken examples in automatic/OUTPUT_CLUSTER.tmp
Found broken examples in automatic/PAMM.tmp
Found broken examples in automatic/PCA.tmp
Found broken examples in automatic/PCAVARS.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in automatic/PYCVINTERFACE.tmp
Found broken examples in automatic/PYTHONFUNCTION.tmp
Found broken examples in automatic/Q3.tmp
Found broken examples in automatic/Q4.tmp
Found broken examples in automatic/Q6.tmp
Found broken examples in automatic/QUATERNION.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_LINEAR_PROJ.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_MAHA_DIST.tmp
Found broken examples in automatic/SPRINT.tmp
Found broken examples in automatic/TETRAHEDRALPORE.tmp
Found broken examples in automatic/TORSIONS.tmp
Found broken examples in automatic/WHAM_WEIGHTS.tmp
Found broken examples in AnalysisPP.md
Found broken examples in CollectiveVariablesPP.md
Found broken examples in MiscelaneousPP.md

Please sign in to comment.