-
-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add helper method to concatenate vectors #36971
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Have you tried something like from itertools import chain
return vector(R, chain(self, other)) It might be faster. At least it could be tested. |
Are you sure we want to have this? |
The checks are not enough for |
Why don't you allow any iterable as I think this would be more practical. Is there any danger of having a result that is invalid but would not raise an error? |
A good reason to have strict specifications is that this could be optimized a lot in subclasses. |
Could you explain how this helps precisely? Or rather, why omitting the checks would make optimisation difficult? |
If you know that other is a free module of the same type, you can use Cython to do something like new_vector = FastVectorConstruction(self._length + other._length)
memcpy(new_vector._data, self._data, self._length * sizeof(mpz_t))
memcpy(new_vector._data + self._data, other._data, other._length * sizeof(mpz_t))
return new_vector |
Checking that two vectors have the same parent can be done efficiently, but checking that two vectors only differ by their dimension is trickier. As far as I know, the sage coercion system is not smart enough for that. |
Yes, but couldn't you do the check in the subclasses you wanted to optimise? (Please excuse my possibly naive questions!) |
I agree with @mantepse about having the general case be as general as possible. Subclasses will have to implement their own version for vectors of the same class, which could then punt up to the base class when the type doesn't match. |
Thanks everyone for the feedback; I gave it another try. |
Documentation preview for this PR (built with commit 4d1f385; changes) is ready! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It says this branch is out-of-date with the base branch, which I assume means it can be merged without conflicts.
The changes look good to me.
Writing
vector(R, list(v) + list(w))
is a common way to concatenate two vectorsv
andw
over some ringR
.In this patch we introduce a simple helper method which allows writing
v.concatenate(w)
instead.