Lazy
Vector operations as lazy generators.
>>> from vector import veclbasis
>>> veclbasis(3)
<generator object veclbasis at 0x0123456789ABCDEF>
>>> tuple(veclbasis(3))
(0, 0, 0, 1)
Prefixed by vecl... (vector - lazy).
Lazy generator versions of functional.
Different behaviour:
vecrandn: normalisation not possible.
Not implemented lazily:
creation
veclzero()
Zero vector.
Source code in vector\lazy\creation.py
10 11 12 13 14 15 16 17 | |
veclbasis(i, c=1, zero=0)
Return the i-th basis vector times c.
Returns a tuple with i zeros followed by c.
Source code in vector\lazy\creation.py
19 20 21 22 23 24 25 26 27 28 | |
veclbases(start=0, c=1, zero=0)
Yield all basis vectors.
See also
- for single basis vector:
vecbasis
Source code in vector\lazy\creation.py
30 31 32 33 34 35 36 37 38 39 40 41 42 | |
veclrand(n)
Return a random vector of n uniform float coefficients in [0, 1[.
Notes
Naming like in numpy.random, because seems more concise
(not random & gauss as in the stdlib).
Source code in vector\lazy\creation.py
44 45 46 47 48 49 50 51 52 53 54 55 56 | |
veclrandn(n, mu=0, sigma=1)
Return a random vector of n normal distributed float coefficients.
Difference to vecrandn: The vector can't be normalised as it isn't materialised.
Notes
Naming like in numpy.random, because seems more concise
(not random & gauss as in the stdlib).
Source code in vector\lazy\creation.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
utility
vecleq(v, w)
Return if two vectors are equal.
Source code in vector\lazy\utility.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
vecltrim(v, tol=1e-09)
Remove all trailing near zero (abs(v_i)<=tol) coefficients.
Notes
- Cutting of elements that are
abs(vi)<=tolinstead ofabs(vi)<tolto allow cutting of elements that are exactly zero bytrim(v, 0)instead oftrim(v, sys.float_info.min). tol=1e-9like in PEP 485.
Source code in vector\lazy\utility.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
veclround(v, ndigits=None)
Round all coefficients to the given precision.
Source code in vector\lazy\utility.py
50 51 52 53 54 55 56 57 | |
veclrshift(v, n, zero=0)
Pad n many zeros to the beginning of the vector.
Source code in vector\lazy\utility.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
vecllshift(v, n)
Remove n many coefficients at the beginning of the vector.
Source code in vector\lazy\utility.py
75 76 77 78 79 80 81 82 83 84 85 86 | |
hilbert_space
try_conjugate(x)
Return the complex conjugate of a scalar.
Trys to call a method conjugate.
If not found, simply returns the element as is.
Source code in vector\lazy\hilbert_space.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
veclconj(v)
Return the elementwise complex conjugate of a vector.
Trys to call a method conjugate on each element.
If not found, simply keeps the element as is.
Source code in vector\lazy\hilbert_space.py
23 24 25 26 27 28 29 30 31 32 33 | |
vector_space
veclpos(v)
Return the vector with the unary positive operator applied.
Source code in vector\lazy\vector_space.py
13 14 15 16 17 18 19 20 | |
veclneg(v)
Return the vector with the unary negative operator applied.
Source code in vector\lazy\vector_space.py
22 23 24 25 26 27 28 29 | |
vecladd(*vs)
Return the sum of vectors.
Source code in vector\lazy\vector_space.py
31 32 33 34 35 36 37 38 | |
vecladdc(v, c, i=0, zero=0)
Return v with c added to the i-th coefficient.
More efficient than vecladd(v, veclbasis(i, c)).
Source code in vector\lazy\vector_space.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
veclsub(v, w)
Return the difference of two vectors.
Source code in vector\lazy\vector_space.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
veclsubc(v, c, i=0, zero=0)
Return v with c added to the i-th coefficient.
More efficient than veclsub(v, veclbasis(i, c)).
Source code in vector\lazy\vector_space.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
veclmul(a, v)
Return the product of a scalar and a vector.
Source code in vector\lazy\vector_space.py
90 91 92 93 94 95 96 97 | |
vecltruediv(v, a)
Return the true division of a vector and a scalar.
Notes
Why called truediv instead of div?
divwould be more appropriate for an absolute clean mathematical implementation, that doesn't care about the language used. But the package might be used for pure integers/integer arithmetic, so both,truedivandfloordivoperations have to be provided, and none should be privileged over the other by getting the universaldivname.truediv/floordivis unambiguous, like Pythonoperators.
Source code in vector\lazy\vector_space.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
veclfloordiv(v, a)
Return the floor division of a vector and a scalar.
Source code in vector\lazy\vector_space.py
119 120 121 122 123 124 125 126 | |
veclmod(v, a)
Return the elementwise mod of a vector and a scalar.
Source code in vector\lazy\vector_space.py
128 129 130 131 132 133 134 135 | |
vecldivmod(v, a)
Return the elementwise divmod of a vector and a scalar.
Source code in vector\lazy\vector_space.py
137 138 139 140 141 142 143 144 145 | |
elementwise
veclhadamard(*vs)
Return the elementwise product of vectors.
Source code in vector\lazy\elementwise.py
14 15 16 17 18 19 20 21 | |
veclhadamardtruediv(v, w)
Return the elementwise true division of two vectors.
Source code in vector\lazy\elementwise.py
23 24 25 26 27 28 29 30 | |
veclhadamardfloordiv(v, w)
Return the elementwise floor division of two vectors.
Source code in vector\lazy\elementwise.py
32 33 34 35 36 37 38 39 | |
veclhadamardmod(v, w)
Return the elementwise mod of two vectors.
Source code in vector\lazy\elementwise.py
41 42 43 44 45 46 47 48 | |
veclhadamarddivmod(v, w)
Return the elementwise divmod of two vectors.
Source code in vector\lazy\elementwise.py
50 51 52 53 54 55 56 57 | |
veclhadamardmin(*vs, key=None)
Return the elementwise minimum of vectors.
Source code in vector\lazy\elementwise.py
59 60 61 62 63 64 65 66 | |
veclhadamardmax(*vs, key=None)
Return the elementwise maximum of vectors.
Source code in vector\lazy\elementwise.py
68 69 70 71 72 73 74 75 | |