How to bind functions which accepts types from external libraries - pybind11

I am trying to bind a function which accepts Gst Buffer as follows
some_function(GstBuffer *buffer)
m.def(some_function,&some_function);
binded it using the above code, when called from python it says
some_function accpets args0:_GstBuffer type, it doens't accpet a python type of Gst.Buffer object.
I have tried to put
GST=py::module::import('gi.repository.Gst') but it didn't work, is there any other way to resolve this problem.
thanks

If you want to bind function which accepts type uknown to pybind you can pass it as generic py::object argument.
m.def("some_function",
[](py::object obj){
...
});
Now can use python interface of the passed py::object in your function. But I guess it's not what you want to do on C++ side.
The problem is in conversion from python-wrapper-around-c++-object to pure-c++-object.
pybind doesn't know the layout of passed wrapper and unable to extract pure C++ part from python object. This is true when you are using types which are binded NOT by pybind (such as gi.repository.Gst).
To get the C++ part of py::object you need to know where C++ part resides. You either need to do it manually or with help of another binding library.

Related

Access to Bind Parameters in MyBatis Interceptor

How do I read the bind parameters inside a MyBatis Interceptor? I'm trying to extract those information so I can write them to a log table.
The guide (http://www.mybatis.org/mybatis-3/configuration.html) didn't mention how to get them, and the JavaDoc (http://www.mybatis.org/mybatis-3/es/apidocs/org/apache/ibatis/mapping/BoundSql.html) does not have a single line of comment. I saw an example on SO about constructing a new BoundSql but that isn't what I needed.
I tried to test what contents are stored in BoundSql.getParameterMappings() and BoundSql.getParameterObject(), but it seems to be pretty complex. There's JavaType and JdbcType, and if there's only one parameter the ParameterObject isn't a Map object.
What is the proper way to get the bind parameters from BoundSql?
After going through MyBatis source code (where comment is an endangered species), I found out how MyBatis processes the bind parameters. However, that requires access to the JDBC Statement object, which is simply not available inside an Interceptor.
Then I did some testing and settled on this:
If there is only a single parameter, BindSql.getParameterObject() will give you the parameter itself. By using BindSql.getParameterMappings() and ParameterMapping.getJavaType() I can tell which Java class the parameter is.
If there are more than one parameter, BindSql.getParameterObject() will return an instance of org.apache.ibatis.binding.MapperMethod.ParamMap, which extends HashMap, or it will be an instance of the DTO you used. Using .getProperty() from ParameterMapping as key or as getter name, you can process the bind parameters one by one.
If anyone has a better way to do this, I'm all ears.

Xtext: Arithmetic example: What uses the calculator class and how?

Ive been looking at the Arithmetics example that comes with xtext and I stumbled upon the Calculator.java class under the org.eclipse.xtext.example.arithmetics.interpreter package but I cannot find any reference to it.
I understand that this class is used to walk the AST and evaluate the expressions but who is calling it and how is it registered?
I have a similar example which I am setting up from scratch and using the arithmetics as an example, however I dont know how to register the AST walker so that each time a tree is visited the particular method is triggered as in the Calculator class.
If you right-click the Calculator class (either directly within the Java Editor or in the Package Explorer) and select References -> Workspace you will get listed all occurrences of the Calculator type. You'll see that it is used in the ArthimeticsValidator and InterpreterAutoEdit types, where the latter is responsible for actually evaluating an expression within its evaluate method. From the InterpreterAutoEdit class, you can work your way up and see that it is registered via the ArthimeticsUiModule.

What arguments should be passed to (wekaCategoricalData)?

I am trying to use the Information Gain algorithm available in here, which is implemented in Matlab and it uses Weka java classes. However, I get the following problem when trying to run the code:
Undefined function 'wekaCategoricalData' for input arguments of type 'double'.
The code line which generates the error is this:
t.buildEvaluator(wekaCategoricalData(X, SY2MY(Y)));
SY2MY is just a transformation function and it is described here.
The algorithm apparently expects an argument of the type (spider data object), which I have no idea what it is exactly. There appears to be something wrong with the number of the arguments sent as well.
Any help is appreciated.
According the readme file included with the package, you need to run the load_fspackage.m script on initial installation of the "Feature Selection Package".
This will setup various M-file on the MATLAB path, as well as add the required Weka JAR-file to the Java classpath.

Using a dll file in matlab code

I need to use a function in Matlab that is defined by a dll file. I got an example that guy converted a dll to mexw32 file but i have known how I do this. I tried use loadlibrary but it didn't create any file.
How I can do this?
loadlibrary is MATLAB's implementation of FFI services, a mechanism of calling functions in external shared libraries. It involves converting between C-types and their equivalent MATLAB data types to pass data around.
MEX-files are also a kind of dynamically linked libraries (with .mex* extension), that can be run directly in MATLAB as a regular function without any special syntax.
The difference is that it has a specific gateway routine called mexFunction, which receives both input and output as mxArray type. mxArray is an opaque type defined in mex.h header file, which is the fundamental type underlying all MATLAB data. You usually manipulate this data using functions in the MEX library API.

How to resolve bindings during execution with embedded Python?

I'm embedding Python into a C++ application. I plan to use PyEval_EvalCode to execute Python code, but instead of providing the locals and globals as dictionaries, I'm looking for a way to have my program resolve symbol references dynamically.
For example, let's say my Python code consists of the following expression:
bear + lion * bunny
Instead of placing bear, lion and bunny and their associated objects into the dictionaries that I'm passing to PyEval_EvalCode, I'd like the Python interpreter to call back my program and request these named objects.
Is there a way to accomplish this?
By providing the locals and globals dictionaries, you are providing the environment in which the evaled code is executed. That effectively provides you with an interface to map names to objects defined in the C++ app.
Can you clarify why you do not want to use the dictionaries?
Another thing you could do is process the string in C++ and do string substitution before you eval the code....
Possibly. I've never tried this but in theory you might be able to implement a small extension class in C++ that overrides the __getattr__ method (probably via the tp_as_mapping or tp_getattro function pointers of PyTypeObject). Pass an instance of this as locals and/or globals to PyEval_EvalCode and your C++ method should be asked to resolve your lions, tigers, & bears for you.