Esempio n. 1
0
 void wrap_mouse_joint()
 {
     class_<b2MouseJoint, bases<b2Joint> >("MouseJoint", no_init)
         .add_property("anchor_a", &b2MouseJoint::GetAnchorA)
         .add_property("anchor_b", &b2MouseJoint::GetAnchorB)
         .add_property("reaction_force", &b2MouseJoint::GetReactionForce)
         .add_property("reaction_torque", &b2MouseJoint::GetReactionTorque)
         .add_property("target", make_function(&b2MouseJoint::GetTarget, return_value_policy<copy_const_reference>()), &b2MouseJoint::SetTarget)
         .add_property("max_force", &b2MouseJoint::GetMaxForce, &b2MouseJoint::SetMaxForce)
         .add_property("frequency", &b2MouseJoint::GetFrequency, &b2MouseJoint::SetFrequency)
         .add_property("damping_ratio", &b2MouseJoint::GetDampingRatio, &b2MouseJoint::SetDampingRatio)
     ;
 }
 std::vector< term > generate( decltype( functions.begin( ) ) it )
 {
     auto f = it->second.first->generate( );
     auto s = it->second.second->generate( );
     f.reserve( f.size( ) + s.size( ) );
     std::copy( s.begin( ), s.end( ), std::back_inserter( f ) );
     if ( arity == 1 ) { return { make_function( it->first.name,  f ) }; }
     else
     {
         assert( f.size( ) == arity );
         return f;
     }
 }
Esempio n. 3
0
static Obj *handle_function(void *root, Obj **env, Obj **list, int type) {
    if ((*list)->type != TCELL || !is_list((*list)->car) || (*list)->cdr->type != TCELL)
        error("Malformed lambda");
    Obj *p = (*list)->car;
    for (; p->type == TCELL; p = p->cdr)
        if (p->car->type != TSYMBOL)
            error("Parameter must be a symbol");
    if (p != Nil && p->type != TSYMBOL)
        error("Parameter must be a symbol");
    DEFINE2(params, body);
    *params = (*list)->car;
    *body = (*list)->cdr;
    return make_function(root, env, type, params, body);
}
Esempio n. 4
0
exprtree*
make_unary_operator_function (scanner_ident_t *name, exprtree *arg)
{
    const char *func_name = get_func_name_for_unary_op(name->str);
    scanner_ident_t *ident;
    exprtree *tree;

    g_assert(func_name != NULL);

    ident = scanner_make_ident(name->region, func_name);
    tree = make_function(ident, arg);
    free(ident);

    return tree;
}
Esempio n. 5
0
exprtree*
make_operator_function (scanner_ident_t *name, exprtree *left, exprtree *right)
{
    const char *func_name = get_func_name_for_op(name->str);
    scanner_ident_t *ident;
    exprtree *tree;

    g_assert(func_name != NULL);

    ident = scanner_make_ident(name->region, func_name);
    tree = make_function(ident, exprlist_append(left, right));
    free(ident);

    return tree;
}
Esempio n. 6
0
 inline object make_iterator_function(
     Accessor1 const& get_start
   , Accessor2 const& get_finish
   , NextPolicies const& /*next_policies*/
   , Iterator const& (*)()
   , abt_boost::type<Target>*
   , int
 )
 {
     return make_function(
         py_iter_<Target,Iterator,Accessor1,Accessor2,NextPolicies>(get_start, get_finish)
       , default_call_policies()
       , mpl::vector2<iterator_range<NextPolicies,Iterator>, back_reference<Target&> >()
     );
 }
