当前位置: 首页>>代码示例>>C++>>正文


C++ AnyType类代码示例

本文整理汇总了C++中AnyType的典型用法代码示例。如果您正苦于以下问题:C++ AnyType类的具体用法?C++ AnyType怎么用?C++ AnyType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AnyType类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: eval

AnyType TPTScriptInterface::tptS_delete(std::deque<std::string> * words)
{
	//Arguments from stack
	AnyType partRef = eval(words);

	Simulation * sim = m->GetSimulation();

	if(partRef.GetType() == TypePoint)
	{
		ui::Point deletePoint = ((PointType)partRef).Value();
		if(deletePoint.X<0 || deletePoint.Y<0 || deletePoint.Y >= YRES || deletePoint.X >= XRES)
			throw GeneralException("Invalid position");
		sim->delete_part(deletePoint.X, deletePoint.Y);
	}
	else if(partRef.GetType() == TypeNumber)
	{
		int partIndex = ((NumberType)partRef).Value();
		if(partIndex < 0 || partIndex >= NPART)
			throw GeneralException("Invalid particle index");
		sim->kill_part(partIndex);
	}
	else
		throw GeneralException("Invalid particle reference");

	return NumberType(0);
}
开发者ID:Ebola-chan,项目名称:The-Powder-Toy,代码行数:26,代码来源:TPTScriptInterface.cpp

示例2: invalid_argument

AnyType
chi2_gof_test_transition::run(AnyType &args) {
    // §4.15.4 ("Aggregate functions") of ISO/IEC 9075-2:2003, "SQL/Foundation"
    // demands that rows containing NULLs are ignored
    // We currently rely on the backend filtering out rows with NULLs, i.e., to
    // perform an action equivalent to:
    // for (uint16_t i = 0; i < args.numFields(); ++i)
    //    if (args[i].isNull)
    //        return state;

    Chi2TestTransitionState<MutableArrayHandle<double> > state = args[0];
    double observed = static_cast<double>(args[1].getAs<int64_t>());
    double expected = args.numFields() <= 2 ? 1 : args[2].getAs<double>();
    int64_t df = args.numFields() <= 3 ? 0 : args[3].getAs<int64_t>();

    if (observed < 0)
        throw std::invalid_argument("Number of observations must be "
            "nonnegative.");
    else if (df < 0)
        throw std::invalid_argument("Degree of freedom must be positive (or 0 "
            "to use the default of <number of rows> - 1).");
    else if (state.df != df) {
        if (state.numRows > 0)
            throw std::invalid_argument("Degree of freedom must be constant.");
        state.df = df;
    }

    updateSumSquaredDeviations(state.numRows.ref(), state.sum_expect.ref(),
        state.sum_obs_square_over_expect.ref(), state.sum_obs.ref(),
        state.sumSquaredDeviations.ref(),
        1, expected, observed * observed / expected,
        observed, 0);

    return state;
}
开发者ID:0x0all,项目名称:madlib,代码行数:35,代码来源:chi_squared_test.cpp

示例3: AnyType

int DataAccess::setMappings(void *data, int numOfCols, char **row, char **colName){

	AnyType *temp;

	temp=new AnyType(numOfCols);
	temp->setItem(row[0]? (string)row[0] : "NULL", "input_str");
	temp->setItem(row[1]? (string)row[1] : "NULL", "latex");
	temp->setItem(row[2]? (string)row[2] : "NULL", "mathml");
	temp->setItem(row[3]? (string)row[3] : "NULL", "exp_type");
	temp->setItem((bool)(strcmp((char*)row[4],"1")==0? true : false), "brac_essential");
	temp->setItem((int)row[5], "no_of_para");
	temp->setItem((long long)row[6], "hits");
	temp->setItem(row[7]? (string)row[7] : "NULL", "para");
	temp->setItem(row[8]? (string)row[8] : "NULL", "input_format");
	DataAccess::tokenMappings->push_back(*temp);

	//WriteToFile(numOfCols, row, colName);
		
	return(0);
}
开发者ID:saroad,项目名称:MEI_Tool,代码行数:20,代码来源:DataAccess.cpp

示例4:

/**
 * @brief Return the Binomial family object: family, linkfun
 */
