C++ library - Using Quadprog++ and Array.hh - c++

I'm trying to use the Quadprog++ library (http://quadprog.sourceforge.net/) but there is no documentation about it. In particular I'm trying to do the exponential of a matrix with the function of Array.hh (http://bit.ly/Za0k1J) but I have no idea how to write it. I thought to write in this way:
Matrix<double> A;
A.resize(4,4);
A=A^2;
But it doesn't work.
Thanks a lot for the help!

Related

Where in the Eigen source is the sum() function defined for a particular matrix?

I am new to Eigen and trying to get a feel for the layout. I noticed that each matrix has a sum() function that returns the sum of all the coefficients in a given matrix. I was interested in how it was implemented, since I wanted to find the best way to loop through an eigen matrix. I went into the source code and found the following interface in "DenseBase.h":
EIGEN_DEVICE_FUNC Scalar sum() const;
Perhaps I misunderstood how Eigen is designed, but I thought it was the case that all functions were defined in their header files. I also looked in "Matrix.h" and "MatrixBase.h", and was unable to find the implementation. Which header file is the definition in?
The sum() function comes from Eigen::internal::scalar_sum_op<Scalar>() being called through redux in Redux.h. scalar_sum_op is defined in Functors.h. After that I lost interest. I found this two ways. The first was to use Visual Studio and right click on sum() and choosing "Go to Definition", following the trail until I was satisfied. The second was to use grep searching for sum() and again following the trail.
If you read through Redux.h you will get a feel for how the developers did it. They spend considerable effort vectorizing and unrolling things to make them work fast. I would say the best way to loop through an Eigen matrix is to use the provided interfaces to do what you want. I doubt you have a use case that has not been covered by the interface somehow.

Complex Digamma Function

Do you know a c++ library where the Digamma Function (http://en.wikipedia.org/wiki/Digamma_function) is implemented with complex arguments?
I did not find a library, but google found this for me:
GammaFunctions.c++
However I did not check the validity of this code.
Try one of these:
GSL - GNU Scientific Library contains gsl_sf_complex_psi_e.
http://www.ensta-paristech.fr/~lunevill/doc_melina++_v039/src/special_functions/GammaFunctions.c++.html
http://www.mathworks.com/matlabcentral/fileexchange/978-special-functions-math-library/content/psi.m - You'll need to convert this to C++.
http://www.netlib.no/netlib/slatec/fnlib/cpsi.f - You'll need to convert this to C++.

Swig wrapping GLM library

I am working on a 2D game engine at the moment and have hit a stumbling block whilst implementing the LUA scripting / Interpreter.
I'm using SWIG and have got the basics all working fine.
In the engine I use the GLM (OpenGL Mathematics Libary http://glm.g-truc.net/) for all Vector and Matrix related areas.
I really need to expose glm (at a basic level) to the via SWIG to LUA so I can call methods in LUA like:
actor:GetPosition() <- Which returns a glm::vec2
GLM is quite a complex library (possibly an understatement lol) and I do not require the whole thing exposed, that would be ridiculous amounts of work I assume. I simply want to be able to access the xy components of the glm::vec2 class.
I'm sure this must be easy as SWIG doesn't require a full class definition and there must be a way to let SWIG just assume that the glm::vec2 class just has x,y params.
I'm not sure If using Proxy classes in SWIG is the way to do this ? or some other method ? I'm quite new to LUA integration and SWIG also.
One route I really don't want to go down is ditching GLM and writing my own Vector/Matrix library which is much more simple, no templates etc and I can then simply wrap with SWIG, but I feel this would be a waste of time and I would ultimately end up with a less powerful Math Library :(.
Thanks in advance and I can provide more info if necessary.
The big problem with GLM is that its vector types use things that have dubious C++ validity. Things that many compilers will allow, but are not allowed by the standard. SWIG uses its own parser to work, so it's going to have a hard time making heads or tails of GLM's definitions.
In a case like this, I would suggest using something like Luabind rather than SWIG. It gives a bit more fine-grained control in such circumstances, and it has the benefit of not using its own parser. Granted, you could effectively rewrite the prototypes for the important parts of GLM in your .swig file.
A solution in luabind would look like this:
#include <luabind/luabind.hpp>
extern "C" int init(lua_State* L)
{
using namespace luabind;
using namespace glm;
open(L);
module(L)
[
class_<dvec2>("dvec2")
.def_readwrite("x", &dvec2::x)
.def_readwrite("y", &dvec2::y)
];
return 0;
}

Making a passthrough interface to library

Sorry if this question has been asked before. I'm really not sure how to search for it.
What I'm trying to do is build up a library of functions for myself to make life easier in my future school work. I built up a set of functions that handle Geometry based things, like 3D vectors and points and planes along with all of their associated methods (dot, cross, scale).
Through some googling, I found the Eigen library which implements everything I want, including alot of SSE stuff to make it fast.
I don't understand SSE and alot of the stuff they did in that library, so I don't want to use it as my development library. What I mean by that is, I want to code everything using my dumb, slow versions that I know how they work so I can make sure I'm doing everything right. Then once I'm sure the math is coming out right, I'd like to switch it over to using the Eigen library for efficiency.
Is there some way to make it so I can set a flag, or pass a variable, (maybe some template thing?) so that I can switch my code from my stuff to the Eigen stuff without having to rewrite my applications?
Basically I'd like to make a standard interface between the two libraries.
The Eigen library code would be included in the same directory. I'd have my Geometry.h, and then a Eigen folder that contains all of that library.
I don't know how to bridge the gap between the two. Would I need to write wrapper methods for all of their stuff so it has a common API?
EDIT ::
I should also add that I'd like this to be as fast as possible. For things like dot, cross, and matrix functions that could get called many times, I'd like to not have to go through virtual functions or too complex of wrapper methods that could negatively impact performance.
Am I asking too much?
END EDIT
Something like this is what I want in effect. But I'm pretty sure this doesn't do what I want.
#ifdef BASIC_LIBRARY
class Vector3
{
float x,y,z;
float dot(Vector3);
}
#endif
#ifdef EIGEN_LIBRARY
//some sort of passthrough to eigen library
#endif
I'd suggest using namespaces for this:
namespace geometry {
class Vector3 {
...
};
}
namespace eigen {
using geometry::Vector3;
...
}
Basically this would allow you to define your basic geometry types & operations, and then use selected portions directly from within the other namespace.

what median_unsafe in C++ mean

I run into a C++ code:
vector<double> PITs;
if(PITs.size() > 0) PIT = util::median_unsafe(PITs);
What is mean by util::median_unsafe, why I cant find it in C++ reference? thanks
Maybe because it is not a part of C++ standard library. It is probably something from another part of the code you have. If you use some IDE it probably supports something like "GoTo Declaration/Definition", so you might be able to find out where that function comes from.