mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-07 13:41:54 +08:00
Handle row and col major matrices in the gdb pretty printer
This commit is contained in:
parent
4da991eaa8
commit
f0315295e9
@ -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
|
||||||
|
if self.rowMajor == 0:
|
||||||
|
if self.currentCol >= self.cols:
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
self.currentRow = self.currentRow + 1
|
self.currentRow = self.currentRow + 1
|
||||||
if self.currentRow >= self.rows:
|
if self.currentRow >= self.rows:
|
||||||
self.currentRow = 0
|
self.currentRow = 0
|
||||||
self.currentCol = self.currentCol + 1
|
self.currentCol = self.currentCol + 1
|
||||||
|
else:
|
||||||
|
if self.currentRow >= self.rows:
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user