Ask Your Question

Revision history [back]

In Sage, vector is a function, not a class, so you can't inherit from it. You should use Vector instead:

from sage.structure.element import Vector
class OneParamSubgroup(Vector):
    ...

In Sage, vector is a function, not a class, so you can't inherit from it. You should use Vector instead:

from sage.structure.element import Vector
class OneParamSubgroup(Vector):
    ...

I found this by looking at the help for vector (vector?). At the end, it tells me

File:           ..../sage/local/lib/python2.7/site-packages/sage/modules/free_module_element.pyx
Type:           builtin_function_or_method

Actually, Vector may not be perfect. What sort of vectors are you working with? Some other classes may provide more methods. Some examples:

sage: type(vector([1, 2])).mro() # integer entries
[<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>,
 <type 'sage.modules.free_module_element.FreeModuleElement'>,
 <type 'sage.structure.element.Vector'>,
 <type 'sage.structure.element.ModuleElement'>,
 <type 'sage.structure.element.Element'>,
 <type 'sage.structure.sage_object.SageObject'>,
 <type 'object'>]
sage: type(vector([1., 2])).mro() # real
[<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>,
 <type 'sage.modules.free_module_element.FreeModuleElement'>,
 <type 'sage.structure.element.Vector'>,
 <type 'sage.structure.element.ModuleElement'>,
 <type 'sage.structure.element.Element'>,
 <type 'sage.structure.sage_object.SageObject'>,
 <type 'object'>]
sage: type(vector([1/2, 2])).mro() # rational
[<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>,
 <type 'sage.modules.free_module_element.FreeModuleElement'>,
 <type 'sage.structure.element.Vector'>,
 <type 'sage.structure.element.ModuleElement'>,
 <type 'sage.structure.element.Element'>,
 <type 'sage.structure.sage_object.SageObject'>,
 <type 'object'>]

So you could instead inherit from Vector_rational_dense, etc.

In Sage, vector is a function, not a class, so you can't inherit from it. You should use Vector instead:

from sage.structure.element import Vector
class OneParamSubgroup(Vector):
    ...

I found this by looking at the help for vector (vector?). At the end, it tells me

File:           ..../sage/local/lib/python2.7/site-packages/sage/modules/free_module_element.pyx
Type:           builtin_function_or_method

Actually, Vector may not be perfect. What sort of vectors are you working with? Some other classes may provide more methods. Some examples:

sage: type(vector([1, 2])).mro() # integer entries
[<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>,
 <type 'sage.modules.free_module_element.FreeModuleElement'>,
 <type 'sage.structure.element.Vector'>,
 <type 'sage.structure.element.ModuleElement'>,
 <type 'sage.structure.element.Element'>,
 <type 'sage.structure.sage_object.SageObject'>,
 <type 'object'>]
sage: type(vector([1., 2])).mro() # real
[<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>,
 <type 'sage.modules.free_module_element.FreeModuleElement'>,
 <type 'sage.structure.element.Vector'>,
 <type 'sage.structure.element.ModuleElement'>,
 <type 'sage.structure.element.Element'>,
 <type 'sage.structure.sage_object.SageObject'>,
 <type 'object'>]
sage: type(vector([1/2, 2])).mro() # rational
[<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>,
 <type 'sage.modules.free_module_element.FreeModuleElement'>,
 <type 'sage.structure.element.Vector'>,
 <type 'sage.structure.element.ModuleElement'>,
 <type 'sage.structure.element.Element'>,
 <type 'sage.structure.sage_object.SageObject'>,
 <type 'object'>]

So you could instead inherit from Vector_rational_dense, etc.

Edit: to use Vector_rational_dense, you could do this:

from sage.modules.vector_rational_dense import Vector_rational_dense

class test(Vector_rational_dense):
    def __init__(self, parent, value):
        Vector_rational_dense.__init__(self, parent, value)

xi2 = test(QQ**3, [2,2,1])

# or do this:

def vector_constructor(value):
    return test(QQ**len(value), value)

xi3 = vector_constructor([2,2,1])