Skip to content

Commit

Permalink
Merge pull request #1677 from veg/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
stevenweaver committed Jan 9, 2024
2 parents 443d204 + c851484 commit 6674e21
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 160 deletions.
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ set_source_files_properties(${SRC_CORE} ${SRC_NEW} {SRC_UTILS} PROPERTIES COMPIL

set(DEFAULT_WARNING_FLAGS " -w -Weffc++ -Wextra -Wall ")
set(DEFAULT_DEBUG_WARNING_FLAGS "-Wall -Wno-int-to-pointer-cast -Wno-conversion-null -Wno-sign-compare")
set(ADDITIONAL_FLAGS "")

if (DEBUGFLAGS)
set(ADDITIONAL_FLAGS "-g")
endif()


if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
Expand Down Expand Up @@ -289,7 +293,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")

#set(DEFAULT_COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS} -fopt-info -fopt-info-vec-missed")
set(DEFAULT_COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS}")
set(DEFAULT_COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS} ${ADDITIONAL_FLAGS}")

if(NOT DEFINED DEFAULT_COMPILE_FLAGS)
set(DEFAULT_COMPILE_FLAGS "")
Expand All @@ -299,7 +303,7 @@ if(NOT DEFINED DEFAULT_LINK_FLAGS)
set(DEFAULT_LINK_FLAGS "")
endif(NOT DEFINED DEFAULT_LINK_FLAGS)

set(DEFAULT_LINK_FLAGS "${DEFAULT_LINK_FLAGS} ")
set(DEFAULT_LINK_FLAGS "${DEFAULT_LINK_FLAGS} ${ADDITIONAL_FLAGS}")

if(NOT DEFINED DEFAULT_WARNING_FLAGS)
set(DEFAULT_WARNING_FLAGS "")
Expand All @@ -309,7 +313,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(DEFAULT_COMPILE_FLAGS "${DEFAULT_COMPILE_FLAGS} -fwasm-exceptions ")
endif()

MESSAGE ("Set default compiler flags to ${DEFAULT_COMPILE_FLAGS}")
MESSAGE ("Set compiler flags to ${DEFAULT_COMPILE_FLAGS}")
MESSAGE ("Set linker flags to ${DEFAULT_LINK_FLAGS}")

#-------------------------------------------------------------------------------
# OpenMP support
Expand Down
2 changes: 1 addition & 1 deletion res/TemplateBatchFiles/SelectionAnalyses/FADE.bf
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ for (fade.residue = 0; fade.residue < 20; fade.residue += 1) {

LikelihoodFunction fade.lf = (fade.lf.components);
estimators.ApplyExistingEstimates ("fade.lf", fade.model_id_to_object, fade.baseline_fit, None);

fade.conditionals.raw = fade.ComputeOnGrid ("fade.lf",
fade.grid.MatrixToDict (fade.cache[terms.fade.cache.grid]),
"fade.pass2.evaluator",
Expand Down
12 changes: 10 additions & 2 deletions res/TemplateBatchFiles/SelectionAnalyses/MEME.bf
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,15 @@ for (meme.partition_index = 0; meme.partition_index < meme.partition_count; meme

SetParameter (DEFER_CONSTRAINT_APPLICATION, 1, 0);

utility.ToggleEnvVariable ("LOOP_TREE_ITERATOR_PREORDER", TRUE);

is_root = TRUE;

for (_node_; in; meme.site_tree_fel) {
if (is_root) {
is_root = FALSE;
continue;
}
_bl_ = ((meme.final_partitioned_mg_results[terms.branch_length])[meme.partition_index])[_node_];
_node_class_ = (meme.selected_branches[meme.partition_index])[_node_];
if (_node_class_ != terms.tree_attributes.test) {
Expand All @@ -669,10 +677,10 @@ for (meme.partition_index = 0; meme.partition_index < meme.partition_count; meme
meme.apply_site_constraints ("meme.site_tree_bsrel",_node_,_bl_,meme.scaler_mapping ['FG']);
meme.apply_site_constraints ("meme.site_tree_fel",_node_,_bl_,meme.scaler_mapping ['FEL-FG']);
}


}

utility.ToggleEnvVariable ("LOOP_TREE_ITERATOR_PREORDER", None);


SetParameter (DEFER_CONSTRAINT_APPLICATION, 0, 0);

Expand Down
24 changes: 22 additions & 2 deletions res/TemplateBatchFiles/SelectionAnalyses/error-filter.bf
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ if (efilter.error_sink_proportion == 0) {
}
efilter.error_sink_prior_odds_ratio = Min (1e25,efilter.error_sink_proportion / efilter.fast_omega_proportion);

efilter.verbose_logging = utility.GetEnvVariable ("VERBOSE_LOGGING");

efilter.site_offset = 0;

utility.ToggleEnvVariable ("LOOP_TREE_ITERATOR_PREORDER", TRUE);



for (p = 0; p < efilter.input[terms.json.partition_count]; p+=1) {
efilter.sequences = {};
efilter.masked_sites = {};
Expand Down Expand Up @@ -175,6 +179,19 @@ for (p = 0; p < efilter.input[terms.json.partition_count]; p+=1) {
efilter.site_BF2 = 1e25;
}

if (efilter.verbose_logging ) {
if (efilter.site_BF >= efilter.threshold || efilter.site_BF2 >= efilter.ratio_threshold) {
if (efilter.site_BF >= efilter.threshold && efilter.site_BF2 >= efilter.ratio_threshold) {
fprintf (stdout, "FILTERED\n");
} else {
fprintf (stdout, "KEPT\n");
}
fprintf (stdout, ">" + (site+1) + "/" + node, " " + efilter.site_BF + ":" +efilter.site_BF2 + "\n");

}
}


if (efilter.site_BF >= efilter.threshold && efilter.site_BF2 >= efilter.ratio_threshold) {
if (efilter.masked_sites/node) { // terminal node
if (efilter.masked_already [ntm] != 1) {
Expand All @@ -189,12 +206,15 @@ for (p = 0; p < efilter.input[terms.json.partition_count]; p+=1) {
if (efilter.masked_already [ntm] != 1) {
efilter.masked_sites [ntm] + (site + efilter.site_offset);
}
}
//console.log ("Masking everything " + site + " " + node + " " + Abs (efilter.leaf_descendants) / Abs (efilter.sequences));
}
if (efilter.verbose_logging) {}
console.log ("Masking everything " + site + " " + node + " " + Abs (efilter.leaf_descendants) / Abs (efilter.sequences));
}
break;
}
for (ntm, ignore; in; efilter.leaf_descendants[node]) {
efilter.write_out[ntm] = "---";
//console.log ("Masking child " + ntm + " of parent " + node + " at site " + (1+site));
if (efilter.masked_already [ntm] != 1) {
efilter.masked_sites [ntm] + (site + efilter.site_offset);
}
Expand Down
176 changes: 96 additions & 80 deletions src/core/formula.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2309,15 +2309,26 @@ bool _Formula::ConvertToSimple (_AVLList& variable_index) {
delete [] simpleExpressionStatus;
simpleExpressionStatus = nil;
}

theStack.Reset();
long available_slots = MIN (32, sizeof (long) * MEMORYSTEP / sizeof (hyFloat));
long used_float_slots = 0;
hyFloat * store_constant = (hyFloat*)theStack.theStack._getStatic();

if (!theFormula.empty()) {

simpleExpressionStatus = new long [theFormula.countitems()];

for (unsigned long i=0UL; i<theFormula.countitems(); i++) {
_Operation* this_op = ItemAt (i);
simpleExpressionStatus[i] = -4L;
simpleExpressionStatus[i] = -64L;
if (this_op->theNumber) {
simpleExpressionStatus[i] = -1L;
if (used_float_slots < available_slots) {
store_constant [used_float_slots++] = this_op->theNumber->Value();
simpleExpressionStatus[i] = -1L - used_float_slots;
} else {
simpleExpressionStatus[i] = -1L;
}
} else if (this_op->theData >= 0) {
this_op->theData = variable_index.FindLong (this_op->theData);
simpleExpressionStatus[i] = this_op->theData;
Expand All @@ -2331,8 +2342,10 @@ bool _Formula::ConvertToSimple (_AVLList& variable_index) {
this_op->numberOfTerms = -3;
}
}
if (this_op->opCode == HY_OP_CODE_RANDOM || this_op->opCode == HY_OP_CODE_TIME)

if (this_op->opCode == HY_OP_CODE_RANDOM || this_op->opCode == HY_OP_CODE_TIME) {
has_volatiles = true;
}

if (this_op->numberOfTerms == 2) {
switch (this_op->opCode) {
Expand Down Expand Up @@ -2393,95 +2406,98 @@ hyFloat _Formula::ComputeSimple (_SimpleFormulaDatum* stack, _SimpleFormulaDatum
if (theFormula.nonempty()) {
long stackTop = 0;
unsigned long upper_bound = NumberOperations();


const hyFloat * constants = (hyFloat*)theStack.theStack._getStatic();

for (unsigned long i=0UL; i<upper_bound; i++) {

if (simpleExpressionStatus[i] == -1L) {
stack[stackTop++].value = ItemAt (i)->theNumber->Value();
/*if (thisOp->theNumber) {
stack[stackTop++].value = thisOp->theNumber->Value();
continue;*/
if (simpleExpressionStatus[i] >= 0L) {
stack[stackTop++] = varValues[simpleExpressionStatus[i]];
} else {
if (simpleExpressionStatus[i] >= 0) {
stack[stackTop++] = varValues[simpleExpressionStatus[i]];
if (simpleExpressionStatus[i] <= -2L && simpleExpressionStatus[i] >= -32L) {
stack[stackTop++].value = constants[-simpleExpressionStatus[i] - 2L];
} else {
if (simpleExpressionStatus[i] <= -10000L) {
stackTop--;
switch (-simpleExpressionStatus[i] - 10000L) {
case HY_OP_CODE_ADD:
stack[stackTop-1].value = stack[stackTop-1].value + stack[stackTop].value;
break;
case HY_OP_CODE_SUB:
stack[stackTop-1].value = stack[stackTop-1].value - stack[stackTop].value;
break;
case HY_OP_CODE_MUL:
stack[stackTop-1].value = stack[stackTop-1].value * stack[stackTop].value;
break;
case HY_OP_CODE_DIV:
stack[stackTop-1].value = stack[stackTop-1].value / stack[stackTop].value;
break;
case HY_OP_CODE_POWER: {
//stack[stackTop-1].value = pow (stack[stackTop-1].value, stack[stackTop].value);

if (stack[stackTop-1].value==0.0) {
if (stack[stackTop].value > 0.0) {
return 0.0;
} else {
return 1.0;
}
}
stack[stackTop-1].value = pow (stack[stackTop-1].value, stack[stackTop].value);

break;
}
default:
HandleApplicationError ("Internal error in _Formula::ComputeSimple - unsupported shortcut operation.)", true);
return 0.0;
}
if (simpleExpressionStatus[i] == -1L) {
stack[stackTop++].value = ((_Operation**)theFormula.list_data)[i]->theNumber->Value();
} else {
_Operation const* thisOp = ItemAt (i);
stackTop--;
if (thisOp->numberOfTerms==2) {
hyFloat (*theFunc) (hyFloat, hyFloat);
theFunc = (hyFloat(*)(hyFloat,hyFloat))thisOp->opCode;
if (stackTop<1L) {
HandleApplicationError ("Internal error in _Formula::ComputeSimple - stack underflow.)", true);
return 0.0;
if (simpleExpressionStatus[i] <= -10000L) {
stackTop--;
switch (-simpleExpressionStatus[i] - 10000L) {
case HY_OP_CODE_ADD:
stack[stackTop-1].value = stack[stackTop-1].value + stack[stackTop].value;
break;
case HY_OP_CODE_SUB:
stack[stackTop-1].value = stack[stackTop-1].value - stack[stackTop].value;
break;
case HY_OP_CODE_MUL:
stack[stackTop-1].value = stack[stackTop-1].value * stack[stackTop].value;
break;
case HY_OP_CODE_DIV:
stack[stackTop-1].value = stack[stackTop-1].value / stack[stackTop].value;
break;
case HY_OP_CODE_POWER: {
//stack[stackTop-1].value = pow (stack[stackTop-1].value, stack[stackTop].value);

if (stack[stackTop-1].value==0.0) {
if (stack[stackTop].value > 0.0) {
return 0.0;
} else {
return 1.0;
}
}
stack[stackTop-1].value = pow (stack[stackTop-1].value, stack[stackTop].value);

break;
}
default:
HandleApplicationError ("Internal error in _Formula::ComputeSimple - unsupported shortcut operation.)", true);
return 0.0;
}
stack[stackTop-1].value = (*theFunc)(stack[stackTop-1].value,stack[stackTop].value);
} else {
switch (thisOp->numberOfTerms) {
case -2 : {
hyFloat (*theFunc) (hyPointer,hyFloat);
theFunc = (hyFloat(*)(hyPointer,hyFloat))thisOp->opCode;
_Operation const* thisOp = ItemAt (i);
stackTop--;
if (thisOp->numberOfTerms==2) {
hyFloat (*theFunc) (hyFloat, hyFloat);
theFunc = (hyFloat(*)(hyFloat,hyFloat))thisOp->opCode;
if (stackTop<1L) {
HandleApplicationError ("Internal error in _Formula::ComputeSimple - stack underflow.)", true);
return 0.0;
}
stack[stackTop-1].value = (*theFunc)(stack[stackTop-1].reference,stack[stackTop].value);
break;
}
case -3 : {
void (*theFunc) (hyPointer,hyFloat,hyFloat);
theFunc = (void(*)(hyPointer,hyFloat,hyFloat))thisOp->opCode;
if (stackTop != 2 || i != theFormula.lLength - 1) {
HandleApplicationError ("Internal error in _Formula::ComputeSimple - stack underflow or MCoord command is not the last one.)", true);

return 0.0;
}
//stackTop = 0;
// value, reference, index
(*theFunc)(stack[1].reference,stack[2].value, stack[0].value);
break;
}
default: {
hyFloat (*theFunc) (hyFloat);
theFunc = (hyFloat(*)(hyFloat))thisOp->opCode;
stack[stackTop].value = (*theFunc)(stack[stackTop].value);
++stackTop;
stack[stackTop-1].value = (*theFunc)(stack[stackTop-1].value,stack[stackTop].value);
} else {
switch (thisOp->numberOfTerms) {
case -2 : {
hyFloat (*theFunc) (hyPointer,hyFloat);
theFunc = (hyFloat(*)(hyPointer,hyFloat))thisOp->opCode;
if (stackTop<1L) {
HandleApplicationError ("Internal error in _Formula::ComputeSimple - stack underflow.)", true);
return 0.0;
}
stack[stackTop-1].value = (*theFunc)(stack[stackTop-1].reference,stack[stackTop].value);
break;
}
case -3 : {
void (*theFunc) (hyPointer,hyFloat,hyFloat);
theFunc = (void(*)(hyPointer,hyFloat,hyFloat))thisOp->opCode;
if (stackTop != 2 || i != theFormula.lLength - 1) {
HandleApplicationError ("Internal error in _Formula::ComputeSimple - stack underflow or MCoord command is not the last one.)", true);

return 0.0;
}
//stackTop = 0;
// value, reference, index
(*theFunc)(stack[1].reference,stack[2].value, stack[0].value);
break;
}
default: {
hyFloat (*theFunc) (hyFloat);
theFunc = (hyFloat(*)(hyFloat))thisOp->opCode;
stack[stackTop].value = (*theFunc)(stack[stackTop].value);
++stackTop;
}
}

}
}

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/global_things.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace hy_global {
kErrorStringMatrixExportError ("Export matrix called with a non-polynomial matrix argument"),
kErrorStringNullOperand ("Attempting to operate on an undefined value; this is probably the result of an earlier 'soft' error condition"),
kErrorNumerical ("To treat numerical errors as warnings, please specify \"ENV=TOLERATE_NUMERICAL_ERRORS=1;\" as the command line argument. This often resolves the issue, which is indicative of numerical instability."),
kHyPhyVersion = _String ("2.5.58"),
kHyPhyVersion = _String ("2.5.59"),

kNoneToken = "None",
kNullToken = "null",
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/formula.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class _Formula {
_List* resultCache;
_Stack theStack;
_List theFormula;
long* simpleExpressionStatus;
long* simpleExpressionStatus;
/**
SLKP: 20200924
Added this shorthand to improve memory locality and speed-up SimpleCompute performance
Expand Down
1 change: 1 addition & 0 deletions src/core/include/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct _CompiledMatrixData {
hyFloat * formulaValues;

long * formulaRefs;
long stackDepth;
bool has_volatile_entries;

_SimpleList varIndex,
Expand Down

0 comments on commit 6674e21

Please sign in to comment.