//-----------------------------------------------------------------------------
// Expose SendProp.
//-----------------------------------------------------------------------------
void export_send_prop(scope _props)
{
	class_<SendProp, SendProp *, boost::noncopyable> SendProp_("SendProp", no_init);
	
	// Properties...
	SendProp_.def_readonly("type", &SendProp::m_Type);
	SendProp_.def_readonly("bits", &SendProp::m_nBits);
	SendProp_.def_readonly("low_value", &SendProp::m_fLowValue);
	SendProp_.def_readonly("high_value", &SendProp::m_fHighValue);
	SendProp_.def_readonly("array_prop", &SendProp::m_pArrayProp);
	SendProp_.def_readonly("length", &SendProp::m_nElements);
	SendProp_.def_readonly("element_stride", &SendProp::m_ElementStride);
	SendProp_.def_readonly("exclude_data_table_name", &SendProp::m_pExcludeDTName);
	SendProp_.def_readonly("parent_array_prop_name", &SendProp::m_pParentArrayPropName);
	SendProp_.add_property("name", &SendProp::GetName);
	SendProp_.def_readonly("high_low_mul", &SendProp::m_fHighLowMul);
	SendProp_.add_property("flags", &SendProp::GetFlags);
	
	SendProp_.add_property("data_table",
		make_function(
			&SendProp::GetDataTable,
			reference_existing_object_policy()
		)
	);
	
	SendProp_.add_property("offset", &SendProp::GetOffset);
	
	// CS:GO specific properties...
	SendProp_.NOT_IMPLEMENTED_ATTR("priority");
	
	// Methods...

	SendProp_.def("is_signed", &SendProp::IsSigned);
	SendProp_.def("is_exclude_prop", &SendProp::IsExcludeProp);
	SendProp_.def("is_inside_array", &SendProp::IsInsideArray);

	SendProp_.def("get_proxy_function", &SendPropSharedExt::get_proxy_function, manage_new_object_policy());

	// CS:GO specific methods...
	SendProp_.NOT_IMPLEMENTED("get_priority");
	
	// Engine specific stuff...
	export_engine_specific_send_prop(_props, SendProp_);
	
	// Add memory tools...
	SendProp_ ADD_MEM_TOOLS(SendProp);
}
	void bindMeshPrimitive()
	{
		RunTimeTypedClass<MeshPrimitive>()
			.def( init<>() )
			.def( init<IntVectorDataPtr, IntVectorDataPtr, optional<const std::string &, V3fVectorDataPtr> >() )
			.def( "numFaces", &MeshPrimitive::numFaces )
			/// \todo I'd rather see these bound as functions rather than properties so they match the C++ interface.
			/// I think this is particularly important for verticesPerFace and vertexIds as it's pretty unintuitive that a property
			/// should return a copy. This is something we need to be more consistent about throughout cortex.
			.add_property( "verticesPerFace", &verticesPerFace, "A copy of the mesh's list of vertices per face." )
			.add_property( "vertexIds", &vertexIds, "A copy of the mesh's list of vertex ids." )
			.add_property( "interpolation", make_function( &MeshPrimitive::interpolation, return_value_policy<copy_const_reference>() ), &MeshPrimitive::setInterpolation )
			.def( "setTopology", &MeshPrimitive::setTopology )
			.def( "createBox", &MeshPrimitive::createBox, ( arg_( "bounds" ) ) ).staticmethod( "createBox" )
			.def( "createPlane", &MeshPrimitive::createPlane, ( arg_( "bounds" ), arg_( "divisions" ) = Imath::V2i( 1 ) ) ).staticmethod( "createPlane" )
			.def( "createSphere", &MeshPrimitive::createSphere, ( arg_( "radius" ), arg_( "zMin" ) = -1.0f, arg_( "zMax" ) = 1.0f, arg_( "thetaMax" ) = 360.0f, arg_( "divisions" ) = Imath::V2i( 20, 40 ) ) ).staticmethod( "createSphere" )
		;
	}
void bindDateTimeData()
{
	PyDateTime_IMPORT;

	ptime_from_python_datetime();
	to_python_converter<posix_time::ptime, ptime_to_python > ();

	TypedDataFromType<DateTimeData>();

	RunTimeTypedClass<DateTimeData>()
		.def( init<>() )
		.def( init<const DateTimeData::ValueType &>() )
		.add_property( "value", make_function( &getValue, return_value_policy<copy_const_reference>() ), &setValue )
		.def( "__repr__", &repr<DateTimeData> )
		.def( "__str__", &str<DateTimeData> )
		.def( "hasBase", &DateTimeData::hasBase ).staticmethod( "hasBase" )
	;
}
Esempio n. 10
0
EXPRESSION *make_closure(MODULE *mod, TYPE *type, DECLARATION *args, BLOCK *body, int source_line)
{
    static int next_id = 0;
    char name[100];
    
    sprintf(name, "closure%d", next_id++);
    char *str = add_string(mod, name, strlen(name));
    
    FUNCTION *func = make_function(type, str, args, source_line);
    tree_get_child(func, 0) = body;
    EXPRESSION *expr = create_ast_node(EXPR_CLOSURE, source_line);
    tree_add_child(expr, func);
    expr->type = make_map_type(args->type, type, source_line);
    
    /* Add new function to module. */
    tree_add_child(mod, func);
    add_to_hash(mod->table, str, strlen(str), func);
    return expr;
}
Esempio n. 11
0
Obj *handle_function(Env *env, Obj *root, Obj **list, int type) {
    if ((*list)->type != TCELL || (*list)->car->type != TCELL ||
        (*list)->cdr->type != TCELL) {
        error("malformed lambda");
    }
    Obj *p = (*list)->car;
    for (;;) {
        if (p->car->type != TSYMBOL)
            error("argument must be a symbol");
        if (p->cdr == Nil)
            break;
        if (p->cdr->type != TCELL)
            error("argument is not a flat list");
        p = p->cdr;
    }
    VAR(car);
    VAR(cdr);
    car = &(*list)->car;
    cdr = &(*list)->cdr;
    return make_function(env, root, type, car, cdr);
}
Esempio n. 12
0
static exprtree*
make_image_call (exprtree *image, exprtree *args, scanner_region_t region)
{
    exprtree *tree;
    scanner_ident_t *ident;

    if (exprlist_length(args) != 1 && exprlist_length(args) != 2)
    {
	sprintf(error_string, _("An image must be invoked with one or two arguments."));
	error_region = region;
	JUMP(1);
    }

    if (args->result.length != 2
	|| (args->result.number != xy_tag_number
	    && args->result.number != ra_tag_number))
    {
	sprintf(error_string, _("The coordinate argument to an image must be of type xy:2 or ra:2."));
	error_region = region;
	JUMP(1);
    }
    if (args->result.number == ra_tag_number)
	args = make_function_from_string("toXY", args, args->region);

    if (args->next != NULL)
    {
	if (args->next->result.length != 1)
	{
	    sprintf(error_string, _("The time argument to an image have length 1."));
	    error_region = region;
	    JUMP(1);
	}
    }

    ident = scanner_make_ident(scanner_null_region, "__origVal");
    tree = make_function(ident, exprlist_append(args, image));
    free(ident);

    return tree;
}
Esempio n. 13
0
//-----------------------------------------------------------------------------
// Exports IClient.
//-----------------------------------------------------------------------------
void export_client(scope _players)
{
	class_<IClient, IClient*, bases<INetChannelHandler>, boost::noncopyable> Client("Client", no_init);

	Client.add_property(
		"name",
		&IClient::GetClientName,
		"Return the client's name."
	);

	Client.add_property(
		"net_channel",
		make_function(
			&IClient::GetNetChannel,
			reference_existing_object_policy()
		)
	);

	// TODO: Export more

	Client ADD_MEM_TOOLS(IClient);
}
Esempio n. 14
0
  template<class Obs, class Bundle> double cost(const Bundle& bundle)
  {
    const auto nb_obs = bundle.template at_obs<Obs>().size();
    if (nb_obs==0) return 0;

//     std::cout << " cost without save " << std::endl;
    
    double total = 0;

//     #pragma omp parallel for reduction(+:total) if(use_omp())
    for(auto iobs = bundle.template at_obs<Obs>().first() ; iobs < nb_obs ; ++iobs)
    {
      //total += (make_function(bundle.obs(iobs))(bundle.map(iobs))).squaredNorm() / 2;
      auto pair_residu = make_function(bundle.obs(iobs))(bundle.map(iobs));
      if (pair_residu.second)
        total += ( pair_residu ).first.squaredNorm();
    }

    if (std::isnan(total))
      throw NAN_ERROR(" NAN : cost_and_save");
    return total/2.0;
  }
