Example #1
0
 //------------------------------------------------------------------------
 QString qt_dbtreemodel_impl::_DisplayRole( const QModelIndex& index ) const
 {
     const row *r = ( row* ) index.internalPointer();
     if( !r )
         return _empty.c_str();
     
     const TreeModel::Content *content = _content( r->level(), index.column() );
     if( !content )
         return _empty.c_str();
             
     if( ! content->calc() )
     {
         return qt_dbtreemodel::tr( _value( r, content->format(), content->columns() ).c_str() );
     }
     
     const TreeModel::Canvas *canvas = _canvas( content, r );
     if( canvas )
     {
         if( canvas->data().size() )
             return qt_dbtreemodel::tr( canvas->data().c_str() );
             
         if( canvas->text().size() )
             return qt_dbtreemodel::tr( canvas->text().c_str() );
     }
     
     return qt_dbtreemodel::tr( _value( r, content->format(), content->columns() ).c_str() );
 }
Example #2
0
const void* LLVMCodeGenerator::visit(ASTCast* node) {
	if (node->original->is_constant) {
		// constant expression
		if (node->type->type() == SLTypeTypePointer) {
			return llvm::ConstantExpr::getPointerCast(static_cast<llvm::Constant*>(_value(node->original)), _llvm_type(node->type));
		}
		return llvm::ConstantExpr::getIntegerCast(static_cast<llvm::Constant*>(_value(node->original)), _llvm_type(node->type), node->original->type->is_signed());
	}
	
	auto rr_type = SLType::RemoveReference(node->original->type);
	
	if (node->type->type() == SLTypeTypePointer) {
		return _builder.CreatePointerCast(_dereferenced_value(node->original), _llvm_type(node->type));
	}

	if (node->type->type() == SLTypeTypeBool && rr_type->type() == SLTypeTypePointer) {
		return _builder.CreateIsNotNull(_dereferenced_value(node->original));
	}

	if (node->type->type() == SLTypeTypeBool && rr_type->is_integer()) {
		return _builder.CreateICmpNE(_dereferenced_value(node->original), llvm::ConstantInt::get(_llvm_type(rr_type), 0));
	}

	if (node->type->type() == SLTypeTypeBool && rr_type->is_floating_point()) {
		return _builder.CreateFCmpONE(_dereferenced_value(node->original), llvm::ConstantFP::get(_llvm_type(rr_type), 0.0));
	}

	return _builder.CreateIntCast(_dereferenced_value(node->original), _llvm_type(node->type), node->original->type->is_signed());
}
Example #3
0
double Problem::value()
{
  numberOfFullEvaluations++;
  if( !initialized )
    initialize();
  return _value();
}
Example #4
0
static struct config_node *_section(struct parser *p)
{
	/* IDENTIFIER SECTION_B_CHAR VALUE* SECTION_E_CHAR */
	struct config_node *root, *n, *l = NULL;
	if (!(root = _create_node(p->mem)))
		return_0;

	if (!(root->key = _dup_tok(p)))
		return_0;

	match(TOK_IDENTIFIER);

	if (p->t == TOK_SECTION_B) {
		match(TOK_SECTION_B);
		while (p->t != TOK_SECTION_E) {
			if (!(n = _section(p)))
				return_0;

			if (!root->child)
				root->child = n;
			else
				l->sib = n;
			n->parent = root;
			l = n;
		}
		match(TOK_SECTION_E);
	} else {
		match(TOK_EQ);
		if (!(root->v = _value(p)))
			return_0;
	}

