本文整理汇总了C++中ArrayHandle::size方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayHandle::size方法的具体用法?C++ ArrayHandle::size怎么用?C++ ArrayHandle::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayHandle
的用法示例。
在下文中一共展示了ArrayHandle::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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{
示例2: run
/**
* @brief This function is the finalfunc of an aggregator computing the
* perplexity.
* @param args[0] The global state
* @return The perplexity
**/
AnyType lda_perplexity_ffunc::run(AnyType & args){
ArrayHandle<int64_t> state = args[0].getAs<ArrayHandle<int64_t> >();
const double * perp = reinterpret_cast<const double *>(state.ptr() + state.size() - 1);
return *perp;
}
示例3: 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));
}
示例4: __max
template<class T> static T __max(ArrayHandle<T> ah){
return __max(ah, 0, ah.size());
}
示例5: invalid_argument
AnyType vcrf_top1_label::run(AnyType& args) {
ArrayHandle<double> mArray = args[0].getAs<ArrayHandle<double> >();
ArrayHandle<double> rArray = args[1].getAs<ArrayHandle<double> >();
const int32_t numLabels = args[2].getAs<int32_t>();
if (numLabels == 0)
throw std::invalid_argument("Number of labels cannot be zero");
int doc_len = static_cast<int>(rArray.size() / numLabels);
double* prev_top1_array = new double[numLabels];
double* curr_top1_array = new double[numLabels];
double* prev_norm_array = new double[numLabels];
double* curr_norm_array = new double[numLabels];
int* path = new int[doc_len*numLabels];
memset(prev_top1_array, 0, numLabels*sizeof(double));
memset(prev_norm_array, 0, numLabels*sizeof(double));
memset(path, 0, doc_len*numLabels*sizeof(int));
for(int start_pos = 0; start_pos < doc_len; start_pos++) {
memset(curr_top1_array, 0, numLabels*sizeof(double));
memset(curr_norm_array, 0, numLabels*sizeof(double));
if (start_pos == 0) {
for (int label = 0; label < numLabels; label++) {
curr_norm_array[label] = rArray[label] + mArray[label];
curr_top1_array[label] = rArray[label] + mArray[label];
}
} else {
for (int curr_label = 0; curr_label < numLabels; curr_label++) {
for (int prev_label = 0; prev_label < numLabels; prev_label++) {
double top1_new_score = prev_top1_array[prev_label]
+ rArray[start_pos*numLabels + curr_label]
+ mArray[(prev_label+1)*numLabels + curr_label];
if (start_pos == doc_len - 1)
top1_new_score += mArray[(numLabels+1)*numLabels + curr_label];
if (top1_new_score > curr_top1_array[curr_label]) {
curr_top1_array[curr_label] = top1_new_score;
path[start_pos*numLabels + curr_label] = prev_label;
}
/* calculate the probability of the best label sequence */
double norm_new_score = prev_norm_array[prev_label]
+ rArray[start_pos * numLabels + curr_label]
+ mArray[(prev_label+1)*numLabels + curr_label];
/* last token in a sentence, the end feature should be fired */
if (start_pos == doc_len - 1)
norm_new_score += mArray[(numLabels+1)*numLabels + curr_label];
/* The following wants to do z = log(exp(x)+exp(y)), the faster implementation is
* z=min(x,y) + log(exp(abs(x-y))+1)
* 0.5 is for rounding
*/
if (curr_norm_array[curr_label] == 0)
curr_norm_array[curr_label] = norm_new_score;
else {
double x = curr_norm_array[curr_label];
double y = norm_new_score;
curr_norm_array[curr_label] = std::min(x,y) +
static_cast<double>(log(std::exp(std::abs(y-x)/1000.0) +1)*1000.0 + 0.5);
}
}
}
}
for (int label = 0; label < numLabels; label++) {
prev_top1_array[label] = curr_top1_array[label];
prev_norm_array[label] = curr_norm_array[label];
}
}
/* find the label of the last token in a sentence */
double max_score = 0.0;
int top1_label = 0;
for(int label = 0; label < numLabels; label++) {
if(curr_top1_array[label] > max_score) {
max_score = curr_top1_array[label];
top1_label = label;
}
}
/* Define the result array with doc_len+1 elements, where the first doc_len
* elements are used to store the best labels and the last element is used
* to store the conditional probability of the sequence.
*/
MutableArrayHandle<int> result(
madlib_construct_array(
NULL, doc_len+1, INT4TI.oid,
INT4TI.len, INT4TI.byval, INT4TI.align));
/* trace back to get the labels for the rest tokens in a sentence */
result[doc_len - 1] = top1_label;
for (int pos = doc_len - 1; pos >= 1; pos--) {
top1_label = path[pos * numLabels + top1_label];
result[pos-1] = top1_label;
}
//.........这里部分代码省略.........