Esempio n. 15
0
//-----------------------------------------------------------------------------
// Exports mstudioseqdesc_t.
//-----------------------------------------------------------------------------
void export_sequence(scope _studio)
{
    class_<mstudioseqdesc_t, mstudioseqdesc_t *, boost::noncopyable> Sequence("Sequence");

    // Properties...
    Sequence.add_property("model_header", make_function(&mstudioseqdesc_t::pStudiohdr, reference_existing_object_policy()));
    Sequence.def_readwrite("label_offset", &mstudioseqdesc_t::szlabelindex);
    Sequence.add_property("label", &SequenceExt::get_label);
    Sequence.def_readwrite("activity_offset", &mstudioseqdesc_t::szactivitynameindex);
    Sequence.add_property("activity", &SequenceExt::get_activity);
    Sequence.def_readwrite("flags", &mstudioseqdesc_t::flags);
    Sequence.def_readwrite("activity_index", &mstudioseqdesc_t::activity);
    Sequence.def_readwrite("act_weight", &mstudioseqdesc_t::actweight);
    Sequence.def_readwrite("events_count", &mstudioseqdesc_t::numevents);
    Sequence.def_readwrite("events_offset", &mstudioseqdesc_t::eventindex);
    Sequence.add_property("min", make_getter(&mstudioseqdesc_t::bbmin, reference_existing_object_policy()));
    Sequence.add_property("max", make_getter(&mstudioseqdesc_t::bbmax, reference_existing_object_policy()));
    Sequence.def_readwrite("blends_count", &mstudioseqdesc_t::numblends);
    Sequence.def_readwrite("animation_offset", &mstudioseqdesc_t::animindexindex);
    Sequence.def_readwrite("movement_index", &mstudioseqdesc_t::movementindex);
    Sequence.def_readwrite("fade_in_time", &mstudioseqdesc_t::fadeintime);
    Sequence.def_readwrite("fade_out_time", &mstudioseqdesc_t::fadeouttime);
    Sequence.def_readwrite("local_entry_node", &mstudioseqdesc_t::localentrynode);
    Sequence.def_readwrite("local_exit_node", &mstudioseqdesc_t::localexitnode);
    Sequence.def_readwrite("node_flags", &mstudioseqdesc_t::nodeflags);
    Sequence.def_readwrite("entry_phase", &mstudioseqdesc_t::entryphase);
    Sequence.def_readwrite("exit_phase", &mstudioseqdesc_t::exitphase);
    Sequence.def_readwrite("lastframe", &mstudioseqdesc_t::lastframe);
    Sequence.def_readwrite("next_sequence", &mstudioseqdesc_t::nextseq);
    Sequence.def_readwrite("pose", &mstudioseqdesc_t::pose);

    // Methods...
    Sequence.def("get_animation_index", &mstudioseqdesc_t::anim);
    Sequence.def("get_weight", &mstudioseqdesc_t::weight);

    // Add memory tools...
    Sequence ADD_MEM_TOOLS(mstudioseqdesc_t);
}
void bindAttributeCache()
{
	bool (AttributeCache::*containsObj)(const AttributeCache::ObjectHandle &) = &AttributeCache::contains;
	bool (AttributeCache::*containsObjAttr)(const AttributeCache::ObjectHandle &, const AttributeCache::AttributeHandle &) = &AttributeCache::contains;

	RefCountedClass<AttributeCache, RefCounted>( "AttributeCache" )
		.def( init<const std::string &, IndexedIO::OpenMode>() )
		.def("write", &AttributeCache::write)
		.def("writeHeader", &AttributeCache::writeHeader)
		.def("read", (ObjectPtr (AttributeCache::*)( const AttributeCache::ObjectHandle &, const AttributeCache::AttributeHandle & ) )&AttributeCache::read)
		.def("read", (CompoundObjectPtr (AttributeCache::*)( const AttributeCache::ObjectHandle & ))&AttributeCache::read)
		.def("readHeader", (ObjectPtr (AttributeCache::*) ( const AttributeCache::HeaderHandle & ))&AttributeCache::readHeader)
		.def("readHeader", (CompoundObjectPtr (AttributeCache::*)())&AttributeCache::readHeader)
		.def("contains", containsObj)
		.def("contains", containsObjAttr)
		.def("objects", &AttributeCacheHelper::objects)
		.def("headers", &AttributeCacheHelper::headers)
		.def("attributes", make_function( &AttributeCacheHelper::attributes, default_call_policies(), ( boost::python::arg_( "obj" ), boost::python::arg_( "regex" ) = object() ) ) )
		.def("remove", (void (AttributeCache::*)( const AttributeCache::ObjectHandle &, const AttributeCache::AttributeHandle & ) )&AttributeCache::remove)
		.def("remove", (void (AttributeCache::*)( const AttributeCache::ObjectHandle & ))&AttributeCache::remove)
		.def("removeHeader", &AttributeCache::removeHeader )
	;
}
Esempio n. 17
0
  object demand_iterator_class(char const* name, Iterator* = 0, NextPolicies const& policies = NextPolicies())
  {
      typedef iterator_range<NextPolicies,Iterator> range_;

      // Check the registry. If one is already registered, return it.
      handle<> class_obj(
          objects::registered_class_object(python::type_id<range_>()));
        
      if (class_obj.get() != 0)
          return object(class_obj);

      typedef typename range_::next_fn next_fn;
      typedef typename next_fn::result_type result_type;
      
      return class_<range_>(name, no_init)
          .def("__iter__", identity_function())
          .def(
              "next"
            , make_function(
                next_fn()
              , policies
              , mpl::vector2<result_type,range_&>()
            ));
  }
