///////////////////////////////////////////////////////////////////////////////////////////////////////// // Pipeline interface int SQY_PipelineEncode_UI8(const char* pipeline, const char* src, long* shape, unsigned shape_size , char* dst, long* dstlength, int nthreads) { int value =1; if(!sqy::dypeline<std::uint8_t>::can_be_built_from(pipeline)) return value; std::vector<std::size_t> shape_(shape, shape+shape_size); auto pipe = sqy::dypeline<std::uint8_t>::from_string(pipeline); if(pipe.empty()){ std::cerr << "[sqeazy]\t received " << pipe.name() << "pipeline of size 0, cannot encode buffer\n"; return value; } pipe.set_n_threads(nthreads); char* encoded_end = pipe.encode(reinterpret_cast<const std::uint8_t*>(src), dst, shape_); if(!encoded_end) return value; else value = 0; *dstlength = encoded_end - dst; return value; }
int SQY_Decode_UI8(const char* src, long srclength, char* dst, int nthreads){ int value =1; sqy::header hdr(src,src+(srclength)); std::vector<std::size_t> inshape_ = {std::size_t(srclength)}; std::vector<std::size_t> outshape_(hdr.shape()->begin(),hdr.shape()->end()); if(!sqy::dypeline<std::uint8_t>::can_be_built_from(hdr.pipeline())){ std::cerr << "[sqeazy]\t" << hdr.pipeline() << " cannot be build with this version of sqeazy\n"; return value; } auto pipe = sqy::dypeline<std::uint8_t>::from_string(hdr.pipeline()); pipe.set_n_threads(nthreads); if(!pipe.size()){ std::cerr << "[sqeazy]\t received " << pipe.name() << "pipeline of size 0, no decoding possible\n"; return value;} value = pipe.decode(src, reinterpret_cast<std::uint8_t*>(dst), inshape_, outshape_); return value; }
/** * Will set the number of threads to the maximum between 1 and piranha::runtime_info::get_hardware_concurrency(). * * @throws unspecfied any exception thrown by set_n_threads(). */ static void reset_n_threads() { const auto candidate = runtime_info::get_hardware_concurrency(); set_n_threads((candidate > 0u) ? candidate : 1u); }