static void gather(const communicator& comm, const std::vector<T>& in, std::vector< std::vector<T> >& out, int root) { std::vector<int> counts(comm.size()); Collectives<int,void*>::gather(comm, (int) in.size(), counts, root); std::vector<int> offsets(comm.size(), 0); for (unsigned i = 1; i < offsets.size(); ++i) offsets[i] = offsets[i-1] + counts[i-1]; std::vector<T> buffer(offsets.back() + counts.back()); MPI_Gatherv(Datatype::address(const_cast<T&>(in[0])), in.size(), Datatype::datatype(), Datatype::address(buffer[0]), &counts[0], &offsets[0], Datatype::datatype(), root, comm); out.resize(comm.size()); size_t cur = 0; for (unsigned i = 0; i < (unsigned)comm.size(); ++i) { out[i].reserve(counts[i]); for (unsigned j = 0; j < (unsigned)counts[i]; ++j) out[i].push_back(buffer[cur++]); } }
void HexView::paintOffsets(QPainter *painter, int &left,int first, int last) { QPen pen; for (int i=first; i<=last ; ++i) { QRect offsets(left,rowHeight() * i,offsetsWidth(),rowHeight()); if (showGuidelines_) { pen.setColor(Qt::green); painter->setPen(pen); painter->drawRect(offsets); } pen.setColor(Qt::black); painter->setPen(pen); QString offset = getHexNumber(i * bytesPerRow(),offsetLen(),true); painter->drawText( offsets ,Qt::AlignCenter ,offset ); } left += offsetsWidth(); if (showGuidelines_) { QRect space(left,0,spacer() ,contentHeight()); pen.setColor(Qt::blue); painter->setPen(pen); painter->drawRect(space); } left += spacer(); }
void StringFile::readHeader() { if(_compressed) { std::vector<uint16_t> offsets(_strings.size()); for(uint16_t i = 0; i < _strings.size(); i++) offsets[i] = _stream.getU16LE(); for(uint16_t i = 0; i < _strings.size(); i++) _strings[i] = decodeString(offsets[i]); } else { _strings.push_back(""); while(!_stream.eof()) { uint8_t byte = _stream.get(); //TODO: Figure out what these non-alpha numeric characters are for, // some sort of formatting perhaps? Let's just treat them as // separators for now... if(byte >= 0x20 && byte <= 0x7e) _strings.back() += byte; else if(_strings.back().size() != 0) _strings.push_back(""); } } }
/* double Network::_dfs_cal_famscore_with_prior(const node_pointer_t &p,condition_t &condition,const int idx){ if(idx<0){ vector<size_t> offsets; size_t total=_get_data_offsets(offsets,condition); // condition_t data_condition(condition); double res=log(math::tgamma_delta_ratio(get_alpha2(p,condition),total)); for(size_t i=0;i<p->get_n_states() && res!=DOUBLE_NEG_INF;i++){ // data_condition[p]=i; // res/=math::tgamma_delta_ratio(get_alpha3(p,condition,i),_get_data_count(data_condition)); res-=log(math::tgamma_delta_ratio(get_alpha3(p,condition,i),_get_data_count(offsets,p,i))); } //return res*math::tgamma_delta_ratio(get_alpha2(p,condition),_get_data_count(condition)); return res; } double res=0.0; node_pointer_t node=p->get_parent(idx); for(size_t i=0;i<node->get_n_states();i++){ condition[node]=i; res+=_dfs_cal_famscore_with_prior(p,condition,idx-1); } return res; } double Network::_dfs_cal_famscore_with_prior( const node_pointer_t &p,condition_t &condition,const vector<size_t> &offset_base,const size_t idx) { if(idx>=p->get_n_parents()){ //more fast: divide each part together and log once. //more accurate: log each part and minus together. size_t total=offset_base.size(); // double res=math::tgamma_delta_ratio(get_alpha2(p,condition),total); //fast double res=log(math::tgamma_delta_ratio(get_alpha2(p,condition),total)); //accurate for(size_t i=0;i<p->get_n_states() && res!=DOUBLE_NEG_INF;i++){ // res/=math::tgamma_delta_ratio(get_alpha3(p,condition,i),_get_data_count(offset_base,p,i)); //fast res-=log(math::tgamma_delta_ratio(get_alpha3(p,condition,i),_get_data_count(offset_base,p,i))); //accurate } // return log(res); //fast return res; //accurate } double res=0.0; node_pointer_t node=p->get_parent(idx); vector<size_t> offsets; for(size_t i=0;i<node->get_n_states() && res!=DOUBLE_NEG_INF;i++){ //prepare the data offsets condition[node]=i; _get_data_offsets(offsets,offset_base,node,i); res+=_dfs_cal_famscore_with_prior(p,condition,offsets,idx+1); offsets.clear(); } return res; } */ double Network::_dfs_cal_famscore_without_prior( const node_pointer_t &p,condition_t &condition,const vector<size_t> &offset_base,const size_t idx) { if(offset_base.empty()){//shortcut static const double none_data_score=0.0;//log(gamma(1.0))==0.0 return none_data_score; } if(idx>=p->get_n_parents()){ //more fast: divide each part together and log once. //more accurate: log each part and minus together. size_t N=offset_base.size(); double res=-lgamma(N+1.0); vector<size_t> offset_temp=offset_base; for(size_t i=0;i<p->get_n_states() && res!=DOUBLE_NEG_INF;i++){ // res+=math::lgamma(pdata->_get_data_count(offset_base,p,i)+1.0); res+=lgamma(pdata->_get_data_count_and_exclude(offset_temp,p,i)+1.0); } return res; } double res=0.0; node_pointer_t node=p->get_parent(idx); // vector<size_t> offsets; vector<vector<size_t> > offsets(node->get_n_states()); pdata->_get_data_offsets_split(offsets,offset_base,node); for(size_t i=0;i<node->get_n_states() && res!=DOUBLE_NEG_INF;i++){ //prepare the data offsets condition[node]=i; // pdata->_get_data_offsets(offsets,offset_base,node,i); res+=_dfs_cal_famscore_without_prior(p,condition,offsets[i],idx+1); // offsets.clear(); } return res; }
int main( int argc, char* argv[] ) { const int N = 100; std::vector<int> a(N), b(N); std::vector<int> offsets(3); offsets[0] = 3; offsets[1] = 94; offsets[2] = 50; { for (int j = 0; j < (int)offsets.size(); ++j) { for (int i = 0; i < N; ++i) { a[i] = i; b[i] = (i + offsets[j]) % N; } rotate1(a, offsets[j]); eq(j, a, b); } } { for (int j = 0; j < (int)offsets.size(); ++j) { for (int i = 0; i < N; ++i) { a[i] = i; b[i] = (i + offsets[j]) % N; } rotate2(a, offsets[j]); eq(j, a, b); } } }
int main(int argc, char **argv) { char *inputFilename; char *outputFilename; if (!parseCmdLineSimple(argc, argv, "ss", &inputFilename, &outputFilename)) { printf("Usage: mtx2gr input output\n"); exit(1); } int nVertices; std::vector<int> srcs; std::vector<int> dsts; std::vector<int> edgeValues; loadGraph(inputFilename, nVertices, srcs, dsts, &edgeValues); printf("Read input file with %d vertices and %zd edges\n", nVertices, dsts.size()); printf("Converting to CSR\n"); std::vector<int> offsets(nVertices + 1); std::vector<int> csrDsts(dsts.size()); std::vector<int> sortIndices(dsts.size()); std::vector<int> sortedEdgeValues(dsts.size()); edgeListToCSR<int>(nVertices, dsts.size(), &srcs[0], &dsts[0] , &offsets[0], &csrDsts[0], &sortIndices[0]); for (size_t i = 0; i < sortIndices.size(); ++i) sortedEdgeValues[i] = edgeValues[sortIndices[i]]; printf("writing output\n"); writeGraph_binaryCSR(outputFilename, nVertices, dsts.size() , &offsets[0], &csrDsts[0], &sortedEdgeValues[0]); }
void mouseHandler(int event, int x, int y, int flags, void* data) { if (event == CV_EVENT_LBUTTONDOWN) { SurgicalGUI* gui = (SurgicalGUI *) data; pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_ptr = gui->get_image_communicator()->get_cloud_ptr(); int cloud_height = cloud_ptr->height; int off[] = {0,1,-1,2,-2,-3,3,-4,4,-5,5}; std::vector<int> offsets(off, off+sizeof(off)/sizeof(int)); for (int x_idx = 0; x_idx < offsets.size(); x_idx += 1) { for (int y_idx = 0; y_idx < offsets.size(); y_idx += 1) { int x_new = round(x/ZOOM_FACTOR) + offsets[x_idx]; int y_new = round(y/ZOOM_FACTOR) + offsets[y_idx]; if ( ( (0 <= x_new) && (x_new < cloud_ptr->width)) && ( (0 <= y_new) && (y_new < cloud_ptr->height)) ) { pcl::PointXYZRGB pt = cloud_ptr->at(x_new,y_new); if (pointIsFinite(pt)) { gui->interact(&pt, x_new, y_new); return; } } } } } }
// Returns a vector of cube offsets static std::vector<Mat4f> MakeCubeMatrices(GLuint count, float max_dist) { std::srand(59039); std::vector<Mat4f> offsets(count); for(GLuint i=0; i!=count; ++i) { float x = float(std::rand())/RAND_MAX; float y = float(std::rand())/RAND_MAX; float z = float(std::rand())/RAND_MAX; float sx = std::rand()%2 ? 1.0f: -1.0f; float sy = std::rand()%2 ? 1.0f: -1.0f; float sz = std::rand()%2 ? 1.0f: -1.0f; offsets[i] = ModelMatrixf::Translation( sx*(1.0f + std::pow(x, 0.9f) * max_dist), sy*(1.0f + std::pow(y, 1.5f) * max_dist), sz*(1.0f + std::pow(z, 0.7f) * max_dist) ) * ModelMatrixf::RotationZ( RightAngles(float(std::rand())/RAND_MAX) ) * ModelMatrixf::RotationY( RightAngles(float(std::rand())/RAND_MAX) ) * ModelMatrixf::RotationX( RightAngles(float(std::rand())/RAND_MAX) ); } return offsets; }
/** * Creates a massvector representing the centre of gravity from a given list of mass vectors * \param masses: The mass vectors, that will be combined */ static BITBOTS_INLINE Eigen::Vector4d create_mass_offset(const Eigen::Matrix4Xd& masses) { Eigen::Matrix4Xd offsets(4,masses.cols()); for(uint i = 0; i < (uint)masses.cols(); ++i) { offsets.col(i) << masses(3, i) * masses.col(i).head<3>(), masses(3, i); } return mass_from_offsets(offsets); }
/* * load the offsets of the user binary into memory */ void IBBL_LargeFile::load_user_offsets() { int num_users; user_offsets.clear(); ifstream offsets(get_user_offset_filename().c_str(), ifstream::binary); offsets.read((char*)&num_users, 4); if (num_users == 0) { cerr << "Couldn't read user offset file: " << get_user_offset_filename(); assert(false); } int id; int offset; for (int i = 0; i < num_users; ++i) { offsets.read((char*)&id, 4); offsets.read((char*)&offset, 4); user_offsets.insert(pair<int, int>(id, offset)); } offsets.close(); }
TYPED_TEST_P(TcTest, ShuffledRdWr) { const char *PATH = "TcTest-ShuffledRdWr.dat"; const int N = 8; /* size of iovs */ struct tc_iovec iovs[N]; const int S = 4096; tc_touch(PATH, N * S); char *data1 = getRandomBytes(N * S); char *data2 = (char *)malloc(N * S); std::vector<int> offsets(N); std::iota(offsets.begin(), offsets.end(), 0); std::mt19937 rng(8887); for (int i = 0; i < 10; ++i) { // repeat for 10 times for (int n = 0; n < N; ++n) { tc_iov2path(&iovs[n], PATH, offsets[n] * S, S, data1 + offsets[n] * S); } EXPECT_OK(tc_writev(iovs, N, false)); for (int n = 0; n < N; ++n) { iovs[n].data = data2 + offsets[n] * S; } EXPECT_OK(tc_readv(iovs, N, false)); EXPECT_EQ(0, memcmp(data1, data2, N * S)); std::shuffle(offsets.begin(), offsets.end(), rng); } free(data1); free(data2); }
// static PassRefPtrWillBeRawPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask textCheckingOptions, TextCheckingProcessType processType, const EphemeralRange& checkingRange, const EphemeralRange& paragraphRange, int requestNumber) { if (checkingRange.isNull()) return nullptr; if (!checkingRange.startPosition().computeContainerNode()->rootEditableElement()) return nullptr; String text = plainText(checkingRange, TextIteratorEmitsObjectReplacementCharacter); if (text.isEmpty()) return nullptr; RefPtrWillBeRawPtr<Range> checkingRangeObject = createRange(checkingRange); RefPtrWillBeRawPtr<Range> paragraphRangeObject = nullptr; // Share identical Range objects. if (checkingRange == paragraphRange) paragraphRangeObject = checkingRangeObject; else paragraphRangeObject = createRange(paragraphRange); const DocumentMarkerVector& markers = checkingRangeObject->ownerDocument().markers().markersInRange(checkingRange, DocumentMarker::SpellCheckClientMarkers()); Vector<uint32_t> hashes(markers.size()); Vector<unsigned> offsets(markers.size()); for (size_t i = 0; i < markers.size(); ++i) { hashes[i] = markers[i]->hash(); offsets[i] = markers[i]->startOffset(); } return adoptRefWillBeNoop(new SpellCheckRequest(checkingRangeObject, paragraphRangeObject, text, textCheckingOptions, processType, hashes, offsets, requestNumber)); }
void HeapRegion::add_continuingHumongousRegion(HeapRegion* cont) { // Must join the blocks of the current H region seq with the block of the // added region. offsets()->join_blocks(bottom(), cont->bottom()); arrayOop obj = (arrayOop)(bottom()); obj->set_length((int) (obj->length() + cont->capacity()/jintSize)); set_end(cont->end()); set_top(cont->end()); }
//#################### FUNCTIONS #################### std::vector<itk::Offset<2> > make_4_connected_offsets() { std::vector<itk::Offset<2> > offsets(4); offsets[0][0] = 0; offsets[0][1] = -1; // above offsets[1][0] = -1; offsets[1][1] = 0; // left offsets[2][0] = 1; offsets[2][1] = 0; // right offsets[3][0] = 0; offsets[3][1] = 1; // below return offsets; }
static std::vector<size_t> offsetsFromParts(const std::vector<c_atable_ptr_t>& parts) { std::vector<size_t> offsets(parts.size()); auto total_size = 0; size_t i = 0; for (const auto& part: parts) { offsets[i++] = total_size; total_size += part->size(); } return offsets; }
static std::vector<table_id_t> tableIdOffsets(const std::vector<c_atable_ptr_t>& parts) { std::vector<table_id_t> offsets(parts.size()+1, 0); std::transform(std::begin(parts), std::end(parts), std::begin(offsets) + 1, [] (const c_atable_ptr_t& part) { return part->subtableCount(); }); std::partial_sum(std::begin(offsets), std::end(offsets), std::begin(offsets)); return offsets; }
double Dnds::change(void) { // update conditional likelihood and transition probability flags Topology* t = modelPtr->getActiveTopology(); t->updateAllCls(true); t->updateAllTis(true); t->flipAllActiveCls(); t->flipAllActiveTis(); // set the maximum distance of the move double x = 0.1; // propose new values for all of the omegas bool isValid = true; std::vector<double> newVals(numCategories); std::vector<double> offsets(numCategories); do { // pick the values for each of the categories for (int i=0; i<numCategories; i++) offsets[i] = x*(ranPtr->uniformRv()-0.5); // calculate the new points for (int i=0; i<numCategories; i++) newVals[i] = dndsVals[i] + offsets[i]; // decide if the new point is valid isValid = true; for (int i=0; i<numCategories; i++) { if (newVals[i] < 0.0) { isValid = false; break; } for (int j=i+1; j<numCategories; j++) { if (newVals[i] > newVals[j]) { isValid = false; break; } } if (isValid == false) break; } } while (isValid == false); // commit the change for (int i=0; i<numCategories; i++) dndsVals[i] = newVals[i]; return 0.0; }
void QTextEngine::shape( int item ) const { assert( item < items.size() ); QScriptItem &si = items[item]; if ( si.num_glyphs ) return; QFont::Script script = (QFont::Script)si.analysis.script; si.glyph_data_offset = used; if ( !si.fontEngine ) si.fontEngine = fnt->engineForScript( script ); si.fontEngine->ref(); si.ascent = si.fontEngine->ascent(); si.descent = si.fontEngine->descent(); si.num_glyphs = 0; if ( si.fontEngine && si.fontEngine != (QFontEngine*)-1 ) { QShaperItem shaper_item; shaper_item.script = si.analysis.script; shaper_item.string = &string; shaper_item.from = si.position; shaper_item.length = length(item); shaper_item.font = si.fontEngine; shaper_item.num_glyphs = QMAX(int(num_glyphs - used), shaper_item.length); shaper_item.flags = si.analysis.bidiLevel % 2 ? RightToLeft : 0; while (1) { // qDebug(" . num_glyphs=%d, used=%d, item.num_glyphs=%d", num_glyphs, used, shaper_item.num_glyphs); ensureSpace(shaper_item.num_glyphs); shaper_item.num_glyphs = num_glyphs - used; // qDebug(" .. num_glyphs=%d, used=%d, item.num_glyphs=%d", num_glyphs, used, shaper_item.num_glyphs); shaper_item.glyphs = glyphs(&si); shaper_item.advances = advances(&si); shaper_item.offsets = offsets(&si); shaper_item.attributes = glyphAttributes(&si); shaper_item.log_clusters = logClusters(&si); if (scriptEngines[shaper_item.script].shape(&shaper_item)) break; } si.num_glyphs = shaper_item.num_glyphs; } ((QTextEngine *)this)->used += si.num_glyphs; si.width = 0; advance_t *advances = this->advances( &si ); advance_t *end = advances + si.num_glyphs; while ( advances < end ) si.width += *(advances++); return; }
void MemoryWatcher::ParseLine(const std::string& line) { m_values[line] = 0; m_addresses[line] = std::vector<u32>(); std::stringstream offsets(line); offsets >> std::hex; u32 offset; while (offsets >> offset) m_addresses[line].push_back(offset); }
std::vector<itk::Offset<3> > make_6_connected_offsets() { std::vector<itk::Offset<3> > offsets(6); offsets[0][0] = 0; offsets[0][1] = 0; offsets[0][2] = -1; offsets[1][0] = 0; offsets[1][1] = -1; offsets[1][2] = 0; offsets[2][0] = -1; offsets[2][1] = 0; offsets[2][2] = 0; offsets[3][0] = 1; offsets[3][1] = 0; offsets[3][2] = 0; offsets[4][0] = 0; offsets[4][1] = 1; offsets[4][2] = 0; offsets[5][0] = 0; offsets[5][1] = 0; offsets[5][2] = 1; return offsets; }
/// Read the string values. This function processes the data produced by /// version 0x01000000 of the write function. On successful completion, it /// returns 0. int ibis::dictionary::readKeys1(const char *evt, FILE *fptr) { uint32_t nkeys; int ierr = fread(&nkeys, 4, 1, fptr); if (ierr != 1) { LOGGER(ibis::gVerbose > 1) << "Warning -- " << evt << " failed to read the number of keys, fread returned " << ierr; return -6; } clear(); array_t<uint64_t> offsets(nkeys+1); ierr = fread(offsets.begin(), 8, nkeys+1, fptr); if (ierr != (int)(1+nkeys)) { LOGGER(ibis::gVerbose > 1) << "Warning -- " << evt << " failed to read the string positions, " "expected fread to return " << nkeys+1 << ", but got " << ierr; return -8; } buffer_.resize(1); buffer_[0] = new char[offsets.back()-offsets.front()]; ierr = fread(buffer_[0], 1, offsets.back()-offsets.front(), fptr); if (ierr != (int)(offsets.back()-offsets.front())) { LOGGER(ibis::gVerbose > 1) << "Warning -- " << evt << " failed to read the strings, " "expected fread to return " << (offsets.back()-offsets.front()) << ", but got " << ierr; return -9; } raw_.resize(nkeys+1); raw_[0] = 0; #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7) key_.reserve(nkeys+nkeys); // older version does not have reserve #endif for (unsigned j = 0; j < nkeys; ++ j) { raw_[j+1] = buffer_[0] + (offsets[j] - offsets[0]); key_[raw_[j+1]] = j+1; #if DEBUG+0 > 2 || _DEBUG+0 > 2 LOGGER(ibis::gVerbose > 0) << "DEBUG -- " << evt << " raw_[" << j+1 << "] = \"" << raw_[j+1] << '"'; #endif } #if DEBUG+0 > 2 || _DEBUG+0 > 2 ibis::util::logger lg; lg() << "DEBUG -- " << evt << " got the following keys"; for (MYMAP::const_iterator it = key_.begin(); it != key_.end(); ++ it) lg() << "\n\t" << it->second << ": " << it->first; #endif return 0; } // ibis::dictionary::readKeys1
void updateOffsets(jintArray javaOffsets) { ScopedIntArrayRW offsets(mEnv, javaOffsets); if (offsets.get() == NULL) { return; } for (size_t i = 0, groupCount = mMatcher->groupCount(); i <= groupCount; ++i) { offsets[2*i + 0] = mMatcher->start(i, mStatus); offsets[2*i + 1] = mMatcher->end(i, mStatus); } }
size_t getImportList( const PartitioningSolution<SolutionAdapter> &solution, const DataAdapter * const data, ArrayRCP<typename DataAdapter::zgid_t> &imports // output ) { typedef typename PartitioningSolution<SolutionAdapter>::part_t part_t; typedef typename PartitioningSolution<SolutionAdapter>::gno_t gno_t; typedef typename DataAdapter::zgid_t zgid_t; size_t numParts = solution.getActualGlobalNumberOfParts(); int numProcs = solution.getCommunicator()->getSize(); if (numParts > size_t(numProcs)) { char msg[256]; sprintf(msg, "Number of parts %lu exceeds number of ranks %d; " "%s requires a MappingSolution for this case\n", numParts, numProcs, __func__); throw std::logic_error(msg); } size_t localNumIds = data->getLocalNumIDs(); const zgid_t *gids = NULL; data->getIDsView(gids); const part_t *parts = solution.getPartListView(); // How many ids to each process? Array<int> counts(numProcs, 0); for (size_t i=0; i < localNumIds; i++) counts[parts[i]]++; Array<gno_t> offsets(numProcs+1, 0); for (int i=1; i <= numProcs; i++){ offsets[i] = offsets[i-1] + counts[i-1]; } Array<typename DataAdapter::zgid_t> gidList(localNumIds); for (size_t i=0; i < localNumIds; i++) { gno_t idx = offsets[parts[i]]; gidList[idx] = gids[i]; offsets[parts[i]] = idx + 1; } Array<int> recvCounts(numProcs, 0); try { AlltoAllv<zgid_t>(*(solution.getCommunicator()), *(solution.getEnvironment()), gidList(), counts(), imports, recvCounts()); } Z2_FORWARD_EXCEPTIONS; return imports.size(); }
static std::vector<Offset> generate(const Lattice& lattice) { Vid dx = OffsetCat::dx_max(lattice); Vid dy = OffsetCat::dy_max(lattice); Vid n = std::min(dx, dy); std::vector<Offset> offsets(n); for (Vid i=0; i<n; i++) { //offsets[i] = {i+1, i+1}; offsets[i].dx = i+1; offsets[i].dy = i+1; } return offsets; }
HexFindResult HexSearcher::FindOffsets(std::vector<unsigned char> const& pattern, size_t limit, ADDRESS& address, const char* func, bool displayError) { if (address) return HexFindResult(ERR_ALREADY_EXISTS, func, displayError); Offsets offsets(FindOffsets(pattern, limit)); if (offsets.empty()) return HexFindResult(ERR_NOTFOUND, func, displayError); if (offsets.size() > 1) return HexFindResult(ERR_MULTIPLE, func, displayError); address = STATIC_REBASE(*offsets.begin()); return HexFindResult(ERR_OK, func, displayError); }
/* * load the offsets from the movie binary into memory */ void IBBL_LargeFile::load_movie_offsets() { movie_offsets.clear(); movie_offsets.push_back(0); ifstream offsets(get_movie_offset_filename().c_str(), ifstream::binary); int offset = 0; for (int i = 1; i <= NUM_MOVIES; ++i) { offsets.read((char*)&offset, 4); movie_offsets.push_back(offset); } offsets.close(); }
Rcpp::List reTrms::condVar(double scale) { if (scale < 0 || !R_finite(scale)) throw runtime_error("scale must be non-negative and finite"); int nf = d_flist.size(); IntegerVector nc = ncols(), nl = nlevs(), nct = nctot(), off = offsets(); List ans(nf); CharacterVector nms = d_flist.names(); ans.names() = clone(nms); for (int i = 0; i < nf; i++) { int ncti = nct[i], nli = nl[i]; IntegerVector trms = terms(i); int *cset = new int[ncti], nct2 = ncti * ncti; NumericVector ansi(Dimension(ncti, ncti, nli)); ans[i] = ansi; double *ai = ansi.begin(); for (int j = 0; j < nli; j++) { int kk = 0; for (int jj = 0; jj < trms.size(); jj++) { int tjj = trms[jj]; for (int k = 0; k < nc[tjj]; k++) cset[kk++] = off[tjj] + j * nc[tjj] + k; } CHM_SP cols = M_cholmod_submatrix(&d_Lambda, (int*)NULL, -1, cset, ncti, 1/*values*/, 1/*sorted*/, &c); CHM_SP sol = d_L.spsolve(CHOLMOD_A, cols); CHM_SP tcols = M_cholmod_transpose(cols, 1/*values*/, &c); M_cholmod_free_sparse(&cols, &c); CHM_SP var = M_cholmod_ssmult(tcols, sol, 0/*stype*/, 1/*values*/, 1/*sorted*/, &c); M_cholmod_free_sparse(&sol, &c); M_cholmod_free_sparse(&tcols, &c); CHM_DN dvar = M_cholmod_sparse_to_dense(var, &c); M_cholmod_free_sparse(&var, &c); Memcpy(ai + j * nct2, (double*)dvar->x, nct2); M_cholmod_free_dense(&dvar, &c); } delete[] cset; transform(ansi.begin(), ansi.end(), ansi.begin(), bind2nd(multiplies<double>(), scale * scale)); } return ans; }
/// Read the ordered strings. This function process the data produced by /// the write function. On successful completion, it returns 0. int ibis::dictionary::readKeys(const char *evt, FILE *fptr) { uint32_t nkeys; int ierr = fread(&nkeys, 4, 1, fptr); if (ierr != 1) { LOGGER(ibis::gVerbose > 1) << "Warning -- " << evt << " failed to read the number of keys, fread returned " << ierr; return -6; } clear(); code_.resize(nkeys); ierr = fread(code_.begin(), 4, nkeys, fptr); if (ierr != (int)nkeys) { LOGGER(ibis::gVerbose > 1) << "Warning -- " << evt << " failed to read the code values, " "expected fread to return " << nkeys << ", but got " << ierr; return -7; } array_t<uint32_t> offsets(nkeys+1); ierr = fread(offsets.begin(), 4, nkeys+1, fptr); if (ierr != (int)(1+nkeys)) { LOGGER(ibis::gVerbose > 1) << "Warning -- " << evt << " failed to read the string positions, " "expected fread to return " << nkeys+1 << ", but got " << ierr; return -8; } buffer_.resize(1); buffer_[0] = new char[offsets.back()-offsets.front()]; ierr = fread(buffer_[0], 1, offsets.back()-offsets.front(), fptr); if (ierr != (int)(offsets.back()-offsets.front())) { LOGGER(ibis::gVerbose > 1) << "Warning -- " << evt << " failed to read the strings, " "expected fread to return " << (offsets.back()-offsets.front()) << ", but got " << ierr; return -9; } raw_.resize(nkeys+1); key_.resize(nkeys); for (unsigned j = 0; j < nkeys; ++ j) key_[j] = buffer_[0] + (offsets[j] - offsets[0]); for (unsigned j = 0; j < nkeys; ++ j) raw_[code_[j]] = key_[j]; return 0; } // ibis::dictionary::readKeys
void convolve_3d(SrcIterT src_begin, ExtentT* src_extents, KernIterT kernel_begin, ExtentT* kernel_extents, OutIterT out_begin) { std::vector<ExtentT> image_shape(src_extents,src_extents+3); std::vector<ExtentT> kernel_shape(kernel_extents,kernel_extents+3); anyfold::image_stack_cref image(src_begin, image_shape); anyfold::image_stack_cref kernel(kernel_begin, kernel_shape); anyfold::image_stack_ref output(out_begin, image_shape); std::vector<ExtentT> offsets(3); for (unsigned i = 0; i < offsets.size(); ++i) offsets[i] = kernel_shape[i]/2; return convolve(image,kernel,output,offsets); }
//============================================================================== int load_BC_data(FEI* fei, PoissonData& poissonData) { //first, have the data object generate the BC data poissonData.calculateBCs(); int numBCNodes = poissonData.getNumBCNodes(); GlobalID* nodeIDs = poissonData.getBCNodeIDs(); int fieldID = poissonData.getBCFieldID(); double* values = poissonData.getBCValues(); std::vector<int> offsets(numBCNodes, 0); CHK_ERR( fei->loadNodeBCs(numBCNodes, nodeIDs, fieldID, &offsets[0], values) ); return(0); }