1 | initial version |
(answer to a previous comment by @kcrisman)
Well, using IntegerVectors
is not straightforward since, when we want to use IntegerVectors
as a tool to generate vectors, it seems that we need to specify the sum of the components, hence we have to chain all possible sums (from 0
to n*q
):
sage: import itertools
sage: multicartvectint = lambda n,q : itertools.chain.from_iterable([IntegerVectors(i,n,max_part=q) for i in range(n*q+1)])
This works as well (the order will be different), but seems slower than using cartesian_product_iterator()
:
sage: timeit('list(multicartvectint(5,5))')
5 loops, best of 3: 3.14 s per loop
sage: timeit('list(multicartvect(5,5))')
5 loops, best of 3: 1.15 s per loop
sage: timeit('list(multicartvectint(6,6))')
5 loops, best of 3: 46.5 s per loop
sage: timeit('list(multicartvect(6,6))')
5 loops, best of 3: 18.3 s per loop
2 | No.2 Revision |
(answer to a previous comment by @kcrisman)
Well, using IntegerVectors
is not straightforward since, when we want to use IntegerVectors
as a tool to generate vectors, it seems that we need to specify the sum of the components, hence we have to chain all possible sums (from 0
to n*q
):
sage: import itertools
sage: multicartvectint = lambda n,q : itertools.chain.from_iterable([IntegerVectors(i,n,max_part=q) for i in range(n*q+1)])
This works as well (the order ordering will be different), but seems slower than using cartesian_product_iterator()
:
sage: timeit('list(multicartvectint(5,5))')
5 loops, best of 3: 3.14 s per loop
sage: timeit('list(multicartvect(5,5))')
5 loops, best of 3: 1.15 s per loop
sage: timeit('list(multicartvectint(6,6))')
5 loops, best of 3: 46.5 s per loop
sage: timeit('list(multicartvect(6,6))')
5 loops, best of 3: 18.3 s per loop