double AD595::measure(uint8_t type) { double value; switch(type) { case TEMPC : value = tempC(); break; case TEMPF : value = tempF(); break; } return value; }
CString CTempFiles::GetTempFilePath() { DWORD len = GetTempPath(0, NULL); auto_buffer<TCHAR> path(len+1); auto_buffer<TCHAR> tempF(len+100); GetTempPath (len+1, path); GetTempFileName (path, TEXT("tsm"), 0, tempF); CString tempfile = CString(tempF); m_arTempFileList.Add(tempfile); return tempfile; }
double ConditionalBayesProcess::negativeCrossValidation() { // This is highly ineffient implementation for comparison purposes. Dataset data(mData); size_t n = data.getNSamples(); double sum = 0.0; matrixd tempF(mMean.mFeatM); // We take the first element, use it for validation and then paste // it at the end. Thus, after every iteration, the first element // is different and, at the end, all the elements should have // rotated. for(size_t i = 0; i<n; ++i) { // Take the first element const double y = data.getSampleY(0); const vectord x = data.getSampleX(0); // Remove it for cross validation data.mX.erase(data.mX.begin()); utils::erase(data.mY,data.mY.begin()); utils::erase_column(mMean.mFeatM,0); // Compute the cross validation computeCholeskyCorrelation(); precomputePrediction(); ProbabilityDistribution* pd = prediction(x); sum += std::log(pd->pdf(y)); //Paste it back at the end data.addSample(x,y); mMean.mFeatM.resize(mMean.mFeatM.size1(),mMean.mFeatM.size2()+1); mMean.mFeatM = tempF; } std::cout << "End" << data.getNSamples(); return -sum; //Because we are minimizing. }
bool CTortoiseMergeApp::TrySavePatchFromClipboard(std::wstring& resultFile) { resultFile.clear(); UINT cFormat = RegisterClipboardFormat(_T("TSVN_UNIFIEDDIFF")); if (cFormat == 0) return false; if (OpenClipboard(NULL) == 0) return false; HGLOBAL hglb = GetClipboardData(cFormat); LPCSTR lpstr = (LPCSTR)GlobalLock(hglb); DWORD len = GetTempPath(0, NULL); std::unique_ptr<TCHAR[]> path(new TCHAR[len+1]); std::unique_ptr<TCHAR[]> tempF(new TCHAR[len+100]); GetTempPath (len+1, path.get()); GetTempFileName (path.get(), _T("tsm"), 0, tempF.get()); std::wstring sTempFile = std::wstring(tempF.get()); FILE* outFile = 0; _tfopen_s(&outFile, sTempFile.c_str(), _T("wb")); if (outFile != 0) { size_t patchlen = strlen(lpstr); size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile); if (size == patchlen) resultFile = sTempFile; fclose(outFile); } GlobalUnlock(hglb); CloseClipboard(); return !resultFile.empty(); }
void COpenDlg::OnOK() { UpdateData(TRUE); bool bUDiffOnClipboard = false; if (OpenClipboard()) { UINT enumFormat = 0; do { if (enumFormat == m_cFormat) { bUDiffOnClipboard = true; } } while((enumFormat = EnumClipboardFormats(enumFormat))!=0); CloseClipboard(); } if (GetDlgItem(IDC_BASEFILEEDIT)->IsWindowEnabled()) { m_sUnifiedDiffFile.Empty(); m_sPatchDirectory.Empty(); } else { m_sBaseFile.Empty(); m_sYourFile.Empty(); m_sTheirFile.Empty(); } UpdateData(FALSE); CString sFile; if (!m_sUnifiedDiffFile.IsEmpty()) if (!PathFileExists(m_sUnifiedDiffFile)) sFile = m_sUnifiedDiffFile; if (!m_sPatchDirectory.IsEmpty()) if (!PathFileExists(m_sPatchDirectory)) sFile = m_sPatchDirectory; if (!m_sBaseFile.IsEmpty()) if (!PathFileExists(m_sBaseFile)) sFile = m_sBaseFile; if (!m_sYourFile.IsEmpty()) if (!PathFileExists(m_sYourFile)) sFile = m_sYourFile; if (!m_sTheirFile.IsEmpty()) if (!PathFileExists(m_sTheirFile)) sFile = m_sTheirFile; if (bUDiffOnClipboard && m_bFromClipboard) { if (OpenClipboard()) { HGLOBAL hglb = GetClipboardData(m_cFormat); LPCSTR lpstr = (LPCSTR)GlobalLock(hglb); DWORD len = GetTempPath(0, NULL); auto_buffer<TCHAR> path(len+1); auto_buffer<TCHAR> tempF(len+100); GetTempPath (len+1, path); GetTempFileName (path, TEXT("tsm"), 0, tempF); CString sTempFile = CString(tempF); FILE * outFile; size_t patchlen = strlen(lpstr); _tfopen_s(&outFile, sTempFile, _T("wb")); if(outFile) { size_t size = fwrite(lpstr, sizeof(char), patchlen, outFile); if (size < patchlen) bUDiffOnClipboard = false; else { m_sUnifiedDiffFile = sTempFile; UpdateData(FALSE); sFile.Empty(); } fclose(outFile); } GlobalUnlock(hglb); CloseClipboard(); } } if (!sFile.IsEmpty()) { CString sErr; sErr.Format(IDS_ERR_PATCH_INVALIDPATCHFILE, (LPCTSTR)sFile); MessageBox(sErr, NULL, MB_ICONERROR); return; } CRegDWORD lastRadioButton(_T("Software\\TortoiseMerge\\OpenRadio"), IDC_MERGERADIO); lastRadioButton = GetCheckedRadioButton(IDC_MERGERADIO, IDC_APPLYRADIO); CStandAloneDialog::OnOK(); }