	return root;
}
Example #5
0
void dcDataFrame::saveToCSV(string filename, bool col_headers)
{
	/// Save a dcDataFrame into a CSV file
	/// Option to write column headers or not.
	
	unsigned int N = _rowname.size();
	unsigned int M = _colname.size();
	
	ofstream f(filename);
	
	if (col_headers)
	{
		f << "row_name,";
		for(unsigned int i=0;i<M;i++)
		{
			f<<_colname[i];
			if(i< M-1) f<<",";
		}
		f << endl;
	}
	
	for (unsigned int i=0;i<N;i++)
	{
		f << _rowname[i] << ",";
		for(unsigned int j=0;j<M;j++)
		{
			f<<_value(i,j);
			if(j< M-1) f<<",";
		}
		f << endl;
	}
	
}
Example #6
0
qreal KSlider::value() const
{
    Q_D(const KSlider);
    qreal val = _value();
    val = val * (d->m_maximum - d->m_minimum) + d->m_minimum;
    return val;
}
Example #7
0
void TiXmlElement::SetAttribute( const char * cname, const char * cvalue )
{
    #ifdef TIXML_USE_STL
	TIXML_STRING _name( cname );
	TIXML_STRING _value( cvalue );
	#else
	const char* _name = cname;
	const char* _value = cvalue;
	#endif

	TiXmlAttribute* node = attributeSet.Find( _name );
	if ( node )
	{
		node->SetValue( _value );
		return;
	}

	TiXmlAttribute* attrib = new TiXmlAttribute( cname, cvalue );
	if ( attrib )
	{
		attributeSet.Add( attrib );
	}
	else
	{
		TiXmlDocument* document = GetDocument();
		if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN );
	}
}
Example #8
0
int str_match(int m,elem_t* a,int n,elem_t* b){
	int match[MAXN+1][MAXN+1],i,j;
	memset(match,0,sizeof(match));
	for (i=0;i<m;i++)
		for (j=0;j<n;j++)
			match[i+1][j+1]=max(max(match[i][j+1],match[i+1][j]),
							(match[i][j]+_value(a[i],b[i]))*_match(a[i],b[j]));
	return match[m][n];
}
Example #9
0
/* operand */
static int _operand(State * state)
	/* value | address */
{
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
	if(_parser_in_set(state, TS_VALUE))
		return _value(state);
	else if(_parser_in_set(state, TS_ADDRESS))
		return _address(state);
	return _parser_error(state, "%s", "Expected value or address");
}
Example #10
0
static struct dm_config_node *_section(struct parser *p, struct dm_config_node *parent)
{
	/* IDENTIFIER SECTION_B_CHAR VALUE* SECTION_E_CHAR */

	struct dm_config_node *root;
	struct dm_config_value *value;
	char *str;

	if (p->t == TOK_STRING_ESCAPED) {
		if (!(str = _dup_string_tok(p)))
			return_NULL;
		dm_unescape_double_quotes(str);

		match(TOK_STRING_ESCAPED);
	} else if (p->t == TOK_STRING) {
		if (!(str = _dup_string_tok(p)))
			return_NULL;

		match(TOK_STRING);
	} else {
		if (!(str = _dup_tok(p)))
			return_NULL;

		match(TOK_IDENTIFIER);
	}

	if (!strlen(str)) {
		log_error("Parse error at byte %" PRIptrdiff_t " (line %d): empty section identifier",
			  p->tb - p->fb + 1, p->line);
		return NULL;
	}

	root = _find_or_make_node(p->mem, parent, str);

	if (p->t == TOK_SECTION_B) {
		match(TOK_SECTION_B);
		while (p->t != TOK_SECTION_E) {
			if (!(_section(p, root)))
				return_NULL;
		}
		match(TOK_SECTION_E);
	} else {
		match(TOK_EQ);
		if (!(value = _value(p)))
			return_NULL;
		if (root->v)
			log_warn("WARNING: Ignoring duplicate"
				 " config value: %s", str);
		root->v = value;
	}

