int le_op ( ) { Matrix a; Matrix b; Matrix c; double lvalue; double rvalue; descriptor *left; descriptor *right; descriptor *result; descriptor temp; int type_error; int status; int cmp; unsigned i; unsigned j; right = pop ( ); result = top ( ); temp = *result; left = &temp; left = deref (left); right = deref (right); if (D_Type (left) != T_String || D_Type (right) != T_String) { left = CoerceData (left, T_Double); right = CoerceData (right, T_Double); } status = 0; type_error = F_False; switch (D_Type (left)) { case T_Double: switch (D_Type (right)) { case T_Double: D_Type (result) = T_Double; D_Temp (result) = F_False; D_Trapped (result) = F_False; D_Double (result) = dbllit (*D_Double (left) <= *D_Double (right)); break; case T_Matrix: a = D_Matrix (right); CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a)); b = D_Matrix (result); lvalue = *D_Double (left); for (i = 1; i <= Mrows (a); i ++) for (j = 1; j <= Mcols (a); j ++) sdata (b, i, j) = lvalue <= mdata (a, i, j); break; default: type_error = F_True; break; } break; case T_Matrix: switch (D_Type (right)) { case T_Double: a = D_Matrix (left); CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a)); b = D_Matrix (result); rvalue = *D_Double (right); for (i = 1; i <= Mrows (a); i ++) for (j = 1; j <= Mcols (a); j ++) sdata (b, i, j) = mdata (a, i, j) <= rvalue; break; case T_Matrix: a = D_Matrix (left); b = D_Matrix (right); CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a)); c = D_Matrix (result); if ((status = CompareLTEMatrices (c, a, b))) MatrixError ("<=", a, b, status, F_False); break; default: type_error = F_True; break; } break; case T_String: switch (D_Type (right)) { case T_String: cmp = strcmp (*D_String (left), *D_String (right)); D_Type (result) = T_Double; D_Temp (result) = F_False; D_Trapped (result) = F_False; D_Double (result) = dbllit (cmp <= 0); break; default: type_error = F_True; break; } break; default: type_error = F_True; break; } if (type_error == F_True) TypeError ("<=", left, right, NULL, F_False); RecycleData (left); RecycleData (right); d_printf ("le ans =\n"); d_PrintData (result); return type_error == F_True || status != 0; }
PyObject *embedBoundsMatrix(python::object boundsMatArg, int maxIters = 10, bool randomizeOnFailure = false, int numZeroFail = 2, python::list weights = python::list(), int randomSeed = -1) { PyObject *boundsMatObj = boundsMatArg.ptr(); if (!PyArray_Check(boundsMatObj)) throw_value_error("Argument isn't an array"); PyArrayObject *boundsMat = reinterpret_cast<PyArrayObject *>(boundsMatObj); // get the dimensions of the array unsigned int nrows = PyArray_DIM(boundsMat, 0); unsigned int ncols = PyArray_DIM(boundsMat, 1); if (nrows != ncols) throw_value_error("The array has to be square"); if (nrows <= 0) throw_value_error("The array has to have a nonzero size"); if (PyArray_DESCR(boundsMat)->type_num != NPY_DOUBLE) throw_value_error("Only double arrays are currently supported"); unsigned int dSize = nrows * nrows; auto *cData = new double[dSize]; double *inData = reinterpret_cast<double *>(PyArray_DATA(boundsMat)); memcpy(static_cast<void *>(cData), static_cast<const void *>(inData), dSize * sizeof(double)); DistGeom::BoundsMatrix::DATA_SPTR sdata(cData); DistGeom::BoundsMatrix bm(nrows, sdata); auto *positions = new RDGeom::Point3D[nrows]; std::vector<RDGeom::Point *> posPtrs; for (unsigned int i = 0; i < nrows; i++) { posPtrs.push_back(&positions[i]); } RDNumeric::DoubleSymmMatrix distMat(nrows, 0.0); // ---- ---- ---- ---- ---- ---- ---- ---- ---- // start the embedding: bool gotCoords = false; for (int iter = 0; iter < maxIters && !gotCoords; iter++) { // pick a random distance matrix DistGeom::pickRandomDistMat(bm, distMat, randomSeed); // and embed it: gotCoords = DistGeom::computeInitialCoords( distMat, posPtrs, randomizeOnFailure, numZeroFail, randomSeed); // update the seed: if (randomSeed >= 0) randomSeed += iter * 999; } if (gotCoords) { std::map<std::pair<int, int>, double> weightMap; unsigned int nElems = PySequence_Size(weights.ptr()); for (unsigned int entryIdx = 0; entryIdx < nElems; entryIdx++) { PyObject *entry = PySequence_GetItem(weights.ptr(), entryIdx); if (!PySequence_Check(entry) || PySequence_Size(entry) != 3) { throw_value_error("weights argument must be a sequence of 3-sequences"); } int idx1 = PyInt_AsLong(PySequence_GetItem(entry, 0)); int idx2 = PyInt_AsLong(PySequence_GetItem(entry, 1)); double w = PyFloat_AsDouble(PySequence_GetItem(entry, 2)); weightMap[std::make_pair(idx1, idx2)] = w; } DistGeom::VECT_CHIRALSET csets; ForceFields::ForceField *field = DistGeom::constructForceField(bm, posPtrs, csets, 0.0, 0.0, &weightMap); CHECK_INVARIANT(field, "could not build dgeom force field"); field->initialize(); if (field->calcEnergy() > 1e-5) { int needMore = 1; while (needMore) { needMore = field->minimize(); } } delete field; } else { throw_value_error("could not embed matrix"); } // ---- ---- ---- ---- ---- ---- ---- ---- ---- // construct the results matrix: npy_intp dims[2]; dims[0] = nrows; dims[1] = 3; PyArrayObject *res = (PyArrayObject *)PyArray_SimpleNew(2, dims, NPY_DOUBLE); double *resData = reinterpret_cast<double *>(PyArray_DATA(res)); for (unsigned int i = 0; i < nrows; i++) { unsigned int iTab = i * 3; for (unsigned int j = 0; j < 3; ++j) { resData[iTab + j] = positions[i][j]; //.x; } } delete[] positions; return PyArray_Return(res); }
int eq_op ( ) { Matrix a; Matrix b; Matrix c; double lvalue; double rvalue; descriptor *left; descriptor *right; descriptor *result; descriptor temp; int type_error; int status; int cmp; unsigned i; unsigned j; right = pop ( ); result = top ( ); temp = *result; left = &temp; left = deref (left); right = deref (right); if (D_Type (left) != T_String || D_Type (right) != T_String) { left = CoerceData (left, T_Double); right = CoerceData (right, T_Double); } status = 0; type_error = F_False; switch (D_Type (left)) { case T_Double: switch (D_Type (right)) { case T_Double: D_Type (result) = T_Double; D_Temp (result) = F_False; D_Trapped (result) = F_False; D_Double (result) = dbllit (*D_Double (left) == *D_Double (right)); break; case T_Matrix: a = D_Matrix (right); CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a)); b = D_Matrix (result); lvalue = *D_Double (left); for (i = 1; i <= Mrows (a); i ++) for (j = 1; j <= Mcols (a); j ++) sdata (b, i, j) = lvalue == mdata (a, i, j); break; default: type_error = F_True; break; } break; case T_Matrix: switch (D_Type (right)) { case T_Double: a = D_Matrix (left); CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a)); b = D_Matrix (result); rvalue = *D_Double (right); for (i = 1; i <= Mrows (a); i ++) for (j = 1; j <= Mcols (a); j ++) sdata (b, i, j) = mdata (a, i, j) == rvalue; break; case T_Matrix: a = D_Matrix (left); b = D_Matrix (right); CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a)); c = D_Matrix (result); if ((status = CompareEQMatrices (c, a, b))) MatrixError ("==", a, b, status, F_False); break; default: type_error = F_True; break; } break; case T_String: switch (D_Type (right)) { case T_String: cmp = strcmp (*D_String (left), *D_String (right)); D_Type (result) = T_Double; D_Temp (result) = F_False; D_Trapped (result) = F_False; D_Double (result) = dbllit (cmp == 0); break; default: type_error = F_True; break; } break; case T_Function: case T_Intrinsic: case T_Array: case T_Pair: if (D_Type (left) == D_Type (right)) { D_Type (result) = T_Double; D_Temp (result) = F_False; D_Trapped (result) = F_False; D_Double (result) = dbllit (D_Pointer (left) == D_Pointer (right)); } else type_error = F_False; break; case T_Constraint: case T_Definition: case T_Element: case T_Force: case T_Load: case T_Material: case T_Node: case T_Stress: case T_External: if (D_Type (left) == D_Type (right)) { cmp = *(void **) D_Pointer (left) == *(void **) D_Pointer (right); D_Type (result) = T_Double; D_Temp (result) = F_False; D_Trapped (result) = F_False; D_Double (result) = dbllit (cmp); } else if (D_Type (right) == T_Null) { cmp = *(void **) D_Pointer (left) == NULL; D_Type (result) = T_Double; D_Temp (result) = F_False; D_Trapped (result) = F_False; D_Double (result) = dbllit (cmp); } else type_error = F_True; break; case T_Null: switch (D_Type (right)) { case T_Constraint: case T_Definition: case T_Element: case T_Force: case T_Load: case T_Material: case T_Node: case T_Stress: case T_External: cmp = *(void **) D_Pointer (right) == NULL; D_Type (result) = T_Double; D_Temp (result) = F_False; D_Trapped (result) = F_False; D_Double (result) = dbllit (cmp); break; default: type_error = F_True; break; } break; default: type_error = F_True; break; } if (type_error == F_True) TypeError ("==", left, right, NULL, F_False); RecycleData (left); RecycleData (right); d_printf ("eq ans =\n"); d_PrintData (result); return type_error == F_True || status != 0; }
LRESULT vmsSniffDllWnd::OnProcessWebPageUrl(LPARAM lp) { LOGFN ("vmsSniffDllWnd::OnProcessWebPageUrl"); static HANDLE _hmxAccMem = CreateMutex (NULL, FALSE, L"FdmFlvSniffDll::mutex::AccMem"); WaitForSingleObject (_hmxAccMem, INFINITE); LOGsnl ("Got mem mutex"); vmsSharedData sdata (L"Fdm::mem::passUrlToFlvSniffDll", TRUE, 0, FILE_MAP_READ); if (sdata.getData () == NULL) { LOGsnl ("Failed to access shared data"); ReleaseMutex (_hmxAccMem); return E_FAIL; } LPTSTR pszUrl = new TCHAR [_tcslen ((LPTSTR)sdata.getData ())+1]; _tcscpy (pszUrl, (LPTSTR)sdata.getData ()); sdata.Release (); LOG ("Got URL: %s", pszUrl); ReleaseMutex (_hmxAccMem); extern vmsFindFlvDownloadsResultsCache _FlvResCache; vmsFindFlvDownloadsResultsCache::ResultPtr result; #ifdef LOG_WEBFILES_TREE extern LONG _cInOnGetItBtnClicked; InterlockedIncrement (&_cInOnGetItBtnClicked); #endif HRESULT hr = _FlvResCache.FindFlvDownloads (stringFromTstring (pszUrl).c_str (), NULL, NULL, NULL, NULL, NULL, result); #ifdef LOG_WEBFILES_TREE InterlockedDecrement (&_cInOnGetItBtnClicked); #endif LOG ("Analyzed"); if (hr == S_OK && result->pTa->get_FlvDownloadCount () != 0) { LOGsnl ("Creating transfer to FDM thread"); result->AddRef (); DWORD dw; CloseHandle ( CreateThread (NULL, 0, _threadTransferDldsToFdm, result, 0, &dw)); } else { LOGsnl ("No downloads found"); } delete [] pszUrl; return hr; }