Ask Your Question
0

subclass from a sage vector

asked 2012-11-07 15:04:38 +0100

Mathmon gravatar image

updated 2012-11-07 15:06:11 +0100

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
0

answered 2012-11-07 23:30:01 +0100

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

Comments

1

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-08 05:22:20 +0100 )edit
Jesus Martinez Garcia gravatar imageJesus Martinez Garcia ( 2019-06-25 23:13:21 +0100 )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

1 follower

Stats

Asked: 2012-11-07 15:04:38 +0100

Seen: 332 times

Last updated: Nov 07 '12