//-----------------------------------------------------------------------------
// Exports IPhysicsEnvironment.
//-----------------------------------------------------------------------------
void export_physics_environment(scope _physics)
{
	class_<IPhysicsEnvironmentWrapper, boost::noncopyable> PhysicsEnvironment("PhysicsEnvironment", no_init);

	PhysicsEnvironment.add_property(
		"gravity",
		make_function(&IPhysicsEnvironmentWrapper::GetGravity, manage_new_object_policy()),
		&IPhysicsEnvironmentWrapper::SetGravity
	);

	PhysicsEnvironment.add_property(
		"air_density",
		&IPhysicsEnvironmentWrapper::GetAirDensity,
		&IPhysicsEnvironmentWrapper::SetAirDensity
	);

	PhysicsEnvironment.def(
		"get_active_object_by_index",
		&IPhysicsEnvironmentWrapper::GetActiveObjectByIndex,
		manage_new_object_policy()
	);

	//PhysicsEnvironment ADD_MEM_TOOLS_WRAPPER(IPhysicsEnvironmentWrapper, IPhysicsEnvironment);
}
Esempio n. 19
0
 // The case A[x_,y_] = RHS : we form the function (make_function) and call auto_assign (by ADL)
 template <typename F, typename RHS, int... Is> FORCEINLINE void operator<<(expr<tags::subscript, F, gfs::tuple_com<_ph<Is>...>> &&ex, RHS &&rhs) {
   triqs_clef_auto_assign(std::get<0>(ex.childs), make_function(std::forward<RHS>(rhs), _ph<Is>()...));
 }
