本文整理汇总了C++中constant函数的典型用法代码示例。如果您正苦于以下问题:C++ constant函数的具体用法?C++ constant怎么用?C++ constant使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了constant函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: output_task_defines
void output_task_defines(void)
{
text("/* MIPS task_struct offsets. */");
offset("#define TASK_STATE ", struct task_struct, state);
offset("#define TASK_FLAGS ", struct task_struct, flags);
constant(" #define _PT_TRACESYS ", PT_TRACESYS);
offset("#define TASK_SIGPENDING ", struct task_struct, sigpending);
offset("#define TASK_NEED_RESCHED ", struct task_struct, need_resched);
offset("#define TASK_PTRACE ", struct task_struct, ptrace);
offset("#define TASK_COUNTER ", struct task_struct, counter);
offset("#define TASK_NICE ", struct task_struct, nice);
offset("#define TASK_MM ", struct task_struct, mm);
offset("#define TASK_PROCESSOR ", struct task_struct, processor);
offset("#define TASK_PID ", struct task_struct, pid);
size( "#define TASK_STRUCT_SIZE ", struct task_struct);
linefeed;
}
开发者ID:dduval,项目名称:kernel-rhel3,代码行数:17,代码来源:offset.c
示例2: setup_shading
boost::shared_ptr<shade::Program> setup_shading(boost::shared_ptr<shade::GLSLWrapper> state, boost::shared_ptr<shade::Texture> texture)
{
boost::shared_ptr<shade::shaders::Surface> shader(new shade::shaders::Surface);
boost::shared_ptr<shade::Program> program(new shade::Program(shader, state));
boost::shared_ptr<shade::shaders::Constant> constant(new shade::shaders::Constant);
constant->color.set_value(shade::vec4<>(1., 0.4, 0.4, 1.));
shader->material = constant;
boost::shared_ptr<shade::shaders::Texture2D> tex(new shade::shaders::Texture2D);
tex->texture_unit.set(texture);
boost::shared_ptr<shade::shaders::UVCoord> uvcoord(new shade::shaders::UVCoord);
tex->uv = uvcoord;
constant->color = tex;
return program;
}
开发者ID:4og,项目名称:avango,代码行数:17,代码来源:texture.cpp
示例3: main
int main(int argc, char *argv[]) {
/*
printf("sizeof(enum Fred) = %lu\n", sizeof(enum Fred));
int keyUp = 1073741906;
printf("keyUp = %d\n", keyUp);
*/
printf("module Constants\n\n");
constant("QUIT", SDL_QUIT);
constant("KEYDOWN", SDL_KEYDOWN);
constant("KEYUP", SDL_KEYUP);
constant("KEY_ESCAPE", SDLK_ESCAPE);
constant("KEY_UP", SDLK_UP);
constant("KEY_RIGHT", SDLK_RIGHT);
constant("KEY_DOWN", SDLK_DOWN);
constant("KEY_LEFT", SDLK_LEFT);
}
开发者ID:steshaw,项目名称:sdl2-playground,代码行数:19,代码来源:generate_constants.c
示例4: switch
void GetByOffsetMethod::dumpInContext(PrintStream& out, DumpContext* context) const
{
out.print(m_kind, ":");
switch (m_kind) {
case Invalid:
out.print("<none>");
return;
case Constant:
out.print(pointerDumpInContext(constant(), context));
return;
case Load:
out.print(offset());
return;
case LoadFromPrototype:
out.print(offset(), "@", pointerDumpInContext(prototype(), context));
return;
}
}
开发者ID:mjparme,项目名称:openjdk-jfx,代码行数:18,代码来源:DFGMultiGetByOffsetData.cpp
示例5: switch
void CCompiler::Prepare(CParser *pParser)
{
s32 high_const = -1,high_temp = -1;
u32 i,j,nICount = pParser->GetInstructionCount();
struct nvfx_insn *insns = pParser->GetInstructions();
for(i=0;i<nICount;i++) {
struct nvfx_insn *insn = &insns[i];
for(j=0;j<3;j++) {
struct nvfx_src *src = &insn->src[j];
switch(src->reg.type) {
case NVFXSR_TEMP:
if((s32)src->reg.index>high_temp) high_temp = src->reg.index;
break;
case NVFXSR_CONST:
if((s32)src->reg.index>high_const) high_const = src->reg.index;
break;
}
}
switch(insn->dst.type) {
case NVFXSR_TEMP:
if((s32)insn->dst.index>high_temp) high_temp = insn->dst.index;
break;
case NVFXSR_CONST:
if((s32)insn->dst.index>high_const) high_const = insn->dst.index;
break;
}
}
if(++high_temp) {
m_nNumRegs = high_temp;
m_rTemp = (struct nvfx_reg*)calloc(high_temp,sizeof(struct nvfx_reg));
for(i=0;i<(u32)high_temp;i++) m_rTemp[i] = temp();
m_rTempsDiscard = 0;
}
if(++high_const) {
m_rConst = (struct nvfx_reg*)calloc(high_const,sizeof(struct nvfx_reg));
for(i=0;i<(u32)high_const;i++) m_rConst[i] = constant(i,0.0f,0.0f,0.0f,0.0f);
}
}
开发者ID:ChillyWillyGuru,项目名称:PSL1GHT,代码行数:44,代码来源:compiler.cpp
示例6: assert
Node* UnaryArithmeticAssignmentNode::expandToAsebaTree(std::wostream* dump, unsigned int index)
{
assert(children.size() == 1);
Node* memoryVector = children[0];
// create a vector of 1's
std::auto_ptr<TupleVectorNode> constant(new TupleVectorNode(sourcePos));
for (unsigned int i = 0; i < memoryVector->getVectorSize(); i++)
constant->addImmediateValue(1);
// expand to "vector (op)= 1"
std::auto_ptr<ArithmeticAssignmentNode> assignment(new ArithmeticAssignmentNode(sourcePos, arithmeticOp, memoryVector->deepCopy(), constant.release()));
std::auto_ptr<Node> finalBlock(assignment->expandToAsebaTree(dump, index));
assignment.release();
delete this;
return finalBlock.release();
}
开发者ID:ardiny,项目名称:aseba,代码行数:20,代码来源:tree-expand.cpp
示例7: body
void body(){
symbol_t t, id;
if(sym->type==CONST){
nextSym();
constant();
}
while(isType(sym)){
t = copySym(sym);
nextSym();
if(sym->type!=ID){
msg(ERR, "missing a identifier after a type name", line);
ERROR_STATUS = 1;
}
id = copySym(sym);
nextSym();
variable(t, id);
mfree(t);
}
statementlist();
}
开发者ID:shenchi,项目名称:mycc,代码行数:20,代码来源:parser.c
示例8: find_variables
static int find_variables()
{
int i,k;
char nimi[LLENGTH];
for (i=0; i<rdim; ++i)
{
poimi(nimi,rlab,lr,i);
if (constant(nimi)) k=-1;
else
{
k=prosparam(nimi); if (k<0) return(-1);
k=varfind(&d,nimi); if (k<0) return(-2);
}
var[i]=k;
}
for (k=0; k<rdim; ++k) lag[k]=0;
for (i=0; i<cdim; ++i)
{
poimi(nimi,clab,lc,i);
if (muste_strcmpi(nimi,"#LAG")==0)
{
for (k=0; k<rdim; ++k) lag[k]=(int)A[i*rdim+k];
k=-1;
}
else
{
k=prosparam(nimi); if (k<0) return(-1);
if (k==0) { outvar[i]=-1; continue; }
k=varfind2(&d,nimi,0);
if (k<0)
{
k=create_newvar1(&d,nimi,'4',4,act);
if (k<0) return(-3);
}
}
outvar[i]=k;
}
return(1);
}
开发者ID:rforge,项目名称:muste,代码行数:41,代码来源:linco.c
示例9: constant
//- Construct from objectRegistry arguments
Foam::engineTime::engineTime
(
const word& name,
const fileName& rootPath,
const fileName& caseName,
const fileName& systemName,
const fileName& constantName,
const fileName& dictName
)
:
Time
(
name,
rootPath,
caseName,
systemName,
constantName
),
dict_
(
IOobject
(
dictName,
constant(),
*this,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
),
rpm_(dict_.lookup("rpm")),
conRodLength_(dimensionedScalar("conRodLength", dimLength, 0)),
bore_(dimensionedScalar("bore", dimLength, 0)),
stroke_(dimensionedScalar("stroke", dimLength, 0)),
clearance_(dimensionedScalar("clearance", dimLength, 0))
{
// the geometric parameters are not strictly required for Time
if (dict_.found("conRodLength"))
{
dict_.lookup("conRodLength") >> conRodLength_;
}
开发者ID:Haider-BA,项目名称:foam-extend-3.0,代码行数:42,代码来源:engineTime.C
示例10: weights
/*------------------------------------------------------------------*/
void AzOptOnTree::updateTreeWeights(AzRgfTreeEnsemble *ens) const
{
int dtree_num = ens->size();
int tx;
for (tx = 0; tx < dtree_num; ++tx) {
ens->tree_u(tx)->resetWeights();
}
const double *weight = weights()->point();
double const_val = constant();
ens->set_constant(const_val);
int num = tree_feat->featNum();
int fx;
for (fx = 0; fx < num; ++fx) {
if (weight[fx] != 0) {
const AzTrTreeFeatInfo *fp = tree_feat->featInfo(fx);
ens->tree_u(fp->tx)->setWeight(fp->nx, weight[fx]);
}
}
}
开发者ID:AlexInTown,项目名称:santander_2016,代码行数:22,代码来源:AzOptOnTree.cpp
示例11: constant
/// Elementwise operator -
AutoDiffBlock operator-(const AutoDiffBlock& rhs) const
{
if (jac_.empty() && rhs.jac_.empty()) {
return constant(val_ - rhs.val_);
}
if (jac_.empty()) {
return val_ - rhs;
}
if (rhs.jac_.empty()) {
return *this - rhs.val_;
}
std::vector<M> jac = jac_;
assert(numBlocks() == rhs.numBlocks());
int num_blocks = numBlocks();
for (int block = 0; block < num_blocks; ++block) {
assert(jac[block].rows() == rhs.jac_[block].rows());
assert(jac[block].cols() == rhs.jac_[block].cols());
jac[block] -= rhs.jac_[block];
}
return function(val_ - rhs.val_, jac);
}
开发者ID:osae,项目名称:opm-autodiff,代码行数:22,代码来源:AutoDiffBlock.hpp
示例12: helper_function
void helper_function()
{
signal_t r = fa_signal_lift2(string("times"), times, NULL, constant(0.1), fa_signal_sin(line(440)));
{
fa_audio_session_t s = fa_audio_begin_session();
fa_audio_device_t i = fa_audio_default_input(s);
fa_audio_device_t o = fa_audio_default_output(s);
fa_audio_stream_t st = fa_audio_open_stream(i, o, just, list(r, r));
if (fa_check(st)) {
fa_error_log(st, NULL);
} else {
while (1) {
fa_thread_sleep(10000);
}
}
fa_audio_end_session(s);
}
}
开发者ID:patrikohlsson,项目名称:faudio,代码行数:21,代码来源:lift.c
示例13: switch
void ExitValue::dumpInContext(PrintStream& out, DumpContext* context) const
{
switch (kind()) {
case InvalidExitValue:
out.print("Invalid");
return;
case ExitValueDead:
out.print("Dead");
return;
case ExitValueArgument:
out.print("Argument(", exitArgument(), ")");
return;
case ExitValueConstant:
out.print("Constant(", inContext(constant(), context), ")");
return;
case ExitValueInJSStack:
out.print("InJSStack:r", virtualRegister());
return;
case ExitValueInJSStackAsInt32:
out.print("InJSStackAsInt32:r", virtualRegister());
return;
case ExitValueInJSStackAsInt52:
out.print("InJSStackAsInt52:r", virtualRegister());
return;
case ExitValueInJSStackAsDouble:
out.print("InJSStackAsDouble:r", virtualRegister());
return;
case ExitValueArgumentsObjectThatWasNotCreated:
out.print("ArgumentsObjectThatWasNotCreated");
return;
case ExitValueRecovery:
out.print("Recovery(", recoveryOpcode(), ", arg", leftRecoveryArgument(), ", arg", rightRecoveryArgument(), ", ", recoveryFormat(), ")");
return;
case ExitValueMaterializeNewObject:
out.print("Materialize(", pointerDump(objectMaterialization()), ")");
return;
}
RELEASE_ASSERT_NOT_REACHED();
}
开发者ID:AndriyKalashnykov,项目名称:webkit,代码行数:40,代码来源:FTLExitValue.cpp
示例14: emit_inc
/*===--------------------------------------------------------------------------
---------------------------------------------------------------------------===*/
static void emit_inc(int ic, symbol *s) {
int cat, post;
symbol *val;
value v;
assert(s->ty);
cat = s->ty->cat;
post = gen_post(cat, cat);
//s1 = cast(l, ty);
if (cat == CAT_POINTER) {
v.i = s->ty->bty->size;
val = constant(v, int_type);
if (ic == IC_DEC)
ic = IC_SUB;
else if (ic == IC_INC)
ic = IC_ADD;
else
assert(0);
emit_ic(ic + i32, s, val);
} else
emit_ic(ic + post, s, NULL);
return;
}
开发者ID:doniexun,项目名称:zcc,代码行数:27,代码来源:icode.c
示例15: add_entry
/**
* @brief Adds a new entry to the truth table
*
* With adding the first entry the dimension of inputs
* and outputs is set. When adding further entries
* it has to make sure that the dimensions fit, else
* an assertion is thrown and false is returned.
*
* @param input Input assignment
* @param output Output assignment
* @return Returns whether the assignment could be added or not
*
* @since 1.0
*/
bool add_entry( const cube_type& input, const cube_type& output )
{
if ( _cubes.size() &&
( input.size() != _cubes.begin()->first.size() ||
output.size() != _cubes.begin()->second.size() ) )
{
assert( false );
return false;
}
if ( !_cubes.size() && !_permutation.size() )
{
/* first entry -> create permutation */
std::copy( boost::counting_iterator<unsigned>( 0 ),
boost::counting_iterator<unsigned>( output.size() ),
std::back_inserter( _permutation ) );
_constants.resize( input.size(), constant() );
_garbage.resize( output.size(), false );
}
_cubes.insert( std::make_pair( input, output ) );
return true;
}
开发者ID:sterin,项目名称:cirkit,代码行数:38,代码来源:truth_table.hpp
示例16: get_icon
Size Button::get_minimum_size_internal() {
Painter *p=get_painter();
Size min;
if (get_icon() >=0 && p->is_bitmap_valid( get_icon() )) {
Size icon_size=p->get_bitmap_size( get_icon() );
min.width+=icon_size.width;
if (min.height < icon_size.height )
min.height=icon_size.height;
if (label_text!="")
min.width+=constant( C_BUTTON_SEPARATION ); //if there is an icon, add the label-icon separation
}
min.width+=p->get_font_string_width( font( FONT_BUTTON ) , label_text );
if (p->get_font_height( font( FONT_BUTTON ) ) > min.height )
min.height=p->get_font_height( font( FONT_BUTTON ) );
if (constant( C_BUTTON_HAS_CHECKBOX )) {
if ( constant( C_BUTTON_CHECKBOX_SIZE )>0 ) {
min.width+=constant( C_BUTTON_CHECKBOX_SIZE );
if (min.height<constant( C_BUTTON_CHECKBOX_SIZE ))
min.height=constant( C_BUTTON_CHECKBOX_SIZE );
} else {
Size uncheck_size=p->get_bitmap_size( bitmap( BITMAP_BUTTON_UNCHECKED ) );
min.width+=uncheck_size.width;
if (min.height<uncheck_size.height)
min.height=uncheck_size.height;
}
min.width+=constant( C_BUTTON_SEPARATION );
}
if (shortcut!=0) {
String s_str = Keyboard::get_code_name( shortcut );
min.width+=constant( C_BUTTON_SEPARATION );
min.width+=p->get_font_string_width( font(FONT_BUTTON), s_str );
}
min.width+=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_LEFT );
min.width+=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_RIGHT );
min.height+=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_TOP );
min.height+=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_BOTTOM );
min.width+=constant( C_BUTTON_EXTRA_MARGIN )*2+constant( C_BUTTON_DISPLACEMENT ); //both margins and displacement
min.height+=constant( C_BUTTON_EXTRA_MARGIN )*2+constant( C_BUTTON_DISPLACEMENT ); //both margins and displacement
return min;
}
开发者ID:BackupTheBerlios,项目名称:pigui-svn,代码行数:65,代码来源:button.cpp
示例17: stylebox
void Button::draw(const Point& p_pos,const Size& p_size,const Rect& p_exposed) {
Painter *p=get_painter();
/* Draw Outline */
//if disabled...
bool draw_displaced=false;
DrawMode draw_mode=get_draw_mode();
if (draw_mode==DRAW_HOVER) { //optative, otherwise draw normal
if (stylebox( SB_BUTTON_HOVER ).mode!=StyleBox::MODE_NONE && (!is_toggle_mode() || (is_toggle_mode() && !is_pressed()))) {
p->draw_stylebox( stylebox( SB_BUTTON_HOVER ) , Point() , p_size, p_exposed );
} else
draw_mode=is_pressed()?DRAW_PRESSED:DRAW_NORMAL;
} ;
if (draw_mode==DRAW_NORMAL) {
p->draw_stylebox( stylebox( SB_BUTTON_NORMAL ) , Point() , p_size, p_exposed );
}
if (draw_mode==DRAW_PRESSED) {
p->draw_stylebox( stylebox( SB_BUTTON_PRESSED ) , Point() , p_size, p_exposed );
draw_displaced=true;
}
Rect area_rect=Rect( p_pos, p_size );
area_rect.pos.x=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_LEFT );
area_rect.pos.y=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_TOP );
area_rect.size-=area_rect.pos;
area_rect.size.x-=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_RIGHT );
area_rect.size.y-=p->get_stylebox_margin( stylebox( SB_BUTTON_NORMAL ), MARGIN_BOTTOM );
area_rect.size.x-=constant( C_BUTTON_EXTRA_MARGIN )*2;
area_rect.pos.x+=constant( C_BUTTON_EXTRA_MARGIN );
area_rect.size.y-=constant( C_BUTTON_EXTRA_MARGIN )*2;
area_rect.pos.y+=constant( C_BUTTON_EXTRA_MARGIN );
area_rect.size.x-=constant( C_BUTTON_DISPLACEMENT );
area_rect.size.y-=constant( C_BUTTON_DISPLACEMENT );
if (draw_displaced)
area_rect.pos+=Point( constant( C_BUTTON_DISPLACEMENT ), constant( C_BUTTON_DISPLACEMENT ) );
if (constant(C_BUTTON_HAS_CHECKBOX)) {
Size cbsize;
if ( constant( C_BUTTON_CHECKBOX_SIZE )>0 ) {
cbsize.width+=constant( C_BUTTON_CHECKBOX_SIZE );
cbsize.height+=constant( C_BUTTON_CHECKBOX_SIZE );
} else {
cbsize=p->get_bitmap_size( bitmap( BITMAP_BUTTON_UNCHECKED ) );
}
Point check_pos=area_rect.pos;
check_pos.y+=(area_rect.size.height-cbsize.height)/2;
if ( constant( C_BUTTON_CHECKBOX_SIZE )>0 ) {
p->draw_stylebox( stylebox( is_pressed() ? SB_BUTTON_CHECKED : SB_BUTTON_UNCHECKED ) , check_pos , cbsize);
} else {
p->draw_bitmap( bitmap( is_pressed() ? BITMAP_BUTTON_CHECKED : BITMAP_BUTTON_UNCHECKED ), check_pos );
}
area_rect.pos.x+=cbsize.x+constant( C_BUTTON_SEPARATION );
area_rect.size.x-=cbsize.x+constant( C_BUTTON_SEPARATION );
}
if (get_icon() >=0 && p->is_bitmap_valid( get_icon() )) {
Size icon_size=p->get_bitmap_size( get_icon() );
Point icon_pos=area_rect.pos;
icon_pos.y+=(area_rect.size.height-icon_size.height)/2;
p->draw_bitmap( get_icon(), icon_pos );
area_rect.pos.x+=icon_size.width;
area_rect.size.x-=icon_size.width;
if (label_text!="") {
area_rect.pos.x+=constant( C_BUTTON_SEPARATION ); //separation for the label
area_rect.size.x-=constant( C_BUTTON_SEPARATION ); //separation for the label
}
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:pigui-svn,代码行数:101,代码来源:button.cpp
示例18: assert
/*===--------------------------------------------------------------------------
--------------------------------------------------------------------------===*/
static symbol *post2ic(ast *t1) {
symbol *s1, *s2, *val, *base;
dlist *args, *d2;
ast *t2;
int node = t1->node, cat, post;
type *ty = t1->ty;
value v;
icode *ic;
assert(ty && "type of post AST empty");
cat = ty->cat; // t1->ty->cat
switch (node) {
case AST_POST_INC:
case AST_POST_DEC:
/*-----------------------------------------
char c = 1; //char
c++; //int
ty is scalar(int/float/double) type
------------------------------------------*/
s1 = post2ic(t1->left);
val = gen_vit_reg(ty);
emit_ic(IC_MOV + gen_post(cat, cat), val, cast(s1, ty));
/// source's post value
post = gen_post(s1->ty->cat, s1->ty->cat);
if (node == AST_POST_INC)
emit_inc(IC_INC, s1);
else
emit_inc(IC_DEC, s1);
return val;
case AST_ARRAY:
s1 = post2ic(t1->left); //base
s2 = expr2ic(t1->right); //index
assert(is_int_cat(s2->ty->cat));
assert(s1->ty->cat == CAT_POINTER);
// the type infer of post-expression is work correct ?
assert(s1->ty->cat == ty->cat);
/* size of array's element*/
assert(ty->size);
v.i = ty->size;
s2 = cast(s2, int_type);
val = constant(v, int_type);
verify_ops(&s2, val); // make sure s2 is a not a immediate value
emit_ic(IC_MUL + i32, s2, val); //offset
/* address = base + offset, can be optimzation using complex address mode*/
base = gen_vit_reg(s1->ty);
emit_ic(IC_ADDR + i32, base, s1);
emit_ic(IC_ADD + i32, s2, base); //base + offset
val = gen_vit_reg(ty);
val->is_addr = 1;
emit_ic(IC_MOV + i32, val, s2);
return val; // lvalue, is a address
case AST_CALL:
s1 = post2ic(t1->left);
args = (dlist *)t1->right->left;
d2 = args = args->prev; //pass argument from right to left
if (d2)
do {
t2 = (ast *)d2->it;
s2 = asgn2ic(t2);
//emit_pass_arg(t2->u.arg_off, s2);
// TODO, pushl arguments ?????
post = gen_post(t2->ty->cat, t2->ty->cat);
ic = emit_ic(IC_MOV_ARG + post, s2, NULL);
ic->u.arg_off = t2->u.arg_off;
d2 = d2->prev;
} while (d2 != args);
if (ty->cat != CAT_VOID)
val = gen_vit_reg(ty);
else { // no return value
assert(ty == void_type);
val = NULL;
}
emit_ic(IC_CALL, val, s1);
return val;
case AST_MEMBER:
s1 = post2ic(t1->left);
s2 = primary2ic(t1->right);
val = emit_member(s1, s2);
return val;
case AST_ARROW:
s1 = post2ic(t1->left);
s2 = primary2ic(t1->right);
val = gen_vit_reg(s1->ty);
emit_ic(IC_MOV + i32, val, s1); // get the address value if in lvalue
val = emit_member(val, s2);
return val; //lvalue, is a address
default:
return primary2ic(t1);
}
assert(0);
}
开发者ID:doniexun,项目名称:zcc,代码行数:94,代码来源:icode.c
示例19: estimate
void estimate(const size_t order, const Points &X, const HistogramY &Y,
const size_t i_min, const size_t i_max, const size_t p_min,
const size_t p_max, bool haveGap, double &out_bg0,
double &out_bg1, double &out_bg2, double &out_chisq_red) {
// Validate input
if (order > 2)
throw std::runtime_error("can only estimate up to order=2");
if (i_min >= i_max) {
std::stringstream err;
err << "i_min (" << i_min << ")cannot be larger or equal to i_max ("
<< i_max << ")";
throw std::runtime_error(err.str());
}
if (i_max > X.size()) {
std::stringstream err;
err << "i_max (" << i_max << ") cannot be larger or equal to size of X "
<< X.size() << ")";
throw std::runtime_error(err.str());
}
if (haveGap && p_min >= p_max)
throw std::runtime_error("p_min cannot larger or equal to p_max");
// ignore when p-range is outside of i-range
// set all output parameters to zero
out_bg0 = 0.;
out_bg1 = 0.;
out_bg2 = 0.;
out_chisq_red = INVALID_CHISQ;
// accumulate sum
double sum = 0.0;
double sumX = 0.0;
double sumY = 0.0;
double sumX2 = 0.0;
double sumXY = 0.0;
double sumX2Y = 0.0;
double sumX3 = 0.0;
double sumX4 = 0.0;
for (size_t i = i_min; i < i_max; ++i) {
if (haveGap && i >= p_min && i < p_max)
continue;
sum += 1.0;
sumX += X[i];
sumX2 += X[i] * X[i];
sumY += Y[i];
sumXY += X[i] * Y[i];
sumX2Y += X[i] * X[i] * Y[i];
sumX3 += X[i] * X[i] * X[i];
sumX4 += X[i] * X[i] * X[i] * X[i];
}
if (sum == 0.) {
return;
}
// Estimate flat
double bg0_flat = 0.;
calcFlatParameters(sum, sumY, bg0_flat);
// Estimate linear
double bg0_linear = 0.;
double bg1_linear = 0.;
calcLinearParameters(sum, sumX, sumY, sumXY, sumX2, bg0_linear, bg1_linear);
// Estimate quadratic
double bg0_quadratic = 0.;
double bg1_quadratic = 0.;
double bg2_quadratic = 0.;
calcQuadraticParameters(sum, sumX, sumY, sumXY, sumX2, sumX2Y, sumX3, sumX4,
bg0_quadratic, bg1_quadratic, bg2_quadratic);
// Setup to calculate the residuals
double chisq_flat = 0.;
double chisq_linear = 0.;
double chisq_quadratic = 0.;
auto residual_flat = constant(bg0_flat);
auto residual_linear = linear(bg0_linear, bg1_linear);
auto residual_quadratic =
quadratic(bg0_quadratic, bg1_quadratic, bg2_quadratic);
double num_points = 0.;
// calculate the chisq - not normalized by the number of points
for (size_t i = i_min; i < i_max; ++i) {
if (haveGap && i >= p_min && i < p_max)
continue;
num_points += 1.;
chisq_flat += residual_flat(X[i], Y[i]);
chisq_linear += residual_linear(X[i], Y[i]);
chisq_quadratic += residual_quadratic(X[i], Y[i]);
}
// convert to <reduced chisq> = chisq / (<number points> - <number
// parameters>)
chisq_flat = chisq_flat / (num_points - 1.);
chisq_linear = chisq_linear / (num_points - 2.);
chisq_quadratic = chisq_quadratic / (num_points - 3.);
if (order < 2) {
chisq_quadratic = BAD_CHISQ;
//.........这里部分代码省略.........
开发者ID:mantidproject,项目名称:mantid,代码行数:101,代码来源:EstimatePolynomial.cpp
示例20: constant
GUI::Size FilterBankFR::get_minimum_size_internal() {
return GUI::Size( constant( C_NODEUI_FILTERBANK_FR_MIN_WIDTH) , 0 );
}
开发者ID:BackupTheBerlios,项目名称:reshaked-svn,代码行数:4,代码来源:filter_bank_fr.cpp
注:本文中的constant函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论