本文整理汇总了C++中IFunction类的典型用法代码示例。如果您正苦于以下问题:C++ IFunction类的具体用法?C++ IFunction怎么用?C++ IFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASFUNCTIONBODY
ASFUNCTIONBODY(Array,forEach)
{
assert_and_throw(argslen == 1 || argslen == 2);
Array* th=static_cast<Array*>(obj);
IFunction* f = static_cast<IFunction*>(args[0]);
ASObject* params[3];
std::map<uint32_t, data_slot>::iterator it=th->data.begin();
for(;it != th->data.end();++it)
{
assert_and_throw(it->second.type==DATA_OBJECT);
params[0] = it->second.data;
it->second.data->incRef();
params[1] = abstract_i(it->first);
params[2] = th;
th->incRef();
ASObject *funcret;
if( argslen == 1 )
{
funcret=f->call(getSys()->getNullRef(), params, 3);
}
else
{
args[1]->incRef();
funcret=f->call(args[1], params, 3);
}
if(funcret)
funcret->decRef();
}
return NULL;
}
示例2: ASFUNCTIONBODY
ASFUNCTIONBODY(Array,forEach)
{
assert_and_throw(argslen == 1 || argslen == 2);
Array* th=static_cast<Array*>(obj);
IFunction* f = static_cast<IFunction*>(args[0]);
ASObject* params[3];
for(unsigned int i=0; i < th->data.size(); i++)
{
assert_and_throw(th->data[i].type==DATA_OBJECT);
params[0] = th->data[i].data;
th->data[i].data->incRef();
params[1] = abstract_i(i);
params[2] = th;
th->incRef();
ASObject *funcret;
if( argslen == 1 )
{
funcret=f->call(new Null, params, 3);
}
else
{
args[1]->incRef();
funcret=f->call(args[1], params, 3);
}
if(funcret)
funcret->decRef();
}
return NULL;
}
示例3: buildin_setfenv
static void buildin_setfenv(const vector<LuaValue>& args, vector<LuaValue>& rets) {
IFunction *func = NULL;
if (args[0].isTypeOf(LVT_Number)) {
auto n = (int)args[0].getNumber();
ASSERT(n >= 0);
if (n > 0) func = Runtime::instance()->getFrame(-n - 1)->getFunc();
} else func = args[0].getFunction();
if (func == NULL) {
Runtime::instance()->setGlobalTable(args[1].getTable());
} else {
func->setfenv(args[1].getTable());
}
}
示例4: inputDirection
Point inputDirection(const IFunction &f, bool assume1 = false)
{
if (f.dimensions() > 1 && !assume1) {
cout << "-- Input direction --" << endl;
return PointHelper::inputPoint(f.dimensions());
}
else {
vector<double> start = vector<double>(f.dimensions());
for (vector<double>::iterator i = start.begin(); i != start.end(); ++i) {
(*i) = 1;
}
return Point(start);
}
}
示例5: buildin_getfenv
static void buildin_getfenv(const vector<LuaValue>& args, vector<LuaValue>& rets) {
IFunction *func = NULL;
if (args.empty()) func = Runtime::instance()->getFrame(-2)->getFunc();
else if (args[0].isTypeOf(LVT_Number)) {
auto n = (int)args[0].getNumber();
ASSERT(n >= 0);
if (n > 0) func = Runtime::instance()->getFrame(-n - 1)->getFunc();
} else func = args[0].getFunction();
LuaTable* table = NULL;
if (func == NULL) table = Runtime::instance()->getGlobalTable();
else table = func->getfenv();
table->addRef();
rets.push_back(LuaValue(table));
}
示例6: addColumn
/**
* Add a column to a table workspace filled with double values
* calculated with a function wich uses another numeric column as its x values.
* @param tws :: The table workspace.
* @param xColumn :: Name of the column with the x-values. Must exist and be numeric
* @param yColumn :: Name of a column to store the calculated values. If a column with
* this name exists it will be overwritten if numeric or exception thrown otherwise.
* If the column doesn't exist it will be created.
* @param fun :: A function to calculate the values.
*/
void AddFunctionValuesToTable::addColumn(API::TableWorkspace_ptr tws,
const std::string& xColumn,
const std::string& yColumn,
const IFunction& fun,
API::NumericColumn::PlotRole role
)
{
auto& x = tws->getDoubleData( xColumn );
if ( tws->hasColumn( yColumn ) )
{
if ( !tws->getColumn( yColumn )->isNumeric() )
throw std::runtime_error("Column "+yColumn+" isn't numeric");
}
else
{
tws->addColumn( "double", yColumn );
}
tws->getColumn( yColumn )->asNumeric()->setPlotRole(role);
auto& y = tws->getDoubleData( yColumn );
FunctionDomain1DView domain( x.data(), x.size() );
FunctionValues values( domain );
fun.function( domain, values );
for(size_t i = 0; i < y.size(); ++i)
{
y[i] = values.getCalculated(i);
}
}
示例7: ASFUNCTIONBODY
ASFUNCTIONBODY(Vector, every)
{
Vector* th=static_cast<Vector*>(obj);
if (argslen < 1)
throwError<ArgumentError>(kWrongArgumentCountError, "Vector.some", "1", Integer::toString(argslen));
if (!args[0]->is<IFunction>())
throwError<TypeError>(kCheckTypeFailedError, args[0]->getClassName(), "Function");
IFunction* f = static_cast<IFunction*>(args[0]);
ASObject* params[3];
ASObject *funcRet;
for(unsigned int i=0; i < th->size(); i++)
{
if (th->vec[i])
{
params[0] = th->vec[i];
th->vec[i]->incRef();
}
else
params[0] = obj->getSystemState()->getNullRef();
params[1] = abstract_i(obj->getSystemState(),i);
params[2] = th;
th->incRef();
if(argslen==1)
{
funcRet=f->call(obj->getSystemState()->getNullRef(), params, 3);
}
else
{
args[1]->incRef();
funcRet=f->call(args[1], params, 3);
}
if(funcRet)
{
if (funcRet->is<Undefined>() || funcRet->is<Null>())
throwError<TypeError>(kCallOfNonFunctionError, funcRet->toString());
if(!Boolean_concrete(funcRet))
{
return funcRet;
}
funcRet->decRef();
}
}
return abstract_b(obj->getSystemState(),true);
}
示例8: ASFUNCTIONBODY
ASFUNCTIONBODY(Vector, every)
{
Vector* th=static_cast<Vector*>(obj);
if (argslen < 1)
throw Class<ArgumentError>::getInstanceS("Error #1063");
if (!args[0]->is<IFunction>())
throw Class<TypeError>::getInstanceS("Error #1034");
IFunction* f = static_cast<IFunction*>(args[0]);
ASObject* params[3];
ASObject *funcRet;
for(unsigned int i=0; i < th->size(); i++)
{
if (th->vec[i])
{
params[0] = th->vec[i];
th->vec[i]->incRef();
}
else
params[0] = getSys()->getNullRef();
params[1] = abstract_i(i);
params[2] = th;
th->incRef();
if(argslen==1)
{
funcRet=f->call(getSys()->getNullRef(), params, 3);
}
else
{
args[1]->incRef();
funcRet=f->call(args[1], params, 3);
}
if(funcRet)
{
if (funcRet->is<Undefined>() || funcRet->is<Null>())
throw Class<TypeError>::getInstanceS("Error #1006");
if(!Boolean_concrete(funcRet))
{
return funcRet;
}
funcRet->decRef();
}
}
return abstract_b(true);
}
示例9: reset
/**
* Reset the reference
* @param fun :: Pointer to a function (composite or simple).
* @param index :: Index of a parameter of fun
* @param isDefault :: Flag to mark as default the value of an object associated with this reference:
* a tie or a constraint.
*/
void ParameterReference::reset(IFunction* fun, std::size_t index, bool isDefault)
{
IFunction* fLocal = fun;
size_t iLocal = index;
CompositeFunction* cf = dynamic_cast<CompositeFunction*>(fun);
while (cf)
{
size_t iFun = cf->functionIndex(iLocal); // TODO squashing the warning breaks the code
fLocal = cf->getFunction(iFun).get();
iLocal = fLocal->parameterIndex(cf->parameterLocalName(iLocal));
cf = dynamic_cast<CompositeFunction*>(fLocal);
}
m_function = fLocal;
m_index = iLocal;
m_isDefault = isDefault;
}
示例10: main
int main(int argc, const char * argv[])
{
IFunction *targetFunction = selectFunction(); // Выбор целевой функции
Point startPoint = inputPoint(*targetFunction); // Ввод стартовой точки
Point direction = inputDirection(*targetFunction, true); // Направление принимаем за единичный вектор
double precision = inputPrecision(); // Ввод точности
Point min = Newton().optimize(*targetFunction, startPoint, direction, precision);
cout << "Minimum is:\t";
min.print(precision);
cout << endl << "F(min) is:\t";
cout << targetFunction->value(min);
return 0;
}
示例11: ASFUNCTIONBODY
ASFUNCTIONBODY(EventDispatcher,dispatchEvent)
{
EventDispatcher* th=Class<EventDispatcher>::cast(obj);
if(args[0]->getClass()==NULL || !(args[0]->getClass()->isSubClass(Class<Event>::getClass())))
return abstract_b(false);
args[0]->incRef();
_R<Event> e=_MR(Class<Event>::cast(args[0]));
assert_and_throw(e->type!="");
if(!e->target.isNull())
{
//Object must be cloned, closing is implemented with the clone AS method
multiname cloneName;
cloneName.name_type=multiname::NAME_STRING;
cloneName.name_s="clone";
cloneName.ns.push_back(nsNameAndKind("",PACKAGE_NAMESPACE));
_NR<ASObject> clone=e->getVariableByMultiname(cloneName);
if(!clone.isNull() && clone->getObjectType()==T_FUNCTION)
{
IFunction* f = static_cast<IFunction*>(clone.getPtr());
e->incRef();
ASObject* funcRet=f->call(e.getPtr(),NULL,0);
//Verify that the returned object is actually an event
Event* newEvent=dynamic_cast<Event*>(funcRet);
if(newEvent==NULL)
{
if(funcRet)
funcRet->decRef();
return abstract_b(false);
}
e=_MR(newEvent);
}
else
{
//TODO: support cloning of actual type
LOG(LOG_NOT_IMPLEMENTED,"Event cloning not supported!");
e=_MR(Class<Event>::getInstanceS(e->type,e->bubbles, e->cancelable));
}
}
th->incRef();
ABCVm::publicHandleEvent(_MR(th), e);
return abstract_b(true);
}
示例12: getProperty
/// Execute
void EstimatePeakErrors::exec() {
IFunction_sptr function = getProperty("Function");
ITableWorkspace_sptr results =
WorkspaceFactory::Instance().createTable("TableWorkspace");
results->addColumn("str", "Parameter");
results->addColumn("double", "Value");
results->addColumn("double", "Error");
auto matrix = function->getCovarianceMatrix();
if (!matrix) {
g_log.warning() << "Function doesn't have covariance matrix.\n";
setProperty("OutputWorkspace", results);
return;
}
IPeakFunction *peak = dynamic_cast<IPeakFunction *>(function.get());
if (peak) {
GSLMatrix covariance(*matrix);
calculatePeakValues(*peak, *results, covariance, "");
} else {
CompositeFunction *cf = dynamic_cast<CompositeFunction *>(function.get());
if (cf) {
size_t ip = 0;
for (size_t i = 0; i < cf->nFunctions(); ++i) {
IFunction *fun = cf->getFunction(i).get();
size_t np = fun->nParams();
peak = dynamic_cast<IPeakFunction *>(fun);
if (peak) {
std::string prefix = "f" + std::to_string(i) + ".";
GSLMatrix covariance(*matrix, ip, ip, np, np);
calculatePeakValues(*peak, *results, covariance, prefix);
}
ip += np;
}
} else {
g_log.warning() << "Function has no peaks.\n";
}
}
setProperty("OutputWorkspace", results);
}
示例13: ASFUNCTIONBODY
ASFUNCTIONBODY(Vector, some)
{
if (argslen < 1)
throw Class<ArgumentError>::getInstanceS("Error #1063");
if (!args[0]->is<IFunction>())
throw Class<TypeError>::getInstanceS("Error #1034");
Vector* th=static_cast<Vector*>(obj);
IFunction* f = static_cast<IFunction*>(args[0]);
ASObject* params[3];
ASObject *funcRet;
for(unsigned int i=0; i < th->size(); i++)
{
if (!th->vec[i])
continue;
params[0] = th->vec[i];
th->vec[i]->incRef();
params[1] = abstract_i(i);
params[2] = th;
th->incRef();
if(argslen==1)
{
funcRet=f->call(new Null, params, 3);
}
else
{
args[1]->incRef();
funcRet=f->call(args[1], params, 3);
}
if(funcRet)
{
if(Boolean_concrete(funcRet))
{
return funcRet;
}
funcRet->decRef();
}
}
return abstract_b(false);
}
示例14: ASFUNCTIONBODY
ASFUNCTIONBODY(EventDispatcher,dispatchEvent)
{
EventDispatcher* th=Class<EventDispatcher>::cast(obj);
if(args[0]->getClass()==NULL || !(args[0]->getClass()->isSubClass(Class<Event>::getClass())))
return abstract_b(false);
args[0]->incRef();
_R<Event> e=_MR(Class<Event>::cast(args[0]));
assert_and_throw(e->type!="");
if(!e->target.isNull())
{
//Object must be cloned, closing is implemented with the clone AS method
multiname cloneName(NULL);
cloneName.name_type=multiname::NAME_STRING;
cloneName.name_s_id=getSys()->getUniqueStringId("clone");
cloneName.ns.push_back(nsNameAndKind("",NAMESPACE));
_NR<ASObject> clone=e->getVariableByMultiname(cloneName);
//Clone always exists since it's implemented in Event itself
assert(!clone.isNull());
IFunction* f = static_cast<IFunction*>(clone.getPtr());
e->incRef();
ASObject* funcRet=f->call(e.getPtr(),NULL,0);
//Verify that the returned object is actually an event
Event* newEvent=dynamic_cast<Event*>(funcRet);
if(newEvent==NULL)
{
if(funcRet)
funcRet->decRef();
return abstract_b(false);
}
e=_MR(newEvent);
}
if(!th->forcedTarget.isNull())
e->setTarget(th->forcedTarget);
th->incRef();
ABCVm::publicHandleEvent(_MR(th), e);
return abstract_b(true);
}
示例15: inputPoint
Point inputPoint(const IFunction &f)
{
cout << "-- Input start point --" << endl;
return PointHelper::inputPoint(f.dimensions());
}