void CyclicCoordinateDescent::update(const ModeFindingArguments& arguments) { const auto maxIterations = arguments.maxIterations; const auto convergenceType = arguments.convergenceType; const auto epsilon = arguments.tolerance; const int maxCount = arguments.maxBoundCount; initialBound = arguments.initialBound; int count = 0; bool done = false; while (!done) { if (arguments.useKktSwindle && jointPrior->getSupportsKktSwindle()) { kktSwindle(arguments); } else { findMode(maxIterations, convergenceType, epsilon); } ++count; if (lastReturnFlag == ILLCONDITIONED && count < maxCount) { // Reset beta and shrink bounding box initialBound /= 10.0; resetBeta(); } else { done = true; } } }
void CyclicCoordinateDescent::findMode(Iterator begin, Iterator end, const int maxIterations, const int convergenceType, const double epsilon) { std::fill(fixBeta.begin(), fixBeta.end(), true); std::for_each(begin, end, [this] (ScoreTuple& tuple) { fixBeta[std::get<0>(tuple)] = false; }); findMode(maxIterations, convergenceType, epsilon); // fixBeta is no longer valid }
void ModeManager::setFocusToCurrentMode() { IMode *mode = findMode(currentMode()); QTC_ASSERT(mode, return); QWidget *widget = mode->widget(); if (widget) { QWidget *focusWidget = widget->focusWidget(); if (!focusWidget) focusWidget = widget; focusWidget->setFocus(); } }
/* * Class: jogamp_newt_driver_x11_RandR13 * Method: getMonitorCurrentMode0 * Signature: (JJ)[I */ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorCurrentMode0 (JNIEnv *env, jclass clazz, jlong screenResources, jlong monitorInfo) { XRRScreenResources *resources = (XRRScreenResources *) (intptr_t) screenResources; XRRCrtcInfo *xrrCrtcInfo = (XRRCrtcInfo *) (intptr_t) monitorInfo; if( NULL == resources || NULL == xrrCrtcInfo ) { // n/a return NULL; } if( None == xrrCrtcInfo->mode || 0 == xrrCrtcInfo->noutput ) { // disabled return NULL; } RRMode modeId = xrrCrtcInfo->mode; XRRModeInfo *mode = findMode(resources, modeId); if( NULL == mode ) { // oops .. return NULL; } unsigned int dots = mode->hTotal * mode->vTotal; int refresh = (int) ( getVRefresh(mode) * 100.0f ); // Hz * 100 int flags = 0; if (mode->modeFlags & RR_Interlace) { flags |= FLAG_INTERLACE; } if (mode->modeFlags & RR_DoubleScan) { flags |= FLAG_DOUBLESCAN; } jint prop[ NUM_MONITOR_MODE_PROPERTIES_ALL ]; int propIndex = 0; prop[propIndex++] = NUM_MONITOR_MODE_PROPERTIES_ALL; prop[propIndex++] = mode->width; prop[propIndex++] = mode->height; prop[propIndex++] = 32; // TODO: XRandR > 1.4 may support bpp prop[propIndex++] = refresh; prop[propIndex++] = flags; prop[propIndex++] = mode->id; prop[propIndex++] = NewtScreen_XRotation2Degree(env, xrrCrtcInfo->rotation); jintArray properties = (*env)->NewIntArray(env, NUM_MONITOR_MODE_PROPERTIES_ALL); if (properties == NULL) { NewtCommon_throwNewRuntimeException(env, "Could not allocate int array of size %d", NUM_MONITOR_MODE_PROPERTIES_ALL); } (*env)->SetIntArrayRegion(env, properties, 0, NUM_MONITOR_MODE_PROPERTIES_ALL, prop); return properties; }
static crtc_t* createCrtcChain(Display *dpy, XRRScreenResources *resources, RRCrtc customCrtc, XRRCrtcInfo *customCrtcInfo, Rotation customRotation, int customX, int customY, XRRModeInfo *customModeInfo) { crtc_t *root_crtc = NULL; crtc_t *iter_crtc = NULL; int i; for(i=0; i<resources->ncrtc; i++) { crtc_t *next_crtc = calloc(1, sizeof(crtc_t)); if( NULL == iter_crtc ) { root_crtc = next_crtc; } else { iter_crtc->next = next_crtc; } iter_crtc = next_crtc; RRCrtc crtcId = resources->crtcs[i]; iter_crtc->crtc_id = crtcId; if( crtcId == customCrtc && 0 != customCrtc ) { iter_crtc->rotation = customRotation; iter_crtc->x = customX; iter_crtc->y = customY; iter_crtc->mode_info = customModeInfo; iter_crtc->mode_id = customModeInfo->id; iter_crtc->crtc_info = customCrtcInfo; } else { XRRCrtcInfo *xrrCrtcInfo = XRRGetCrtcInfo (dpy, resources, crtcId); iter_crtc->rotation = xrrCrtcInfo->rotation; iter_crtc->x = xrrCrtcInfo->x; iter_crtc->y = xrrCrtcInfo->y; iter_crtc->mode_id = xrrCrtcInfo->mode; iter_crtc->mode_info = findMode(resources, iter_crtc->mode_id); iter_crtc->crtc_info = xrrCrtcInfo; } iter_crtc->panning_info = XRRGetPanning(dpy, resources, crtcId); } return root_crtc; }
int main() { srand(time(0)); const int SIZE = 100; int quickArray[SIZE]; std::cout << "Values before: "; for (int i = 0; i < SIZE; i++) { if (i % 2 == 0) quickArray[i] = i; else quickArray[i] = -i; std::cout << quickArray[i] << " "; } std::cout << std::endl << std::endl; std::sort(quickArray, quickArray + SIZE); std::cout << "Values after sort: "; for (int i = 0; i < SIZE; i++) { std::cout << quickArray[i] << " "; } std::cout << std::endl << std::endl; std::vector<int> result = findMode(quickArray, SIZE); std::cout << "Mode(s): "; for (int i = 0; i < result.size(); i++) { std::cout << result[i] << " "; } std::cout << std::endl; std::cin.get(); return 0; }
OpenNI2Interface::OpenNI2Interface(int inWidth, int inHeight, int fps) : width(inWidth), height(inHeight), fps(fps), initSuccessful(true) { //Setup openni::Status rc = openni::STATUS_OK; const char * deviceURI = openni::ANY_DEVICE; rc = openni::OpenNI::initialize(); std::string errorString(openni::OpenNI::getExtendedError()); if(errorString.length() > 0) { errorText.append(errorString); initSuccessful = false; } else { rc = device.open(deviceURI); if (rc != openni::STATUS_OK) { errorText.append(openni::OpenNI::getExtendedError()); openni::OpenNI::shutdown(); initSuccessful = false; } else { openni::VideoMode depthMode; depthMode.setFps(fps); depthMode.setPixelFormat(openni::PIXEL_FORMAT_DEPTH_1_MM); depthMode.setResolution(width, height); openni::VideoMode colorMode; colorMode.setFps(fps); colorMode.setPixelFormat(openni::PIXEL_FORMAT_RGB888); colorMode.setResolution(width, height); rc = depthStream.create(device, openni::SENSOR_DEPTH); if (rc == openni::STATUS_OK) { depthStream.setVideoMode(depthMode); rc = depthStream.start(); if (rc != openni::STATUS_OK) { errorText.append(openni::OpenNI::getExtendedError()); depthStream.destroy(); initSuccessful = false; } } else { errorText.append(openni::OpenNI::getExtendedError()); initSuccessful = false; } rc = rgbStream.create(device, openni::SENSOR_COLOR); if (rc == openni::STATUS_OK) { rgbStream.setVideoMode(colorMode); rc = rgbStream.start(); if (rc != openni::STATUS_OK) { errorText.append(openni::OpenNI::getExtendedError()); rgbStream.destroy(); initSuccessful = false; } } else { errorText.append(openni::OpenNI::getExtendedError()); initSuccessful = false; } if (!depthStream.isValid() || !rgbStream.isValid()) { errorText.append(openni::OpenNI::getExtendedError()); openni::OpenNI::shutdown(); initSuccessful = false; } if(initSuccessful) { //For printing out formatMap[openni::PIXEL_FORMAT_DEPTH_1_MM] = "1mm"; formatMap[openni::PIXEL_FORMAT_DEPTH_100_UM] = "100um"; formatMap[openni::PIXEL_FORMAT_SHIFT_9_2] = "Shift 9 2"; formatMap[openni::PIXEL_FORMAT_SHIFT_9_3] = "Shift 9 3"; formatMap[openni::PIXEL_FORMAT_RGB888] = "RGB888"; formatMap[openni::PIXEL_FORMAT_YUV422] = "YUV422"; formatMap[openni::PIXEL_FORMAT_GRAY8] = "GRAY8"; formatMap[openni::PIXEL_FORMAT_GRAY16] = "GRAY16"; formatMap[openni::PIXEL_FORMAT_JPEG] = "JPEG"; assert(findMode(width, height, fps) && "Sorry, mode not supported!"); latestDepthIndex.assignValue(-1); latestRgbIndex.assignValue(-1); for(int i = 0; i < numBuffers; i++) { uint8_t * newImage = (uint8_t *)calloc(width * height * 3, sizeof(uint8_t)); rgbBuffers[i] = std::pair<uint8_t *, int64_t>(newImage, 0); } for(int i = 0; i < numBuffers; i++) { uint8_t * newDepth = (uint8_t *)calloc(width * height * 2, sizeof(uint8_t)); uint8_t * newImage = (uint8_t *)calloc(width * height * 3, sizeof(uint8_t)); frameBuffers[i] = std::pair<std::pair<uint8_t *, uint8_t *>, int64_t>(std::pair<uint8_t *, uint8_t *>(newDepth, newImage), 0); } rgbCallback = new RGBCallback(lastRgbTime, latestRgbIndex, rgbBuffers); depthCallback = new DepthCallback(lastDepthTime, latestDepthIndex, latestRgbIndex, rgbBuffers, frameBuffers); depthStream.setMirroringEnabled(false); rgbStream.setMirroringEnabled(false); device.setDepthColorSyncEnabled(true); device.setImageRegistrationMode(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR); setAutoExposure(true); setAutoWhiteBalance(true); rgbStream.addNewFrameListener(rgbCallback); depthStream.addNewFrameListener(depthCallback); } } } }
void CyclicCoordinateDescent::kktSwindle(const ModeFindingArguments& arguments) { const auto maxIterations = arguments.maxIterations; const auto convergenceType = arguments.convergenceType; const auto epsilon = arguments.tolerance; // Make sure internal state is up-to-date checkAllLazyFlags(); std::list<ScoreTuple> activeSet; std::list<ScoreTuple> inactiveSet; std::list<int> excludeSet; // Initialize sets int intercept = -1; if (hXI.getHasInterceptCovariate()) { intercept = hXI.getHasOffsetCovariate() ? 1 : 0; } for (int index = 0; index < J; ++index) { if (fixBeta[index]) { excludeSet.push_back(index); } else { if (index == intercept || // Always place intercept into active set !jointPrior->getSupportsKktSwindle(index)) { // activeSet.push_back(index); activeSet.push_back(std::make_tuple(index, 0.0, true)); } else { inactiveSet.push_back(std::make_tuple(index, 0.0, false)); } } } bool done = false; int swindleIterationCount = 1; // int initialActiveSize = activeSet.size(); int perPassSize = arguments.swindleMultipler; while (!done) { if (noiseLevel >= QUIET) { std::ostringstream stream; stream << "\nKKT Swindle count " << swindleIterationCount << ", activeSet size = " << activeSet.size(); logger->writeLine(stream); } // Enforce all beta[inactiveSet] = 0 for (auto& inactive : inactiveSet) { if (getBeta(std::get<0>(inactive)) != 0.0) { // Touch only if necessary setBeta(std::get<0>(inactive), 0.0); } } double updateTime = 0.0; lastReturnFlag = SUCCESS; if (activeSet.size() > 0) { // find initial mode auto start = bsccs::chrono::steady_clock::now(); findMode(begin(activeSet), end(activeSet), maxIterations, convergenceType, epsilon); auto end = bsccs::chrono::steady_clock::now(); bsccs::chrono::duration<double> elapsed_seconds = end-start; updateTime = elapsed_seconds.count(); } if (noiseLevel >= QUIET) { std::ostringstream stream; stream << "update time: " << updateTime << " in " << lastIterationCount << " iterations."; logger->writeLine(stream); } if (inactiveSet.size() == 0 || lastReturnFlag != SUCCESS) { // Computed global mode, nothing more to do, or failed done = true; } else { // still inactive covariates if (swindleIterationCount == maxIterations) { lastReturnFlag = MAX_ITERATIONS; done = true; if (noiseLevel > SILENT) { std::ostringstream stream; stream << "Reached maximum swindle iterations"; logger->writeLine(stream); } } else { auto checkConditions = [this] (const ScoreTuple& score) { return (std::get<1>(score) <= jointPrior->getKktBoundary(std::get<0>(score))); }; // auto checkAlmostConditions = [this] (const ScoreTuple& score) { // return (std::get<1>(score) < 0.9 * jointPrior->getKktBoundary(std::get<0>(score))); // }; // Check KKT conditions computeKktConditions(inactiveSet); bool satisfied = std::all_of(begin(inactiveSet), end(inactiveSet), checkConditions); if (satisfied) { done = true; } else { // auto newActiveSize = initialActiveSize + perPassSize; auto count1 = std::distance(begin(inactiveSet), end(inactiveSet)); auto count2 = std::count_if(begin(inactiveSet), end(inactiveSet), checkConditions); // Remove elements from activeSet if less than 90% of boundary // computeKktConditions(activeSet); // TODO Already computed in findMode // // // for (auto& active : activeSet) { // // std::ostringstream stream; // // stream << "Active: " << std::get<0>(active) << " : " << std::get<1>(active) << " : " << std::get<2>(active); // // logger->writeLine(stream); // // } // // int countActiveViolations = 0; // while(activeSet.size() > 0 && // checkAlmostConditions(activeSet.back()) // ) { // auto& back = activeSet.back(); // // // std::ostringstream stream; // // stream << "Remove: " << std::get<0>(back) << ":" << std::get<1>(back) // // << " cut @ " << jointPrior->getKktBoundary(std::get<0>(back)) // // << " diff = " << (std::get<1>(back) - jointPrior->getKktBoundary(std::get<0>(back))); // // logger->writeLine(stream); // // inactiveSet.push_back(back); // activeSet.pop_back(); // ++countActiveViolations; // } // end // Move inactive elements into active if KKT conditions are not met while (inactiveSet.size() > 0 && !checkConditions(inactiveSet.front()) // && activeSet.size() < newActiveSize ) { auto& front = inactiveSet.front(); // std::ostringstream stream; // stream << std::get<0>(front) << ":" << std::get<1>(front); // logger->writeLine(stream); activeSet.push_back(front); inactiveSet.pop_front(); } if (noiseLevel >= QUIET) { std::ostringstream stream; // stream << " Active set violations: " << countActiveViolations << std::endl; stream << "Inactive set violations: " << (count1 - count2); logger->writeLine(stream); } } } } ++swindleIterationCount; perPassSize *= 2; logger->yield(); // This is not re-entrant safe } // restore fixBeta std::fill(fixBeta.begin(), fixBeta.end(), false); for (auto index : excludeSet) { fixBeta[index] = true; } }
int main(int argc, char **argv) { merylStreamReader *AF = 0L; merylStreamReader *TF = 0L; merylStreamReader *AC = 0L; merylStreamReader *DC = 0L; merylStreamReader *CO = 0L; uint32 AFmode = 0; uint32 TFmode = 0; char dumpSCZFname[1024] = {0}; // single contig, zero frags char dumpMCZFname[1024] = {0}; // low contig, zero frags char dumpMCSFname[1024] = {0}; // medium contig, low frags char dumpMCMFname[1024] = {0}; // everything else, contig > frags bool beVerbose = false; argc = AS_configure(argc, argv); int arg=1; while (arg < argc) { if (strcmp(argv[arg], "-af") == 0) { // All frags ++arg; AFmode = findMode(argv[arg]); AF = new merylStreamReader(argv[arg]); AF->nextMer(); } else if (strcmp(argv[arg], "-tf") == 0) { // Trimmed frags ++arg; TFmode = findMode(argv[arg]); TF = new merylStreamReader(argv[arg]); TF->nextMer(); } else if (strcmp(argv[arg], "-ac") == 0) { // All contigs AC = new merylStreamReader(argv[++arg]); AC->nextMer(); } else if (strcmp(argv[arg], "-dc") == 0) { // Degenerate contigs DC = new merylStreamReader(argv[++arg]); DC->nextMer(); } else if (strcmp(argv[arg], "-co") == 0) { // Contigs CO = new merylStreamReader(argv[++arg]); CO->nextMer(); } else if (strcmp(argv[arg], "-dump") == 0) { arg++; dumpFlag = true; sprintf(dumpSCZFname, "%s.0.singlecontig.zerofrag.fasta", argv[arg]); sprintf(dumpMCZFname, "%s.1.multiplecontig.zerofrag.fasta", argv[arg]); sprintf(dumpMCSFname, "%s.2.multiplecontig.lowfrag.fasta", argv[arg]); sprintf(dumpMCMFname, "%s.3.multiplecontig.multiplefrag.fasta", argv[arg]); } else if (strcmp(argv[arg], "-v") == 0) { beVerbose = true; } else { fprintf(stderr, "unknown option '%s'\n", argv[arg]); } arg++; } if ((AF == 0L) && (TF == 0L) && (AC == 0L) && (DC == 0L) && (CO == 0L)) { fprintf(stderr, "usage: %s [opts] [-v] [-dump prefix]\n", argv[0]); fprintf(stderr, "At least one fragcounts and one contigcounts are needed.\n"); fprintf(stderr, " -af | -tf fragcounts\n"); fprintf(stderr, " -ac | -dc | -co contigcounts \n"); fprintf(stderr, "Dumping is probably only useful with exactly one frag and\n"); fprintf(stderr, "one contig, but I'll let you do it with any number.\n"); exit(1); } if ((AF == 0L) && (TF == 0L)) { fprintf(stderr, "ERROR - need at least one of -af, -tf\n"); exit(1); } if ((AC == 0L) && (DC == 0L) && (CO == 0L)) { fprintf(stderr, "ERROR - need at least one of -ac, -dc, -co\n"); exit(1); } // Check mersizes. // uint32 merSize = 0; uint32 ms[5] = { 0 }; if (AF) merSize = ms[0] = AF->merSize(); if (TF) merSize = ms[1] = TF->merSize(); if (AC) merSize = ms[2] = AC->merSize(); if (DC) merSize = ms[3] = DC->merSize(); if (CO) merSize = ms[4] = CO->merSize(); bool differ = false; if ((ms[0] > 0) && (ms[0] != merSize)) differ = true; if ((ms[1] > 0) && (ms[1] != merSize)) differ = true; if ((ms[2] > 0) && (ms[2] != merSize)) differ = true; if ((ms[3] > 0) && (ms[3] != merSize)) differ = true; if ((ms[4] > 0) && (ms[4] != merSize)) differ = true; if (differ) { fprintf(stderr, "error: mer size differ.\n"); fprintf(stderr, " AF - "F_U32"\n", ms[0]); fprintf(stderr, " TF - "F_U32"\n", ms[1]); fprintf(stderr, " AC - "F_U32"\n", ms[2]); fprintf(stderr, " DC - "F_U32"\n", ms[3]); fprintf(stderr, " CO - "F_U32"\n", ms[4]); exit(1); } if (dumpFlag) { errno = 0; dumpSCZF = fopen(dumpSCZFname, "w"); dumpMCZF = fopen(dumpMCZFname, "w"); dumpMCSF = fopen(dumpMCSFname, "w"); dumpMCMF = fopen(dumpMCMFname, "w"); if (errno) fprintf(stderr, "Failed to open the dump files: %s\n", strerror(errno)), exit(1); } uint32 AFvsAC[NUMCATEGORIES][NUMCATEGORIES]; uint32 AFvsDC[NUMCATEGORIES][NUMCATEGORIES]; uint32 AFvsCO[NUMCATEGORIES][NUMCATEGORIES]; uint32 TFvsAC[NUMCATEGORIES][NUMCATEGORIES]; uint32 TFvsDC[NUMCATEGORIES][NUMCATEGORIES]; uint32 TFvsCO[NUMCATEGORIES][NUMCATEGORIES]; for (uint32 i=0; i<NUMCATEGORIES; i++) for (uint32 j=0; j<NUMCATEGORIES; j++) { AFvsAC[i][j] = 0; AFvsDC[i][j] = 0; AFvsCO[i][j] = 0; TFvsAC[i][j] = 0; TFvsDC[i][j] = 0; TFvsCO[i][j] = 0; } // The default constructor for kMer sets the mer to size 0, all A. // We need it to be the proper size, and all T. kMer minmer(merSize); // Don't care what we pick, as long as it's a mer in the set. // if (AF && AF->validMer()) minmer = AF->theFMer(); if (TF && TF->validMer()) minmer = TF->theFMer(); if (AC && AC->validMer()) minmer = AC->theFMer(); if (DC && DC->validMer()) minmer = DC->theFMer(); if (CO && CO->validMer()) minmer = CO->theFMer(); speedCounter *C = new speedCounter(" Examining: %7.2f Mmers -- %5.2f Mmers/second\r", 1000000.0, 0x1fffff, beVerbose); bool morestuff = true; while (morestuff) { // Find any mer in our set if (AF && AF->validMer()) minmer = AF->theFMer(); if (TF && TF->validMer()) minmer = TF->theFMer(); if (AC && AC->validMer()) minmer = AC->theFMer(); if (DC && DC->validMer()) minmer = DC->theFMer(); if (CO && CO->validMer()) minmer = CO->theFMer(); // Find the smallest mer in our set if (AF && AF->validMer() && (AF->theFMer() < minmer)) minmer = AF->theFMer(); if (TF && TF->validMer() && (TF->theFMer() < minmer)) minmer = TF->theFMer(); if (AC && AC->validMer() && (AC->theFMer() < minmer)) minmer = AC->theFMer(); if (DC && DC->validMer() && (DC->theFMer() < minmer)) minmer = DC->theFMer(); if (CO && CO->validMer() && (CO->theFMer() < minmer)) minmer = CO->theFMer(); // We need to do up to six comparisons here. if (AF && AC) compare(AF, AC, minmer, AFmode, AFvsAC); if (AF && DC) compare(AF, DC, minmer, AFmode, AFvsDC); if (AF && CO) compare(AF, CO, minmer, AFmode, AFvsCO); if (TF && AC) compare(TF, AC, minmer, TFmode, TFvsAC); if (TF && DC) compare(TF, DC, minmer, TFmode, TFvsDC); if (TF && CO) compare(TF, CO, minmer, TFmode, TFvsCO); C->tick(); #if 0 if (C->tick()) { char stringjunk[256]; fprintf(stderr, "\nMM %s\n", minmer.merToString(stringjunk)); if (AF) fprintf(stderr, "AF %s\n", AF->theFMer().merToString(stringjunk)); if (TF) fprintf(stderr, "TF %s\n", TF->theFMer().merToString(stringjunk)); if (AC) fprintf(stderr, "AC %s\n", AC->theFMer().merToString(stringjunk)); if (DC) fprintf(stderr, "DC %s\n", DC->theFMer().merToString(stringjunk)); if (CO) fprintf(stderr, "CO %s\n", CO->theFMer().merToString(stringjunk)); } #endif // Advance to the next mer, if we were just used morestuff = false; if ((AF) && (AF->theFMer() == minmer)) morestuff |= AF->nextMer(); if ((TF) && (TF->theFMer() == minmer)) morestuff |= TF->nextMer(); if ((AC) && (AC->theFMer() == minmer)) morestuff |= AC->nextMer(); if ((DC) && (DC->theFMer() == minmer)) morestuff |= DC->nextMer(); if ((CO) && (CO->theFMer() == minmer)) morestuff |= CO->nextMer(); } delete C; // output if ((AF) && (AC)) output("all frags vs all contigs", AFmode, AFvsAC); if ((AF) && (DC)) output("all frags vs deg. contigs", AFmode, AFvsDC); if ((AF) && (CO)) output("all frags vs non-deg. contigs", AFmode, AFvsCO); if ((TF) && (AC)) output("trimmed frags vs all contigs", TFmode, TFvsAC); if ((TF) && (DC)) output("trimmed frags vs deg. contigs", TFmode, TFvsDC); if ((TF) && (CO)) output("trimmed frags vs non-deg. contigs", TFmode, TFvsCO); delete AF; delete TF; delete AC; delete DC; delete CO; exit(0); }
/* * Class: jogamp_newt_driver_x11_RandR13 * Method: setMonitorMode0 * Signature: (JJJIIIII)Z */ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_RandR13_setMonitorMode0 (JNIEnv *env, jclass clazz, jlong display, jint screen_idx, jlong screenResources, jlong monitorInfo, jint crt_id, jint jmode_id, jint rotation, jint x, jint y) { jboolean res = JNI_FALSE; Display * dpy = (Display *) (intptr_t) display; Window root = RootWindow(dpy, (int)screen_idx); XRRScreenResources *resources = (XRRScreenResources *) (intptr_t) screenResources; RRCrtc crtc = findRRCrtc( resources, (RRCrtc)(intptr_t)crt_id ); if( 0 == crtc ) { // n/a DBG_PRINT("RandR13_setMonitorMode0.0: n/a: resources %p (%d), crt_id %#lx \n", resources, (NULL == resources ? 0 : resources->ncrtc), (RRCrtc)(intptr_t)crt_id); return res; } XRRCrtcInfo *xrrCrtcInfo = (XRRCrtcInfo *) (intptr_t) monitorInfo; if( NULL == xrrCrtcInfo ) { // n/a DBG_PRINT("RandR13_setMonitorMode0.1: n/a: resources %p (%d), xrrCrtcInfo %p, crtc %#lx\n", resources, (NULL == resources ? 0 : resources->ncrtc), xrrCrtcInfo, crtc); return res; } if( None == xrrCrtcInfo->mode || 0 == xrrCrtcInfo->noutput ) { // disabled DBG_PRINT("RandR13_setMonitorMode0: disabled: mode %d, noutput %d\n", xrrCrtcInfo->mode, xrrCrtcInfo->noutput); return res; } if( 0 >= jmode_id ) { // oops .. DBG_PRINT("RandR13_setMonitorMode0: inv. modeId: modeId %d\n", jmode_id); return res; } RRMode mode_id = (RRMode)(intptr_t)jmode_id; XRRModeInfo *mode_info = findMode(resources, mode_id); if( NULL == mode_info ) { // oops .. DBG_PRINT("RandR13_setMonitorMode0: inv. mode_id: mode_id %#lx\n", mode_id); return res; } if( 0 > x || 0 > y ) { x = xrrCrtcInfo->x; y = xrrCrtcInfo->y; } Rotation xrotation = NewtScreen_Degree2XRotation(env, rotation); int rot_change = xrrCrtcInfo->rotation != xrotation; DBG_PRINT("RandR13_setMonitorMode0: crt %#lx, noutput %d -> 0x%X, mode %#lx -> %#lx, pos %d / %d, rotation %d -> %d (change %d)\n", crtc, xrrCrtcInfo->noutput, xrrCrtcInfo->outputs[0], xrrCrtcInfo->mode, mode_id, x, y, (int)xrrCrtcInfo->rotation, (int)xrotation, rot_change); XRRSelectInput (dpy, root, RRScreenChangeNotifyMask); Status status = RRSetConfigSuccess; int pre_fb_width=0, pre_fb_height=0; int fb_width=0, fb_height=0; int fb_width_mm=0, fb_height_mm=0; crtc_t *root_crtc = get_screen_size1(dpy, root, &fb_width, &fb_height, resources, crtc, xrrCrtcInfo, xrotation, x, y, mode_info); Bool fb_change = get_screen_sizemm(dpy, screen_idx, fb_width, fb_height, &fb_width_mm, &fb_height_mm, &pre_fb_width, &pre_fb_height); DBG_PRINT("RandR13_setMonitorMode0: crt %#lx, fb[change %d: %d x %d -> %d x %d [%d x %d mm]\n", crtc, fb_change, pre_fb_width, pre_fb_height, fb_width, fb_height, fb_width_mm, fb_height_mm); if(fb_change) { // Disable CRTC first, since new size differs from current // and we shall avoid invalid intermediate configuration (see spec)! #if 0 { // Disable all CRTCs (Not required!) crtc_t * iter_crtc; for(iter_crtc=root_crtc; RRSetConfigSuccess == status && NULL!=iter_crtc; iter_crtc=iter_crtc->next) { if( None == iter_crtc->mode_id || NULL == iter_crtc->mode_info || 0 == iter_crtc->crtc_info->noutput ) { // disabled continue; } status = XRRSetCrtcConfig (dpy, resources, iter_crtc->crtc_id, CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0); } } #else status = XRRSetCrtcConfig (dpy, resources, crtc, CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0); #endif DBG_PRINT("RandR13_setMonitorMode0: crt %#lx disable: %d -> %d\n", crtc, status, RRSetConfigSuccess == status); if( RRSetConfigSuccess == status ) { XRRSetScreenSize (dpy, root, fb_width, fb_height, fb_width_mm, fb_height_mm); DBG_PRINT("RandR13_setMonitorMode0: crt %#lx screen-size\n", crtc); } } if( RRSetConfigSuccess == status ) { #if 0 { // Enable/Set all CRTCs (Not required!) crtc_t * iter_crtc; for(iter_crtc=root_crtc; RRSetConfigSuccess == status && NULL!=iter_crtc; iter_crtc=iter_crtc->next) { if( None == iter_crtc->mode_id || NULL == iter_crtc->mode_info || 0 == iter_crtc->crtc_info->noutput ) { // disabled continue; } status = XRRSetCrtcConfig( dpy, resources, iter_crtc->crtc_id, CurrentTime, iter_crtc->x, iter_crtc->y, iter_crtc->mode_id, iter_crtc->rotation, iter_crtc->crtc_info->outputs, iter_crtc->crtc_info->noutput ); } } #else status = XRRSetCrtcConfig( dpy, resources, crtc, CurrentTime, x, y, mode_id, xrotation, xrrCrtcInfo->outputs, xrrCrtcInfo->noutput ); #endif DBG_PRINT("RandR13_setMonitorMode0: crt %#lx set-config: %d -> %d\n", crtc, status, RRSetConfigSuccess == status); } res = status == RRSetConfigSuccess; DBG_PRINT("RandR13_setMonitorMode0: FIN: %d -> ok %d\n", status, res); destroyCrtcChain(root_crtc, crtc); root_crtc=NULL; return res; }
int main(int argc, char *argv[]) { enum Mode mode = MR122; int ch, dtx = 0; const char *infile, *outfile; FILE *out; void *wav, *amr; int format, sampleRate, channels, bitsPerSample; int inputSize; uint8_t* inputBuf; while ((ch = getopt(argc, argv, "r:d")) != -1) { switch (ch) { case 'r': mode = findMode(optarg); break; case 'd': dtx = 1; break; case '?': default: usage(argv[0]); return 1; } } if (argc - optind < 2) { usage(argv[0]); return 1; } infile = argv[optind]; outfile = argv[optind + 1]; wav = wav_read_open(infile); if (!wav) { fprintf(stderr, "Unable to open wav file %s\n", infile); return 1; } if (!wav_get_header(wav, &format, &channels, &sampleRate, &bitsPerSample, NULL)) { fprintf(stderr, "Bad wav file %s\n", infile); return 1; } if (format != 1) { fprintf(stderr, "Unsupported WAV format %d\n", format); return 1; } if (bitsPerSample != 16) { fprintf(stderr, "Unsupported WAV sample depth %d\n", bitsPerSample); return 1; } if (channels != 1) fprintf(stderr, "Warning, only compressing one audio channel\n"); if (sampleRate != 8000) fprintf(stderr, "Warning, AMR-NB uses 8000 Hz sample rate (WAV file has %d Hz)\n", sampleRate); inputSize = channels*2*160; inputBuf = (uint8_t*) malloc(inputSize); amr = Encoder_Interface_init(dtx); out = fopen(outfile, "wb"); if (!out) { perror(outfile); return 1; } fwrite("#!AMR\n", 1, 6, out); while (1) { short buf[160]; uint8_t outbuf[500]; int read, i, n; read = wav_read_data(wav, inputBuf, inputSize); read /= channels; read /= 2; if (read < 160) break; for (i = 0; i < 160; i++) { const uint8_t* in = &inputBuf[2*channels*i]; buf[i] = in[0] | (in[1] << 8); } n = Encoder_Interface_Encode(amr, mode, buf, outbuf, 0); fwrite(outbuf, 1, n, out); } free(inputBuf); fclose(out); Encoder_Interface_exit(amr); wav_read_close(wav); return 0; }
int main(int argc, char **argv) { TypePosition orderstart=1, orderend=10; char option[256], inputFileName[SIZE_BUFFER_CHAR], outputFileName[SIZE_BUFFER_CHAR], bufferOutput[SIZE_BUFFER_CHAR], *table, outputFormat = 'r', typeDec = 'l', typeAlphabet = '?', typeCalc = 'g', type = 't'; TypeSetOfSequences *set, seq; TypeAlignment aln, atmp; int fixed = 0; double threshold = 0.001, tmin = 1E-20, tmax=0.1, tstep = 0.00001, qmin = -25, qmax = -3, qprec = 0.5; double thre; TypeNumber n; TypeDistance distA, distB; TypePosition l, tot, lmax = 50; TypeSuffixTree *suffixTree; TypeMarkovModel *model; TypeCodeScheme *scheme; /* TypeDistFunction *distfunc[MAX_FUNC]= {computeProba, computeKullbackLeiber1, computePham, computeCommon, computeCommonBis, computeGillesPham, computeMatchesBis, computeMatches, computeAlex, computeAlexBis}; */ FILE *fi, *fo; int i = 1, typeDist = 0; for(i=0; i<256; i++) option[i] = 0; for(i=1; i<argc && *(argv[i]) == '-'; i++) { int j; for(j=1; argv[i][j] != '\0'; j++) option[argv[i][j]] = 1; if(option['f']) { option['f'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &outputFormat) == 1) i++; } if(option['s']) { option['s'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &typeAlphabet) == 1) i++; } if(option['c']) { option['c'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &typeCalc) == 1) i++; } if(option['m']) { option['m'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%lf", &tmin) == 1) i++; if(typeDist >= MAX_FUNC) typeDist = 0; } if(option['t']) { option['t'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%lf", &threshold) == 1) i++; } if(option['y']) { option['y'] = 0; if((i+1)<argc && sscanf(argv[i+1], "%c", &type) == 1) i++; } if(option['h']) { printf("%s\n", HELPMESSAGE); exitProg(ExitOk, NULL); } } if (i>=argc || sscanf(argv[i++], "%s", inputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE); if (i>=argc || sscanf(argv[i++], "%s", outputFileName) != 1) exitProg(ErrorArgument, HELPMESSAGE); switch(typeAlphabet) { case 'd': table = (char*) monmalloc((strlen(DNA)+1)*sizeof(char)); strcpy(table, DNA); break; case 'r': table = (char*) monmalloc((strlen(RNA)+1)*sizeof(char)); strcpy(table, RNA); break; case 'p': table = (char*) monmalloc((strlen(PRO)+1)*sizeof(char)); strcpy(table, PRO); break; case '?': default: table = (char*) monmalloc(sizeof(char)); table[0] = '\0'; } if(fi = fopen(inputFileName, "r")) { aln = readAlignement(fi, table, typeAlphabet == '?'); switch(typeAlphabet) { case 'd': case 'r': aln.ambiguity = getXNAAmbiguity(); break; case 'p': aln.ambiguity = getProteinAmbiguity(); break; case '?': default: aln.ambiguity.number = 0; } aln.cardinal -= aln.ambiguity.number; fclose(fi); } else { exitProg(ErrorReading, inputFileName); } fixAlignmentAmbiguity(&aln); set=toSequences(&aln); if(!(fo = fopen(outputFileName, "w"))) exitProg(ErrorWriting, outputFileName); distA = computeWholeDistancePairAln(aln, computeNorm1Aln); scheme = (TypeCodeScheme*) monmalloc(sizeof(TypeCodeScheme)); scheme->suffixTree = getSuffixTree(set); scheme->code = (TypePosition*) monmalloc(scheme->suffixTree->size*sizeof(TypePosition)); scheme->buffSize = INC_SIZE_CODE; scheme->lengthCode = (TypePosition*) monmalloc(scheme->buffSize*sizeof(TypePosition)); if(type == 't') { int l; model = estimateMarkovModel(set); // for(thre=tmin; thre<=tmax; thre *= 10.0) { for(l=tmin; l<=-1; l++) { double t; int k; thre = pow(10.0, (double) l); for(k=0; k<10; k++) { // for(t=thre; t<thre*10; t+=thre) { double corr, sc; TypeSetOfSequences *dec; t = ((double)k+1.)*thre; scheme->cardCode = 0; buildCodeThreshold(t, scheme->suffixTree->root, 0, 1., model, scheme); //printLengthDistribution(stdout, scheme->lengthCode,scheme->cardCode); dec = getDecodedFromScheme(scheme); //printf("cardinal dec = %ld\n", dec->cardinal); distB = computeWholeDistanceDec(dec); corr = computeCorrelation(distA, distB); monfree((void*)distB.table); sc = score(dec); printf("%lE\t%lf\t%.2lf\n", t, corr, sc); fprintf(fo, "%lE\t%lf\t%.2lf\n", t, corr, sc); for(n=0; n<dec->number; n++) monfree((void*) dec->sequence[n]); monfree((void*) dec->sequence); monfree((void*) dec->size); monfree((void*) dec); } } fprintf(stdout, "\n\n%.4lE\n\n", findMode(set, qmin, qmax, qprec, scheme, model)); freeModel(model); } else { for(l = lmax; l>=1; l--) { double corr; TypeSetOfSequences *dec; scheme->cardCode = 0; buildCodeLength(l, scheme->suffixTree->root, 0, scheme); //printLengthDistribution(stdout, scheme->lengthCode,scheme->cardCode); dec = getDecodedFromScheme(scheme); //printf("cardinal dec = %ld\n", dec->cardinal); distB = computeWholeDistanceDec(dec); corr = computeCorrelation(distA, distB); monfree((void*)distB.table); fprintf(fo, "%ld\t%lf\n", l, corr); fprintf(stdout, "%ld\t%lf\n", l, corr); for(n=0; n<dec->number; n++) monfree((void*) dec->sequence[n]); monfree((void*) dec->sequence); monfree((void*) dec->size); monfree((void*) dec); } } freeScheme(scheme); monfree((void*)distA.table); fprintf(stdout, "\n\n%ld\n\n", totalLength(*set)); monfree((void*)set->size); for(n=0; n<set->number; n++) monfree((void*)set->sequence[n]); monfree((void*)set->sequence); monfree((void*)set); fclose(fo); /* sprintf(bufferOutput, "%s_Ali.nex", outputFileName); if(!(fo = fopen(bufferOutput, "w"))) exitProg(ErrorWriting, bufferOutput); printDistanceNexus(fo, distA); fclose(fo); sprintf(bufferOutput, "%s_New.nex", outputFileName); if(!(fo = fopen(bufferOutput, "w"))) exitProg(ErrorWriting, bufferOutput); printDistanceNexus(fo, distB); fclose(fo); */ ; exitProg(ExitOk,NULL); return 0; }