Commit 0d3fa271 authored by hjk's avatar hjk

debugger: add dumper for Eigen::Matrix

parent 2b9c0106
......@@ -2295,6 +2295,55 @@ def qdump__QScriptValue(d, item):
d.putSubItem(Item(dd["jscValue"], item.iname, "jscValue", "jscValue"))
#######################################################################
#
# Eigen
#
#######################################################################
def qdump__Eigen__Matrix(d, item):
innerType = templateArgument(item.value.type, 0)
storage = item.value["m_storage"]
options = numericTemplateArgument(item.value.type, 3)
rowMajor = (int(options) & 0x1)
p = storage["m_data"]
if p.type.code == gdb.TYPE_CODE_STRUCT: # Static
nrows = numericTemplateArgument(item.value.type, 1)
ncols = numericTemplateArgument(item.value.type, 2)
p = p["array"].cast(innerType.pointer())
else: # Dynamic
ncols = storage["m_cols"]
nrows = storage["m_rows"]
d.putValue("(%s x %s), %s" % (nrows, ncols, ["ColumnMajor", "RowMajor"][rowMajor]))
d.putField("keeporder", "1")
d.putNumChild(nrows * ncols)
limit = 100
nncols = min(ncols, limit)
nnrows = min(nrows, limit * limit / nncols)
if d.isExpanded(item):
iname = item.iname
with Children(d, nrows * ncols, innerType):
if ncols == 1:
for i in range(0, nnrows):
v = (p + i).dereference()
d.putSubItem(Item(v, item.iname))
elif nrows == 1:
for i in range(0, nncols):
v = (p + i).dereference()
d.putSubItem(Item(v, item.iname))
elif rowMajor == 1:
for i in range(0, nnrows):
for j in range(0, nncols):
name = "[%d,%d]" % (i, j)
v = (p + i * ncols + j).dereference()
d.putSubItem(Item(v, item.iname, None, name))
else:
for j in range(0, nncols):
for i in range(0, nnrows):
name = "[%d,%d]" % (i, j)
v = (p + i * ncols + j).dereference()
d.putSubItem(Item(v, item.iname, None, name))
#######################################################################
......@@ -2445,3 +2494,4 @@ if False:
d.putValue(item.value["type"])
d.putType(" ")
......@@ -90,12 +90,17 @@
#define USE_PRIVATE 1
//#define USE_BOOST 1
//#define USE_EIGEN 1
#if USE_BOOST
#include <boost/optional.hpp>
#include <boost/shared_ptr.hpp>
#endif
#if USE_EIGEN
#include <eigen2/Eigen/Core>
#endif
#if USE_PRIVATE
#include <QtCore/private/qobject_p.h>
#endif
......@@ -142,6 +147,7 @@ int z;
}
}
#if USE_PRIVATE
class DerivedObjectPrivate : public QObjectPrivate
......@@ -2579,8 +2585,35 @@ void testKR()
}
void testEigen()
{
#if USE_EIGEN
using namespace Eigen;
Matrix3d myMatrix = Matrix3d::Constant(5);
MatrixXd myDynamicMatrix(30, 10);
myDynamicMatrix(0, 0) = 0;
myDynamicMatrix(1, 0) = 1;
myDynamicMatrix(2, 0) = 2;
Matrix<double, 2, 1, RowMajor> rowMajorMatrix1;
rowMajorMatrix1 << 34, 44;
Matrix<double, 2, 2, RowMajor> rowMajorMatrix;
rowMajorMatrix << 0, 1, 2, 3;
int i = 0;
++i;
++i;
++i;
#endif
}
int main(int argc, char *argv[])
{
testEigen();
testKR();
int *x = new int(32);
Q_UNUSED(x);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment