3.2.3 Matrix or Vector from Object

Provide a _matrix_ method for an object that can be coerced to a matrix over a ring $ R$ . Then the Sage function matrix will work for this object.

The following is from SAGE_ROOT/devel/sage/sage/graphs/graph.py:

class GenericGraph(SageObject):
    ...
    def _matrix_(self, R=None):
        if R is None:
            return self.am()
        else:
            return self.am().change_ring(R)


    def adjacency_matrix(self, sparse=None, boundary_first=False):
        ...

Similarly, provide a _vector_ method for an object that can be coerced to a vector over a ring $ R$ . Then the Sage function vector will work for this object.

See About this document... for information on suggesting changes.