예제 #1
0
inline void Remap(RawVector<T>& dst, const U& src, const RawVector<std::pair<float, int>>& sort_data)
{
    dst.resize_discard(sort_data.size());
    size_t count = std::min<size_t>(sort_data.size(), src->size());
    auto src_data = src->get();
    for (size_t i = 0; i < count; ++i)
        dst[i] = (T)src_data[sort_data[i].second];
}
예제 #2
0
파일: amsr.cpp 프로젝트: cran/oce
// [[Rcpp::export]]
RawVector do_amsr_average(RawVector a, RawVector b)
{
  int na = a.size(), nb=b.size();
  if (na != nb)
     ::Rf_error("lengths must agree but length(a) is %d and length(b) is %d", na, nb);
  RawVector res(na);
  unsigned char A, B;
  for (int i = 0; i < na; i++) {
    A = a[i];
    B = b[i];
    if (A < 0xfb && B < 0xfb) { // A and B are both OK (the most common case, so put first here)
      res[i] = (unsigned char)(0.5+0.5*(A+B)); // note rounding

    } else if (A == 0xff) { // A is land; ignore B and return code for land
      res[i] = 0xff;
    } else if (B == 0xff) { // B is land; ignore A and return code for land
      res[i] = 0xff;

    } else if (A == 0xfe) { // 254
      res[i] = B; // no A observation, so use B, whatever it is
    } else if (B == 0xfe) {
      res[i] = A; // no B observation, so use A, whatever it is

    } else if (A == 0xfd) { // 253
      res[i] = B; // bad A observation, so use B, whatever it is
    } else if (B == 0xfd) {
      res[i] = A; // bad B observation, so use A, whatever it is

    } else if (A == 0xfc) { // 252
      res[i] = B; // A had sea ice; try B (although it is likely also ice)
    } else if (B == 0xfc) {
      res[i] = A; // A had sea ice; try A (although it is likely also ice)

    } else if (A == 0xfb) { // 251
      res[i] = B; // A was too rainy; try B, on the hope that rain is short-lived
    } else if (B == 0xfb) {
      res[i] = A; // B was too rainy; try A, on the hope that rain is short-lived

    } else {
      res[i] = 0xff; // Cannot get here
    }
  }
  return(res);
}
예제 #3
0
 void push(const RawVector &rv)
 {
   try
   {
     _pmq->send(&(rv[0]), rv.size(), 0);
   }
   catch (interprocess_exception &e)
   {
     Rprintf("%s\n", e.what());
   }
 }
예제 #4
0
파일: get_bit.cpp 프로젝트: cran/oce
// Cross-reference work:
// 1. update ../src/registerDynamicSymbol.c with an item for this
// 2. main code should use the autogenerated wrapper in ../R/RcppExports.R
//
// [[Rcpp::export]]
NumericVector do_get_bit(RawVector buf, int bit) // bit=0 for rightmost bit, =7 for leftmost bit
{
  static unsigned char mask[] = {1, 2, 4, 8, 16, 32, 64, 128};
  int n = buf.size();
  if (bit < 0)
    ::Rf_error("cannot have bit number less than 0; got %d", bit);
  if (bit > 7)
    ::Rf_error("cannot have bit number greater than 7; got %d", bit);
  NumericVector res(n);
  for (int i = 0; i < n; i++) {
    res[i] = (buf[i] & mask[bit]) != 0;
  }
  return(res);
}
예제 #5
0
 RawVector raw_initializer_list(){
     RawVector x = {0,1,2,3} ;
     for( int i=0; i<x.size(); i++) x[i] = x[i]*2 ;
     return x ;
 }
예제 #6
0
// [[Rcpp::export]]
RawVector raw_REALSXP( RawVector x ){
    for( int i=0; i<x.size(); i++) {
    	x[i] = x[i]*2 ;
    }
    return x ;
}