本文整理汇总了C++中ArrayHandle::ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayHandle::ptr方法的具体用法?C++ ArrayHandle::ptr怎么用?C++ ArrayHandle::ptr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayHandle
的用法示例。
在下文中一共展示了ArrayHandle::ptr方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
AnyType matrix_mem_trans::run(AnyType & args)
{
ArrayHandle<double> m = args[0].getAs<ArrayHandle<double> >();
if (m.dims() != 2){
throw std::invalid_argument(
"invalid argument - 2-d array expected");
}
int row_m = static_cast<int>(m.sizeOfDim(0));
int col_m = static_cast<int>(m.sizeOfDim(1));
int dims[2] = {col_m, row_m};
int lbs[2] = {1, 1};
MutableArrayHandle<double> r = madlib_construct_md_array(
NULL, NULL, 2, dims, lbs, FLOAT8TI.oid,
FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align);
for (int i = 0; i < row_m; i++){
for(int j = 0; j < col_m; j++){
*(r.ptr() + j * row_m + i) = *(m.ptr() + i * col_m + j);
}
}
return r;
}
示例2: run
/**
* @brief This function is the sfunc of an aggregator computing the
* perplexity.
* @param args[0] The current state
* @param args[1] The unique words in the documents
* @param args[2] The counts of each unique words
* @param args[3] The topic counts in the document
* @param args[4] The model (word topic counts and corpus topic
* counts)
* @param args[5] The Dirichlet parameter for per-document topic
* multinomial, i.e. alpha
* @param args[6] The Dirichlet parameter for per-topic word
* multinomial, i.e. beta
* @param args[7] The size of vocabulary
* @param args[8] The number of topics
* @return The updated state
**/
AnyType lda_perplexity_sfunc::run(AnyType & args){
ArrayHandle<int32_t> words = args[1].getAs<ArrayHandle<int32_t> >();
ArrayHandle<int32_t> counts = args[2].getAs<ArrayHandle<int32_t> >();
ArrayHandle<int32_t> topic_counts = args[3].getAs<ArrayHandle<int32_t> >();
double alpha = args[5].getAs<double>();
double beta = args[6].getAs<double>();
int32_t voc_size = args[7].getAs<int32_t>();
int32_t topic_num = args[8].getAs<int32_t>();
if(alpha <= 0)
throw std::invalid_argument("invalid argument - alpha");
if(beta <= 0)
throw std::invalid_argument("invalid argument - beta");
if(voc_size <= 0)
throw std::invalid_argument(
"invalid argument - voc_size");
if(topic_num <= 0)
throw std::invalid_argument(
"invalid argument - topic_num");
if(words.size() != counts.size())
throw std::invalid_argument(
"dimensions mismatch: words.size() != counts.size()");
if(__min(words) < 0 || __max(words) >= voc_size)
throw std::invalid_argument(
"invalid values in words");
if(__min(counts) <= 0)
throw std::invalid_argument(
"invalid values in counts");
if(topic_counts.size() != (size_t)(topic_num))
throw std::invalid_argument(
"invalid dimension - topic_counts.size() != topic_num");
if(__min(topic_counts, 0, topic_num) < 0)
throw std::invalid_argument("invalid values in topic_counts");
MutableArrayHandle<int64_t> state(NULL);
if(args[0].isNull()){
if(args[4].isNull())
throw std::invalid_argument("invalid argument - the model \
parameter should not be null for the first call");
ArrayHandle<int64_t> model = args[4].getAs<ArrayHandle<int64_t> >();
if(model.size() != (size_t)((voc_size + 1) * topic_num))
throw std::invalid_argument(
"invalid dimension - model.size() != (voc_size + 1) * topic_num");
if(__min(model) < 0)
throw std::invalid_argument("invalid topic counts in model");
state = madlib_construct_array(NULL,
static_cast<int>(model.size()) + 1,
INT8TI.oid,
INT8TI.len,
INT8TI.byval,
INT8TI.align);
memcpy(state.ptr(), model.ptr(), model.size() * sizeof(int64_t));
}else{
示例3: run
AnyType lda_parse_model::run(AnyType & args){
ArrayHandle<int64_t> state = args[0].getAs<ArrayHandle<int64_t> >();
int32_t voc_size = args[1].getAs<int32_t>();
int32_t topic_num = args[2].getAs<int32_t>();
const int32_t *model = reinterpret_cast<const int32_t *>(state.ptr());
int dims[2] = {voc_size/2, topic_num};
int lbs[2] = {1, 1};
MutableArrayHandle<int32_t> model_part1(
madlib_construct_md_array(
NULL, NULL, 2, dims, lbs, INT4TI.oid, INT4TI.len, INT4TI.byval,
INT4TI.align));
for(int32_t i = 0; i < voc_size/2; i++){
for(int32_t j = 0; j < topic_num; j++){
model_part1[i * topic_num + j] = model[i * (topic_num+1) + j];
}
}
int dims2[2] = {voc_size - voc_size/2, topic_num};
MutableArrayHandle<int32_t> model_part2(
madlib_construct_md_array(
NULL, NULL, 2, dims2, lbs, INT4TI.oid, INT4TI.len, INT4TI.byval,
INT4TI.align));
for(int32_t i = voc_size/2; i < voc_size; i++){
for(int32_t j = 0; j < topic_num; j++){
model_part2[(i-voc_size/2) * topic_num + j] = model[i * (topic_num+1) + j];
}
}
//int dims3[1] = {topic_num};
//int lbs3[1] = {1};
MutableNativeColumnVector total_topic_counts(allocateArray<double>(topic_num));
for (int i = 0; i < voc_size; i ++) {
for (int j = 0; j < topic_num; j ++) {
total_topic_counts[j] += static_cast<double>(model[i * (topic_num + 1) + j]);
}
}
AnyType tuple;
tuple << model_part1
<< model_part2
<< total_topic_counts;
return tuple;
}
示例4: invalid_argument
/**
* @brief The function is used for the initlization of the SRF. The SRF unnests
* a 2-D array into a set of 1-D arrays.
**/
void * lda_unnest::SRF_init(AnyType &args)
{
ArrayHandle<int64_t> inarray = args[0].getAs<ArrayHandle<int64_t> >();
if(inarray.dims() != 2)
throw std::invalid_argument("invalid dimension");
sr_ctx * ctx = new sr_ctx;
ctx->inarray = inarray.ptr();
ctx->maxcall = static_cast<int32_t>(inarray.sizeOfDim(0));
ctx->dim = static_cast<int32_t>(inarray.sizeOfDim(1));
ctx->curcall = 0;
return ctx;
}
示例5: Base
inline
HandleMap<const Matrix, ArrayHandle<double> >::HandleMap(
const ArrayHandle<double>& inHandle)
: Base(const_cast<double*>(inHandle.ptr()), inHandle.sizeOfDim(1),
inHandle.sizeOfDim(0)),
mMemoryHandle(inHandle) { }
示例6: accumulate
/**
* @brief Get the sum of an array - for parameter checking
* @return The sum
* @note The caller will ensure that ah is always non-null.
**/
static int32_t __sum(ArrayHandle<int32_t> ah){
const int32_t * array = ah.ptr();
size_t size = ah.size();
return std::accumulate(array, array + size, static_cast<int32_t>(0));
}
示例7:
/**
* @brief Get the max value of an array - for parameter checking
* @return The max value
* @note The caller will ensure that ah is always non-null.
**/
template<class T> static T __max(
ArrayHandle<T> ah, size_t start, size_t len){
const T * array = ah.ptr() + start;
return *std::max_element(array, array + len);
}