void Test_ScheduleTasks(TestResult *result) { char buffer[80]; sprintf(buffer, "For %s, RECUR_N=%d and NUM_TASKS=%d\n" "RUN_IN_PARALLEL=%d, ", GetTestModeString(TEST_MODE).c_str(), RECUR_N, NUM_TASKS, RUN_IN_PARALLEL); result->overall += std::string(buffer); std::vector<int> data_vec; // own the memory. // Comment the line below will make the job crash due to address // change during container's memory reallocation. See comment on // top of this file. data_vec.reserve(NUM_TASKS); TaskManager task_manager; ScheduleTasks(NUM_TASKS, &data_vec, &task_manager); result->details += (GetNowString() + " Before: " + PrintVector(data_vec) + "\n"); CpuTimer timer; timer.Start(); task_manager.Run(); timer.Stop(); result->details += (GetNowString() + " After: " + PrintVector(data_vec) + "\n"); sprintf(buffer, "total in ms: %d\n", timer.GetInMs()); result->overall += std::string(buffer); result->cost_in_ms = timer.GetInMs(); }
void Saliency::Evaluate(const string gtImgsW, const string &salDir, const string &resName) { vector<vecD> prec(SAL_TYPE_NUM), recall(SAL_TYPE_NUM); static const int SHOW_COLOR_NUM = 7; static const char* colorShow[SHOW_COLOR_NUM] = {"'k'", "'b'", "'g'", "'r'", "'c'", "'m'", "'y'"}; FILE* f = fopen(resName.c_str(), "w"); CV_Assert(f != NULL); fprintf(f, "clear;\nclose all;\nclc;\nhold on;\nfigure(1);\n\n"); #pragma omp parallel for for (int i = 0; i < SAL_TYPE_NUM; i++) Evaluate(salDir + "*" + SAL_TYPE_DES[i] + ".png", gtImgsW, prec[i], recall[i]); string leglendStr("legend("); for (int i = 0; i < SAL_TYPE_NUM; i++) { string strPre = format("Precision%s", SAL_TYPE_DES[i]); string strRecal = format("Recall%s", SAL_TYPE_DES[i]); int dim = PrintVector(f, recall[i], strRecal); PrintVector(f, prec[i], strPre, dim); fprintf(f, "plot(%s, %s, %s, 'linewidth', 2);\n\n", strRecal.c_str(), strPre.c_str(), colorShow[i % SHOW_COLOR_NUM]); leglendStr += format("'%s', ", SAL_TYPE_DES[i] + 1); } leglendStr.resize(leglendStr.size() - 2); leglendStr += ");"; fprintf(f, "hold off;\nxlabel('Recall');\nylabel('Precision');\n\n%s\ngrid on;\n", leglendStr.c_str()); fprintf(f, "\n\nfigure(2);hold on;\n"); for (int i = 0; i < SAL_TYPE_NUM; i++) fprintf(f, "plot(Recall%s, %s, 'linewidth', 2);\n", SAL_TYPE_DES[i], colorShow[i % SHOW_COLOR_NUM]); fprintf(f, "%s\nhold off;\nxlabel('Threshold');\nylabel('Recall');\ngrid on;", leglendStr.c_str()); fclose(f); CmLog::LogProgress("Evaluation finished%-40s\n", ""); }
void Objectness::illustrate() { Mat xP1f, xN1f; CV_Assert(matRead(_modelName + ".xP", xP1f) && matRead(_modelName + ".xN", xN1f)); CV_Assert(xP1f.cols == xN1f.cols && xP1f.cols == _W*_W && xP1f.type() == CV_32F && xN1f.type() == CV_32F); Mat meanP, meanN, stdDevP, stdDevN; meanStdDev(xP1f, meanP, stdDevP); meanStdDev(xN1f, meanN, stdDevN); Mat meanV(_W, _W*2, CV_32F), stdDev(_W, _W*2, CV_32F); meanP.reshape(1, _W).copyTo(meanV.colRange(0, _W)); meanN.reshape(1, _W).copyTo(meanV.colRange(_W, _W*2)); stdDevP.reshape(1, _W).copyTo(stdDev.colRange(0, _W)); stdDevN.reshape(1, _W).copyTo(stdDev.colRange(_W, _W*2)); normalize(meanV, meanV, 0, 255, NORM_MINMAX, CV_8U); CmShow::showTinyMat(_voc.resDir + "PosNeg.png", meanV); FILE* f = fopen(_S(_voc.resDir + "PosNeg.m"), "w"); CV_Assert(f != NULL); fprintf(f, "figure(1);\n\n"); PrintVector(f, getVector(meanP), "MeanP"); PrintVector(f, getVector(meanN), "MeanN"); PrintVector(f, getVector(stdDevP), "StdDevP"); PrintVector(f, getVector(stdDevN), "StdDevN"); PrintVector(f, getVector(_svmFilter), "Filter"); fprintf(f, "hold on;\nerrorbar(MeanP, StdDevP, 'r');\nerrorbar(MeanN, StdDevN, 'g');\nhold off;"); fclose(f); }
// Dump cube state void Cube::Dump(void) { PrintVector(CornerCubiePermutations, NumberOfCornerCubies); PrintVector(CornerCubieOrientations, NumberOfCornerCubies); PrintVector(EdgeCubiePermutations, NumberOfEdgeCubies); PrintVector(EdgeCubieOrientations, NumberOfEdgeCubies); }
void Problem_4( ) { // create file io::create( "Hector Medina", "problem4.txt" ); // Original data Vect *p = &V[0]; fprintf(io::getHandle(),"original\n"); for( int i = 0; i < 11; i++) { fprintf(io::getHandle()," V[%2d]: %d %d %d \n", i, p->a, p->b, p->c ); p++; } // a) Load the V[] data into a vector // print it to the file (begin to end) order std::vector<Vect> Vect_V(V,V+11); PrintVector("stl: vector",Vect_V); // b) Sort the new STL vector with strict weak ordering // print it to the file (begin to end) order std::sort(Vect_V.begin(),Vect_V.end()); PrintVector("stl: strict weak ordering", Vect_V); // bye bye fprintf(io::getHandle(),"\n"); io::destroy(); }
void handle_ANALOG(RF24NetworkHeader& header, short index_node, byte mode) { uint8_t command_rx[34]; uint8_t j, Ndata_received; uint8_t analog_pins[num_analog_pins]; //{2, 3}; uint16_t analog_states[num_analog_pins]; if (header.from_node == 00) //nothing if base return; if (index_node == -1) index_node = add_nodeFlash(header.from_node); //if index = -1, then add the node in the table and extract the new index // The 'T' message is just a ulong, containing the time network.read(header, command_rx, 32); // printf_P(PSTR("BASE has received ANALOG DATA from 0%o\n\r"), header.from_node); //command_rx[1] --> number of received data (1 data = 8 bit) Ndata_received = command_rx[1]; SystemNRF24LPins[index_node].ana_num = Ndata_received / 2; //16 bits if (mode == 0) { copyArray(command_rx, (uint8_t *)analog_states, 2, Ndata_received); //analog_states 16 bits IF_SERIAL_DEBUG_NRF(printf_P(PSTR("ANALOG VALUES, node: 0%o, index: %d, data:"), header.from_node, index_node)); IF_SERIAL_DEBUG_NRF(PrintVector(analog_states, Ndata_received / 2)); #if DEBUG_SERIAL_NRF24L == 1 float vcc_remote = ((float) SystemNRF24LPins[index_node].Supply) / 1000.0; Serial.print("Remote batt voltage: "); Serial.print(vcc_remote, 2); Serial.println("V"); #endif for (j = 0; j < Ndata_received / 2; j++) SystemNRF24LPins[index_node].AnaPin[j].state = analog_states[j]; } else if (mode == 1) { copyArray(command_rx, analog_pins, 2, Ndata_received); //analog_pins 8 bits IF_SERIAL_DEBUG_NRF(printf_P(PSTR("ANALOG PIN POSITION, node: 0%o, index: %d, data:"), header.from_node, index_node)); IF_SERIAL_DEBUG_NRF(PrintVector(analog_pins, Ndata_received)); SystemNRF24LPins[index_node].RNF24LAddr = header.from_node; for (j = 0; j < Ndata_received; j++) { SystemNRF24LPins[index_node].AnaPin[j].pin = analog_pins[j]; SystemNRF24LPins[index_node].AnaPin[j].used = true; } } }
void PrintView( View v, std::ostream & out) { out << "steps=" << v.steps << std::endl; out << "bisect_count=" << v.bisect_count << std::endl; out << "surf=" << v.surf << "=" << SurfString(v.surf) << std::endl; PrintVector( v.starting_point, std::string("start").c_str(), out ); PrintVector( v.DirectionVector, std::string("dirVec").c_str(), out ); PrintVector( v.angle, std::string("angle").c_str(), out ); out << "scale=" << v.scale << std::endl; out << "distance=" << v.distance << std::endl; }
void Objectness::evaluatePerImgRecall(const vector<vector<Vec4i> > &boxesTests, CStr &saveName, const int NUM_WIN) { vecD recalls(NUM_WIN); vecD avgScore(NUM_WIN); const int TEST_NUM = _voc.testSet.size(); for (int i = 0; i < TEST_NUM; i++) { const vector<Vec4i> &boxesGT = _voc.gtTestBoxes[i]; const vector<Vec4i> &boxes = boxesTests[i]; const int gtNumCrnt = boxesGT.size(); vecI detected(gtNumCrnt); vecD score(gtNumCrnt); double sumDetected = 0, abo = 0; for (int j = 0; j < NUM_WIN; j++) { if (j >= (int)boxes.size()) { recalls[j] += sumDetected/gtNumCrnt; avgScore[j] += abo/gtNumCrnt; continue; } for (int k = 0; k < gtNumCrnt; k++) { double s = DataSetVOC::interUnio(boxes[j], boxesGT[k]); score[k] = max(score[k], s); detected[k] = score[k] >= 0.5 ? 1 : 0; } sumDetected = 0, abo = 0; for (int k = 0; k < gtNumCrnt; k++) sumDetected += detected[k], abo += score[k]; recalls[j] += sumDetected/gtNumCrnt; avgScore[j] += abo/gtNumCrnt; } } for (int i = 0; i < NUM_WIN; i++) { recalls[i] /= TEST_NUM; avgScore[i] /= TEST_NUM; } int idx[8] = {1, 10, 100, 1000, 2000, 3000, 4000, 5000}; for (int i = 0; i < 8; i++) { if (idx[i] > NUM_WIN) continue; printf("%d:%.3g,%.3g\t", idx[i], recalls[idx[i] - 1], avgScore[idx[i] - 1]); } printf("\n"); FILE* f = fopen(_S(_voc.resDir + saveName), "w"); CV_Assert(f != NULL); fprintf(f, "figure(1);\n\n"); PrintVector(f, recalls, "DR"); PrintVector(f, avgScore, "MABO"); fprintf(f, "semilogx(1:%d, DR(1:%d));\nhold on;\nsemilogx(1:%d, DR(1:%d));\naxis([1, 5000, 0, 1]);\nhold off;\n", NUM_WIN, NUM_WIN, NUM_WIN, NUM_WIN); fclose(f); }
void SelectPPCoincMapRegions::LoadSettings(ConfigEntry *dbentry) { ExtensibleDb *db = dbentry->GetExtensibleDb(); if (db==NULL) throw -1; db->GetValues("Pedestal",fPed); if (fPed.size()==0) throw -1; db->GetValues("Threshold",fThresh); if (fThresh.size()==0) throw -1; db->GetValues("LowCut",fLowCut); if (fLowCut.size()==0) throw -1; db->GetValues("HighCut",fHighCut); if (fHighCut.size()==0) throw -1; db->GetValues("LowCut2",fLowCut2); if (fLowCut2.size()==0) throw -1; db->GetValues("HighCut2",fHighCut2); if (fHighCut2.size()==0) throw -1; db->GetValues("LowCut3",fLowCut3); if (fLowCut3.size()==0) throw -1; db->GetValues("HighCut3",fHighCut3); if (fHighCut3.size()==0) throw -1; db->GetValues("LowTOFCut",fLowTOFCut); if (fLowTOFCut.size()==0) throw -1; db->GetValues("HighTOFCut",fHighTOFCut); if (fHighTOFCut.size()==0) throw -1; db->GetValues("PedThreshold",fPedThresh); if (fPedThresh.size()==0) throw -1; db->GetValues("GlobalUpperBound", fGlobalUpperBound); if (fGlobalUpperBound.size()==0) throw -1; #ifdef VERBOSE_SelectPPCoincMapRegions std::cout << std::setw(15) << "Pedestal" << ":"; PrintVector(fPed); std::cout << std::setw(15) << "Threshold" << ":"; PrintVector(fThresh); std::cout << std::setw(15) << "LowCut" << ":"; PrintVector(fLowCut); std::cout << std::setw(15) << "HighCut" << ":"; PrintVector(fHighCut); #endif }
void PP2d::LoadSettings(ConfigEntry *dbentry) { dbentry->GetExtensibleDb()->GetValues("Pedestal",fPed); dbentry->GetExtensibleDb()->GetValues("Threshold",fThresh); dbentry->GetExtensibleDb()->GetValues("LowCut",fLowCut); dbentry->GetExtensibleDb()->GetValues("HighCut",fHighCut); #ifdef VERBOSE_PROOFPLOT std::cout << std::setw(15) << "Pedestal" << ":"; PrintVector(fPed); std::cout << std::setw(15) << "Threshold" << ":"; PrintVector(fThresh); std::cout << std::setw(15) << "LowCut" << ":"; PrintVector(fLowCut); std::cout << std::setw(15) << "HighCut" << ":"; PrintVector(fHighCut); #endif }
/** Evaulate function at given X values and parameters. Calculate residual * from given Y values. */ void CurveFit::EvaluateFxn(Darray const& Xvals_, Darray const& Yvals_, Darray const& ParamsIn, Darray& residual) { Params_to_Pvec(fParms_, ParamsIn); PrintVector("Param", fParms_); fxn_(Xvals_, fParms_, finalY_); for (dsize im = 0; im != m_; im++) { // Residual residual[im] = finalY_[im] - Yvals_[im]; } // Apply weights for (dsize im = 0; im != Weights_.size(); im++) residual[im] *= Weights_[im]; PrintVector("Residual", residual); }
static int testVector(void) { int errors=0; Vector *AL = iVector.Create(sizeof(void *),10); char **p; iVector.SetCompareFunction(AL,compareStrings); iVector.Add(AL,&Table[0]); iVector.Insert(AL,&Table[1]); if (!iVector.Contains(AL,&Table[0],NULL)) { Abort(); } if (2 != iVector.Size(AL)) Abort(); iVector.InsertAt(AL,1,&Table[2]); iVector.InsertAt(AL,2,&Table[3]); if (4 != iVector.Size(AL)) Abort(); iVector.Erase(AL,&Table[1]); /*PrintVector(AL);*/ iVector.PushBack(AL,&Table[4]); /*PrintVector(AL);*/ iVector.PopBack(AL,NULL); /*PrintVector(AL);*/ p = iVector.GetElement(AL,1); printf("Item position 1:%s\n",*p); PrintVector(AL); return errors; }
//One Variable is 32bit void handle_VARIABLE(RF24NetworkHeader& header, short index_node, byte mode) { uint8_t command_rx[34]; uint8_t j, Ndata_received; float variable_states[NRF24LMaxVariable]; if (header.from_node == 00) //nothing if base return; if (index_node == -1) index_node = add_nodeFlash(header.from_node); //if index = -1, then add the node in the table and extract the new index // IF_SERIAL_DEBUG_NRF(printf_P(PSTR("Payload: %d \n\r"), radio.getPayloadSize())); network.read(header, command_rx, 32); Ndata_received = command_rx[1]; //IF_SERIAL_DEBUG_NRF(PrintVector(command_rx, Ndata_received+2)); SystemNRF24LPins[index_node].var_num = Ndata_received / 4; //32 bits copyArray(command_rx, (uint8_t *)variable_states, 2, Ndata_received); //analog_states 16 bits IF_SERIAL_DEBUG_NRF(printf_P(PSTR("VARIABLE VALUES, node: 0%o, index: %d, data:"), header.from_node, index_node)); IF_SERIAL_DEBUG_NRF(PrintVector(variable_states, Ndata_received / 4)); for (j = 0; j < Ndata_received / 4; j++) SystemNRF24LPins[index_node].VarPin[j].value = variable_states[j]; }
bool sendCommand (uint16_t to, unsigned char cmd, uint8_t *states, uint8_t num) { uint8_t tx_buffer[50]; radio.powerUp(); tx_buffer[0] = cmd; tx_buffer[1] = num; copyArray(states, tx_buffer + 2, 0, num); delay(100); RF24NetworkHeader header(/*to node*/ to, /*type*/ cmd /*Time*/); IF_SERIAL_DEBUG_NRF(printf_P(PSTR("---------------------------------\n\r"))); IF_SERIAL_DEBUG_NRF(printf_P(PSTR("SENSOR is sending to node 0%o...\n\r"), to)); bool ok = network.write(header, tx_buffer, num + 2); IF_SERIAL_DEBUG_NRF(PrintVector(tx_buffer, num + 2)); #if DEBUG_SERIAL_NRF24L == 1 if (ok) printf("Command ok\n\r"); else printf("Command failed\n\r"); // radio.powerDown(); #endif return (ok); }
int Mymain() { //vector<int> nums = {1, 2, 3, 4, 5, 6, 7, }; vector<int> nums = {1, 2, 3, 4, }; PrintVector(productExceptSelf(nums)); return 0; }
std::ostream & operator<<(std::ostream & ost, TRuleSequences const & s) { PrintVector(ost, s, [](RuleSequence const & r) { auto const sep = r.GetAnySeparator(); return (sep == "||" ? ' ' + sep + ' ' : sep + ' '); }); return ost; }
Matrix4 RPhysics::GetOrientTransform(Vector4 dirStart, Vector4 upStart1, Vector4 dirEnd, Vector4 upEnd1) { Vector4 temp = CrossProduct(dirStart,upStart1); Vector4 upStart = CrossProduct(temp,dirStart); temp = CrossProduct(dirEnd,upEnd1); Vector4 upEnd = CrossProduct(temp,dirEnd); dirStart = Normalize3(dirStart); dirEnd = Normalize3(dirEnd); upStart = Normalize3(upStart); upEnd = Normalize3(upEnd); Matrix4 transform; transform.Identity(); Vector4 axis1 = CrossProduct(dirStart,dirEnd); if(Length3(axis1)==0) axis1 = upEnd; float angle1 = Angle3(dirStart,dirEnd); Matrix4 rotMat; rotMat.Rotation(angle1,axis1); Vector4 newUp = rotMat*upStart; Vector4 axis2 = CrossProduct(newUp,upEnd); if(Length3(axis2)==0) axis2 = dirEnd; float angle2 = Angle3(upEnd,newUp); if(angle1*angle2*0!=0) return transform; Matrix4 toRot; toRot.Rotation(angle2,axis2); transform= transform*toRot; toRot.Rotation(angle1,axis1); transform = transform*toRot; if(!(transform[0][0]<=3||transform[0][0]>=3)) { cerr<<endl; cerr<<angle1<<endl; cerr<<angle2<<endl; PrintVector(dirStart); PrintVector(upStart); PrintVector(dirEnd); PrintVector(upEnd); cout<<flush; exit(1); } return transform; }
void CCharShape::PrintAction (int idx) { if (idx < 0 || idx >= numNodes) return; TCharAction *act = Actions[idx]; PrintInt (act->num); for (int i=0; i<act->num; i++) { PrintInt (act->type[i]); PrintDouble (act->dval[i]); PrintVector (act->vec[i]); } }
void CCharShape::PrintAction (size_t idx) const { if (idx >= numNodes) return; TCharAction *act = Nodes[idx]->action; PrintInt ((int)act->num); for (size_t i=0; i<act->num; i++) { PrintInt (act->type[i]); PrintDouble (act->dval[i]); PrintVector (act->vec[i]); } }
// Print contact law settings for cracks and finalize variables void CrackSurfaceContact::MaterialOutput(void) { // Global material contact law (must be set,if not force to frictionless) materialContactLawID = MaterialBase::GetContactLawNum(materialContactLawID); if(materialContactLawID<0) throw CommonException("Multimaterial mode must select a default contact law","CrackSurfaceContact::MaterialOutput"); materialContactLaw = (ContactLaw *)theMaterials[materialContactLawID]; cout << "Default Contact Law: " << materialContactLaw->name << " (number " << (materialContactLawID+1) << ")" << endl; if(materialContactLaw->IsImperfectInterface()) hasImperfectInterface=true; // print contact detection method char join[3]; join[0]=0; cout << "Contact Detection: "; if(materialContactVmin>0.) { cout << "(Vrel >= " << materialContactVmin << ")"; strcpy(join," & "); } cout << join << "(Normal dv < 0)"; strcpy(join," & "); if(displacementCheck) { cout << join << "(Normal cod < 0)" << endl; mpmgrid.OutputContactByDisplacements(); } else cout << endl; cout << "Normal Calculation: "; switch(materialNormalMethod) { case MAXIMUM_VOLUME_GRADIENT: cout << " gradient of material or paired material (if all nonrigid), or the rigid material (if" << endl; cout << " one rigid material), that has highest magnitude. When has rigid" << endl; cout << " material, prefer rigid material gradient with bias factor = " << rigidGradientBias; rigidGradientBias*=rigidGradientBias; // squared as needed in algorithm break; case MAXIMUM_VOLUME: cout << " gradient of material with maximum volume"; break; case AVERAGE_MAT_VOLUME_GRADIENTS: cout << " volume-weighted mean gradient of material and other materials lumped (if all nonrigid)," << endl; cout << " on just the rigid material (if one rigid material). When has rigid" << endl; cout << " material, prefer rigid material gradient with bias factor = " << rigidGradientBias; rigidGradientBias*=rigidGradientBias; // squared as needed in algorithm break; case EACH_MATERIALS_MASS_GRADIENT: cout << " each material's own mass gradient"; break; case SPECIFIED_NORMAL: cout << " use the specified normal of "; PrintVector("",&contactNormal); default: break; } cout << endl; }
MatrSolver::MatrSolver(int size) { InitVars(size); InitRand(); InitMatr(); SetMtx(matr, b_matr, n); PrintMtx(matr, n); std::cout << "Матрица В: " << std::endl; PrintVector(b_matr, n); //Solve(); }
/* * PrintParticle (particle *p) * * Args : the address of a particle, p. * * Returns : nothing. * * Side Effects : Prints to stdout the information stored for p. * */ void PrintParticle (particle *p) { if (p != NULL) { printf("P %6d :", p->id); printf(" Pos = "); PrintVector(&(p->pos)); } else printf("Particle has not been initialized yet.\n"); }
void main() { int arr[][4] = { {15, 20, 40, 85}, {20, 35, 80, 95}, {30, 55, 95, 105}, {40, 80, 100, 120}}; vector< vector< int > > vArr; vArr.push_back(vector< int >(&arr[0][0], &arr[0][4])); vArr.push_back(vector< int >(&arr[1][0], &arr[1][4])); vArr.push_back(vector< int >(&arr[2][0], &arr[2][4])); vArr.push_back(vector< int >(&arr[3][0], &arr[3][4])); PrintVector(vArr); RotateMatrix(vArr); PrintVector(vArr); }
void MatrSolver::Solve(){ det = Det(matr, n); std::cout << "Определитель матрицы = " << det << std::endl; if (det) FindObrMatr(); else std::cout << "Т.к. определитель матрицы = 0,\nто матрица вырожденная и обратной не имеет!!!" << std::endl; TransponMtx(obr_matr, tobr_matr, n); PrintMtx(tobr_matr, n); SolveEquation(tobr_matr, b_matr, res, n); std::cout << "Результат: " << std::endl; PrintVector(res, n); FreeResources(); }
int main() { int i,mass; mass = 1; struct Vector2 pacmanPosition; do { scanf("%d", &count); } while(count < 0); scanf("%f", &pacmanPosition.X); scanf("%f", &pacmanPosition.Y); struct Vector2 nacepinPositions[count]; for(i = 0; i < count; ++i) { struct Vector2 nacepinPosition; scanf("%f", &nacepinPositions[i].X); scanf("%f", &nacepinPositions[i].Y); } for(i = 0; i < count; ++i) { struct Vector2 MoveVector = CalculateMoveVector(&pacmanPosition,nacepinPositions[i],mass); mass ++; pacmanPosition.X += MoveVector.X; pacmanPosition.Y += MoveVector.Y; PrintVector(&MoveVector); } PrintVector(&pacmanPosition); return 0; }
int _tmain(int argc, _TCHAR* argv[]) { cVector3 v1(1, 2, 3); cVector3 v2(0, 1, -3); cVector3 v3(1, 2, 3); PrintVector(v1 * 3.0f); std::cout << v1.Normalize().Length() << std::endl; cVector3 v = cVector3::Cross(v1, v2); std::cout << cVector3::Dot(v, v1) << std::endl; return 0; }
std::ostream & operator<<(std::ostream & ost, WeekdayRange const & range) { ost << range.GetStart(); if (range.HasEnd()) { ost << '-' << range.GetEnd(); } else { if (range.HasNth()) { ost << '['; PrintVector(ost, range.GetNths(), ","); ost << ']'; } PrintOffset(ost, range.GetOffset(), true); } return ost; }
DescType DescriptorMakerCpu::ComputeEachDescriptor(cl_float4 ctpoint, cl_float4 ctnormal , const cl_float4* pointCloud, const cl_int* neighborIndices, int niOffset, int numNeighbs , bool b_print) { // matrix for linear equation, solution vector float linEq[DESC_EQUATION_SIZE]; float ysol[L_DIM]; for(int i=0; i<DESC_EQUATION_SIZE; i++) linEq[i] = 0; for(int i=0; i<L_DIM; i++) ysol[i] = 0; // set linear equation for matrix A // set F'*F part SetUpperLeft(ctpoint, pointCloud, neighborIndices, niOffset, numNeighbs, linEq); // set G parts SetUpperRight(ctnormal, linEq); SetLowerLeft(ctnormal, linEq); // set b in Ax=b SetRightVector(ctpoint, ctnormal, pointCloud, neighborIndices, niOffset, numNeighbs, linEq); if(b_print) PrintMatrix(L_DIM, L_WIDTH, linEq, "Old: linEq"); SolveLinearEq(L_DIM, linEq, ysol); if(b_print) PrintVector(L_DIM, ysol, "Old: ysol"); // compute shape descriptor by using eigen decomposition cl_float4 descriptor = GetDescriptorByEigenDecomp(ysol); if(b_print) std::cout << "Old: descriptor" << descriptor.x << " " << descriptor.y << " " << descriptor.z << std::endl; // if(b_print) // qDebug() << "descriptor output" << descriptor; return descriptor; }
SimTK::State StateInitializer::getOptimizedInitState() { if(_n_Z == 0) return _initState; StateInitializerQP qp(this); qp.setNumParameters(_n_controls); PrintVector(_lower_bd_actuatorforces,"_lower_bd_actuatorforces",std::cout); PrintVector(_upper_bd_actuatorforces,"_upper_bd_actuatorforces",std::cout); qp.setParameterLimits(_lower_bd_actuatorforces,_upper_bd_actuatorforces); qp.setNumEqualityConstraints(_UDotRef.size()); qp.setNumInequalityConstraints(0); //SimTK::Optimizer opt(qp,SimTK::CFSQP); SimTK::Optimizer opt(qp, SimTK::InteriorPoint); opt.setConvergenceTolerance(1e-4); //tol opt.setMaxIterations(200); //200 Vector result(_n_controls); result.setToZero(); SimTK::Real f = 0.0; // qp.testQP(); try{ f = opt.optimize(result); } catch(const std::exception& ex) { std::cout<<ex.what()<<std::endl; } std::cout<<"Initial State Optimization Error: "<<f<<std::endl; SimTK::State stateOpt = _initState; Vector muscleForces(_n_muscles); Vector result_forces = result.elementwiseMultiply(_opt_actuator_forces); muscleForces = result_forces.block(0,0,_n_muscles,1).getAsVector(); Vector tol_lm(_n_muscles), tol_acts(_n_muscles); Vector muscleFiberLens(_n_muscles), activations(_n_muscles); tol_lm.setTo(1.0e-6); tol_acts.setTo(1.0e-3); PrintVector(result,"result",std::cout); rootSolveMuscleFiberLength(stateOpt,muscleForces,_lm_min,_lm_max,tol_lm,muscleFiberLens); ROCINForceController::setStateFiberLength(*_model,muscleFiberLens,stateOpt); Vector lm_dot(_n_muscles); lm_dot.setToZero(); _model->getMultibodySystem().realize(_initState,SimTK::Stage::Dynamics); int idx_musc = 0; for(int i=0;i<_n_controls;i++) { Actuator& act = _model->getActuators().get(i); Muscle* m = dynamic_cast<Muscle*>(&act); if(m!= NULL) { lm_dot[idx_musc] = m->getSpeed(_initState);//m->getSpeed(_initState)/m->getCosPennationAngle(_initState);//0;//m->getSpeed(_initState); idx_musc++; } } rootSolveActivations(stateOpt,muscleForces,muscleFiberLens,lm_dot,_acts_min,_acts_max,tol_acts,activations); ROCINForceController::setStateActivation(*_model,activations,stateOpt); return stateOpt; }
void Output::PrintHand(Leap::Hand hand){ Leap::Vector handCenter = hand.palmPosition(); std::cout << "Hand " << std::endl; PrintVector(handCenter); std::cout<< std::endl; }