Ask Your Question

subclass from a sage vector

asked 2012-11-07 08:04:38 -0500

Mathmon gravatar image

updated 2012-11-07 08:06:11 -0500

Hello all,

I have another question regarding the vector class shipped with sage. I would like to add some properties to a vector to store some additional information. But I am not sure which class I should choose as a base class, since there are a lot of different vector classes:

sage: type(vector([1.123,324.1]))
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>
sage: type(vector([1,2]))        
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>
sage: type(vector([1,6/2]))
<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>

Do I have to pick one of those classes (I excpect a real vector would do OK) or is it possible to subclass in such a way that I can have different base_ring()s for my class?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-11-07 16:30:01 -0500

Jason Grout gravatar image

It sounds like the easiest thing to do is to make your class a subclass of the particular type you are talking about. Alternatively, I think you could make a new python "mixin" class that has the attributes that you want and then make a subclass of each vector class that also inherits from your "mixin".

edit flag offensive delete link more


Could you provide me with some example code? I am not sure about how to call the constructor of the FreeModuleElement_generic_dense class

Mathmon gravatar imageMathmon ( 2012-11-07 22:22:20 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-11-07 08:04:38 -0500

Seen: 71 times

Last updated: Nov 07 '12