	return root;
}
Example #11
0
void dcDataFrame::display()
{
	unsigned int n = _rowname.size();
	unsigned int ncol = _value.getNbCols();
	
	cout << endl << "dcDataFrame Content:"<<endl;
	
	string sep = "\t\t|\t";
	
	if (ncol==0) cout << "EMPTY!"<<endl;
	
	// Print headers
	if (ncol>0)
	{
		cout << "_rowname" << sep;
		
		for (int i=0; i<ncol; i++)
			cout << _colname[i] << sep;
		
		cout<<endl;
	}
	
	if (ncol==1)
	{
		coutline(20);
		
		for (int i=0; i<n; i++)
		{
			cout << _rowname[i] << sep <<  _value[i] <<endl;
		}
		
		coutline(20);
	}
	
	
	if (ncol>1)
	{
		coutline(80);
		
		for (int i=0; i<n; i++)
		{
			cout << _rowname[i] << sep;
			
			for (int j=0;j<ncol; j++)
				cout <<  _value(i,j)<<"\t";
			
			cout << endl;
		}
		
		coutline(80);
	}
	
}
Example #12
0
void BandMatrix::mult(const doublereal* b, doublereal* prod) const
{
    for (size_t m = 0; m < m_n; m++) {
        double sum = 0.0;
        size_t start = (m >= m_kl) ? m - m_kl : 0;
        size_t stop = std::min(m + m_ku + 1, m_n);
        for (size_t j = start; j < stop; j++) {
            sum += _value(m,j) * b[j];
        }
        prod[m] = sum;
    }
}
Example #13
0
void BandMatrix::leftMult(const doublereal* const b, doublereal* const prod) const
{
    for (size_t n = 0; n < m_n; n++) {
        double sum = 0.0;
        size_t start = (n >= m_ku) ? n - m_ku : 0;
        size_t stop = std::min(n + m_kl + 1, m_n);
        for (size_t i = start; i < stop; i++) {
            sum += _value(i,n) * b[i];
        }
        prod[n] = sum;
    }
}
Example #14
0
 /**
  * Multiply b*A and write result to \c prod.
  */
 void BandMatrix::leftMult(const double* b, double* prod) const {
     int nc = columns();
     int n, i;
     double sum = 0.0;
     for (n = 0; n < nc; n++) {
         sum = 0.0;
         for (i = n - m_ku; i <= n + m_kl; i++) {
             if (i >= 0 && i < m_n)
                 sum += _value(i,n)*b[i];
         }
         prod[n] = sum;
     }
 }
Example #15
0
 /**
  * Multiply A*b and write result to \c prod.
  */
 void BandMatrix::mult(const double* b, double* prod) const {
     int nr = rows();
     int m, j;
     double sum = 0.0;
     for (m = 0; m < nr; m++) {
         sum = 0.0;
         for (j = m - m_kl; j <= m + m_ku; j++) {
             if (j >= 0 && j < m_n)
                 sum += _value(m,j)*b[j];
         }
         prod[m] = sum;
     }
 }
