本文整理汇总了C++中slice函数的典型用法代码示例。如果您正苦于以下问题:C++ slice函数的具体用法?C++ slice怎么用?C++ slice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了slice函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: version
Foam::masterCollatingOFstream::~masterCollatingOFstream()
{
autoPtr<OSstream> osPtr;
if (UPstream::master())
{
// Note: always write binary. These are strings so readable
// anyway. They have already be tokenised on the sending side.
osPtr.reset
(
new OFstream
(
pathName_,
IOstream::BINARY,
version(),
IOstream::UNCOMPRESSED //compression_
)
);
//writeHeader(osPtr());
// We don't have IOobject so cannot use writeHeader
OSstream& os = osPtr();
IOobject::writeBanner(os)
<< "FoamFile\n{\n"
<< " version " << version() << ";\n"
<< " format " << os.format() << ";\n"
<< " class " << decomposedBlockData::typeName << ";\n"
<< " location " << pathName_ << ";\n"
<< " object " << pathName_.name() << ";\n"
<< "}" << nl;
IOobject::writeDivider(os) << nl;
}
string s(str());
UList<char> slice(const_cast<char*>(s.data()), label(s.size()));
List<std::streamoff> start;
decomposedBlockData::writeBlocks(osPtr, start, slice, commsType_);
if (osPtr.valid() && !osPtr().good())
{
FatalIOErrorInFunction(osPtr())
<< "Failed writing to " << pathName_ << exit(FatalIOError);
}
}
示例2: slice
// extracts rules of the form Target <= {(Src_1,Dt_1),..,(Src_n,Dt_n)}
// for deltaTimes Dt_1 < .. < Dt_n
void Correlator::extract_rules(JacobianRules& rules, uint64_t episode_size)
{
uint64_t num_calls = episode_size - SLICE_SIZE;
rules.reserve(num_calls);
JacobianSlice slice(SLICE_SIZE, LSTMState(32));
for (int64_t t = num_calls - 1; t >= 0; --t) {
// perform sensitivity analysis
corcor.getJacobian(t, t + SLICE_SIZE, slice);
// the last one is the target
JacobianRule rule;
rule.target = findBestMatch(slice.back().begin(), rule.confidence);
if (rule.confidence < OBJECT_THR) {
continue;
}
// the later objects occurred closer to the target, so iterate in reverse
JacobianSlice::reverse_iterator it = ++slice.rbegin();
JacobianSlice::reverse_iterator end = slice.rend();
for (uint16_t deltaTime = 1; it != end; ++it, ++deltaTime) {
double match;
r_code::Code* source = findBestMatch(it->begin(), match);
// no confidence, no correlation
if (match >= OBJECT_THR) {
Source src;
src.source = source;
src.deltaTime = deltaTime;
rule.sources.push_back(src);
rule.confidence += match;
}
}
if (!rule.sources.empty()) {
rule.confidence /= rule.sources.size() + 1;
if (rule.confidence >= RULE_THR) {
rules.push_back(rule);
}
}
}
}
示例3: log_error
int SSDBImpl::getset(const Bytes &key, std::string *val, const Bytes &newval, char log_type){
if(key.empty()){
log_error("empty key!");
//return -1;
return 0;
}
Transaction trans(binlogs);
int found = this->get(key, val);
std::string buf = encode_kv_key(key);
binlogs->Put(buf, slice(newval));
binlogs->add_log(log_type, BinlogCommand::KSET, buf);
leveldb::Status s = binlogs->commit();
if(!s.ok()){
log_error("set error: %s", s.ToString().c_str());
return -1;
}
return found;
}
示例4: slice
vector<gpu::GpuMat> SimilarityAssessment::splitDatasetGPU(Handle3DDataset <imgT>dataset)
{
DATAINFO imgInfo = dataset.getDatasetInfo(0);
vector<gpu::GpuMat> datasetSlicesGPU;
for( int i = 0; i < imgInfo.resDepth; i++ )
{
unsigned short** d = dataset.getDataset(0);
Mat slice(imgInfo.resHeight,imgInfo.resWidth,CV_16UC1,d[i]);
Mat plane;
gpu::GpuMat planeGPU;
slice.convertTo(plane,CV_8UC3);
planeGPU.upload(plane);
datasetSlicesGPU.push_back(planeGPU);
}
return datasetSlicesGPU;
}
示例5: fix_types
bool scratch_programt::check_sat() {
fix_types();
add_instruction(END_FUNCTION);
#ifdef DEBUG
cout << "Checking following program for satness:" << endl;
output(ns, "scratch", cout);
#endif
symex.constant_propagation = constant_propagation;
goto_symex_statet::propagationt::valuest constants;
symex(symex_state, functions, *this);
slice(equation);
equation.convert(checker);
return (checker.dec_solve() == decision_proceduret::D_SATISFIABLE);
}
示例6: it
big_number leveldb_chain_keeper::end_slice_difficulty(size_t slice_begin_index)
{
big_number total_work = 0;
leveldb_iterator it(db_.block->NewIterator(leveldb::ReadOptions()));
data_chunk raw_height = uncast_type(slice_begin_index);
for (it->Seek(slice(raw_height)); it->Valid(); it->Next())
{
constexpr size_t bits_field_offset = 4 + 2 * hash_digest_size + 4;
BITCOIN_ASSERT(it->value().size() >= 84);
// Deserialize only the bits field of block header.
const char* bits_field_begin = it->value().data() + bits_field_offset;
std::string raw_bits(bits_field_begin, 4);
auto deserial = make_deserializer(raw_bits.begin(), raw_bits.end());
uint32_t bits = deserial.read_4_bytes();
// Accumulate the total work.
total_work += block_work(bits);
}
return total_work;
}
示例7: switch
inline beziersurface<point_t>
beziervolume<point_t>::slice( boundary_t b ) const
{
switch ( b )
{
case umin : return slice ( point_type::u, 0);
case umax : return slice ( point_type::u, _points.width() - 1);
case vmin : return slice ( point_type::v, 0);
case vmax : return slice ( point_type::v, _points.height() - 1);
case wmin : return slice ( point_type::w, 0);
case wmax : return slice ( point_type::w, _points.depth() - 1);
default : throw std::runtime_error("invalid boundary type");
}
}
示例8: old
// if sizes==0, then keep current shape
int Data::realloc(Data::Type t, const int * sizes, int n){
Data old(*this); // REV0
if(sizes){ // new shape requested
clear();
shape(sizes, n);
}
else{ // just changing type, leave shape unchanged
// Data old(*this); // REV0
clear();
shape(old.mSizes, old.maxDim());
}
if(size()){
mType = t;
mStride= 1;
switch(type()){
case Data::BOOL: mData = pointer(new bool[size()]); break;
case Data::INT: mData = pointer(new int[size()]); break;
case Data::FLOAT: mData = pointer(new float[size()]); break;
case Data::DOUBLE: mData = pointer(new double[size()]); break;
case Data::STRING: mData = pointer(new std::string[size()]); break;
default: goto end;
}
acquire(mData);
offset(0);
// if(hasData() && isNumerical()) assignAll(0); // REV0
if(hasData() && isNumerical()){
if(old.hasData()){
assign(old); // copy over as many old elements as possible
if(size() > old.size()) slice(old.size()).assignAll(0);
}
else{
assignAll(0);
}
}
}
end:
return sizeBytes() - old.sizeBytes();
}
示例9: assert
StringData* StringData::shrinkImpl(size_t len) {
assert(!isImmutable() && !hasMultipleRefs());
assert(isFlat());
assert(len <= m_len);
assert(len <= capacity());
auto const sd = Make(len);
auto const src = slice();
auto const dst = sd->mutableData();
assert(len <= src.len);
sd->setSize(len);
auto const mcret = memcpy(dst, src.ptr, len);
auto const ret = static_cast<StringData*>(mcret) - 1;
// Recalculating ret from mcret avoids a spill.
assert(ret == sd);
assert(ret->checkSane());
return ret;
}
示例10: slice
DataType StringData::isNumericWithVal(int64_t &lval, double &dval,
int allow_errors, int* overflow) const {
if (m_hash < 0) return KindOfNull;
DataType ret = KindOfNull;
auto s = slice();
if (s.size()) {
ret = is_numeric_string(
s.data(),
s.size(),
&lval,
&dval,
allow_errors,
overflow
);
if (ret == KindOfNull && !isProxy() && allow_errors) {
m_hash |= STRHASH_MSB;
}
}
return ret;
}
示例11: it
bool leveldb_chain_keeper::end_slice(size_t slice_begin_index,
block_detail_list& sliced_blocks)
{
leveldb::WriteBatch blk_batch, blk_hash_batch;
leveldb_transaction_batch tx_batch;
leveldb_iterator it(db_blocks_->NewIterator(leveldb::ReadOptions()));
data_chunk raw_depth = uncast_type(slice_begin_index);
for (it->Seek(slice(raw_depth)); it->Valid(); it->Next())
{
std::stringstream ss;
ss.str(it->value().ToString());
protobuf::Block proto_block;
proto_block.ParseFromIstream(&ss);
// Convert protobuf block header into actual block
block_type sliced_block;
if (!reconstruct_block(common_, proto_block, sliced_block))
return false;
// Add to list of sliced blocks
block_detail_ptr sliced_detail =
std::make_shared<block_detail>(sliced_block);
sliced_blocks.push_back(sliced_detail);
// Make sure to delete hash secondary index too.
hash_digest block_hash = hash_block_header(sliced_block);
// Delete block header...
blk_batch.Delete(it->key());
// And it's secondary index.
blk_hash_batch.Delete(slice_block_hash(block_hash));
// Remove txs + spends + addresses too
for (const transaction_type& block_tx: sliced_block.transactions)
if (!clear_transaction_data(tx_batch, block_tx))
return false;
}
leveldb::WriteOptions options;
// Execute batches.
db_blocks_->Write(options, &blk_batch);
db_blocks_hash_->Write(options, &blk_hash_batch);
db_txs_->Write(options, &tx_batch.tx_batch);
db_spends_->Write(options, &tx_batch.spends_batch);
db_address_->Write(options, &tx_batch.address_batch);
return true;
}
示例12: fix_types
bool scratch_programt::check_sat(bool do_slice)
{
fix_types();
add_instruction(END_FUNCTION);
remove_skip(*this);
update();
#ifdef DEBUG
std::cout << "Checking following program for satness:\n";
output(ns, "scratch", std::cout);
#endif
symex.constant_propagation=constant_propagation;
goto_symex_statet::propagationt::valuest constants;
symex(symex_state, functions, *this);
if(do_slice)
{
slice(equation);
}
if(equation.count_assertions()==0)
{
// Symex sliced away all our assertions.
#ifdef DEBUG
std::cout << "Trivially unsat\n";
#endif
return false;
}
equation.convert(*checker);
#ifdef DEBUG
std::cout << "Finished symex, invoking decision procedure.\n";
#endif
return (checker->dec_solve()==decision_proceduret::D_SATISFIABLE);
}
示例13: toString
static std::string toString(const Matrix& matrix, size_t limit)
{
if(matrix.empty())
{
return "[]";
}
if(matrix.size().size() <= 2)
{
return toString2D(matrix, limit);
}
size_t lastDimension = matrix.size().back();
std::stringstream stream;
stream << "[\n";
for(size_t i = 0; i < lastDimension; ++i)
{
auto base = matrix.size();
auto start = zeros(base);
auto end = base;
start.back() = i;
end.back() = i + 1;
auto newSize = base;
newSize.pop_back();
stream << toString(reshape(slice(matrix, start, end), newSize), limit);
stream << ",\n";
}
stream << "]";
return stream.str();
}
示例14: create_spent_key
bool leveldb_common::fetch_spend(const output_point& spent_output,
input_point& input_spend)
{
data_chunk spent_key = create_spent_key(spent_output);
std::string raw_spend;
leveldb::Status status = db_.spend->Get(
leveldb::ReadOptions(), slice(spent_key), &raw_spend);
if (status.IsNotFound())
return false;
else if (!status.ok())
{
log_fatal(LOG_BLOCKCHAIN) << "fetch_spend: " << status.ToString();
return false;
}
const data_chunk raw_spend_data(raw_spend.begin(), raw_spend.end());
auto deserial = make_deserializer(
raw_spend_data.begin(), raw_spend_data.end());
input_spend.hash = deserial.read_hash();
input_spend.index = deserial.read_4_bytes();
return true;
}
示例15: main
int main(int argc, char **argv)
{
int parts = atoi(argv[3]);
const char *srcPath = argv[1];
const char *destPath = argv[2];
slice(srcPath, destPath, parts);
char **partsArr = calloc(parts, sizeof(char *));
if (!partsArr)
{
printf("No memory to allocate");
return 1;
}
int i;
for (i = 0; i < parts; i++)
{
size_t destLen = strlen(destPath);
partsArr[i] = calloc(11 + destLen, sizeof(char));
if (!partsArr[i])
{
printf("No memory to allocate");
return 1;
}
sprintf(partsArr[i], "%sPart-%d.jpg", destPath, i);
}
assemble(partsArr, destPath);
for (i = 0; i < parts; i++)
{
free(partsArr[i]);
}
free(partsArr);
return 0;
}