Hi Felix, On 2013-11-20, Felix Breuer <fe...@fbreuer.de> wrote: > If I am reading this correctly, this means that most of the time (~10 > seconds) is not spent doing the actual computation (using foo and bar) but > simply creating vectors and read/writing values to/from vectors (in > apply_map). (Do something like return vector((foo(vi,d) for vi in v)) instead > of apply_map does not make much a difference.) > > > Now, my questions are: > > 1) Why is this so slow? Am I missing something here?
I did not read your example in detail, but when you do "vector((foo(vi,d) for vi in v))" then a lot of computations are to do behind the scenes, some of them probably useless for your applications. You can read the source code by evaluating vector?? or just the documentation by evaluating vector? First, the input needs to be checked. This is expensive, because a vector can be provided by different types of data. Secondly, a vector is an element of a vector space. Hence, the vector space needs to be created. Since you don't explicitly provide the field containing the return values of foo(vi,d), Sage needs to determine this field all by itself, in order to create the vector space. And then, each vector needs to be initialised as such. This probably takes a lot longer than, say, creating a Python tuple. > 2) Is there anything I can do to improve performance? It depends on what you really need. - Do you really need vectors in the sense stated above (namely: elements of a vector space)? If you just need tuples, then use tuples. If you really need vectors, you could try to help Sage: - If you know both the underlying field (say, K) and the number of entries of your vector (say, n), then you should provide this information to the "vector" function, namely vector(K, n, <list or iterator of the entries>) - If you actually know the vector space (i.e., if the vector space is always the same, say, V), then you can create your vectors directly as elements of V, namely V(<list of the entries>) (could be that an iterator won't work here). Best regards, Simon -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/groups/opt_out.