Multilinear Sparse
Sparse tensor arithmetic.
Prefixed by tens... (tensor - sparse).
Handle sparse multiaxis tensors, that for example represent multivariate polynomials.
Sparse tensors are accepted and returned as dicts whos keys are trimmed (no trailing zeros), non-negative int tuples.
creation
tenszero = {}
Zero tensor.
An empty dictionary: {}.
tensbasis(i, c=1)
Return a basis tensor.
Returns a dictionary with a single element i:c.
Source code in vector\multilinear_sparse\creation.py
21 22 23 24 25 26 27 28 29 30 | |
tensrand(*d)
Return a random tensor 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\multilinear_sparse\creation.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
tensrandn(*d, mu=0, sigma=1)
Return a random tensor of normal sampled float coefficients.
The coefficients are sampled from a normal distribution.
Notes
Naming like numpy.random,
because seems more concise (not random & gauss as in the stdlib).
Source code in vector\multilinear_sparse\creation.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
conversion
tenstod(t, zero=0)
Return a sparse tensor (dict) as a dense tensor (numpy.ndarray).
Source code in vector\multilinear_sparse\conversion.py
11 12 13 14 15 16 | |
tendtos(t)
Return a dense tensor (numpy.ndarray) as a sparse tensor (dict).
The resulting dict is not trimmed.
Source code in vector\multilinear_sparse\conversion.py
18 19 20 21 22 23 | |
utility
tensrank(t)
Return the rank.
Source code in vector\multilinear_sparse\utility.py
13 14 15 16 17 18 19 20 | |
tensdim(t)
Return the dimensionalities.
Source code in vector\multilinear_sparse\utility.py
22 23 24 25 26 27 28 29 | |
tenseq(s, t)
Return whether two tensors are equal.
Source code in vector\multilinear_sparse\utility.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
tenstrim(t, tol=None)
Remove all near zero (abs(t_i)<=tol) coefficients.
tol may also be None,
then all coefficients that evaluate to False are trimmed.
Notes
- Cutting of elements that are
abs(t_i)<=tolinstead ofabs(t_i)<tolto allow cutting of elements that are exactly zero bytrim(t, 0)instead oftrim(t, sys.float_info.min).
Source code in vector\multilinear_sparse\utility.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
tensitrim(t, tol=None)
Remove all near zero (abs(t_i)<=tol) coefficients.
tol may also be None,
then all coefficients that evaluate to False are trimmed.
Notes
- Cutting of elements that are
abs(t_i)<=tolinstead ofabs(t_i)<tolto allow cutting of elements that are exactly zero bytrim(t, 0)instead oftrim(t, sys.float_info.min).
Source code in vector\multilinear_sparse\utility.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
tensrshift(t, n)
Shift coefficients up.
Source code in vector\multilinear_sparse\utility.py
88 89 90 91 92 | |
tenslshift(t, n)
Shift coefficients down.
Source code in vector\multilinear_sparse\utility.py
94 95 96 97 98 99 100 101 | |
hilbert_space
tensconj(t)
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\multilinear_sparse\hilbert_space.py
9 10 11 12 13 14 15 16 17 18 19 | |
tensiconj(t)
Complex conjugate.
Tries to call a method conjugate on each element.
If not found, simply keeps the element as is.
Source code in vector\multilinear_sparse\hilbert_space.py
21 22 23 24 25 26 27 28 29 30 31 32 33 | |
vector_space
tenspos(t)
Return the identity.
Source code in vector\multilinear_sparse\vector_space.py
15 16 17 18 19 20 21 22 | |
tensipos(t)
Apply unary plus.
Source code in vector\multilinear_sparse\vector_space.py
24 25 26 27 28 29 30 31 32 33 | |
tensneg(t)
Return the negation.
Source code in vector\multilinear_sparse\vector_space.py
35 36 37 38 39 40 41 42 | |
tensineg(t)
Negate.
Source code in vector\multilinear_sparse\vector_space.py
44 45 46 47 48 49 50 51 52 53 | |
tensadd(*ts)
Return the sum.
See also
- for sum on a single coefficient:
tensaddc
Source code in vector\multilinear_sparse\vector_space.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
tensiadd(s, *ts)
Add.
See also
- for sum on a single coefficient:
tensiaddc
Source code in vector\multilinear_sparse\vector_space.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
tensaddc(t, c, i=())
Return the sum with a basis tensor.
See also
- for sum on more coefficients:
tensadd
Source code in vector\multilinear_sparse\vector_space.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
tensiaddc(t, c, i=())
Add a basis tensor.
See also
- for sum on more coefficients:
tensiadd
Source code in vector\multilinear_sparse\vector_space.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
tenssub(s, t)
Return the difference.
See also
- for difference on a single coefficient:
tenssubc
Source code in vector\multilinear_sparse\vector_space.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
tensisub(s, t)
Subtract.
See also
- for difference on a single coefficient:
tensisubc
Source code in vector\multilinear_sparse\vector_space.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
tenssubc(t, c, i=())
Return the difference with a basis tensor.
See also
- for difference on more coefficients:
tenssub
Source code in vector\multilinear_sparse\vector_space.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
tensisubc(t, c, i=())
Subtract a basis tensor.
See also
- for difference on more coefficients:
tensisub
Source code in vector\multilinear_sparse\vector_space.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
tensmul(t, a)
Return the product.
Source code in vector\multilinear_sparse\vector_space.py
201 202 203 204 205 206 207 208 | |
tensrmul(a, t)
Return the product.
Source code in vector\multilinear_sparse\vector_space.py
210 211 212 213 214 215 216 217 | |
tensimul(t, a)
Multiply.
Source code in vector\multilinear_sparse\vector_space.py
219 220 221 222 223 224 225 226 227 228 | |
tenstruediv(t, a)
Return the true quotient.
Source code in vector\multilinear_sparse\vector_space.py
230 231 232 233 234 235 236 237 | |
tensitruediv(t, a)
True divide.
Notes
Why called truediv instead of div?
divwould be more appropriate for an absolutely 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\multilinear_sparse\vector_space.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
tensfloordiv(t, a)
Return the floor quotient.
Source code in vector\multilinear_sparse\vector_space.py
261 262 263 264 265 266 267 268 | |
tensifloordiv(t, a)
Floor divide.
Source code in vector\multilinear_sparse\vector_space.py
270 271 272 273 274 275 276 277 278 279 | |
tensmod(t, a)
Return the remainder.
Source code in vector\multilinear_sparse\vector_space.py
281 282 283 284 285 286 287 288 | |
tensimod(t, a)
Mod.
Source code in vector\multilinear_sparse\vector_space.py
290 291 292 293 294 295 296 297 298 299 | |
tensdivmod(t, a)
Return the floor quotient and remainder.
Source code in vector\multilinear_sparse\vector_space.py
301 302 303 304 305 306 307 308 309 310 311 | |
elementwise
tenshadamard(*ts)
Return the elementwise product.
Source code in vector\multilinear_sparse\elementwise.py
11 12 13 14 15 16 17 18 19 20 21 22 23 | |
tenshadamardtruediv(s, t)
Return the elementwise true quotient.
Source code in vector\multilinear_sparse\elementwise.py
25 26 27 28 29 30 31 32 | |
tenshadamardfloordiv(s, t)
Return the elementwise floor quotient.
Source code in vector\multilinear_sparse\elementwise.py
34 35 36 37 38 39 40 41 | |
tenshadamardmod(s, t)
Return the elementwise remainder.
Source code in vector\multilinear_sparse\elementwise.py
43 44 45 46 47 48 49 50 | |
tenshadamarddivmod(s, t)
Return the elementwise floor quotient and remainder.
Source code in vector\multilinear_sparse\elementwise.py
52 53 54 55 56 57 58 59 60 61 62 63 | |
tenshadamardmin(*ts, key=None)
Return the elementwise minimum.
Source code in vector\multilinear_sparse\elementwise.py
65 66 67 68 69 70 71 72 73 74 75 76 77 | |
tenshadamardmax(*ts, key=None)
Return the elementwise maximum.
Source code in vector\multilinear_sparse\elementwise.py
79 80 81 82 83 84 85 86 87 88 89 90 91 | |