Beispiel #1
0
static void tensorEye(rpc::RPCMessage& raw_message) {
  thpp::Tensor *tensor = unpackRetrieveTensor(raw_message);
  long n = unpackInteger(raw_message);
  long m = unpackInteger(raw_message);
  finalize(raw_message);
  tensor->eye(n, m);
}
Beispiel #2
0
static void tensorMean(rpc::RPCMessage& raw_message) {
  thpp::Tensor *r = unpackRetrieveTensor(raw_message);
  thpp::Tensor *t = unpackRetrieveTensor(raw_message);
  int dimension = unpackInteger(raw_message);
  int keepdim = unpackInteger(raw_message);
  finalize(raw_message);
  r->mean(*t, dimension, keepdim);
}
Beispiel #3
0
static void tensorSort(rpc::RPCMessage& raw_message) {
  thpp::Tensor *rt = unpackRetrieveTensor(raw_message);
  thpp::Tensor *ri = unpackRetrieveTensor(raw_message);
  thpp::Tensor *tensor = unpackRetrieveTensor(raw_message);
  int dimension = unpackInteger(raw_message);
  int desc = unpackInteger(raw_message);
  finalize(raw_message);
  rt->sort(*ri, *tensor, dimension, desc);
}
Beispiel #4
0
static void tensorStd(rpc::RPCMessage& raw_message) {
  thpp::Tensor *r = unpackRetrieveTensor(raw_message);
  thpp::Tensor *t = unpackRetrieveTensor(raw_message);
  int dimension = unpackInteger(raw_message);
  int biased = unpackInteger(raw_message);
  int keepdim = unpackInteger(raw_message);
  finalize(raw_message);
  r->std(*t, dimension, biased, keepdim);
}
Beispiel #5
0
static void tensorCatArray(rpc::RPCMessage& raw_message) {
  thpp::Tensor *result = unpackRetrieveTensor(raw_message);
  int numInputs = unpackInteger(raw_message);
  std::vector<thpp::Tensor*> inputs(numInputs);
  for (std::size_t i = 0; i < numInputs; i++)
    inputs[i] = unpackRetrieveTensor(raw_message);
  int dimension = unpackInteger(raw_message);
  finalize(raw_message);
  result->catArray(inputs, dimension);
}
Beispiel #6
0
static void tensorTopk(rpc::RPCMessage& raw_message) {
  thpp::Tensor *rt = unpackRetrieveTensor(raw_message);
  thpp::Tensor *ri = unpackRetrieveTensor(raw_message);
  thpp::Tensor *tensor = unpackRetrieveTensor(raw_message);
  long k = unpackInteger(raw_message);
  int dimension = unpackInteger(raw_message);
  int dir = unpackInteger(raw_message);
  int sorted = unpackInteger(raw_message);
  finalize(raw_message);
  rt->topk(*ri, *tensor, k, dimension, dir, sorted);
}
Beispiel #7
0
static void tensorTriu(rpc::RPCMessage& raw_message) {
  thpp::Tensor *r = unpackRetrieveTensor(raw_message);
  thpp::Tensor *t = unpackRetrieveTensor(raw_message);
  long k = unpackInteger(raw_message);
  finalize(raw_message);
  r->triu(*t, k);
}
Beispiel #8
0
static void tensorRandperm(rpc::RPCMessage& raw_message) {
  thpp::Tensor *r = unpackRetrieveTensor(raw_message);
  thpp::Generator *_generator = unpackRetrieveGenerator(raw_message);
  long n = unpackInteger(raw_message);
  finalize(raw_message);
  r->randperm(*_generator, n);
}
Beispiel #9
0
/** Unpack an entire setting description from the buffer
 *
 * @param pBuffer the buffer to unpack from
 * @param index the index in the buffer to start at
 * @param size the size of the buffer in bytes
 * @param setting the structure to hold the setting value
 *
 * @return the new index for the next piece of data or 0 if an error occurs.
 */
