ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 25 Jun 2019 16:13:21 -0500subclass from a sage vectorhttp://ask.sagemath.org/question/9510/subclass-from-a-sage-vector/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?
Wed, 07 Nov 2012 08:04:38 -0600http://ask.sagemath.org/question/9510/subclass-from-a-sage-vector/Answer by Jason Grout for <p>Hello all,</p>
<p>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:</p>
<pre><code>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'>
</code></pre>
<p>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?</p>
http://ask.sagemath.org/question/9510/subclass-from-a-sage-vector/?answer=14238#post-id-14238It 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".
Wed, 07 Nov 2012 16:30:01 -0600http://ask.sagemath.org/question/9510/subclass-from-a-sage-vector/?answer=14238#post-id-14238Comment by Jesus Martinez Garcia for <p>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".</p>
http://ask.sagemath.org/question/9510/subclass-from-a-sage-vector/?comment=47003#post-id-47003@Mathmon Please, see here: https://ask.sagemath.org/question/46995/wrapping-vector-class/Tue, 25 Jun 2019 16:13:21 -0500http://ask.sagemath.org/question/9510/subclass-from-a-sage-vector/?comment=47003#post-id-47003Comment by Mathmon for <p>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".</p>
http://ask.sagemath.org/question/9510/subclass-from-a-sage-vector/?comment=18742#post-id-18742Could you provide me with some example code? I am not sure about how to call the constructor of the FreeModuleElement_generic_dense classWed, 07 Nov 2012 22:22:20 -0600http://ask.sagemath.org/question/9510/subclass-from-a-sage-vector/?comment=18742#post-id-18742