/** * Create a new vector of peaks in results. m/z value of peaks will * now be a bin number, not an actual m/z value. Intensities of * multiple peaks in one bin are summed. * \returns The sum of the intensties of all raw peaks. */ double PeakProcessor::binPeaks(vector<PEAK_T>& peaks, vector<PEAK_T>& results ) { // start with an empty vector results.clear(); // if no peaks, return if( peaks.empty() ){ return 0; } double totalIntensity = 0; //initialize results to the first peak PEAK_T tmpPeak; tmpPeak.mz = getBin( peaks.at(0).mz ); tmpPeak.intensity = peaks.at(0).intensity; results.push_back( tmpPeak ); totalIntensity = tmpPeak.intensity; for(int i=1; i<(int)peaks.size(); i++) { tmpPeak.mz = getBin( peaks.at(i).mz ); tmpPeak.intensity = peaks.at(i).intensity; totalIntensity += peaks.at(i).intensity; if( tmpPeak.mz == results.back().mz ) results.back().intensity += peaks.at(i).intensity; else results.push_back(tmpPeak); } return totalIntensity; }
void Ring::getPoints(){ double x1 = cellRange[0]; double y1 = circle(x1); int yyy = 1; points.push_back(make_pair(x1,y1)); for(int i=1; i<=vecDim; i++){ double x2 = cellRange[i]; double y2 = circle(x2); if(getBin(y1) != getBin(y2)){ x2 = circle(cellRange[vecDim-yyy]); y2 = cellRange[vecDim-yyy]; yyy+=1; } if(x2>m_maxX){ x2 = m_maxX; y2 = circle(m_maxX); points.push_back(make_pair(x2,y2)); break; } points.push_back(make_pair(x2,y2)); if(x2<cellRange[i]){ x2 = cellRange[i]; y2 = circle(x2); points.push_back(make_pair(x2,y2)); } x1 = x2; y1 = y2; } }
void Ring::length(double x1, double x2, double y1, double y2){ double L = arclen(x1,x2,y1,y2); int x = getBin(x2); int y = getBin(y1); probMap[make_pair(x,y)]+= L; probMap[make_pair(y,x)]+= L; }
bool SpacePartition::getBinsInBox( int i, int j, int N, std::vector< SpaceBin* >* bins_in_box ) { int left = i - N; int right = i + N; int top = j - N; int bottom = j + N; if( left >= num_horizontal_bins || right < 0 || top >= num_vertical_bins || bottom < 0 ) { return false; } for( int p=left; p <= right; p++ ) { for( int q=top; q <= bottom; q++ ) { SpaceBin* bin = getBin( p, q ); if( bin ) { bins_in_box->push_back( bin ); } } } return true; }
void TileHolder::makeTile(const GridPt &tilePt, ImgFetcher &fetch, Mat &out, Mat &bg) { Point2f tileTl(tl.x + tilePt[0] * tileSz.width, tl.y + tilePt[1] * tileSz.height); const set<ImData> &bin = getBin(tilePt); out = Mat::zeros(tileSz, CV_32FC1);//gather the tile data in out Mat weightIm = Mat::zeros(tileSz, CV_32FC1) + FLT_MIN;//+ 1e-90; // avoid divide by zero, maybe static this? Mat curIm; for (const ImData &dat : bin) { fetch.getMat(dat.file, curIm); if (curIm.type() == CV_8U) { curIm.convertTo(curIm, CV_32F, 1. / 255); } else if (curIm.type() != CV_32F) { fprintf(stderr, "err: bad image type\n"); exit(1); } if (bg.data) { assert(bg.size() == curIm.size()); curIm -= bg; } std::cout << dat.file << std::endl; //saveFloatIm("testsomewhere.tif", weightMat); blit(curIm.mul(weightMat), out, dat.pos - tileTl); blit(weightMat, weightIm, dat.pos - tileTl); } out /= weightIm; }
static void processAlloc(const AllocInfo& info, uint64_t finalizeTime) { uint64_t lifetime = finalizeTime - info.serial; unsigned timeslice = info.serial / timesliceSize; unsigned lifetimeBin = getBin(lifetime); assert(lifetimeBin < lifetimeBins); ++allocCountByHeapAndKind[info.initialHeap][info.kind]; ++allocCountByHeapAndLifetime[info.initialHeap][lifetimeBin]; ++allocCountByHeapKindAndLifetime[info.initialHeap][info.kind][lifetimeBin]; if (info.kind <= LastObjectAllocKind) { const TypeInfo& typeInfo = types[info.typeId]; const ClassInfo& classInfo = classes[typeInfo.classId]; ++objectCountByType.at(typeInfo.id); ++objectCountByClass[classInfo.id]; ++objectCountByHeapAndClass[info.initialHeap][classInfo.id]; ++objectCountByHeapClassAndLifetime[info.initialHeap][classInfo.id][lifetimeBin]; ++objectCountByTypeHeapAndLifetime.at(typeInfo.id)[info.initialHeap][lifetimeBin]; if (info.initialHeap == TenuredHeap) { FinalizerKind f = classes[classInfo.id].hasFinalizer; ++heapObjectCountByFinalizerAndLifetime[f][lifetimeBin]; if (f == HasFinalizer) ++finalizedHeapObjectCountByClassAndLifetime[classInfo.id][lifetimeBin]; } } uint64_t size = thingSizes[info.kind]; gcBytesAllocatedInSlice[timeslice] += size; gcBytesFreedInSlice[finalizeTime / timesliceSize] += size; }
void SpacePartition::clearBin( int i, int j ) { SpaceBin* bin = getBin( i, j ); if( bin ) { bin->clear(); } }
void SpacePartition::clearAllBins() { for( int i=0; i < num_horizontal_bins; i++ ) { for( int j=0; j < num_vertical_bins; j++ ) { SpaceBin* bin = getBin( i, j ); bin->clear(); } } }
static void testBinning() { assert(getBin(0) == 0); assert(getBin(FirstBinSize - 1) == 0); assert(getBin(FirstBinSize) == 1); assert(getBin(2 * FirstBinSize - 1) == 1); assert(getBin(2 * FirstBinSize) == 2); assert(getBin(4 * FirstBinSize - 1) == 2); assert(getBin(4 * FirstBinSize) == 3); assert(binLimit(0) == FirstBinSize); assert(binLimit(1) == 2 * FirstBinSize); assert(binLimit(2) == 4 * FirstBinSize); assert(binLimit(3) == 8 * FirstBinSize); }
// Write out the R-Type instruction void rtype_instruction(char *instruction, char *rs, char *rt, char *rd, int shamt, FILE *Out) { // Set the instruction bits char *opcode = "000000"; char *rdBin = "00000"; if (strcmp(rd, "00000") != 0) rdBin = register_address(rd); char *rsBin = "00000"; if (strcmp(rs, "00000") != 0) rsBin = register_address(rs); char *rtBin = "00000"; if (strcmp(rt, "00000") != 0) rtBin = register_address(rt); char *func = NULL; char shamtBin[6]; // Convert shamt to binary and put in shamtBin as a char* getBin(shamt, shamtBin, 5); size_t i; for (i = 0; rMap[i].name != NULL; i++) { if (strcmp(instruction, rMap[i].name) == 0) { func = rMap[i].function; } } if(RADIX == 16) { char buf[40]; sprintf(buf,"%s%s%s%s%s%s", opcode, rsBin, rtBin, rdBin, shamtBin, func); int hex = getDec(buf); // Print out the instruction to the file fprintf(Out, "%08X,\n",hex); } else { fprintf(Out, "%s%s%s%s%s%s,\n", opcode, rsBin, rtBin, rdBin, shamtBin, func); } }
bool SpacePartition::getNthRing( int i, int j , int N, std::vector< SpaceBin* >* nth_ring ) { if( i < 0 || i >= num_horizontal_bins || j < 0 || j >= num_vertical_bins ) { return false; } if( ( i-N ) < 0 && ( i+N ) >= num_horizontal_bins && ( j-N ) < 0 && ( j+N ) >= num_vertical_bins ) { return false; } if( N < 0 ) { return false; } if( N == 0 ) { SpaceBin* bin_center = getBin( i, j ); nth_ring->push_back( bin_center ); return true; } // N >= 1 SpaceBin* bin_left_top = getBin( i-N, j-N ); SpaceBin* bin_right_top = getBin( i+N, j-N ); SpaceBin* bin_right_bottom = getBin( i+N, j+N ); SpaceBin* bin_left_bottom = getBin( i-N, j+N ); int p, q; if( bin_left_top && !bin_left_top->isEmpty() ) { nth_ring->push_back( bin_left_top ); } for( p=i-N+1, q=j-N; p <= i+N-1; p++ ) { SpaceBin* bin_top = getBin( p, q ); if( bin_top && !bin_top->isEmpty() ) { nth_ring->push_back( bin_top ); } } if( bin_right_top && !bin_right_top->isEmpty() ) { nth_ring->push_back( bin_right_top ); } for( p=i+N, q=j-N+1; q <= j+N-1; q++ ) { SpaceBin* bin_right = getBin( p, q ); if( bin_right && !bin_right->isEmpty() ) { nth_ring->push_back( bin_right ); } } if( bin_right_bottom && !bin_right_bottom->isEmpty() ) { nth_ring->push_back( bin_right_bottom ); } for( p=i+N-1, q=j+N; p >= i-N+1; p-- ) { SpaceBin* bin_bottom = getBin( p, q ); if( bin_bottom && !bin_bottom->isEmpty() ) { nth_ring->push_back( bin_bottom ); } } if( bin_left_bottom && !bin_left_bottom->isEmpty() ) { nth_ring->push_back( bin_left_bottom ); } for( p=i-N, q=j+N-1; q >= j-N+1; q-- ) { SpaceBin* bin_left = getBin( p, q ); if( bin_left && !bin_left->isEmpty() ) { nth_ring->push_back( bin_left ); } } return true; }
SpaceBin* SpacePartition::getBin( double x, double z ) { int i, j; calcGridCoords( x, z, &i, &j ); return getBin( i, j ); }
void Histogram::addAngle(double theta, double length) { _bins[getBin(theta)] += length; }
void itype_parse(char *token, char *tok_ptr, hash_table_t *hash_table, int32_t instruction_count, FILE *Out) { int i; // la is pseudo instruction for lui and ori // Convert to lui and ori and pass those instructions if (strcmp(token, "la") == 0) { // Parse the instruction - get register & immediate char *inst_ptr = tok_ptr; char *reg = NULL; // Create an array of char* that stores rd, rs and shamt char **reg_store; reg_store = (char**)malloc(2 * sizeof(char*)); if (reg_store == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } for (i = 0; i < 2; i++) { reg_store[i] = (char*)malloc(20 * sizeof(char)); if (reg_store[i] == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } } // Keeps a reference to which register has been parsed for storage int count = 0; while (1) { reg = parse_token(inst_ptr, " $,\n\t", &inst_ptr, NULL); if (reg == NULL || *reg == '#') { break; } strcpy(reg_store[count], reg); count++; free(reg); } // Interpret la instruction. // The register is at reg_store[0] and the variable is at reg_store[1] // Find address of label in hash table int *address = (int*)hash_find(hash_table, reg_store[1], strlen(reg_store[1])+1); // Convert address to binary in char* char addressBinary[33]; getBin(*address, addressBinary, 32); // Get upper and lower bits of address char upperBits[16]; char lowerBits[16]; for (i = 0; i < 32; i++) { if (i < 16) lowerBits[i] = addressBinary[i]; else upperBits[i-16] = addressBinary[i]; } // Call the lui instruction with: lui $reg, upperBits // Convert upperBits binary to int int immediate = getDec(upperBits); itype_instruction("lui", "00000", reg_store[0], immediate, Out); // Call the ori instruction with: ori $reg, $reg, lowerBits // Convert lowerBits binary to int immediate = getDec(lowerBits); itype_instruction("ori", reg_store[0], reg_store[0], immediate, Out); // Dealloc reg_store for (i = 0; i < 2; i++) { free(reg_store[i]); } free(reg_store); } // I-Type $rt, i($rs) else if (strcmp(token, "lw") == 0 || strcmp(token, "sw") == 0 || strcmp(token, "lb") == 0 || strcmp(token, "lbu") == 0 || strcmp(token, "lh") == 0 || strcmp(token, "lhu") == 0 || strcmp(token, "sb") == 0 || strcmp(token, "sh") == 0 ) { // Parse the instructio - rt, immediate and rs char *inst_ptr = tok_ptr; char *reg = NULL; // // Create an array of char* that stores rd, rs, rt respectively char **reg_store; reg_store =(char**) malloc(3 * sizeof(char*)); if (reg_store == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } for (i = 0; i < 3; i++) { reg_store[i] =(char*) malloc(20 * sizeof(char)); if (reg_store[i] == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } } // Keeps a reference to which register has been parsed for storage int count = 0; while (1) { reg = parse_token(inst_ptr, " $,\n\t()", &inst_ptr, NULL); if (reg == NULL || *reg == '#') { break; } strcpy(reg_store[count], reg); count++; free(reg); } // rt in position 0, immediate in position 1 and rs in position2 int immediate = atoi(reg_store[1]); itype_instruction(token, reg_store[2], reg_store[0], immediate, Out); // Dealloc reg_store for (i = 0; i < 3; i++) { free(reg_store[i]); } free(reg_store); } // I-Type rt, rs, im else if (strcmp(token, "andi") == 0 || strcmp( token, "ori") == 0 || strcmp(token, "xori") == 0 || strcmp(token, "sltiu") == 0 || strcmp(token, "slti") == 0 || strcmp(token, "addi") == 0 || strcmp(token, "addiu") == 0 ) { // Parse the instruction - rt, rs, immediate char *inst_ptr = tok_ptr; char *reg = NULL; // Create an array of char* that stores rt, rs char **reg_store; reg_store =(char**) malloc(3 * sizeof(char*)); if (reg_store == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } for (i = 0; i < 3; i++) { reg_store[i] =(char*) malloc(20 * sizeof(char)); if (reg_store[i] == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } } // Keeps a reference to which register has been parsed for storage int count = 0; while (1) { reg = parse_token(inst_ptr, " $,\n\t", &inst_ptr, NULL); if (reg == NULL || *reg == '#') { break; } strcpy(reg_store[count], reg); count++; free(reg); } // rt in position 0, rs in position 1 and immediate in position 2 int immediate = atoi(reg_store[2]); itype_instruction(token, reg_store[1], reg_store[0], immediate, Out); // Dealloc reg_store for ( i = 0; i < 3; i++) { free(reg_store[i]); } free(reg_store); } // I-Type $rt, immediate else if (strcmp(token, "lui") == 0) { // Parse the insturction, rt - immediate char *inst_ptr = tok_ptr; char *reg = NULL; // Create an array of char* that stores rs, rt char **reg_store; reg_store =(char**) malloc(2 * sizeof(char*)); if (reg_store == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } for (i = 0; i < 2; i++) { reg_store[i] =(char*) malloc(20 * sizeof(char)); if (reg_store[i] == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } } // Keeps a reference to which register has been parsed for storage int count = 0; while (1) { reg = parse_token(inst_ptr, " $,\n\t", &inst_ptr, NULL); if (reg == NULL || *reg == '#') { break; } strcpy(reg_store[count], reg); count++; free(reg); } // rt in position 0, immediate in position 1 int immediate = atoi(reg_store[1]); itype_instruction(token, "00000", reg_store[0], immediate, Out); // Dealloc reg_store for (i = 0; i < 2; i++) { free(reg_store[i]); } free(reg_store); } // I-Type $rs, $rt, label else if (strcmp(token, "beq") == 0 || strcmp(token, "bne") == 0) { // Parse the instruction - rs, rt char *inst_ptr = tok_ptr; char *reg = NULL; // Create an array of char* that stores rs, rt char **reg_store; reg_store =(char**) malloc(2 * sizeof(char*)); if (reg_store == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } for (i = 0; i < 2; i++) { reg_store[i] =(char*) malloc(20 * sizeof(char)); if (reg_store[i] == NULL) { fprintf(Out, "Out of memory\n"); exit(1); } } // Keeps a reference to which register has been parsed for storage int count = 0; while (1) { reg = parse_token(inst_ptr, " $,\n\t", &inst_ptr, NULL); if (reg == NULL || *reg == '#') { break; } strcpy(reg_store[count], reg); count++; free(reg); if (count == 2) break; } reg = parse_token(inst_ptr, " $,\n\t", &inst_ptr, NULL); // Find hash address for a register and put in an immediate int *address =(int*) hash_find(hash_table, reg, strlen(reg)+1); // beq跳转地址有问题 int immediate = (*address - instruction_count) >> 2; // Send instruction to itype function itype_instruction(token, reg_store[0], reg_store[1], immediate, Out); // Dealloc reg_store for (i = 0; i < 2; i++) { free(reg_store[i]); } free(reg_store); }
void generateTensorHistogram(const Handle<float> inputTensor, Handle<float> existingHistogram, float &min, float &max) { auto minMaxPos = inputTensor.minMaxArg(); float minInput = inputTensor.raw(minMaxPos.first); float maxInput = inputTensor.raw(minMaxPos.second); if (existingHistogram.isZero()) { min = minInput; max = maxInput; } size_t nBins = existingHistogram.size(); // Check if we need to rescale histogram. if (minInput < min || maxInput > max) { float newMin = std::min(minInput, min); float newMax = std::max(maxInput, max); float destBinWidth = (newMax - newMin) / nBins; float srcBinWidth = (max - min) / nBins; std::vector<float> scaledHistogram(nBins); for (size_t i = 0; i < nBins; ++i) { if (existingHistogram.raw(i) == 0) continue; float srcBinBegin = min + srcBinWidth * i; size_t destBin = (srcBinBegin - newMin) / destBinWidth; float destBinEnd = newMin + destBinWidth * (destBin + 1); float srcBinEnd = srcBinBegin + srcBinWidth; size_t destBinToVerify = (srcBinEnd - newMin) / destBinWidth; // Make sure that destination bin is mapped at most to 2 final bins, based // on that redistribute percentage is calculated. assert(destBinToVerify <= destBin + 2); (void)destBinToVerify; // Calculate how much we need to redistribute. uint64_t dstBinCnt = static_cast<uint64_t>(std::min( static_cast<float>(round((destBinEnd - srcBinBegin) / srcBinWidth * existingHistogram.raw(i))), existingHistogram.raw(i))); size_t newBin = getBin(nBins, destBinWidth, newMin, srcBinBegin); scaledHistogram[newBin] += dstBinCnt; if (dstBinCnt < existingHistogram.raw(i)) { size_t newBin = getBin(nBins, destBinWidth, newMin, srcBinBegin + destBinWidth); scaledHistogram[newBin] += existingHistogram.raw(i) - dstBinCnt; } } // Copy scaled histogram back to the existing histogram. for (size_t i = 0, e = scaledHistogram.size(); i < e; ++i) { existingHistogram.raw(i) = scaledHistogram[i]; } // Update global min and max. min = newMin; max = newMax; } float binWidth = (max - min) / nBins; for (size_t i = 0, e = inputTensor.size(); i < e; ++i) { size_t newBin = getBin(nBins, binWidth, min, inputTensor.raw(i)); existingHistogram.raw(newBin)++; } }