Esempio n. 20
0
int
main (void)
{
  double result[TRIALS], error[TRIALS];
  double a = 0.1;
  double c = (1.0 + sqrt (10.0)) / 9.0;

  gsl_monte_function Fc = make_function(&fconst, 0, 0);
  gsl_monte_function F0 = make_function(&f0, 0, &a);
  gsl_monte_function F1 = make_function(&f1, 0, &a);
  gsl_monte_function F2 = make_function(&f2, 0, &a);
  gsl_monte_function F3 = make_function(&f3, 0, &c);

  /* The relationship between the variance of the function itself, the
     error on the integral and the number of calls is,

     sigma = sqrt(variance/N)

     where the variance is the <(f - <f>)^2> where <.> denotes the
     volume average (integral over the integration region divided by
     the volume) */

  int n = 0;
  struct problem * I;
  struct problem problems[256];

#ifdef CONSTANT
    /* variance(Fc) = 0 */

    add(problems,&n, &Fc, xl, xu,  1, 1000, 1.0, 0.0, "constant, 1d");
    add(problems,&n, &Fc, xl, xu,  2, 1000, 1.0, 0.0, "constant, 2d");
    add(problems,&n, &Fc, xl, xu,  3, 1000, 1.0, 0.0, "constant, 3d");
    add(problems,&n, &Fc, xl, xu,  4, 1000, 1.0, 0.0, "constant, 4d");
    add(problems,&n, &Fc, xl, xu,  5, 1000, 1.0, 0.0, "constant, 5d");
    add(problems,&n, &Fc, xl, xu,  6, 1000, 1.0, 0.0, "constant, 6d");
    add(problems,&n, &Fc, xl, xu,  7, 1000, 1.0, 0.0, "constant, 7d");
    add(problems,&n, &Fc, xl, xu,  8, 1000, 1.0, 0.0, "constant, 8d");
    add(problems,&n, &Fc, xl, xu,  9, 1000, 1.0, 0.0, "constant, 9d");
    add(problems,&n, &Fc, xl, xu, 10, 1000, 1.0, 0.0, "constant, 10d");
#endif

#ifdef PRODUCT
    /* variance(F0) = (4/3)^d - 1 */

    add(problems,&n, &F0, xl, xu,  1, 3333,   1.0, 0.01, "product, 1d" );
    add(problems,&n, &F0, xl, xu,  2, 7777,   1.0, 0.01, "product, 2d" );
    add(problems,&n, &F0, xl, xu,  3, 13703,  1.0, 0.01, "product, 3d" );
    add(problems,&n, &F0, xl, xu,  4, 21604,  1.0, 0.01, "product, 4d" );
    add(problems,&n, &F0, xl, xu,  5, 32139,  1.0, 0.01, "product, 5d" );
    add(problems,&n, &F0, xl, xu,  6, 46186,  1.0, 0.01, "product, 6d" );
    add(problems,&n, &F0, xl, xu,  7, 64915,  1.0, 0.01, "product, 7d" );
    add(problems,&n, &F0, xl, xu,  8, 89887,  1.0, 0.01, "product, 8d" );
    add(problems,&n, &F0, xl, xu,  9, 123182, 1.0, 0.01, "product, 9d" );
    add(problems,&n, &F0, xl, xu, 10, 167577, 1.0, 0.01, "product, 10d" );
#endif

#ifdef GAUSSIAN
    /* variance(F1) = (1/(a sqrt(2 pi)))^d - 1 */

    add(problems,&n, &F1, xl, xu,  1, 298,      1.0, 0.1, "gaussian, 1d" );
    add(problems,&n, &F1, xl, xu,  2, 1492,     1.0, 0.1, "gaussian, 2d" );
    add(problems,&n, &F1, xl, xu,  3, 6249,     1.0, 0.1, "gaussian, 3d" );
    add(problems,&n, &F1, xl, xu,  4, 25230,    1.0, 0.1, "gaussian, 4d" );
    add(problems,&n, &F1, xl, xu,  5, 100953,   1.0, 0.1, "gaussian, 5d" );
    add(problems,&n, &F1, xl, xu,  6, 44782,    1.0, 0.3, "gaussian, 6d" );
    add(problems,&n, &F1, xl, xu,  7, 178690,   1.0, 0.3, "gaussian, 7d" );
    add(problems,&n, &F1, xl, xu,  8, 712904,   1.0, 0.3, "gaussian, 8d" );
    add(problems,&n, &F1, xl, xu,  9, 2844109,  1.0, 0.3, "gaussian, 9d" );
    add(problems,&n, &F1, xl, xu, 10, 11346390, 1.0, 0.3, "gaussian, 10d" );
#endif

#ifdef DBLGAUSSIAN
    /* variance(F2) = 0.5 * (1/(a sqrt(2 pi)))^d - 1 */

    add(problems,&n, &F2, xl, xu,  1, 9947,  1.0, 0.01, "double gaussian, 1d" );
    add(problems,&n, &F2, xl, xu,  2, 695,   1.0, 0.1, "double gaussian, 2d" );
    add(problems,&n, &F2, xl, xu,  3, 3074,  1.0, 0.1, "double gaussian, 3d" );
    add(problems,&n, &F2, xl, xu,  4, 12565, 1.0, 0.1, "double gaussian, 4d" );
    add(problems,&n, &F2, xl, xu,  5, 50426, 1.0, 0.1, "double gaussian, 5d" );
    add(problems,&n, &F2, xl, xu,  6, 201472, 1.0, 0.1, "double gaussian, 6d" );
    add(problems,&n, &F2, xl, xu,  7, 804056, 1.0, 0.1, "double gaussian, 7d" );
    add(problems,&n, &F2, xl, xu,  8, 356446, 1.0, 0.3, "double gaussian, 8d" );
    add(problems,&n, &F2, xl, xu,  9, 1422049, 1.0, 0.3, "double gaussian, 9d" );
    add(problems,&n, &F2, xl, xu, 10, 5673189, 1.0, 0.3, "double gaussian, 10d" );
#endif

#ifdef TSUDA
    /* variance(F3) = ((c^2 + c + 1/3)/(c(c+1)))^d - 1 */

    add(problems,&n, &F3, xl, xu,  1, 4928,   1.0, 0.01, "tsuda function, 1d" );
    add(problems,&n, &F3, xl, xu,  2, 12285,  1.0, 0.01, "tsuda function, 2d" );
    add(problems,&n, &F3, xl, xu,  3, 23268,  1.0, 0.01, "tsuda function, 3d" );
    add(problems,&n, &F3, xl, xu,  4, 39664,  1.0, 0.01, "tsuda function, 4d" );
    add(problems,&n, &F3, xl, xu,  5, 64141,  1.0, 0.01, "tsuda function, 5d" );
    add(problems,&n, &F3, xl, xu,  6, 100680, 1.0, 0.01, "tsuda function, 6d" );
    add(problems,&n, &F3, xl, xu,  7, 155227, 1.0, 0.01, "tsuda function, 7d" );
    add(problems,&n, &F3, xl, xu,  8, 236657, 1.0, 0.01, "tsuda function, 8d" );
    add(problems,&n, &F3, xl, xu,  9, 358219, 1.0, 0.01, "tsuda function, 9d" );
    add(problems,&n, &F3, xl, xu, 10, 539690, 1.0, 0.01, "tsuda function, 10d" );
#endif

    add(problems,&n,   0,  0,  0, 0,    0,   0,   0, 0  );


  /* gsl_set_error_handler (&my_error_handler); */
  gsl_ieee_env_setup ();
  gsl_rng_env_setup ();

#ifdef A
  printf ("testing allocation/input checks\n");

  status = gsl_monte_plain_validate (s, xl, xu3, 1, 1);
  gsl_test (status != 0, "error if limits too large");
  status = gsl_monte_plain_validate (s, xl, xu, 0, 10);
  gsl_test (status != 0, "error if num_dim = 0");
  status = gsl_monte_plain_validate (s, xl, xu, 1, 0);
  gsl_test (status != 0, "error if calls = 0");
  status = gsl_monte_plain_validate (s, xu, xl, 1, 10);
  gsl_test (status != 0, "error if xu < xl");
#endif

#ifdef PLAIN
#define NAME "plain"
#define MONTE_STATE gsl_monte_plain_state
#define MONTE_ALLOC gsl_monte_plain_alloc
#define MONTE_INTEGRATE gsl_monte_plain_integrate
#define MONTE_FREE gsl_monte_plain_free
#define MONTE_SPEEDUP 1
#define MONTE_ERROR_TEST(err,expected) gsl_test_factor(err,expected, 5.0, NAME ", %s, abserr[%d]", I->description, i)
#include "test_main.c"
#undef NAME
#undef MONTE_STATE
#undef MONTE_ALLOC
#undef MONTE_INTEGRATE
#undef MONTE_FREE
#undef MONTE_ERROR_TEST
#undef MONTE_SPEEDUP
#endif

#ifdef MISER
#define NAME "miser"
#define MONTE_STATE gsl_monte_miser_state
#define MONTE_ALLOC gsl_monte_miser_alloc
#define MONTE_INTEGRATE gsl_monte_miser_integrate
#define MONTE_FREE gsl_monte_miser_free
#define MONTE_SPEEDUP 2
#define MONTE_ERROR_TEST(err,expected) gsl_test(err > 5.0 * expected, NAME ", %s, abserr[%d] (obs %g vs plain %g)", I->description, i, err, expected)
#include "test_main.c"
#undef NAME
#undef MONTE_STATE
#undef MONTE_ALLOC
#undef MONTE_INTEGRATE
#undef MONTE_FREE
#undef MONTE_ERROR_TEST
#undef MONTE_SPEEDUP
#endif

#ifdef VEGAS
#define NAME "vegas"
#define MONTE_STATE gsl_monte_vegas_state
#define MONTE_ALLOC gsl_monte_vegas_alloc
#define MONTE_INTEGRATE(f,xl,xu,dim,calls,r,s,res,err) { gsl_monte_vegas_integrate(f,xl,xu,dim,calls,r,s,res,err) ; if (s->chisq < 0.5 || s->chisq > 2) gsl_monte_vegas_integrate(f,xl,xu,dim,calls,r,s,res,err); }
#define MONTE_FREE gsl_monte_vegas_free
#define MONTE_SPEEDUP 3
#define MONTE_ERROR_TEST(err,expected) gsl_test(err > 3.0 * (expected == 0 ? 1.0/(I->calls/MONTE_SPEEDUP) : expected), NAME ", %s, abserr[%d] (obs %g vs exp %g)", I->description, i, err, expected)
#include "test_main.c"
#undef NAME
#undef MONTE_STATE
#undef MONTE_ALLOC
#undef MONTE_INTEGRATE
#undef MONTE_FREE
#undef MONTE_ERROR_TEST
#undef MONTE_SPEEDUP
#endif
      
  exit (gsl_test_summary ());
}
Esempio n. 21
0
object make_function(lua_State* L, F f)
{
    return make_function(L, detail::deduce_signature(f), detail::null_type());
}
Esempio n. 22
0
 object make_function1(T fn, ...) { return make_function(fn); }
