Handle row and col major matrices in the gdb pretty printer

This commit is contained in:
Benjamin Schindler 2009-12-08 19:12:26 +01:00
parent 4da991eaa8
commit f0315295e9

View File

@ -58,6 +58,11 @@ class EigenMatrixPrinter:
self.rows = int(template_params[1]) self.rows = int(template_params[1])
self.cols = int(template_params[2]) self.cols = int(template_params[2])
self.options = 0 # default value
if len(template_params) > 3:
self.options = template_params[3];
self.rowMajor = (int(self.options) & 0x1)
if self.rows == 10000: if self.rows == 10000:
self.rows = val['m_storage']['m_rows'] self.rows = val['m_storage']['m_rows']
@ -76,26 +81,38 @@ class EigenMatrixPrinter:
self.data = self.data.cast(self.innerType.pointer()) self.data = self.data.cast(self.innerType.pointer())
class _iterator: class _iterator:
def __init__ (self, rows, cols, dataPtr): def __init__ (self, rows, cols, dataPtr, rowMajor):
self.rows = rows self.rows = rows
self.cols = cols self.cols = cols
self.dataPtr = dataPtr self.dataPtr = dataPtr
self.currentRow = 0 self.currentRow = 0
self.currentCol = 0 self.currentCol = 0
self.rowMajor = rowMajor
def __iter__ (self): def __iter__ (self):
return self return self
def next(self): def next(self):
if self.currentCol >= self.cols:
raise StopIteration
row = self.currentRow row = self.currentRow
col = self.currentCol col = self.currentCol
self.currentRow = self.currentRow + 1 if self.rowMajor == 0:
if self.currentRow >= self.rows: if self.currentCol >= self.cols:
self.currentRow = 0 raise StopIteration
self.currentRow = self.currentRow + 1
if self.currentRow >= self.rows:
self.currentRow = 0
self.currentCol = self.currentCol + 1
else:
if self.currentRow >= self.rows:
raise StopIteration
self.currentCol = self.currentCol + 1 self.currentCol = self.currentCol + 1
if self.currentCol >= self.cols:
self.currentCol = 0
self.currentRow = self.currentRow + 1
item = self.dataPtr.dereference() item = self.dataPtr.dereference()
self.dataPtr = self.dataPtr + 1 self.dataPtr = self.dataPtr + 1
@ -104,10 +121,10 @@ class EigenMatrixPrinter:
def children(self): def children(self):
return self._iterator(self.rows, self.cols, self.data) return self._iterator(self.rows, self.cols, self.data, self.rowMajor)
def to_string(self): def to_string(self):
return "Eigen::Matrix<%s,%d,%d> (data ptr: %s)" % (self.innerType, self.rows, self.cols, self.data) return "Eigen::Matrix<%s,%d,%d,%s> (data ptr: %s)" % (self.innerType, self.rows, self.cols, "RowMajor" if self.rowMajor else "ColMajor", self.data)
def build_eigen_dictionary (): def build_eigen_dictionary ():
pretty_printers_dict[re.compile('^Eigen::Matrix<.*>$')] = lambda val: EigenMatrixPrinter(val) pretty_printers_dict[re.compile('^Eigen::Matrix<.*>$')] = lambda val: EigenMatrixPrinter(val)