Attributes of daebuilder class of casadi - python-2.7

I am trying to convert implicit DAE or semi-explicit DAE into explicit ODE using DAEbuilder class of casadi in python. I cannot find proper documentation for this class which is difficult to find the attributes. Can someone help on this matter?

Related

Spawn Blueprint Class with input parameters C++

I am fairly new to UE4 development so apologies if I am missing something obvious.
I am trying to convert a system from blueprints to C++. In an attempt to convert the SpawnActor node, I found that I am unable to provide input parameters like in the image below where ‘Index’ is a custom input.
In other places, to resolve this issue, I have used BeginDeferredActorSpawnFromClass, used an initialise function to provide parameters, then call FinishSpawningActor. This has worked where I am calling a C++ class.
In this case however, the actor I want to spawn is a blueprint class which is a child based on a C++ class. I am unable to implement BeginDeferredActorSpawnFromClass for this, and therefore am not sure how to pass my parameter to this.
For extra context, in the project there can be multiple characters spawned in the world. I want to pass the index of the character in order to set the material colour of each individual character using the nodes shown below.
I am able to achieve this by spawning the BP character using:
Character = GetWorld()->SpawnActor(...)
Character->Index = Index
And then using EventTick instead of EventBeginPlay but feel this is a bad solution. I would appreciate if someone could advise how to initialise the spawned actor with the required parameter.
Thanks in advance.
I was being stupid. SpawnActorDeferred is the function which serves the purpose required.

Specify typing for Django field in model (for Pylint)

I have created custom Django model-field subclasses based on CharField but which use to_python() to ensure that the model objects returned have more complex objects (some are lists, some are dicts with a specific format, etc.) -- I'm using MySQL so some of the PostGreSql field types are not available.
All is working great, but Pylint believes that all values in these fields will be strings and thus I get a lot of "unsupported-membership-test" and "unsubscriptable-object" warnings on code that uses these models. I can disable these individually, but I would prefer to let Pylint know that these models return certain object types. Type hints are not helping, e.g.:
class MealPrefs(models.Model):
user = ...foreign key...
prefs: dict[str, list[str]] = \
custom_fields.DictOfListsExtendsCharField(
default={'breakfast': ['cereal', 'toast'],
'lunch': ['sandwich']},
)
I know that certain built-in Django fields return correct types for Pylint (CharField, IntegerField) and certain other extensions have figured out ways of specifying their type so Pylint is happy (MultiSelectField) but digging into their code, I can't figure out where the "magic" specifying the type returned would be.
(note: this question is not related to the INPUT:type of Django form fields)
Thanks!
I had a look at this out of curiosity, and I think most of the "magic" actually comes for pytest-django.
In the Django source code, e.g. for CharField, there is nothing that could really give a type hinter the notion that this is a string. And since the class inherits only from Field, which is also the parent of other non-string fields, the knowledge needs to be encoded elsewhere.
On the other hand, digging through the source code for pylint-django, though, I found where this most likely happens:
in pylint_django.transforms.fields, several fields are hardcoded in a similar fashion:
_STR_FIELDS = ('CharField', 'SlugField', 'URLField', 'TextField', 'EmailField',
'CommaSeparatedIntegerField', 'FilePathField', 'GenericIPAddressField',
'IPAddressField', 'RegexField', 'SlugField')
Further below, a suspiciously named function apply_type_shim, adds information to the class based on the type of field it is (either 'str', 'int', 'dict', 'list', etc.)
This additional information is passed to inference_tip, which according to the astroid docs, is used to add inference info (emphasis mine):
astroid can be used as more than an AST library, it also offers some
basic support of inference, it can infer what names might mean in a
given context, it can be used to solve attributes in a highly complex
class hierarchy, etc. We call this mechanism generally inference
throughout the project.
astroid is the underlying library used by Pylint to represent Python code, so I'm pretty sure that's how the information gets passed to Pylint. If you follow what happens when you import the plugin, you'll find this interesting bit in pylint_django/.plugin, where it actually imports the transforms, effectively adding the inference tip to the AST node.
I think if you want to achieve the same with your own classes, you could either:
Directly derive from another Django model class that already has the associated type you're looking for.
Create, and register an equivalent pylint plugin, that would also use Astroid to add information to the class so that Pylint know what to do with it.
I thought initially that you use a plugin pylint-django, but maybe you explicitly use prospector that automatically installs pylint-django if it finds Django.
The checker pylint neither its plugin doesn't check the code by use information from Python type annotations (PEP 484). It can parse a code with annotations without understanding them and e.g. not to warn about "unused-import" if a name is used in annotations only. The message unsupported-membership-test is reported in a line with expression something in object_A simply if the class A() doesn't have a method __contains__. Similarly the message unsubscriptable-object is related to method __getitem__.
You can patch pylint-django for your custom fields this way:
Add a function:
def my_apply_type_shim(cls, _context=None): # noqa
if cls.name == 'MyListField':
base_nodes = scoped_nodes.builtin_lookup('list')
elif cls.name == 'MyDictField':
base_nodes = scoped_nodes.builtin_lookup('dict')
else:
return apply_type_shim(cls, _context)
base_nodes = [n for n in base_nodes[1] if not isinstance(n, nodes.ImportFrom)]
return iter([cls] + base_nodes)
into pylint_django/transforms/fields.py
and also replace apply_type_shim by my_apply_type_shim in the same file at this line:
def add_transforms(manager):
manager.register_transform(nodes.ClassDef, inference_tip(my_apply_type_shim), is_model_or_form_field)
This adds base classes list or dict respectively, with their magic methods explained above, to your custom field classes if they are used in a Model or FormView.
Notes:
I thought also about a plugin stub solution that does the same, but the alternative with "prospector" seems so complicated for SO that I prefer to simply patch the source after installation.
Classes Model or FormView are the only classes created by metaclasses, used in Django. It is a great idea to emulate a metaclass by a plugin code and to control the analysis simple attributes. If I remember, MyPy, referenced in some comment here, has also a plugin mypy-django for Django, but only for FormView, because writing annotations for django.db is more complicated than to work with attributes. - I was trying to work on it for one week.

C++ : meta-data information in source code. To see through AST

After parsing, I want to get a meta-data of the source code's field, or method.
The purpose of this is to collect info of the source code after parsing.
In java, I used annotation.
After parsing, I find user-defined annotation on class, field, or method.
Under code is example.
#BizObject //By this annotation I could understand this class is related with bissness.
public class biz ... {
#DI //this field needs Dependency Injection.
public Logger logger;
}
By parsing, I want to collect user-specified meta-info of the source.
How user write the meta-data on the source code?? like java annotation.
I know in C++ there is no direct attribute for this purpose.
I just wondering how to mark meta-data indirectly using other things.
Self response.
I solved this problem by using attribute specifier.
It is similar to Java's annotation.
http://en.cppreference.com/w/cpp/language/attributes
http://www.codesynthesis.com/~boris/blog/2012/04/18/cxx11-generalized-attributes/
https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
By using attribute specifier and CDT parser, I could get meta data related syntax's node.
CDT parser support GNU.

Save CPLEX preprocessing/aggregation

I'm using the C++ CPLEX API to model MILP problems. CPLEX "simplifies" my models before solving them (i.e., via the aggregator, MILP presolve, substitutions, etc.). When I use the exportModel method of the IloCplex class it only considers the original model.
Is it possible to save the reduced model?
Thank you for your help
It is not possible to do this using the C++ API (you don't have access to the presolve model via the object oriented Concert layers). You can do it programmatically with the C Callable Library or the Python API. Alternatively, you can do it manually with the interactive, like so:
CPLEX> read model.sav
CPLEX> write model.lp
CPLEX> write presolved.pre
CPLEX> read presolved.pre
CPLEX> write presolved.lp
This example assumes that you've exported your original model in SAV format. After following those steps, you'd end up with presolved.lp (the presolved model in LP format). If you wanted to do it programmatically (using one of the API's above), you'd follow the same steps.

Custom sorl-thumbnail processor

I found a question (and an answer) related to sorl-thumbnail that looks like a good point related to what I’m looking for :
Image filtering with the new sorl-thumbnail. But my django knowledge is far too weak to understand what I could do with that.
I’d like to extend sorll-thumbnail so that I could process an image before serving it. For example : add a blur effect. I can deal with the image processing part (already done such things with php/imagemagick), but I don’t know where to start to plug my own function above sorl-thumbnail.
In my project, I installed the lib with pip. Where in my code can I create a class/subclass so that I could pass an argument to the templatetag? What should this class look like?
Is the RoundedCornerEngine class described in the mentioned post ok ? Where should I have this code ?
Thanks for your help.
Anywhere… Ok…
The only detail is to correctly link the new Engine from the settings :
THUMBNAIL_ENGINE = "my.module.MyEngine"
If anyone is looking for custom processors, built with PIL on top of sorl-thumbnail, here are two examples : https://gist.github.com/1647660 and https://gist.github.com/1920535.