31 from bisect
import bisect_left
72 "Print Eigen Matrix or Array of some kind"
75 "Extract all the necessary information"
82 if type.code == gdb.TYPE_CODE_REF:
84 self.
type = type.unqualified().strip_typedefs()
86 regex = re.compile(
'<.*>')
87 m = regex.findall(tag)[0][1:-1]
88 template_params = m.split(
',')
89 template_params = [x.replace(
" ",
"")
for x
in template_params]
91 if template_params[1] ==
'-0x00000000000000001' or template_params[1] ==
'-0x000000001' or template_params[1] ==
'-1':
92 self.
rows = val[
'm_storage'][
'm_rows']
94 self.
rows =
int(template_params[1])
96 if template_params[2] ==
'-0x00000000000000001' or template_params[2] ==
'-0x000000001' or template_params[2] ==
'-1':
97 self.
cols = val[
'm_storage'][
'm_cols']
99 self.
cols =
int(template_params[2])
102 if len(template_params) > 3:
103 self.
options = template_params[3];
113 if self.
data.type.code == gdb.TYPE_CODE_STRUCT:
118 def __init__ (self, rows, cols, dataPtr, rowMajor):
127 item = self.
dataPtr.dereference()
130 return (
'[%d]' % (row,), item)
132 return (
'[%d]' % (col,), item)
133 return (
'[%d,%d]' % (row, col), item)
143 "Print an Eigen SparseMatrix"
146 "Extract all the necessary information"
149 if type.code == gdb.TYPE_CODE_REF:
151 self.
type = type.unqualified().strip_typedefs()
153 regex = re.compile(
'<.*>')
154 m = regex.findall(tag)[0][1:-1]
155 template_params = m.split(
',')
156 template_params = [x.replace(
" ",
"")
for x
in template_params]
159 if len(template_params) > 1:
160 self.
options = template_params[1];
182 outer = row
if self.
rowMajor else col
183 inner = col
if self.
rowMajor else row
184 start = self.
val[
'm_outerIndex'][outer]
185 end = ((start + self.
val[
'm_innerNonZeros'][outer])
if self.
val[
'm_innerNonZeros']
else
186 self.
val[
'm_outerIndex'][outer+1])
189 data = self.
val[
'm_data']
192 elif (end > start)
and (inner == data[
'm_indices'][end-1]):
193 item = data[
'm_values'][end-1]
196 indices = [data[
'm_indices'][x]
for x
in range(
int(start),
int(end)-1)]
198 idx =
int(start) + bisect_left(indices, inner)
199 if ((idx < end)
and (data[
'm_indices'][idx] == inner)):
200 item = data[
'm_values'][idx]
204 return (
'[%d,%d]' % (row, col), item)
214 return self.
val[
'm_outerSize']
if self.
rowMajor else self.
val[
'm_innerSize']
217 return self.
val[
'm_innerSize']
if self.
rowMajor else self.
val[
'm_outerSize']
222 status = (
"not compressed" if self.
val[
'm_innerNonZeros']
else "compressed")
225 dimensions =
"%d x %d" % (self.
rows(), self.
cols())
226 layout =
"row" if self.
rowMajor else "column"
228 return "Eigen::SparseMatrix<%s>, %s, %s major, %s" % (
229 self.
innerType, dimensions, layout, status )
232 "Print an Eigen Quaternion"
235 "Extract all the necessary information"
238 if type.code == gdb.TYPE_CODE_REF:
240 self.
type = type.unqualified().strip_typedefs()
245 self.
data = self.
val[
'm_coeffs'][
'm_storage'][
'm_data'][
'array']
268 item = self.
dataPtr.dereference()
277 return "Eigen::Quaternion<%s> (data ptr: %s)" % (self.
innerType, self.
data)
281 pretty_printers_dict[re.compile(
'^Eigen::Matrix<.*>$')] =
lambda val:
EigenMatrixPrinter(
"Matrix", val)
283 pretty_printers_dict[re.compile(
'^Eigen::Array<.*>$')] =
lambda val:
EigenMatrixPrinter(
"Array", val)
286 "Register eigen pretty-printers with objfile Obj"
290 obj.pretty_printers.append(lookup_function)
293 "Look-up and return a pretty-printer that can print va."
297 if type.code == gdb.TYPE_CODE_REF:
300 type = type.unqualified().strip_typedefs()
306 for function
in pretty_printers_dict:
307 if function.search(typename):
308 return pretty_printers_dict[function](val)
312 pretty_printers_dict = {}
314 build_eigen_dictionary ()