const XMLCh* DOMElementNSImpl::getBaseURI() const { const XMLCh* baseURI = (fNode.fOwnerNode)->getBaseURI(); if (fAttributes) { const XMLCh baseString[] = { chLatin_b, chLatin_a, chLatin_s, chLatin_e, chNull }; DOMNode* attrNode = fAttributes->getNamedItemNS(DOMNodeImpl::getXmlURIString(), baseString); if (attrNode) { const XMLCh* uri = attrNode->getNodeValue(); if (uri && *uri) {// attribute value is always empty string try { XMLUri temp(baseURI, ((DOMDocumentImpl *)this->getOwnerDocument())->getMemoryManager()); XMLUri temp2(&temp, uri, ((DOMDocumentImpl *)this->getOwnerDocument())->getMemoryManager()); uri = ((DOMDocumentImpl *)this->getOwnerDocument())->cloneString(temp2.getUriText()); } catch(const OutOfMemoryException&) { throw; } catch (...){ // REVISIT: what should happen in this case? return 0; } return uri; } } } return baseURI; }
void filter_object::test<1>() { set_test_name("LLEventMatching"); LLEventPump& driver(pumps.obtain("driver")); listener0.reset(0); // Listener isn't derived from LLEventTrackable specifically to test // various connection-management mechanisms. But that means we have a // couple of transient Listener objects, one of which is listening to // a persistent LLEventPump. Capture those connections in local // LLTempBoundListener instances so they'll disconnect // on destruction. LLTempBoundListener temp1( listener0.listenTo(driver)); // Construct a pattern LLSD: desired Event must have a key "foo" // containing string "bar" LLEventMatching filter(driver, LLSD().insert("foo", "bar")); listener1.reset(0); LLTempBoundListener temp2( listener1.listenTo(filter)); driver.post(1); check_listener("direct", listener0, LLSD(1)); check_listener("filtered", listener1, LLSD(0)); // Okay, construct an LLSD map matching the pattern LLSD data; data["foo"] = "bar"; data["random"] = 17; driver.post(data); check_listener("direct", listener0, data); check_listener("filtered", listener1, data); }
/** * Constructor for testing using an IplImage */ Auvsi_Recognize::Auvsi_Recognize( IplImage * img ) { // std::printf("begining recognize constructor\n"); // Set equal to image cv::Mat _input = img ; cv::Mat temp2( _input.size(), CV_32F ); _image = cv::Mat( IMAGE_HEIGHT, IMAGE_WIDTH, CV_32F ); _input.convertTo( temp2, _image.type(), 1.0/255.0f ); cv::imshow( "Input", _input ); cv::resize(temp2, _image, _image.size() ); cv::cvtColor( _image, _image, CV_RGB2Lab ); //std::printf("converted color in constructor\n"); // Only use A and B channels #ifdef TWO_CHANNEL std::vector<cv::Mat> splitData; cv::split( _image, splitData ); splitData.erase( splitData.begin() ); cv::merge( splitData, _image ); #endif }
// run the initilized retina filter in order to perform gray image tone mapping, after this call all retina outputs are updated void RetinaFilter::_runGrayToneMapping(const std::valarray<float> &grayImageInput, std::valarray<float> &grayImageOutput, const float PhotoreceptorsCompression, const float ganglionCellsCompression) { // stability controls value update ++_ellapsedFramesSinceLastReset; std::valarray<float> temp2(grayImageInput.size()); // apply tone mapping on the multiplexed image // -> photoreceptors local adaptation (large area adaptation) _photoreceptorsPrefilter.runFilter_LPfilter(grayImageInput, grayImageOutput, 2); // compute low pass filtering modeling the horizontal cells filtering to acess local luminance _photoreceptorsPrefilter.setV0CompressionParameterToneMapping(PhotoreceptorsCompression, grayImageOutput.sum()/(float)_photoreceptorsPrefilter.getNBpixels()); _photoreceptorsPrefilter.runFilter_LocalAdapdation(grayImageInput, grayImageOutput, temp2); // adapt contrast to local luminance // high pass filter //_spatiotemporalLPfilter(_localBuffer, _filterOutput, 2); // compute low pass filtering (high cut frequency (remove spatio-temporal noise) //for (unsigned int i=0;i<_NBpixels;++i) // _localBuffer[i]-= _filterOutput[i]/2.0; // -> ganglion cells local adaptation (short area adaptation) _photoreceptorsPrefilter.runFilter_LPfilter(temp2, grayImageOutput, 1); // compute low pass filtering (high cut frequency (remove spatio-temporal noise) _photoreceptorsPrefilter.setV0CompressionParameterToneMapping(ganglionCellsCompression, temp2.max(), temp2.sum()/(float)_photoreceptorsPrefilter.getNBpixels()); _photoreceptorsPrefilter.runFilter_LocalAdapdation(temp2, grayImageOutput, grayImageOutput); // adapt contrast to local luminance }
static BOOL bign_keyunwrap(byte *X, byte *d, byte *untoken){ Point q; REV_PI(X, q); BigInteger Q = bign_curve256v1::getQ(); byte s0[32]; memcpy(s0, d, sizeof s0); for (size_t jj = 0; jj < 32; jj += 4) change_endian(s0 + jj); BigInteger S0(s0, 32); S0 <<= 128; S0 %= Q; byte h_belt[32]; memcpy(h_belt, H, 32); for (size_t jj = 0; jj <32; jj += 4) change_endian(h_belt + jj); BigInteger temp2(h_belt, 32); temp2 %= Q; byte _qq[32]; memcpy(_qq, d + 32, sizeof _qq); for (size_t jj = 0; jj < 32; jj += 4) change_endian(_qq + jj); BigInteger S1(_qq, 32); if (S1 >= Q) return false; BigInteger rr = (temp2 + S1) % Q; BigInteger zero = BigInteger(0); Point G(zero, bign_curve256v1::getY()); Point R = shamir(G, rr, q, S0); if (R.x == zero && R.y == zero) return false; byte toHash[108]; byte bR[64]; PI(bR, R); belt_hash(toHash, sizeof toHash, h_belt); for (size_t jj = 0; jj < 32; ++jj) if (h_belt[jj] != bR[jj]) return false; return true; }
static BOOL bign_verify(byte *H, byte *_q, byte *S, uint32 size){ Point q; REV_PI(_q, q); BigInteger Q = bign_curve256v1::getQ(); byte s0[32]; memcpy(s0, S, sizeof s0); for (size_t jj = 0; jj < 32; jj += 4) change_endian(s0 + jj); BigInteger S0(s0, 32); S0 <<= 128; S0 %= Q; byte _qq[32]; memcpy(_qq, S + 32, sizeof _qq); for (size_t jj = 0; jj < 32; jj += 4) change_endian(_qq + jj); BigInteger S1(_qq, 32); if (S1 >= Q) return false; byte h_belt[32]; memcpy(h_belt, H, 32); for (size_t jj = 0; jj <32; jj += 4) change_endian(h_belt + jj); BigInteger temp2(h_belt, 32); temp2 %= Q; BigInteger rr = (temp2 + S1) % Q; BigInteger zero = BigInteger(0); Point G(zero, bign_curve256v1::getY()); Point R = shamir(G, rr, q, S0); if (R.x == zero && R.y == zero) return false; byte toHash[108]; byte bR[64]; PI(bR, R); memcpy(toHash, OID, sizeof OID); memcpy(toHash + sizeof OID, bR, sizeof bR); memcpy(toHash + sizeof OID + sizeof bR, H, 32); belt_hash(toHash, sizeof toHash, h_belt); for (size_t jj = 0; jj < 32; ++jj) if (h_belt[jj] != S[jj]) return false; return true; }
DataProcessor::DataProcessor(ros::NodeHandle & n): n_(n) { processed_pointcloud_ = false; new_cloud_wanted_ = false; nocluster_count_ = 0; process_service_ = n_.advertiseService("process_pcd", &DataProcessor::processDataCallback, this); pub_active_region_ = n_.advertise<sensor_msgs::PointCloud2>("activeregion",1); marker_pub_ = n_.advertise<visualization_msgs::Marker>("visualization_marker", 1); regions_pub_ = n_.advertise<visualization_msgs::MarkerArray>("region_nums", 1); //ros::Subscriber sub = n.subscribe("/camera/rgb/points",1,got_point_cloud); //client_grasp_ = n_.serviceClient<duplo_v1::Grasp_Duplo>("grasp_duplo"); client_manipulate_ = n_.serviceClient<duplo_v1::Manipulate_Duplo>("manipulate_duplo"); //client_tumble_ = n_.serviceClient<duplo_v1::Tumble_Duplo>("tumble_duplo"); reset_posn.x = 0.6; reset_posn.y = -0.5; reset_posn.z = 1; while ( !ros::service::waitForService("get_new_pcd",ros::Duration(2.0)) && n.ok() ) ROS_INFO("DUPLO: Waiting for object detection service to come up"); if (!n.ok()) exit(0); pcl::PointCloud<pcl::PointXYZRGB>::Ptr temp1(new pcl::PointCloud<pcl::PointXYZRGB>); object_cloud_ = temp1; pcl::PointCloud<pcl::PointXYZRGB>::Ptr temp2(new pcl::PointCloud<pcl::PointXYZRGB>); planar_cloud_ = temp2; ROS_INFO("Ready to process input point cloud data."); client_newpcd_ = n.serviceClient<duplo_v1::Get_New_PCD>("get_new_pcd"); }
void PAN::rotate(Mat image){ //namedWindow("", WINDOW_NORMAL); //imshow("", image); //waitKey(); //namedWindow("", WINDOW_NORMAL); //imshow("", *panimage.img); //waitKey(); cvtColor(image,image, CV_BGR2GRAY); Mat part1(image, Rect(Point((image.cols / 2) - 5, image.rows), Point(image.cols / 2, image.rows))); Mat part2(image, Rect(Point(image.cols - 5, 0), Point(image.cols, image.rows))); adaptiveThreshold(part1, part1, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY,3, 11); adaptiveThreshold(part1, part1, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 3, 11); PAN::Image temp1(&part1, 0, part1.cols, 0, part1.rows, Point(0, 0)); PAN::Image temp2(&part2, 0, part2.cols, 0, part2.rows, Point(0, 0)); cout << "here"; namedWindow("o", WINDOW_NORMAL); imshow("o", *temp1.img); waitKey(); imshow("o", *temp2.img); waitKey(); }
Matrix<double> BspCurvBasisFuncSet::CreateMatrixIntegral(int lev) const { KnotSet kset = KnotSet(*kts,ord,num).CreateKnotSetDeriv(lev); Matrix<double> mat(kset.GetNum()-(ord-lev),kset.GetNum()-(ord-lev)); BspCurvBasisFuncSet basis(kset.GetKnots(),ord-lev,kset.GetNum()); Matrix<double> mat1(kset.GetNum()-ord+lev,kset.GetNum()-ord+lev,0.0); for (int i=0; i<kset.GetNum()-ord+lev; i++) for (int j=0; j<=i; j++) { // create the two std::sets representing the two knot std::sets Vector<double> temp1((*(basis.b))[i].GetKnots()); Vector<double> temp2((*(basis.b))[j].GetKnots()); std::set<double> s1(temp1.begin(),temp1.end()); std::set<double> s2(temp2.begin(),temp2.end()); // if there is an intersection if (*(--s2.end()) > *(s1.begin())) { // form the intersection std::set<double> s3; std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),std::inserter(s3,s3.begin())); // if there is an intersection if (s3.size() > 1) { Vector<double> v(s3.size()); std::set<double>::iterator s = s3.begin(); // copy the elements into a vector for (unsigned int k=0; k<s3.size(); k++) v[k] = *s++; // create the compbezcurvs Vector<BezCurv<double> > vec1(s3.size()-1); Vector<BezCurv<double> > vec2(s3.size()-1); BspCurv<double> b1((*(basis.b))[i].GetBspCurv()), b2((*(basis.b))[j].GetBspCurv()); // find the segments of intersection for (unsigned int k=0; k<s3.size()-1; k++) { int segb1 = b1.GetKnotSet().Find_segment(v[k]); int segb2 = b2.GetKnotSet().Find_segment(v[k]); vec1[k] = b1.GetSegment(segb1); vec2[k] = b2.GetSegment(segb2); } CompBezCurv<double> cb1(vec1,s3.size()-1,v); CompBezCurv<double> cb2(vec2,s3.size()-1,v); CompBezCurv<double> prod = cb1.Product(cb2); mat1[i][j] = prod.ConvertBspCurv().Integrate((*kts)[ord-1],(*kts)[num-ord]); } } } for (int i=0; i<kset.GetNum()-ord+lev-1; i++) for (int j=i+1; j<kset.GetNum()-ord+lev; j++) mat1[i][j] = mat1[j][i]; return mat1; }
TEST(Test_Container_SharedRabundVector, Constructors) { TestSharedRabundVector test; SharedRAbundVector noGroup; EXPECT_EQ(noGroup.getNumBins(), 0); EXPECT_EQ(noGroup.getNumSeqs(), 0); EXPECT_EQ(noGroup.getMaxRank(), 0); EXPECT_EQ(noGroup.getGroup(), ""); SharedRAbundVector noGroup2(10); EXPECT_EQ(noGroup2.getNumBins(), 10); EXPECT_EQ(noGroup2.getNumSeqs(), 0); EXPECT_EQ(noGroup2.getMaxRank(), 0); EXPECT_EQ(noGroup2.getGroup(), ""); vector<int> abunds(10, 5); SharedRAbundVector noGroup3(abunds, 5, 10, 50); EXPECT_EQ(noGroup3.getNumBins(), 10); EXPECT_EQ(noGroup3.getNumSeqs(), 50); EXPECT_EQ(noGroup3.getMaxRank(), 5); EXPECT_EQ(noGroup3.getGroup(), ""); SharedRAbundVector noGroup4(abunds); EXPECT_EQ(noGroup4.getNumBins(), 10); EXPECT_EQ(noGroup4.getNumSeqs(), 50); EXPECT_EQ(noGroup4.getMaxRank(), 5); EXPECT_EQ(noGroup4.getGroup(), ""); SharedRAbundVector noGroup5(noGroup4); EXPECT_EQ(noGroup5.getNumBins(), 10); EXPECT_EQ(noGroup5.getNumSeqs(), 50); EXPECT_EQ(noGroup5.getMaxRank(), 5); EXPECT_EQ(noGroup5.getGroup(), ""); ifstream in; Utils util; util.openInputFile(test.sharedFile, in); util.getline(in); //gobble headers SharedRAbundVector temp(in); EXPECT_EQ(temp.getNumBins(), 58); EXPECT_EQ(temp.getNumSeqs(), 20); EXPECT_EQ(temp.getMaxRank(), 5); EXPECT_EQ(temp.getGroup(), "F003D000"); SharedRAbundVector temp2(in); EXPECT_EQ(temp2.getNumBins(), 58); EXPECT_EQ(temp2.getNumSeqs(), 18); EXPECT_EQ(temp2.getMaxRank(), 3); EXPECT_EQ(temp2.getGroup(), "F003D002"); int numBins; string label, groupN; in >> label >> groupN >> numBins; SharedRAbundVector temp3(in, label, groupN, numBins); EXPECT_EQ(temp3.getNumBins(), 58); EXPECT_EQ(temp3.getNumSeqs(), 18); EXPECT_EQ(temp3.getMaxRank(), 5); EXPECT_EQ(temp3.getGroup(), "F003D004"); in.close(); }
QT_BEGIN_NAMESPACE DSVideoDeviceControl::DSVideoDeviceControl(QObject *parent) : QVideoDeviceControl(parent) { m_session = qobject_cast<DSCameraSession*>(parent); devices.clear(); descriptions.clear(); CoInitialize(NULL); ICreateDevEnum* pDevEnum = NULL; IEnumMoniker* pEnum = NULL; // Create the System device enumerator HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, reinterpret_cast<void**>(&pDevEnum)); if(SUCCEEDED(hr)) { // Create the enumerator for the video capture category hr = pDevEnum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory, &pEnum, 0); if (S_OK == hr) { pEnum->Reset(); // go through and find all video capture devices IMoniker* pMoniker = NULL; while(pEnum->Next(1, &pMoniker, NULL) == S_OK) { IPropertyBag *pPropBag; hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void**)(&pPropBag)); if(FAILED(hr)) { pMoniker->Release(); continue; // skip this one } // Find the description WCHAR str[120]; VARIANT varName; varName.vt = VT_BSTR; hr = pPropBag->Read(L"FriendlyName", &varName, 0); if(SUCCEEDED(hr)) { wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0])); QString temp(QString::fromUtf16((unsigned short*)str)); devices.append(QString("ds:%1").arg(temp).toLocal8Bit().constData()); hr = pPropBag->Read(L"Description", &varName, 0); wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0])); QString temp2(QString::fromUtf16((unsigned short*)str)); descriptions.append(temp2.toLocal8Bit().constData()); } pPropBag->Release(); pMoniker->Release(); } pEnum->Release(); } pDevEnum->Release(); } CoUninitialize(); selected = 0; }
bool Tringle::isPointOutTringle (const Point& p) const { Tringle temp1 (first, second, p); Tringle temp2 (second, third, p); Tringle temp3 (third, first, p); if (temp1.square() + temp2.square() + temp3.square() == this->square()) return false; return true; }
void DSServicePlugin::updateDevices() const { m_cameraDevices.clear(); m_cameraDescriptions.clear(); BOOL bFound = TRUE; CoInitialize(NULL); ICreateDevEnum* pDevEnum = NULL; IEnumMoniker* pEnum = NULL; // Create the System device enumerator HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, reinterpret_cast<void**>(&pDevEnum)); if(SUCCEEDED(hr)) { // Create the enumerator for the video capture category hr = pDevEnum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory, &pEnum, 0); if (S_OK == hr) { pEnum->Reset(); // go through and find all video capture devices IMoniker* pMoniker = NULL; while(pEnum->Next(1, &pMoniker, NULL) == S_OK) { IPropertyBag *pPropBag; hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag, (void**)(&pPropBag)); if(FAILED(hr)) { pMoniker->Release(); continue; // skip this one } bFound = TRUE; // Find the description WCHAR str[120]; VARIANT varName; varName.vt = VT_BSTR; hr = pPropBag->Read(L"FriendlyName", &varName, 0); if(SUCCEEDED(hr)) { wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0])); QString temp(QString::fromUtf16((unsigned short*)str)); m_cameraDevices.append(QString("ds:%1").arg(temp).toLocal8Bit().constData()); hr = pPropBag->Read(L"Description", &varName, 0); wcsncpy(str, varName.bstrVal, sizeof(str)/sizeof(str[0])); QString temp2(QString::fromUtf16((unsigned short*)str)); m_cameraDescriptions.append(temp2); } else { qWarning() << "No friendly name"; } pPropBag->Release(); pMoniker->Release(); } pEnum->Release(); } pDevEnum->Release(); } CoUninitialize(); if (!bFound) { qWarning() << "No camera devices found"; } }
void CalculateHann(Mat &cos_window, Size sz){ Mat temp1(Size(sz.width, 1), CV_64FC1); Mat temp2(Size(sz.height, 1), CV_64FC1); for (int i = 0; i < sz.width; ++i) temp1.at<double>(0, i) = 0.5*(1 - cos(2 * PI*i / (sz.width - 1))); for (int i = 0; i < sz.height; ++i) temp2.at<double>(0, i) = 0.5*(1 - cos(2 * PI*i / (sz.height - 1))); cos_window = temp2.t()*temp1; }
Individual* OptimizedCrossSGP::crossover(const Individual& ind1, const Individual& ind2, const Dataset& train, const Dataset& test) { double coeff = best_coefficient(ind1, ind2, train); Individual coeff_ind(coeff, train, test); Individual compl_ind(1.0 - coeff, train, test); Individual temp1("*", coeff_ind, ind1); Individual temp2("*", compl_ind, ind2); return new Individual("+", temp1, temp2); }
PS2Sprite3D::PS2Sprite3D(): conversionMatrix(Matrix4x4::IDENTITY) { Vector4 temp1(-1,-1,0,1); Vector4 temp2(1,-1,0,1); Vector4 temp3(1,1,0,1); Vector4 temp4(-1,1,0,1); Initialise(temp1, temp2, temp3, temp4); }
void crossing::crossover() { std::vector<unsigned int> chosen; std::default_random_engine generator; std::uniform_real_distribution<double> distribution(0.0,1.0); std::vector<double> randomvector(fpop.size(), 0.0); for(unsigned int i=0; i < fpop.size(); i++ ) { randomvector[i] = distribution(generator); if(randomvector[i] < 0.25) { chosen.push_back(i); //std::cout<<"i = "<<i<<std::endl; } } if((chosen.size()%2 != 0) || (chosen.size() == 1)) { chosen.pop_back(); } Chromosome temp1(fpop[0].size(), 0.0); Chromosome temp2(fpop[0].size(), 0.0); unsigned int position = static_cast<unsigned int>(distribution(generator)*fpop[0].size()); //std::cout<<"fpop size = "<<fpop.size()<<std::endl; //std::cout<<" position = "<<position<<std::endl; #pragma omp parallel for for(unsigned int i = 0; i < chosen.size(); i = i+2) { std::copy(fpop[chosen[i]].begin(), fpop[chosen[i]].end(), temp1.begin() ); std::copy(fpop[chosen[i+1]].begin(), fpop[chosen[i+1]].end(), temp2.begin() ); //#pragma omp parallel for for(unsigned int k = position; k<fpop[0].size(); k++) { temp1[k] = fpop[chosen[i+1]][k]; temp2[k] = fpop[chosen[i]][k]; //std::cout<<" end number chosen = "<<chosen.size()<<std::endl; std::copy(temp1.begin(), temp1.end(), fpop[chosen[i]].begin() ); std::copy(temp2.begin(), temp2.end(), fpop[chosen[i+1]].begin() ); } } }
// static nsresult nsHTMLTags::AddRefTable(void) { if (gTableRefCount++ == 0) { NS_ASSERTION(!gTagTable, "pre existing hash!"); gTagTable = PL_NewHashTable(64, HTMLTagsHashCodeUCPtr, HTMLTagsKeyCompareUCPtr, PL_CompareValues, nsnull, nsnull); NS_ENSURE_TRUE(gTagTable, NS_ERROR_OUT_OF_MEMORY); // Fill in gTagTable with the above static PRUnichar strings as // keys and the value of the corresponding enum as the value in // the table. PRInt32 i; for (i = 0; i < NS_HTML_TAG_MAX; ++i) { PRUint32 len = nsCRT::strlen(kTagUnicodeTable[i]); PL_HashTableAdd(gTagTable, kTagUnicodeTable[i], NS_INT32_TO_PTR(i + 1)); if (len > sMaxTagNameLength) { sMaxTagNameLength = len; } } //NS_ASSERTION(sMaxTagNameLength == NS_HTMLTAG_NAME_MAX_LENGTH, // "NS_HTMLTAG_NAME_MAX_LENGTH not set correctly!"); // Fill in our static atom pointers NS_RegisterStaticAtoms(kTagAtoms_info, NS_ARRAY_LENGTH(kTagAtoms_info)); #ifdef DEBUG { // let's verify that all names in the the table are lowercase... for (i = 0; i < NS_HTML_TAG_MAX; ++i) { nsCAutoString temp1(kTagAtoms_info[i].mString); nsCAutoString temp2(kTagAtoms_info[i].mString); ToLowerCase(temp1); NS_ASSERTION(temp1.Equals(temp2), "upper case char in table"); } // let's verify that all names in the unicode strings above are // correct. for (i = 0; i < NS_HTML_TAG_MAX; ++i) { nsAutoString temp1(kTagUnicodeTable[i]); nsAutoString temp2; temp2.AssignWithConversion(kTagAtoms_info[i].mString); NS_ASSERTION(temp1.Equals(temp2), "Bad unicode tag name!"); } } #endif } return NS_OK; }
bool EqSys::Solve_Gauss(Vector& x_out, Vector& err_out) { Matrix mat(A); //Vector vec(b.Size()); //vec=b; mat.Resize(mat.Rows(), mat.Cols()+1); for(int i=0; i<b.Size(); i++) mat[i][mat.Cols()-1] = b[i]; //mat.Print(); for(int i=0; i<size; i++) { if(mat[i][i]==0) { int imax=i; for(int j=i+1; j<size; j++) if(abs(mat[j][i]) > abs(mat[imax][i])) imax=j; if(mat[imax][i]==0){std::cerr << "Uklad sprzeczny/niejednoznaczny\n"; return false;} //std::cout << "DEBUG_b:\n" << "i=" << i << " imax=" << imax << std::endl; //std::cout << "[i]: "; mat[i].Print(); std::cout << "[imax]: "; mat[imax].Print(); if(i!=imax) { Vector temp2(mat[i]); mat[i]=mat[imax]; mat[imax]=temp2; // double temp = vec[i]; // vec[i]=vec[imax]; // vec[imax]=temp; } //std::cout << "DEBUG_a:\n" << "i=" << i << " imax=" << imax << std::endl; //std::cout << "[i]: "; mat[i].Print(); std::cout << "[imax]: "; mat[imax].Print(); } // vec[i]=vec[i]/mat[i][i]; mat[i]=mat[i]/mat[i][i]; // vec.Print(); for(int j=i+1; j<size; j++) { mat[j]=mat[j]+((mat[i]*(-1))*(mat[j][i]/mat[i][i])); // vec[j]=vec[j]+(-1*vec[i]*(mat[j][i]/mat[i][i])); } } for(int i=mat.Rows()-1; i>=0; i--) for(int j=i-1; j>=0; j--) mat[j]=mat[j]+((mat[i]*-1)*mat[j][i]); // mat.Print(); x_out.Resize(mat.Rows()); for(int i=0; i<x_out.Size(); i++) x_out[i]=mat[i][mat.Cols()-1]; err_out.Resize(A.Rows()); err_out=A*x_out+(b*-1); return true; }
PRBool nsStaticCaseInsensitiveNameTable::Init(const char* const aNames[], PRInt32 Count) { NS_ASSERTION(!mNameArray, "double Init"); NS_ASSERTION(!mNameTable.ops, "double Init"); NS_ASSERTION(aNames, "null name table"); NS_ASSERTION(Count, "0 count"); mNameArray = (nsDependentCString*) nsMemory::Alloc(Count * sizeof(nsDependentCString)); if (!mNameArray) return PR_FALSE; if (!PL_DHashTableInit(&mNameTable, &nametable_CaseInsensitiveHashTableOps, nsnull, sizeof(NameTableEntry), Count)) { mNameTable.ops = nsnull; return PR_FALSE; } for (PRInt32 index = 0; index < Count; ++index) { const char* raw = aNames[index]; #ifdef DEBUG { // verify invariants of contents nsCAutoString temp1(raw); nsDependentCString temp2(raw); ToLowerCase(temp1); NS_ASSERTION(temp1.Equals(temp2), "upper case char in table"); NS_ASSERTION(nsCRT::IsAscii(raw), "non-ascii string in table -- " "case-insensitive matching won't work right"); } #endif // use placement-new to initialize the string object nsDependentCString* strPtr = &mNameArray[index]; new (strPtr) nsDependentCString(raw); NameTableKey key(strPtr); NameTableEntry *entry = static_cast<NameTableEntry*> (PL_DHashTableOperate(&mNameTable, &key, PL_DHASH_ADD)); if (!entry) continue; NS_ASSERTION(entry->mString == 0, "Entry already exists!"); entry->mString = strPtr; // not owned! entry->mIndex = index; } return PR_TRUE; }
hMatrix Pseudo_Inverse(hMatrix Mat){ int row = Mat.GetRow(), col = Mat.GetCol(); hMatrix trans(col,row); trans =Transpose(Mat); hMatrix temp1(row,row); temp1 = Inverse(Mat*trans); hMatrix temp2(col,row); temp2 = trans*temp1; return temp2; }
Machine::Machine() { std::shared_ptr<stack_t> temp1(new stack_t); std::shared_ptr<stack_t> temp2(new stack_t); std::shared_ptr<stack_t> temp3(new stack_t); D = nullptr; S = temp1; E = temp2; C = temp3; }
ColorMap::ColorMap(int _width, int _heidht) : width(_width + 1) , height(_heidht + 1) { for (int i = 0; i < width; i++) { vector<double> temp(height, 0); vector<double> temp1(height, 0); vector<double> temp2(height, 0); red.push_back(temp); green.push_back(temp1); blue.push_back(temp2); } }
void gmm::mult(const gmm::GMMGSmoothAMatrix &m, const std::vector<double> &x, std::vector<double> &y) { std::vector<double> temp1(m.B->nrows()), temp2(m.P->nrows()); gmm::mult(*m.B, x, temp1); //temp1 = G * x; gmm::mult(*m.P, temp1, temp2); //temp2 = P * temp1; gmm::mult(gmm::transposed(*m.P), temp2, temp1); //temp1 = P.trans_mult(temp2); gmm::mult(gmm::transposed(*m.B), temp1, y); //temp2 = G.trans_mult(temp1); gmm::mult(*m.S, x, y, y); }
void BPTree::insert(Value key,PtrType pointer) { PtrType nodePtr = findLeafNode(key); Node node(dbName,nodePtr,indexName,tableInstance,n); if (node.getCount() < (n - 1)) insertLeaf(node,key,pointer); else { //排序 vector<Value> keyList = node.getInfo();//只读键值对 if (isLess(key,keyList[0])) { keyList.insert(keyList.begin(),key); Value temp(_TYPE_INT,pointer); keyList.insert(keyList.begin(),temp); } else { for (int i = (keyList.size() - 1 - 1); i >= 0; i-=2) { if (isLessEqual(keyList.at(i),key)) { Value tempPtr(_TYPE_INT,pointer); keyList.insert(keyList.begin() + i+1,tempPtr); keyList.insert(keyList.begin() + i+2,key); break; } } } //更新尾指针 Node newNode(dbName,indexName,tableInstance,n); PtrType newNodePtr = newNode.getNodePtr(); newNode.setLastPtr(node.getLastPtr()); node.setLastPtr(newNodePtr); //赋值元素到该到的地方 int breakPoint = 0; if (n % 2 == 0) breakPoint = (n /2)*2; else breakPoint = ((n / 2) + 1)*2; vector<Value> temp(keyList.begin(),keyList.begin() + breakPoint); node.set(temp);//只写键值对 vector<Value> temp2(keyList.begin() + breakPoint,keyList.end());//TODO:左闭右开? newNode.set(temp2); insertNonleaf(node,temp2[0],newNodePtr); } }
//通过引用,修改rotation和scale,使shape1和shape2差距最小 void SimilarityTransform(const Mat_<double>& shape1, const Mat_<double>& shape2, Mat_<double>& rotation, double& scale) { rotation = Mat::zeros(2, 2, CV_64FC1); scale = 0; // center the data double center_x_1 = 0; double center_y_1 = 0; double center_x_2 = 0; double center_y_2 = 0; for (int i = 0; i < shape1.rows; i++) { center_x_1 += shape1(i, 0); center_y_1 += shape1(i, 1); center_x_2 += shape2(i, 0); center_y_2 += shape2(i, 1); } center_x_1 /= shape1.rows; center_y_1 /= shape1.rows; center_x_2 /= shape2.rows; center_y_2 /= shape2.rows; Mat_<double> temp1 = shape1.clone(); Mat_<double> temp2 = shape2.clone(); for (int i = 0; i < shape1.rows; i++) { temp1(i, 0) -= center_x_1; temp1(i, 1) -= center_y_1; temp2(i, 0) -= center_x_2; temp2(i, 1) -= center_y_2; } //至此,temp1(与shape1形状相同)和temp2(与shape2形状相同)已经移到了以(0,0)为原点的坐标系 Mat_<double> covariance1, covariance2; //covariance = 协方差 Mat_<double> mean1, mean2; // calculate covariance matrix calcCovarMatrix(temp1, covariance1, mean1, CV_COVAR_COLS); //输出covariance1为temp1的协方差,mean1为temp1的均值 calcCovarMatrix(temp2, covariance2, mean2, CV_COVAR_COLS); double s1 = sqrt(norm(covariance1)); //norm用来计算covariance1的L2范数 double s2 = sqrt(norm(covariance2)); scale = s1 / s2; temp1 = 1.0 / s1 * temp1; temp2 = 1.0 / s2 * temp2; // 至此,通过缩放,temp1和temp2的差距最小(周叔说,这是最小二乘法) double num = 0; double den = 0; for (int i = 0; i < shape1.rows; i++) { num = num + temp1(i, 1) * temp2(i, 0) - temp1(i, 0) * temp2(i, 1); den = den + temp1(i, 0) * temp2(i, 0) + temp1(i, 1) * temp2(i, 1); } double norm = sqrt(num * num + den * den); double sin_theta = num / norm; double cos_theta = den / norm; rotation(0, 0) = cos_theta; rotation(0, 1) = -sin_theta; rotation(1, 0) = sin_theta; rotation(1, 1) = cos_theta; }
void MainWindow::on_convert_end() { QPixmap temp2(DataManager::getImageName(DataManager::converted_image)); ui->bad_image->setPixmap(temp2); ui->bad_image->resize(temp2.size()); QString psnr; psnr = psnr.number(mainManager.getMetrics(MetricsManager::psnr, DataManager::converted_image)); ui->textEdit->append("PSNR web-safe image: " + psnr); QString ssim; ssim = ssim.number(mainManager.getMetrics(MetricsManager::ssim, DataManager::converted_image)); ui->textEdit->append("SSIM web-safe image: " + ssim); }
void gmm::mult(const gmm::GMMGSmoothAMatrix &m, const gmm::VectorRef &ref, const std::vector<double> &v, std::vector<double>& y) { std::vector<double> x(m.B->ncols()), temp1(m.B->nrows()), temp2(m.P->nrows()); x.assign(ref.begin_, ref.end_); mult(*m.B, x, temp1); //temp1 = G * x; gmm::mult(*m.P, temp1, temp2); //temp2 = P * temp1; gmm::mult(gmm::transposed(*m.P), temp2, temp1); //temp1 = P.trans_mult(temp2); gmm::mult(gmm::transposed(*m.B), temp1, y); //temp2 = G.trans_mult(temp1); gmm::mult(*m.S, x, y, y); gmm::add(v, y, y); }
/** * Read line. * * @param qreal &x * @param qreal &y * @param qreal &z */ void filereader::ReadLine( qreal &x, qreal &y, qreal &z ) { if(fileName.isEmpty()) return; QString line = file.readLine(); // Get x std::string line2(line.toUtf8()); line2.erase(0,line2.find_first_of("x")); line2.erase(0,3); std::string temp = line2.substr(0,line2.find_first_of(" ")); QString temp2( temp.c_str() ); x = temp2.toFloat(); // Get y line2.erase(0,line2.find_first_of("y")); line2.erase(0,3); temp = line2.substr(0,line2.find_first_of(" ")); temp2 = temp.c_str(); y = temp2.toFloat(); // Get z line2.erase(0,line2.find_first_of("z")); line2.erase(0,3); // Is there space character? if(line2.find_first_of(" ") != std::string::npos) { temp = line2.substr(0,line2.find_first_of(" ")); } else { temp = line2; } //temp = line2.substr(0,line2.find_first_of(" ")); temp2 = temp.c_str(); z = temp2.toFloat(); }
void spreadsheet::save_spreadsheet(std::string filename) { string File = "../Saves";// one dot local two for parent string cell_info; string cell_name; string cell_contents; // heavily modified code from Ingo Leonhardt but seems really basic once you understand it http://stackoverflow.com/questions/18100097/portable-way-to-check-if-directory-exists-windows-linux-c /* struct stat info; if( stat( File.c_str(), &info ) != 0 )//changed pathname to file printf( "cannot access %s\n", File.c_str()); else if( info.st_mode & S_IFDIR ) printf( "%s is a directory\n", File.c_str()); else{ printf( "%s is no directory creating one \n", File.c_str()); // modified mkdir(File.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); // my line of code }*/ //end of cited code string full_name = filename; ofstream save_file(full_name.c_str()); if (save_file.is_open()){ for (map<string, string>::iterator it = cells.begin(); it != cells.end(); ++it){ cell_name = it->first; cell_contents = it->second; string temp1(cell_name); string temp2(cell_contents); string cell_info = temp1 + "|" + temp2; save_file << cell_info << endl; } } }