static int unpackSetting(unsigned char *pBuffer, int index, int size, SettingDescription &setting) {
  if ((index + 1)>=size) // Make sure we have the type modifier at least
    return 0;
  // 1 byte for type
  setting.typeAndModifier = pBuffer[index++];
  // The name
  if ((index=unpackString(pBuffer, index, size, &setting.name))<=0)
    return index;
  // And the value itself
  switch(setting.typeAndModifier & SETTING_TYPE_MASK) {
    case StringSetting:
      index = unpackString(pBuffer, index, size, &setting.value.string);
      break;
    case IntegerSetting:
      index = unpackInteger(pBuffer, index, size, setting.value.integer);
      break;
    case BooleanSetting:
      index = unpackBoolean(pBuffer, index, size, setting.value.boolean);
      break;
    case NumberSetting:
      index = unpackDouble(pBuffer, index, size, setting.value.number);
      break;
    default:
      index = 0;
    }
  return index;
  }
Beispiel #10
0
static void tensorDiag(rpc::RPCMessage& raw_message) {
  thpp::Tensor *r = unpackRetrieveTensor(raw_message);
  thpp::Tensor *t = unpackRetrieveTensor(raw_message);
  int k = unpackInteger(raw_message);
  finalize(raw_message);
  r->diag(*t, k);
}
Beispiel #11
0
static void tensorIndexFill(rpc::RPCMessage& raw_message) {
  thpp::Tensor *tensor = unpackRetrieveTensor(raw_message);
  int dim = unpackInteger(raw_message);
  thpp::Tensor *index = unpackRetrieveTensor(raw_message);
  thpp::Type type = peekType(raw_message);
  if (thpp::isInteger(type)) {
    auto val = unpackInteger(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::IntTensor*>(tensor)->indexFill(dim, *index, val);
  } else if (thpp::isFloat(type)) {
    auto val = unpackFloat(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::FloatTensor*>(tensor)->indexFill(dim, *index, val);
  } else {
    throw std::runtime_error("expected a scalar type");
  }
}
Beispiel #12
0
static void tensorIndexAdd(rpc::RPCMessage& raw_message) {
  thpp::Tensor *tensor = unpackRetrieveTensor(raw_message);
  int dim = unpackInteger(raw_message);
  thpp::Tensor *index = unpackRetrieveTensor(raw_message);
  thpp::Tensor *src = unpackRetrieveTensor(raw_message);
  finalize(raw_message);
  tensor->indexAdd(dim, *index, *src);
}
Beispiel #13
0
static void tensorNorm(rpc::RPCMessage& raw_message) {
  thpp::Tensor *r = unpackRetrieveTensor(raw_message);
  thpp::Tensor *t = unpackRetrieveTensor(raw_message);
  int dimension = unpackInteger(raw_message);
  int keepdim = unpackInteger(raw_message);
  if (thpp::isInteger(r->type())) {
    long long value = unpackInteger(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::IntTensor*>(r)->norm(*t, value, dimension, keepdim);
  } else if (thpp::isFloat(r->type())) {
    double value = unpackFloat(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::FloatTensor*>(r)->norm(*t, value, dimension, keepdim);
  } else {
    throw std::runtime_error("expected scalar type");
  }
}
Beispiel #14
0
static void tensorLogspace(rpc::RPCMessage& raw_message) {
  thpp::Tensor *r = unpackRetrieveTensor(raw_message);
  long n = unpackInteger(raw_message);

  if (thpp::isInteger(r->type())) {
    long long a = unpackInteger(raw_message);
    long long b = unpackInteger(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::IntTensor*>(r)->logspace(a, b, n);
  } else if (thpp::isFloat(r->type())) {
    double a = unpackFloat(raw_message);
    double b = unpackFloat(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::FloatTensor*>(r)->logspace(a, b, n);
  } else {
    throw std::invalid_argument("expected scalar type");
  }
}
Beispiel #15
0
static void tensorBhistc(rpc::RPCMessage& raw_message) {
  thpp::Tensor *hist = unpackRetrieveTensor(raw_message);
  thpp::Tensor *tensor = unpackRetrieveTensor(raw_message);
  long nbins = unpackInteger(raw_message);

  if (thpp::isInteger(hist->type())) {
    long long minvalue = unpackInteger(raw_message);
    long long maxvalue = unpackInteger(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::IntTensor*>(hist)->bhistc(*tensor, nbins, minvalue, maxvalue);
  } else if (thpp::isFloat(hist->type())) {
    double minvalue = unpackFloat(raw_message);
    double maxvalue = unpackFloat(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::FloatTensor*>(hist)->bhistc(*tensor, nbins, minvalue, maxvalue);
  } else {
    throw std::invalid_argument("expected scalar type");
  }
}
Beispiel #16
0
static void tensorRange(rpc::RPCMessage& raw_message) {
  thpp::Tensor *r = unpackRetrieveTensor(raw_message);
  thpp::Type type = peekType(raw_message);
  if (thpp::isInteger(type)) {
    long long xmin = unpackInteger(raw_message);
    long long xmax = unpackInteger(raw_message);
    long long step = unpackInteger(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::IntTensor*>(r)->range(xmin, xmax, step);
  } else if (thpp::isFloat(type)) {
    double xmin = unpackFloat(raw_message);
    double xmax = unpackFloat(raw_message);
    double step = unpackFloat(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::FloatTensor*>(r)->range(xmin, xmax, step);
  } else {
    throw std::runtime_error("expected a scalar type");
  }
}
Beispiel #17
0
static void tensorRenorm(rpc::RPCMessage& raw_message) {
  thpp::Tensor *res = unpackRetrieveTensor(raw_message);
  thpp::Tensor *src = unpackRetrieveTensor(raw_message);
  int dimension = unpackInteger(raw_message);

  if (thpp::isInteger(res->type())) {
    long long value = unpackInteger(raw_message);
    long long maxnorm = unpackInteger(raw_message);
    finalize(raw_message);

    dynamic_cast<thpp::IntTensor*>(res)->renorm(*src, value, dimension, maxnorm);
  } else if (thpp::isFloat(res->type())) {
    double value = unpackFloat(raw_message);
    double maxnorm = unpackFloat(raw_message);
    finalize(raw_message);

    dynamic_cast<thpp::FloatTensor*>(res)->renorm(*src, value, dimension, maxnorm);
  } else {
    throw std::invalid_argument("expected scalar type");
  }
}
Beispiel #18
0
static void tensorFill(rpc::RPCMessage& raw_message) {
  thpp::Tensor *t = unpackRetrieveTensor(raw_message);
  thpp::Type type = peekType(raw_message);
  if (thpp::isInteger(type)) {
    auto value = unpackInteger(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::IntTensor*>(t)->fill(value);
  } else if (thpp::isFloat(type)) {
    auto value = unpackFloat(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::FloatTensor*>(t)->fill(value);
  } else {
    throw std::runtime_error("expected a scalar type");
  }
}
Beispiel #19
0
static void tensorStdall(rpc::RPCMessage& raw_message) {
  thpp::Tensor *tensor = unpackRetrieveTensor(raw_message);
  int biased = unpackInteger(raw_message);
  finalize(raw_message);

  if (thpp::isInteger(tensor->type())) {
    long long response = dynamic_cast<thpp::IntTensor*>(tensor)->stdall(biased);
    sendValueToMaster(response);
  } else if (thpp::isFloat(tensor->type())) {
    double response = dynamic_cast<thpp::FloatTensor*>(tensor)->stdall(biased);
    sendValueToMaster(response);
  } else {
    throw std::invalid_argument("expected scalar type");
  }
}
Beispiel #20
0
static void tensorTpow(rpc::RPCMessage& raw_message) {
  thpp::Tensor *r = unpackRetrieveTensor(raw_message);
  thpp::Tensor *t = unpackRetrieveTensor(raw_message);
  if (thpp::isInteger(r->type())) {
    long long value = unpackInteger(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::IntTensor*>(r)->tpow(value, *t);
  } else if (thpp::isFloat(t->type())) {
    double value = unpackFloat(raw_message);
    finalize(raw_message);
    dynamic_cast<thpp::FloatTensor*>(r)->tpow(value, *t);
  } else {
    throw std::runtime_error("expected a scalar type");
  }
}
Beispiel #21
0
static void tensorNormall(rpc::RPCMessage& raw_message) {
  thpp::Tensor *r = unpackRetrieveTensor(raw_message);

  if (thpp::isInteger(r->type())) {
    long long value = unpackInteger(raw_message);
    finalize(raw_message);

    long long response = dynamic_cast<thpp::IntTensor*>(r)->normall(value);
    sendValueToMaster(response);
  } else if (thpp::isFloat(r->type())) {
    double value = unpackFloat(raw_message);
    finalize(raw_message);

    double response = dynamic_cast<thpp::FloatTensor*>(r)->normall(value);
    sendValueToMaster(response);
  } else {
    throw std::invalid_argument("expected scalar type");
  }
}