Example #16
0
doublereal BandMatrix::oneNorm() const
{
    double value = 0.0;
    for (size_t j = 0; j < m_n; j++) {
        double sum = 0.0;
        size_t start = (j >= m_ku) ? j - m_ku : 0;
        size_t stop = std::min(j + m_kl + 1, m_n);
        for (size_t i = start; i < stop; i++) {
            sum += std::abs(_value(i,j));
        }
        value = std::max(sum, value);
    }
    return value;
}
Example #17
0
int str_match(int m,elem_t* a,int n,elem_t* b,elem_t* ret){
	int match[MAXN+1][MAXN+1],last[MAXN+1][MAXN+1],i,j,t;
	memset(match,0,sizeof(match));
	for (i=0;i<m;i++)
		for (j=0;j<n;j++){
			match[i+1][j+1]=(match[i][j+1]>match[i+1][j]?match[i][j+1]:match[i+1][j]);
			last[i+1][j+1]=(match[i][j+1]>match[i+1][j]?3:1);
			if ((t=(match[i][j]+_value(a[i],b[i]))*_match(a[i],b[j]))>match[i+1][j+1])
				match[i+1][j+1]=t,last[i+1][j+1]=2;
		}
	for (;match[i][j];i-=(last[t=i][j]>1),j-=(last[t][j]<3))
		ret[match[i][j]-1]=(last[i][j]<3?a[i-1]:b[j-1]);
	return match[m][n];
}
Example #18
0
const void* LLVMCodeGenerator::visit(ASTInlineAsm* node) {
	std::vector<llvm::Type*> input_types;
	std::vector<llvm::Value*> args;

	size_t i = 0;
	for (ASTExpression* exp : node->inputs) {
		if (node->constraints[node->outputs.size() + i].find('*') != std::string::npos) {
			// indirect
			args.push_back(_value(exp));
			input_types.push_back(_llvm_type(exp->type)->getPointerTo());
		} else {
			args.push_back(_dereferenced_value(exp));
			input_types.push_back(_llvm_type(exp->type));
		}
		++i;
	}

	std::vector<llvm::Type*> output_types;
	for (ASTExpression* exp : node->outputs) {
		output_types.push_back(_llvm_type(exp->type));
	}

	llvm::Type* type = _builder.getVoidTy();
	
	if (output_types.size() == 1) {
		type = output_types[0];
	} else if (output_types.size() > 1) {
		type = llvm::StructType::create(output_types);
	}

	std::string constraint_str = "";
	bool first = true;
	for (std::string& c : node->constraints) {
		if (first) {
			first = false;
		} else {
			constraint_str += ',';
		}
		constraint_str += c;
	}

	llvm::InlineAsm* as = llvm::InlineAsm::get(llvm::FunctionType::get(type, input_types, false), node->assembly, constraint_str, true);
	_builder.Insert(llvm::CallInst::Create(as, args));
	
	// TODO: store outputs
	
	return nullptr;
}
Example #19
0
void BandMatrix::mult(const doublereal* b, doublereal* prod) const
{
    int kl = static_cast<int>(m_kl);
    int ku = static_cast<int>(m_ku);
    int nr = static_cast<int>(nRows());
    doublereal sum = 0.0;
    for (int m = 0; m < nr; m++) {
        sum = 0.0;
        for (int j = m - kl; j <= m + ku; j++) {
            if (j >= 0 && j < (int) m_n) {
                sum += _value(m,j) * b[j];
            }
        }
        prod[m] = sum;
    }
}
Example #20
0
veValue::veValue(Type type)
    : USE_VE_PTR_INIT
    , _type(type)
{

}

veValue::~veValue()
{

}

veValueFixed::veValueFixed()
    : veValue(Type::VAL_FIXED)
    , _value(0.0f)
{

}

veValueFixed::~veValueFixed()
{

}

veReal veValueFixed::getValue(veReal x)
{
    return _value;
}

veValueRandom::veValueRandom()
    : veValue(Type::VAL_RANDOM)
    , _min(0.0f)
    , _max(0.0f)
{

}

veValueRandom::~veValueRandom()
{

}

veReal veValueRandom::getValue(veReal x)
{
    veReal t = veMath::veRandomUnitization();
    return _min * t + _max * (1.0f - t);
}
Example #21
0
const void* LLVMCodeGenerator::visit(ASTUnaryOp* node) {
	if (node->op == "&") {
		assert(node->right->type->referenced_type());
		return _value(node->right);
	} else if (node->op == "*") {
		assert(SLType::RemoveReference(node->right->type)->pointed_to_type());
		return _dereferenced_value(node->right);
	} else if (node->op == "!") {
		return _builder.CreateNot(_dereferenced_value(node->right));
	} else if (node->op == "-") {
		auto value = _dereferenced_value(node->right);
		return value->getType()->isFPOrFPVectorTy() ? _builder.CreateFNeg(value) : _builder.CreateNeg(value);
	}

	assert(false);
	return nullptr;
}
Example #22
0
void BandMatrix::leftMult(const doublereal* const b, doublereal* const prod) const
{
    int kl = static_cast<int>(m_kl);
    int ku = static_cast<int>(m_ku);
    int nc = static_cast<int>(nColumns());
    doublereal sum = 0.0;
    for (int n = 0; n < nc; n++) {
        sum = 0.0;
        for (int i = n - ku; i <= n + kl; i++) {
            if (i >= 0 && i < (int) m_n) {
                size_t ii = i;
                sum += _value(ii,n) * b[ii];
            }
        }
        prod[n] = sum;
    }
}
Example #23
0
 //------------------------------------------------------------------------
 const TreeModel::Canvas* qt_dbtreemodel_impl::_canvas( const TreeModel::Content *content, const row *r ) const
 {
     if( ! content || ! r )
         return NULL;
     
     const TreeModel::Canvas *canvas = NULL;
     if( content->calc() )
     {
         string value = _value( r, content->format(), content->columns() );
         canvas = content->canvas( value );
     }
     else
     {
         canvas = content->canvas();
     }
     
     return canvas;
 }
