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).
Functions are generators.
Lazy generator versions of dense.
Different behaviour:
vecrandn: normalisation not possible.
Not implemented lazily as these are consumers:
creation
veclzero()
Zero vector.
An empty generator.
Source code in vector\lazy\creation.py
10 11 12 13 14 15 16 17 18 19 | |
veclbasis(i, c=1, zero=0)
Return a basis vector.
Yields i zeros followed by c.
See also
- for all basis vectors:
veclbases
Source code in vector\lazy\creation.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
veclbases(start=0, c=1, zero=0)
Yield all basis vectors.
See also
- for single basis vector:
veclbasis
Source code in vector\lazy\creation.py
36 37 38 39 40 41 42 43 44 45 46 47 48 | |
veclrand(n)
Return a random vector of uniform sampled float coefficients.
The coefficients are sampled from a uniform distribution in [0, 1[.
Notes
Naming like numpy.random,
because seems more concise (not random & gauss as in the stdlib).
Source code in vector\lazy\creation.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
veclrandn(n, mu=0, sigma=1)
Return a random vector of normal sampled float coefficients.
The coefficients are sampled from a normal distribution.
Difference to vecrandn:
The vector can't be normalised as it isn't materialised.
Notes
Naming like numpy.random,
because seems more concise (not random & gauss as in the stdlib).
Source code in vector\lazy\creation.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
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=None)
Remove all trailing near zero (abs(v_i)<=tol) coefficients.
tol may also be None,
then all coefficients that evaluate to False are trimmed.
Notes
- Cutting of elements that are
abs(v_i)<=tolinstead ofabs(v_i)<tolto allow cutting of elements that are exactly zero bytrim(v, 0)instead oftrim(v, sys.float_info.min).
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 49 50 | |
veclrshift(v, n, zero=0)
Shift coefficients up.
Source code in vector\lazy\utility.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
vecllshift(v, n)
Shift coefficients down.
Source code in vector\lazy\utility.py
68 69 70 71 72 73 74 75 76 77 78 79 | |
hilbert_space
veclconj(v)
Return the complex conjugate.
Tries 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
9 10 11 12 13 14 15 16 17 18 19 | |
vector_space
veclpos(v)
Return the identity.
Source code in vector\lazy\vector_space.py
13 14 15 16 17 18 19 20 | |
veclneg(v)
Return the negation.
Source code in vector\lazy\vector_space.py
22 23 24 25 26 27 28 29 | |
vecladd(*vs)
Return the sum.
See also
- for sum on a single coefficient:
vecladdc
Source code in vector\lazy\vector_space.py
31 32 33 34 35 36 37 38 39 40 41 42 | |
vecladdc(v, c, i=0, zero=0)
Return the sum with a basis vector.
More efficient than vecladd(v, veclbasis(i, c)).
See also
- for sum on more coefficients:
vecladd
Source code in vector\lazy\vector_space.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
veclsub(v, w)
Return the difference.
See also
- for difference on a single coefficient:
veclsubc
Source code in vector\lazy\vector_space.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
veclsubc(v, c, i=0, zero=0)
Return the difference with a basis vector.
More efficient than veclsub(v, veclbasis(i, c)).
See also
- for difference on more coefficients:
veclsub
Source code in vector\lazy\vector_space.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
veclmul(v, a)
Return the product.
Source code in vector\lazy\vector_space.py
106 107 108 109 110 111 112 113 | |
veclrmul(a, v)
Return the product.
Source code in vector\lazy\vector_space.py
115 116 117 118 119 120 121 122 | |
vecltruediv(v, a)
Return the true quotient.
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
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
veclfloordiv(v, a)
Return the floor quotient.
Source code in vector\lazy\vector_space.py
144 145 146 147 148 149 150 151 | |
veclmod(v, a)
Return the remainder.
Source code in vector\lazy\vector_space.py
153 154 155 156 157 158 159 160 | |
vecldivmod(v, a)
Return the floor quotient and remainder.
Source code in vector\lazy\vector_space.py
162 163 164 165 166 167 168 169 170 | |
elementwise
veclhadamard(*vs)
Return the elementwise product.
Source code in vector\lazy\elementwise.py
14 15 16 17 18 19 20 21 | |
veclhadamardtruediv(v, w)
Return the elementwise true quotient.
Source code in vector\lazy\elementwise.py
23 24 25 26 27 28 29 30 | |
veclhadamardfloordiv(v, w)
Return the elementwise floor quotient.
Source code in vector\lazy\elementwise.py
32 33 34 35 36 37 38 39 | |
veclhadamardmod(v, w)
Return the elementwise remainder.
Source code in vector\lazy\elementwise.py
41 42 43 44 45 46 47 48 | |
veclhadamarddivmod(v, w)
Return the elementwise floor quotient and remainder.
Source code in vector\lazy\elementwise.py
50 51 52 53 54 55 56 57 | |
veclhadamardmin(*vs, key=None)
Return the elementwise minimum.
Source code in vector\lazy\elementwise.py
59 60 61 62 63 64 65 66 | |
veclhadamardmax(*vs, key=None)
Return the elementwise maximum.
Source code in vector\lazy\elementwise.py
68 69 70 71 72 73 74 75 | |