vector
An infinite-dimensional vector Python package.
>>> from vector import vecadd
>>> vecadd((1, 2), (4, 5, 6))
(5, 7, 6)
>>>
>>> from vector import Vector
>>> v = Vector((1, 2))
>>> w = Vector((4, 5, 6))
>>> v + w
Vector(5, 7, 6, ...)
>>>
>>> from vector import vecnpadd
>>> vecnpadd((1, 2), ((3, 4, 5),
... (6, 7, 8)))
array([[4, 6, 5],
[7, 9, 8]])
Installation
pip install git+https://github.com/goessl/vector.git
Usage
This package includes
- general-purpose functions (prefixed
vec...) in pure Python with perfect complexity, - lazy generators (prefixed
vecl...), - a clean class (
Vector) with easy to use syntax, - improved numpy-routines (prefixed
vecnp...) for parallelised operations & - tensor functions (prefixed
ten...) for multiaxis operations
to handle type-independent, infinite-dimensional vectors. It operates on vectors of different lengths, treating them as infinite-dimensional by assuming that all components after the given ones are zero.
All vectors are zero-indexed.
Design choices
- Integers are the best. As many functions as possible should work with pure integer arithmetic.
- Floats are necessary. (Also let's don't forget about complex numbers.)
When possible, extended precision intermediates are used (
sum,sumprod, ...) - Python allows operator overloading.
Exclusive type arithmetic should be possible (
zero,one&infarguments; ...)
Prefix Design
Could use no prefix to be more mathematically pure, like add instead of
vecadd, but then you would always have to use from vec import add as vecadd
if used with other libraries (like operator).
Also avoids keyword collisions (abs is reserved, vecabs isn't).
Do it like numpy.polynomial.polynomial. ....
Roadmap
-
zipversion betweenzip&zip_longest. Yields different sized tuples. Done: goessl/zipvar -
vecdivmod - docstrings
-
numpyroutines - multiaxis vectors: tensors?
- Absolute type safety.
- Complexity analysis. Perfect complexity
- argument checks
- dimensionality signature (e.g.
vecadd: \(\mathbb{K}^m\times\mathbb{K}^n\to\mathbb{K}^{\max{m, n}}\)) -
vechadamardminmax - never use
numpy.int64, they don't detect overflows - sparse vectors (
dicts) - C++ & Java version
- Ballin
- Fields medal
License (MIT)
Copyright (c) 2022-2025 Sebastian Gössl
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.