AnyType
binomial::run(AnyType &args) {
	std::string linkfunc;

	// 1. get the linkfun argument: default value -- "identity"
	if (args.isNull()) linkfunc = "logit";
	else linkfunc = args[0].getAs<char*>();
	std::transform(linkfunc.begin(), linkfunc.end(), linkfunc.begin(), ::tolower);

    // 3. return family information
    std::string family = "binomial";
    AnyType tuple;
	tuple << family << linkfunc;
	return tuple;
}
开发者ID:randomizedthinking,项目名称:madlib,代码行数:18,代码来源:glm_family.cpp

示例5: toObject

System::Object^ toObject(const AnyType &source)
{    
    if (source.type() == typeid(AnyBoolean))
        return boost::any_cast<AnyBoolean>(source);    
    else if (source.type() == typeid(AnyInt64))
        return boost::any_cast<AnyInt64>(source);
    else if (source.type() == typeid(AnyInt32))
        return boost::any_cast<AnyInt32>(source);
    else if (source.type() == typeid(AnyInt16))
        return boost::any_cast<AnyInt16>(source);
    else if (source.type() == typeid(AnyInt8))
        return boost::any_cast<AnyInt8>(source);
    else if (source.type() == typeid(AnyUInt64))
        return boost::any_cast<AnyUInt64>(source);
    else if (source.type() == typeid(AnyUInt32))
        return boost::any_cast<AnyUInt32>(source);
    else if (source.type() == typeid(AnyUInt16))
        return boost::any_cast<AnyUInt16>(source);
    else if (source.type() == typeid(AnyUInt8))
        return boost::any_cast<AnyUInt8>(source);
    else if (source.type() == typeid(AnyFloat128))
        return boost::any_cast<AnyFloat128>(source);
    else if (source.type() == typeid(AnyFloat64))
        return boost::any_cast<AnyFloat64>(source);
    else if (source.type() == typeid(AnyFloat32))
        return boost::any_cast<AnyFloat32>(source);
    else if (source.type() == typeid(AnyDateTime))
        return anyDateTimeToDateTime(boost::any_cast<AnyDateTime>(source));
    else if (source.type() == typeid(AnyAsciiChar))
        return boost::any_cast<AnyAsciiChar>(source);
    else if (source.type() == typeid(AnyUnicodeChar))
        return boost::any_cast<AnyUnicodeChar>(source);
    else if (source.type() == typeid(AnyAsciiString))
        return anyAsciiStringToSystemString(boost::any_cast<AnyAsciiString>(source));
    else if (source.type() == typeid(AnyUnicodeString))
        return anyUnicodeStringToSystemString(boost::any_cast<AnyUnicodeString>(source));
    else if (source.type() == typeid(AnyByteArray))
        return anyByteArrayToByteArray(boost::any_cast<AnyByteArray>(source));
	else if (source.type() == typeid(AnyAsciiStringArray))
		return anyAsciiStringArrayToStringArray(boost::any_cast<AnyAsciiStringArray>(source));
	else if (source.type() == typeid(AnyUnicodeStringArray))
		return anyUnicodeStringArrayToStringArray(boost::any_cast<AnyUnicodeStringArray>(source));

	return nullptr;
}
开发者ID:nequeo,项目名称:base,代码行数:45,代码来源:anyHelper.cpp

示例6: run

/**
 * @brief This function learns the topics of words in a document and is the
 * main step of a Gibbs sampling iteration. The word topic counts and
 * corpus topic counts are passed to this function in the first call and
 * then transfered to the rest calls through args.mSysInfo->user_fctx for
 * efficiency.
 * @param args[0]   The unique words in the documents
 * @param args[1]   The counts of each unique words
 * @param args[2]   The topic counts and topic assignments in the document
 * @param args[3]   The model (word topic counts and corpus topic
 *                  counts)
 * @param args[4]   The Dirichlet parameter for per-document topic
 *                  multinomial, i.e. alpha
 * @param args[5]   The Dirichlet parameter for per-topic word
 *                  multinomial, i.e. beta
 * @param args[6]   The size of vocabulary
 * @param args[7]   The number of topics
 * @param args[8]   The number of iterations (=1:training, >1:prediction)
 * @return          The updated topic counts and topic assignments for
 *                  the document
 **/