Example #24
0
/**
	This routine is the same as the normal strtod() routine except that it
	doesn't accept 'd' or 'D' as radix values.  Some locale configurations
	use 'd' or 'D' as radix values just as 'e' or 'E' might be used.  This
	confuses subsequent commands held on the same line as the coordinate.
 */
double Excellon::special_strtod( const char *value, const char **end ) const
{
	std::string _value(value);
	char *_end = NULL;

	std::string::size_type offset = _value.find_first_of( "dD" );
	if (offset != std::string::npos)
	{
		_value.erase(offset);
	}

	double dval = strtod( _value.c_str(), &_end );
	if (end)
	{
		*end = value + (_end - _value.c_str());
	}
	return(dval);
}
Example #25
0
/* address */
static int _address(State * state)
	/* "[" [ space ] [ sign [ space ] ] value [ space ] [ offset [ space ] ] "]" */
{
	int ret;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
	state->address = 1;
	/* "[" */
	ret = _parser_scan(state);
	/* [ space ] */
	if(_parser_in_set(state, TS_SPACE))
		ret |= _space(state);
	/* [ sign [ space ] ] */
	if(_parser_in_set(state, TS_SIGN))
	{
		ret |= _sign(state);
		if(_parser_in_set(state, TS_SPACE))
			ret |= _space(state);
	}
	else
		state->negative = 0;
	/* value */
	if(_parser_in_set(state, TS_VALUE))
		ret |= _value(state);
	else
		ret |= _parser_error(state, "%s", "Expected value");
	/* [ space ] */
	if(_parser_in_set(state, TS_SPACE))
		ret |= _space(state);
	/* [ offset [ space ] ] */
	if(_parser_in_set(state, TS_OFFSET))
	{
		state->address = 2;
		ret |= _offset(state);
		if(_parser_in_set(state, TS_SPACE))
			ret |= _space(state);
	}
	state->address = 0;
	/* "]" */
	return ret | _parser_check(state, AS_CODE_OPERATOR_RBRACKET);
}
Example #26
0
const void* LLVMCodeGenerator::visit(ASTBinaryOp* node) {
	if (node->op == "=") {
		// assign
		llvm::Value* left = _value(node->left);
		_builder.CreateStore(_dereferenced_value(node->right), left);
		return left;
	} else {
		auto left       = _dereferenced_value(node->left);
		auto right      = _dereferenced_value(node->right);
		bool signed_op  = node->left->type->is_signed() || node->right->type->is_signed();
		if (node->op == "*") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFMul(left, right) : _builder.CreateMul(left, right);
		} else if (node->op == "/") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFDiv(left, right) : (signed_op ? _builder.CreateSDiv(left, right) : _builder.CreateUDiv(left, right));
		} else if (node->op == "%") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFRem(left, right) : (signed_op ? _builder.CreateSRem(left, right) : _builder.CreateURem(left, right));
		} else if (node->op == "+") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFAdd(left, right) : _builder.CreateAdd(left, right);
		} else if (node->op == "-") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFSub(left, right) : _builder.CreateSub(left, right);
		} else if (node->op == "==") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFCmpOEQ(left, right) : _builder.CreateICmpEQ(left, right);
		} else if (node->op == "!=") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFCmpONE(left, right) : _builder.CreateICmpNE(left, right);
		} else if (node->op == "<") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFCmpOLT(left, right) : (signed_op ? _builder.CreateICmpSLT(left, right) : _builder.CreateICmpULT(left, right));
		} else if (node->op == "<=") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFCmpOLE(left, right) : (signed_op ? _builder.CreateICmpSLE(left, right) : _builder.CreateICmpULE(left, right));
		} else if (node->op == ">") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFCmpOGT(left, right) : (signed_op ? _builder.CreateICmpSGT(left, right) : _builder.CreateICmpUGT(left, right));
		} else if (node->op == ">=") {
			return left->getType()->isFPOrFPVectorTy() ? _builder.CreateFCmpOGE(left, right) : (signed_op ? _builder.CreateICmpSGE(left, right) : _builder.CreateICmpUGE(left, right));
		} else if (node->op == "&&" || node->op == "and") {
			return _builder.CreateAnd(left, right);
		} else if (node->op == "||" || node->op == "or") {
			return _builder.CreateOr(left, right);
		}
	}

	assert(false);
	return nullptr;
}
Example #27
0
/* offset */
static int _offset(State * state)
	/* sign [ space ] value */
{
	int ret;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
	/* sign */
	ret = _sign(state);
	/* [ space ] */
	if(_parser_in_set(state, TS_SPACE))
		ret |= _space(state);
	/* value */
	if(_parser_in_set(state, TS_VALUE))
		ret |= _value(state);
	else
		ret |= _parser_error(state, "%s", "Expected a value");
	return ret;
}
Example #28
0
double	dcDataFrame::getValue(string varname, unsigned int j)
{
	// Find row position of 'varname'
	unsigned int i;
	bool found = false;
	
	for (i=0; i<=_rowname.size() && !found; i++)
	{
		if (_rowname[i]==varname) found=true;
	}
	i--;
	
	if (i==_rowname.size())
	{
		cout << endl << " ERROR [dcDataFrame::getValue]: variable name '"<<varname<<"' does not exist!"<<endl;
		exit(1);
	}
	
	return _value(i,j);
}
Example #29
0
size_t BandMatrix::checkColumns(doublereal& valueSmall) const
{
    valueSmall = 1.0E300;
    size_t jSmall = npos;
    for (size_t j = 0; j < m_n; j++) {
        double valueS = 0.0;
        size_t start = (j > m_ku) ? j - m_ku : 0;
        size_t stop = std::min(j + m_kl + 1, m_n);
        for (size_t i = start; i < stop; i++) {
            valueS = std::max(fabs(_value(i,j)), valueS);
        }
        if (valueS < valueSmall) {
            jSmall = j;
            valueSmall = valueS;
            if (valueSmall == 0.0) {
                return jSmall;
            }
        }
    }
    return jSmall;
}
Example #30
0
/**
	When a string is passed into a Python routine, it needs to be surrounded by
	single (or double) quote characters.  If the contents of the string contain
	backslash characters then these may be interpreted by Python as part of
	a special character representation.  eg: '\n' represents a single newline
	character.  If we pass a Windows path in then the backslash characters that
	separate directory names may be interpreted rather than be taken literaly.
	This routine also adds the single quotes to the beginning and end of the
	string passed in.

	eg: if value = "abcde" then the returned string would be 'abcde'
	    if value = "c:\temp\myfile.txt" then the returned string would be 'c:\\temp\\myfile.txt'
		if value = "abc'de" then the returned string would be 'abc\'de'.
 */
wxString PythonString( const wxString value )
{
	wxString _value(value);
	wxString result;
	if ((_value[0] == '\'') || (_value[0] == '\"'))
	{
		_value.erase(0, 1);
	}

	if ((_value.EndsWith(_T("\'"))) || (_value.EndsWith(_T("\""))))
	{
		_value.erase(_value.Len()-1);
	}

	_value.Replace(_T("\\"), _T("\\\\"), true );
	_value.Replace(_T("\'"), _T("\\\'"), true );
	_value.Replace(_T("\""), _T("\\\""), true );

	result << _T("\'") << _value << _T("\'");
	return(result);
}