/** Dimensionality check during initialization */ bool dimCheck(){ if( Sx_.rows() != Sx_.cols() ){ std::cerr << "Error: MatType must be a square matrix \n"; return false; } if( Sx_.rows() != x_.size() ){ std::cerr << "Error: VecType and MatType dimension mismatch \n"; return false; } nDim_ = x_.size(); return true; }
inline typename VecType::value_type entry_or_zero(const VecType &v, unsigned i) { if (i >= v.size()) return 0; else return v[i]; }
PartialVolumeAnalysisClusteringCalculator::ClusterResultType PartialVolumeAnalysisClusteringCalculator::CalculateCurves(ParamsType params, VecType xVals) const { int arraysz = xVals.size(); ClusterResultType result(arraysz); for( int j=0; j<2; j++) { for(int i=0; i<arraysz; i++) { double d = xVals(i)-params.means[j]; double amp = params.ps[j]/sqrt(2*PVA_PI*params.sigmas[j]); result.vals[j](i) = amp*exp(-0.5 * (d*d)/params.sigmas[j]); } } for(int i=0; i<arraysz; i++) { result.mixedVals[0](i) = 0; } for(double t=0; t<=1; t = t + 1.0/(m_StepsNumIntegration-1.0)) { for(int i=0; i<arraysz; i++) { double d = xVals(i)-(t*params.means[0]+(1-t)*params.means[1]); double v = t*params.sigmas[0]+(1-t)*params.sigmas[1]; double p = 1.0 - params.ps[0] - params.ps[1]; double amp = (1.0/m_StepsNumIntegration) * p / sqrt(2.0*PVA_PI*v); result.mixedVals[0](i) = result.mixedVals[0](i) + amp*exp(-0.5 * (d*d)/v); // MITK_INFO << "d=" << d << "v=" <<v << "p=" << p << "amp=" << amp << "result=" << amp*exp(-0.5 * (d*d)/v) << std::endl; } // MITK_INFO << "t=" << t << std::endl; // params.Print(); // result.Print(); } for(int i=0; i<arraysz; i++) { result.combiVals(i) = result.mixedVals[0](i) + result.vals[0](i) + result.vals[1](i); } return result; }
inline void setVec(DblVec& x, const VarVector& vars, const VecType& vals) { assert(vars.size() == vals.size()); for (int i = 0; i < vars.size(); ++i) { x[vars[i].var_rep->index] = vals[i]; } }
bool Legalizer::runOnMachineFunction(MachineFunction &MF) { // If the ISel pipeline failed, do not bother running that pass. if (MF.getProperties().hasProperty( MachineFunctionProperties::Property::FailedISel)) return false; DEBUG(dbgs() << "Legalize Machine IR for: " << MF.getName() << '\n'); init(MF); const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>(); MachineOptimizationRemarkEmitter MORE(MF, /*MBFI=*/nullptr); LegalizerHelper Helper(MF); // FIXME: an instruction may need more than one pass before it is legal. For // example on most architectures <3 x i3> is doubly-illegal. It would // typically proceed along a path like: <3 x i3> -> <3 x i8> -> <8 x i8>. We // probably want a worklist of instructions rather than naive iterate until // convergence for performance reasons. bool Changed = false; MachineBasicBlock::iterator NextMI; using VecType = SmallSetVector<MachineInstr *, 8>; VecType WorkList; VecType CombineList; for (auto &MBB : MF) { for (auto MI = MBB.begin(); MI != MBB.end(); MI = NextMI) { // Get the next Instruction before we try to legalize, because there's a // good chance MI will be deleted. NextMI = std::next(MI); // Only legalize pre-isel generic instructions: others don't have types // and are assumed to be legal. if (!isPreISelGenericOpcode(MI->getOpcode())) continue; unsigned NumNewInsns = 0; WorkList.clear(); CombineList.clear(); Helper.MIRBuilder.recordInsertions([&](MachineInstr *MI) { // Only legalize pre-isel generic instructions. // Legalization process could generate Target specific pseudo // instructions with generic types. Don't record them if (isPreISelGenericOpcode(MI->getOpcode())) { ++NumNewInsns; WorkList.insert(MI); CombineList.insert(MI); } }); WorkList.insert(&*MI); LegalizerCombiner C(Helper.MIRBuilder, MF.getRegInfo(), Helper.getLegalizerInfo()); bool Changed = false; LegalizerHelper::LegalizeResult Res; do { assert(!WorkList.empty() && "Expecting illegal ops"); while (!WorkList.empty()) { NumNewInsns = 0; MachineInstr *CurrInst = WorkList.pop_back_val(); Res = Helper.legalizeInstrStep(*CurrInst); // Error out if we couldn't legalize this instruction. We may want to // fall back to DAG ISel instead in the future. if (Res == LegalizerHelper::UnableToLegalize) { Helper.MIRBuilder.stopRecordingInsertions(); if (Res == LegalizerHelper::UnableToLegalize) { reportGISelFailure(MF, TPC, MORE, "gisel-legalize", "unable to legalize instruction", *CurrInst); return false; } } Changed |= Res == LegalizerHelper::Legalized; // If CurrInst was legalized, there's a good chance that it might have // been erased. So remove it from the Combine List. if (Res == LegalizerHelper::Legalized) CombineList.remove(CurrInst); #ifndef NDEBUG if (NumNewInsns) for (unsigned I = WorkList.size() - NumNewInsns, E = WorkList.size(); I != E; ++I) DEBUG(dbgs() << ".. .. New MI: " << *WorkList[I];); #endif } // Do the combines. while (!CombineList.empty()) { NumNewInsns = 0; MachineInstr *CurrInst = CombineList.pop_back_val(); SmallVector<MachineInstr *, 4> DeadInstructions; Changed |= C.tryCombineInstruction(*CurrInst, DeadInstructions); for (auto *DeadMI : DeadInstructions) { DEBUG(dbgs() << ".. Erasing Dead Instruction " << *DeadMI); CombineList.remove(DeadMI); WorkList.remove(DeadMI); DeadMI->eraseFromParent(); } #ifndef NDEBUG if (NumNewInsns) for (unsigned I = CombineList.size() - NumNewInsns, E = CombineList.size(); I != E; ++I) DEBUG(dbgs() << ".. .. Combine New MI: " << *CombineList[I];); #endif } } while (!WorkList.empty()); Helper.MIRBuilder.stopRecordingInsertions(); }
void writeGlobalArray(std::ostream& os, const string& prefix, const VecType& g) { for (size_t i = 0; i < g.size(); ++i) { os << prefix << g[i].type << " " << g[i].name << ";\n"; } }