use type signature in functions for matrix and vector
Hi,
I'm trying to create a function that takes a vector and a matrix. I want to explicitly used typed variables but I'm not sure what to type for the types matrix and vector.
Example with : fun(i:int): return 0
So what is the equivalent for this with func(M, V)
? I tried func(M: matrix, V :vector)
and func(M: sage.matrix, V :sage.vector)
but both gave : "name 'matrix' is not defined"
Thanks in advance
Welcome to Ask Sage!
Thank you for your question!
It seems you opened two accounts and asked the question twice, here and at
Sorry that our moderation takes a little time.
Hello, @mocha! I am not very versed on type hinting in Python. please, let me know if this solves your problem, so i can elaborate it and post it as an answer.
You can exploit the
type()
function for this purpose. For example, defineand then write
type(v)
in order to know the specific data type. In this particular case, it issage.modules.vector_integer_dense.Vector_integer_dense
. Of course, this is way too long to be practical, so maybe you could simply make something likemyVector = sage.modules.vector_integer_dense.Vector_integer_dense
and then usemyVector
for short.Do be careful with using
myVector
arbitrarily. For example,vector([1., 2., 3.])
is of typesage.modules.free_module_element.FreeModuleElement_generic_dense
.I hope this helps!
Sorry for the duplicate, I got a message that my first post was flagged as spam, so I thought It didn't pass trough. I removed the other post.
Thanks a lot for your reply. This is actually what I have done but I was looking for a shorter syntax. For example for the type "sage.rings.integer.Integer" it's enough to use "int" so I was wondering if there is a similarly short way to achieve this for matrix and vector types.