Esempio n. 23
0
Function_decl&
Builder::make_function(char const* s, Decl_list const& ps, Type& r)
{
  return make_function(get_id(s), ps, r);
}
Esempio n. 24
0
		
		.def("add_sub_key",
			&KeyValues::AddSubKey,
			"Adds a sub key. Make sure the subkey isn't a child of some other KeyValues.",
			args("sub_key")
		)

		.def("remove_sub_key",
			&KeyValues::RemoveSubKey,
			"Removes a subkey from the list. DOES NOT DELETE IT!",
			args("sub_key")
		)

		.add_property("first_sub_key",
			make_function(
				&KeyValues::GetFirstSubKey,
				reference_existing_object_policy()
			),
			"Returns the first subkey in the list. Will iterate over the keys AND the values."
		)

		.add_property("next_key",
			make_function(
				&KeyValues::GetNextKey,
				reference_existing_object_policy()
			),
			&KeyValues::SetNextKey,
			"Returns the next subkey. Will iterate the keys AND the values."
		)

		.add_property("first_true_sub_key",
			make_function(
//-----------------------------------------------------------------------------
// Exports IPhysicsObject.
//-----------------------------------------------------------------------------
void export_physics_object(scope _physics)
{
	class_<IPhysicsObjectWrapper, boost::noncopyable> PhysicsObject("PhysicsObject", no_init);

	PhysicsObject.def(
		"is_static",
		&IPhysicsObjectWrapper::IsStatic,
		"Return True if the object is static."
	);

	PhysicsObject.add_property(
		"asleep",
		&IPhysicsObjectWrapper::IsAsleep,
		&IPhysicsObjectWrapper::EnableSleep,
		"Return True if the object is asleep."
	);

	PhysicsObject.def(
		"is_trigger",
		&IPhysicsObjectWrapper::IsTrigger,
		"Return True if the object is a trigger."
	);

	PhysicsObject.def(
		"is_fluid",
		&IPhysicsObjectWrapper::IsFluid,
		"Return True if the object is fluid."
	);

	PhysicsObject.def(
		"is_hinged",
		&IPhysicsObjectWrapper::IsHinged,
		"Return True if the object is hinged."
	);

	PhysicsObject.add_property(
		"collision_enabled",
		&IPhysicsObjectWrapper::IsCollisionEnabled,
		&IPhysicsObjectWrapper::EnableCollisions,
		"Return True if collisions are enabled."
	);

	PhysicsObject.add_property(
		"gravity_enabled",
		&IPhysicsObjectWrapper::IsGravityEnabled,
		&IPhysicsObjectWrapper::EnableGravity,
		"Return True if gravity is enabled."

	);

	PhysicsObject.add_property(
		"drag_enabled",
		&IPhysicsObjectWrapper::IsDragEnabled,
		&IPhysicsObjectWrapper::EnableDrag,
		"Return True if air fraction/drag is enabled."

	);

	PhysicsObject.add_property(
		"motion_enabled",
		&IPhysicsObjectWrapper::IsMotionEnabled,
		&IPhysicsObjectWrapper::EnableMotion,
		"Return True if motion is enabled."

	);

	PhysicsObject.def(
		"is_moveable",
		&IPhysicsObjectWrapper::IsMoveable
	);

	PhysicsObject.def(
		"is_attached_to_constraint",
		&IPhysicsObjectWrapper::IsAttachedToConstraint
	);


	PhysicsObject.add_property(
		"game_data",
		make_function(&IPhysicsObjectWrapper::GetGameData, return_by_value_policy()),
		&IPhysicsObjectWrapper::SetGameData
	);

	PhysicsObject.add_property(
		"game_flags",
		&IPhysicsObjectWrapper::GetGameFlags,
		&IPhysicsObjectWrapper::SetGameFlags
	);

	PhysicsObject.add_property(
		"game_index",
		&IPhysicsObjectWrapper::GetGameIndex,
		&IPhysicsObjectWrapper::SetGameIndex
	);

	PhysicsObject.add_property(
		"callback_flags",
		&IPhysicsObjectWrapper::GetCallbackFlags,
		&IPhysicsObjectWrapper::SetCallbackFlags
	);

	PhysicsObject.add_property(
		"mass",
		&IPhysicsObjectWrapper::GetMass,
		&IPhysicsObjectWrapper::SetMass
	);
	
	
	PhysicsObject.def(
		"recheck_collision_filter",
		&IPhysicsObjectWrapper::RecheckCollisionFilter
	);
	
	PhysicsObject.def(
		"recheck_contact_points",
		&IPhysicsObjectWrapper::RecheckContactPoints
	);


	PhysicsObject.add_property(
		"inertia",
		&IPhysicsObjectWrapper::GetInertia,
		&IPhysicsObjectWrapper::SetInertia
	);

	PhysicsObject.add_property(
		"material_index",
		&IPhysicsObjectWrapper::GetMaterialIndex,
		&IPhysicsObjectWrapper::SetMaterialIndex
	);

	PhysicsObject.add_property(
		"contents",
		&IPhysicsObjectWrapper::GetContents,
		&IPhysicsObjectWrapper::SetContents
	);

	PhysicsObject.add_property(
		"sphere_radius",
		&IPhysicsObjectWrapper::GetSphereRadius,
		"Return the radius if this is a sphere object (zero if this is a polygonal mesh)."
	);

	PhysicsObject.add_property(
		"energy",
		&IPhysicsObjectWrapper::GetEnergy
	);

	PhysicsObject.add_property(
		"mass_center_local_space",
		&IPhysicsObjectWrapper::GetMassCenterLocalSpace
	);

	PhysicsObject.add_property(
		"position",
		&IPhysicsObjectWrapper::GetPosition,
		"Return a tuple that contains the position and the angle of the object."
	);

	PhysicsObject.def(
		"set_position",
		&IPhysicsObjectWrapper::SetPosition
	);

	PhysicsObject.add_property(
		"velocity",
		&IPhysicsObjectWrapper::GetVelocity,
		"Return a tuple that contains the velocity in worldspace and relative to the object."
	);

	PhysicsObject.def(
		"set_velocity",
		&IPhysicsObjectWrapper::SetVelocity
	);

	PhysicsObject.def(
		"set_velocity_instantaneous",
		&IPhysicsObjectWrapper::SetVelocityInstantaneous
	);

	PhysicsObject.def(
		"apply_force_center",
		&IPhysicsObjectWrapper::ApplyForceCenter
	);



	PhysicsObject.add_property(
		"name",
		&IPhysicsObjectWrapper::GetName
	);



	PhysicsObject.def(
		"output_debug_info",
		&IPhysicsObjectWrapper::OutputDebugInfo
	);
}
	object make_function(lua_State* L, F f)
	{
		return make_function(L, f, typename detail::call_types<F>::signature_type(), no_policies());
	}
Esempio n. 27
0
int main() { 

 F1 f(7);

 test1( 5*x_) ;
 test2(x_  + 2*y_);
 test2(x_  + 2*y_ + x_);
 test2(x_/2.0  + 2*y_);
 test2( f(x_) );
 test2( f(x_)   + 2*y_);
 test2( 1/f(x_)   + 2*y_);
 
#ifdef LONG
 test2( 1/f(x_)   + 2*y_ + x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_);
#endif
#ifdef LONG2
 test2( 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_+ x_ + 2*x_ + 1/f(x_)   + 2*y_ + x_ );
#endif

 { 
  auto expr1 = x_ *2  ;
  auto myf1  = make_function(expr1, x_);  
  std::cout<< myf1(2) << " = "<< 4 << std::endl;

  auto expr = x_  + 2*y_;
  auto myf  = make_function(expr, x_,y_);  
  auto myf_r  = make_function(expr, y_,x_);  
 
  std::cout<< myf(2,5) << " = "<< 12 << std::endl;
  std::cout<< myf(5,2) << " = " << 9<<std::endl;
  std::cout<< myf_r(2,5) << " = "<< 9 <<std::endl;
  std::cout<< myf_r(5,2) << " = "<< 12 << std::endl;
  std::cout<<"-------------"<<std::endl;
 }


 { 
  // testing the LHS wrting on an object caught by ref
  F1 f(7);
  std::cerr  << " operator(double) still ok "<< f(2) << std::endl; 
  std::cout<< " f.v before assign "<<f.v<<" "<<  std::endl;
  f(x_ ) << 8*x_ ;
  //f(x_ + y_) << 8*x_ ;// leads to a compile error as expected
  // test.cpp:129:14: error: no viable overloaded '='
  // f(x_ + y_) << 8*x_ ;
  // ~~~~~~~~~~ ^ ~~~~
  std::cout<< " f.v after assign "<<f.v<<" "<<  std::endl;
  std::cout<<"-------------"<<std::endl;
  std::cerr  <<F1{9}(2,x_, F1{2})<<std::endl;
  auto expr = F1{9}(x_);
  expr << 7*x_;
  std::cerr  << expr << std::endl ;
  F1{9}(x_ ) << 8*x_ ;
  std::cerr<<"-------------"<<std::endl;

 }

 { 
  // testing fnt of 2 variables
  F2 ff;
  std::cout<<"expr = "<< (ff(x_,y_)  + 2*y_)<< std::endl;
  std::cout<<"eval(expr,x_ =1, y_ =2) =  "<<   eval(ff(x_,y_)  + 2*y_ , x_=x, y_=y)  << " and it should be "<< ff(x,y)  + 2*y <<std::endl;
  auto tmp =  ff(2.0, y_) ;

  std::cout<<" tmp =" << tmp<<std::endl;
  std::cout<<"another  =  "<<   eval( tmp , x_=x)  << std::endl;
  std::cout<<"another  =  "<<   eval( ff(x_,2) , x_=x)  <<std::endl;
  std::cout<<"-------------"<<std::endl;
 }

{ 
 // testing expression if
 TEST(eval( if_else( true , 2*x_ , y_) , x_=1, y_=3));
 TEST(eval( if_else( false , 2*x_ , y_) ,x_=1, y_=3));
 TEST(eval( if_else( x_>y_ , 2*x_ , y_) ,x_=1, y_=3));
}
 std::cout << (x_ < y_) <<std::endl;
}
Esempio n. 28
0
void env_init(Atom *env)
{
	*env = env_create(nil);
	//env_set(env, make_symbol("IF"), make_function(builtin_if));

	env_set(*env, make_symbol("CAR"), make_function(builtin_car));
	env_set(*env, make_symbol("CDR"), make_function(builtin_cdr));
	env_set(*env, make_symbol("CONS"), make_function(builtin_cons));
	env_set(*env, make_symbol("+"), make_function(builtin_add));
	env_set(*env, make_symbol("-"), make_function(builtin_sub));
	env_set(*env, make_symbol("*"), make_function(builtin_mul));
	env_set(*env, make_symbol("/"), make_function(builtin_div));

	env_set(*env, make_symbol("<"), make_function(builtin_less));
	env_set(*env, make_symbol("="), make_function(builtin_equal));
	env_set(*env, make_symbol(">"), make_function(builtin_greater));

	env_set(*env, make_symbol("AND"), make_function(builtin_and));
	env_set(*env, make_symbol("OR"), make_function(builtin_or));
	env_set(*env, make_symbol("NOT"), make_function(builtin_not));

	env_set(*env, make_symbol("T"), make_symbol("T"));
}
	object make_function(lua_State* L, F f, meta::type_list< PolicyInjectors... >)
	{
		return make_function(L, f, typename detail::call_types<F>::signature_type(), meta::type_list< PolicyInjectors... >());
	}
Esempio n. 30
0
  static object make()
  {
    return make_function(call, default_call_policies(),
			    (arg("input1"), arg("input2"), arg("output")=object()));
  }