AnyType lda_gibbs_sample::run(AnyType & args)
{
    ArrayHandle<int32_t> words = args[0].getAs<ArrayHandle<int32_t> >();
    ArrayHandle<int32_t> counts = args[1].getAs<ArrayHandle<int32_t> >();
    MutableArrayHandle<int32_t> doc_topic = args[2].getAs<MutableArrayHandle<int32_t> >();
    double alpha = args[4].getAs<double>();
    double beta = args[5].getAs<double>();
    int32_t voc_size = args[6].getAs<int32_t>();
    int32_t topic_num = args[7].getAs<int32_t>();
    int32_t iter_num = args[8].getAs<int32_t>();
    size_t model64_size = static_cast<size_t>(voc_size * (topic_num + 1) + 1) * sizeof(int32_t) / sizeof(int64_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(iter_num <= 0)
        throw std::invalid_argument(
            "invalid argument - iter_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");

    int32_t word_count = __sum(counts);
    if(doc_topic.size() != (size_t)(word_count + topic_num))
        throw std::invalid_argument(
            "invalid dimension - doc_topic.size() != word_count + topic_num");
    if(__min(doc_topic, 0, topic_num) < 0)
        throw std::invalid_argument("invalid values in topic_count");
    if(
        __min(doc_topic, topic_num, word_count) < 0 ||
        __max(doc_topic, topic_num, word_count) >= topic_num)
        throw std::invalid_argument( "invalid values in topic_assignment");

    if (!args.getUserFuncContext()) {
        ArrayHandle<int64_t> model64 = args[3].getAs<ArrayHandle<int64_t> >();
        if (model64.size() != model64_size) {
            std::stringstream ss;
            ss << "invalid dimension: model64.size() = " << model64.size();
            throw std::invalid_argument(ss.str());
        }
        if (__min(model64) < 0) {
            throw std::invalid_argument("invalid topic counts in model");
        }

        int32_t *context =
            static_cast<int32_t *>(
                MemoryContextAllocZero(
                    args.getCacheMemoryContext(),
                    model64.size() * sizeof(int64_t)
                        + topic_num * sizeof(int64_t)));
        memcpy(context, model64.ptr(), model64.size() * sizeof(int64_t));
        int32_t *model = context;

        int64_t *running_topic_counts = reinterpret_cast<int64_t *>(
                context + model64_size * sizeof(int64_t) / sizeof(int32_t));
        for (int i = 0; i < voc_size; i ++) {
            for (int j = 0; j < topic_num; j ++) {
                running_topic_counts[j] += model[i * (topic_num + 1) + j];
            }
        }

        args.setUserFuncContext(context);
    }

    int32_t *context = static_cast<int32_t *>(args.getUserFuncContext());
//.........这里部分代码省略.........
开发者ID:BruceZhou2012,项目名称:incubator-madlib,代码行数:101,代码来源:lda.cpp

示例7: eval

AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
{
	//Arguments from stack
	StringType property = eval(words);
	AnyType selector = eval(words);
	AnyType value = eval(words);

	Simulation * sim = m->GetSimulation();
	unsigned char * partsBlock = (unsigned char*)&sim->parts[0];

	int returnValue = 0;

	FormatType propertyFormat;
	int propertyOffset = GetPropertyOffset(property.Value(), propertyFormat);

	if(propertyOffset==-1)
		throw GeneralException("Invalid property");

	//Selector
	int newValue;
	if(value.GetType() == TypeNumber)
		newValue = ((NumberType)value).Value();
	else if(value.GetType() == TypeString)
	{
		newValue = GetParticleType(((StringType)value).Value());
		if (newValue < 0 || newValue >= PT_NUM)
			throw GeneralException("Invalid element");
	}
	else
		throw GeneralException("Invalid value for assignment");
	if (property.Value() == "type" && (newValue < 0 || newValue >= PT_NUM))
		throw GeneralException("Invalid element");

	if(selector.GetType() == TypePoint || selector.GetType() == TypeNumber)
	{
		int partIndex = -1;
		if(selector.GetType() == TypePoint)
		{
			ui::Point tempPoint = ((PointType)selector).Value();
			if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES)
				throw GeneralException("Invalid position");

		}
		else
			partIndex = ((NumberType)selector).Value();
		if(partIndex<0 || partIndex>NPART || sim->parts[partIndex].type==0)
			throw GeneralException("Invalid particle");

		switch(propertyFormat)
		{
		case FormatInt:
			*((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
			break;
		case FormatFloat:
			*((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
			break;
		}
		returnValue = 1;
	}
	else if(selector.GetType() == TypeString && ((StringType)selector).Value() == "all")
	{
		switch(propertyFormat)
		{
		case FormatInt:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type)
					{
						returnValue++;
						*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		case FormatFloat:
			{
				for(int j = 0; j < NPART; j++)
					if(sim->parts[j].type)
					{
						returnValue++;
						*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
					}
			}
			break;
		}
	}
	else if(selector.GetType() == TypeString || selector.GetType() == TypeNumber)
	{
		int type;
		if(selector.GetType() == TypeNumber)
			type = ((NumberType)selector).Value();
		else if(selector.GetType() == TypeString)
			type = GetParticleType(((StringType)selector).Value());

		if(type<0 || type>=PT_NUM)
			throw GeneralException("Invalid particle type");
		std::cout << propertyOffset << std::endl;
		switch(propertyFormat)
		{
		case FormatInt:
			{
//.........这里部分代码省略.........
开发者ID:Ristovski,项目名称:PowderToypp,代码行数:101,代码来源:TPTScriptInterface.cpp

示例8: run

/**
 * @brief This function learns the topics of words in a document and is the
 * main step of a Gibbs sampling iteration. The word topic counts and
 * corpus topic counts are passed to this function in the first call and
 * then transfered to the rest calls through args.mSysInfo->user_fctx for
 * efficiency. 
 * @param args[0]   The unique words in the documents
 * @param args[1]   The counts of each unique words
 * @param args[2]   The topic counts and topic assignments in the document
 * @param args[3]   The model (word topic counts and corpus topic
 *                  counts)
 * @param args[4]   The Dirichlet parameter for per-document topic
 *                  multinomial, i.e. alpha
 * @param args[5]   The Dirichlet parameter for per-topic word
 *                  multinomial, i.e. beta
 * @param args[6]   The size of vocabulary
 * @param args[7]   The number of topics
 * @param args[8]   The number of iterations (=1:training, >1:prediction)
 * @return          The updated topic counts and topic assignments for
 *                  the document
 **/
AnyType lda_gibbs_sample::run(AnyType & args)
{
    ArrayHandle<int32_t> words = args[0].getAs<ArrayHandle<int32_t> >();
    ArrayHandle<int32_t> counts = args[1].getAs<ArrayHandle<int32_t> >();
    MutableArrayHandle<int32_t> doc_topic = args[2].getAs<MutableArrayHandle<int32_t> >();
    double alpha = args[4].getAs<double>();
    double beta = args[5].getAs<double>();
    int32_t voc_size = args[6].getAs<int32_t>();
    int32_t topic_num = args[7].getAs<int32_t>();
    int32_t iter_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(iter_num <= 0)
        throw std::invalid_argument(
            "invalid argument - iter_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");

    int32_t word_count = __sum(counts);
    if(doc_topic.size() != (size_t)(word_count + topic_num))
        throw std::invalid_argument(
            "invalid dimension - doc_topic.size() != word_count + topic_num");
    if(__min(doc_topic, 0, topic_num) < 0)
        throw std::invalid_argument("invalid values in topic_count");
    if(
        __min(doc_topic, topic_num, word_count) < 0 ||
        __max(doc_topic, topic_num, word_count) >= topic_num)
        throw std::invalid_argument( "invalid values in topic_assignment");

    if (!args.getUserFuncContext())
    {
        if(args[3].isNull())
            throw std::invalid_argument("invalid argument - the model \
            parameter should not be null for the first call");
        ArrayHandle<int64_t> model = args[3].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");

        int64_t * state = 
            static_cast<int64_t *>(
                MemoryContextAllocZero(
                    args.getCacheMemoryContext(), 
                    model.size() * sizeof(int64_t)));
        memcpy(state, model.ptr(), model.size() * sizeof(int64_t));
        args.setUserFuncContext(state);
    }

    int64_t * state = static_cast<int64_t *>(args.getUserFuncContext());
    if(NULL == state){
        throw std::runtime_error("args.mSysInfo->user_fctx is null");
    }

    int32_t unique_word_count = static_cast<int32_t>(words.size());
    for(int32_t it = 0; it < iter_num; it++){
        int32_t word_index = topic_num;
        for(int32_t i = 0; i < unique_word_count; i++) {
            int32_t wordid = words[i];
            for(int32_t j = 0; j < counts[i]; j++){
                int32_t topic = doc_topic[word_index];
//.........这里部分代码省略.........
开发者ID:adirastogi,项目名称:madlib,代码行数:101,代码来源:lda.cpp


注:本文中的AnyType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。