Skip to content

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:

Not implemented lazily as these are consumers:

creation

veclzero() -> Generator[Never]

Zero vector.

\[ \vec{0} \qquad \mathbb{K}^0 \]

An empty generator.

Source code in vector\lazy\creation.py
11
12
13
14
15
16
17
18
19
20
def veclzero() -> Generator[Never]:
    r"""Zero vector.

    $$
        \vec{0} \qquad \mathbb{K}^0
    $$

    An empty generator.
    """
    yield from ()

veclbasis(i: int, c: Any = 1, zero: Any = 0) -> Generator[Any]

Return a basis vector.

\[ c\vec{e}_i \qquad \mathbb{K}^{i+1} \]

Yields i zeros followed by c.

See also
Source code in vector\lazy\creation.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def veclbasis(i:int, c:Any=1, zero:Any=0) -> Generator[Any]:
    r"""Return a basis vector.

    $$
        c\vec{e}_i \qquad \mathbb{K}^{i+1}
    $$

    Yields `i` zeros followed by `c`.

    See also
    --------
    - for all basis vectors: [`veclbases`][vector.lazy.creation.veclbases]
    """
    yield from chain(repeat(zero, i), (c,))

veclbases(start: int = 0, c: Any = 1, zero: Any = 0) -> Generator[Generator[Any]]

Yield all basis vectors.

\[ \left(\vec{e}_n\right)_{n\in\mathbb{N}_{\geq\text{start}}} = \left(\vec{e}_\text{start}, \vec{e}_{\text{start}+1}, \dots \right) \]
See also
Source code in vector\lazy\creation.py
37
38
39
40
41
42
43
44
45
46
47
48
49
def veclbases(start:int=0, c:Any=1, zero:Any=0) -> Generator[Generator[Any]]:
    r"""Yield all basis vectors.

    $$
        \left(\vec{e}_n\right)_{n\in\mathbb{N}_{\geq\text{start}}} = \left(\vec{e}_\text{start}, \vec{e}_{\text{start}+1}, \dots \right)
    $$

    See also
    --------
    - for single basis vector: [`veclbasis`][vector.lazy.creation.veclbasis]
    """
    for i in count(start=start):
        yield veclbasis(i, c=c, zero=zero)

veclrand(n: int) -> Generator[float]

Return a random vector of uniformly sampled float coefficients.

\[ \vec{v}\sim\mathcal{U}^n([0, 1[) \qquad \mathbb{K}^n \]

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def veclrand(n:int) -> Generator[float]:
    r"""Return a random vector of uniformly sampled `float` coefficients.

    $$
        \vec{v}\sim\mathcal{U}^n([0, 1[) \qquad \mathbb{K}^n
    $$

    The coefficients are sampled from a uniform distribution in `[0, 1[`.

    Notes
    -----
    Naming like [`numpy.random`](https://numpy.org/doc/stable/reference/random/legacy.html),
    because seems more concise (not `random` & `gauss` as in the stdlib).
    """
    yield from (random() for _ in range(n))

veclrandn(n: int, mu: float = 0, sigma: float = 1) -> Generator[float]

Return a random vector of normally sampled float coefficients.

\[ \vec{v}\sim\mathcal{N}^n(\mu, \sigma) \qquad \mathbb{K}^n \]

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def veclrandn(n:int, mu:float=0, sigma:float=1) -> Generator[float]:
    r"""Return a random vector of normally sampled `float` coefficients.

    $$
        \vec{v}\sim\mathcal{N}^n(\mu, \sigma) \qquad \mathbb{K}^n
    $$

    The coefficients are sampled from a normal distribution.

    Difference to [`vecrandn`][vector.dense.vecrandn]:
    The vector can't be normalised as it isn't materialised.

    Notes
    -----
    Naming like [`numpy.random`](https://numpy.org/doc/stable/reference/random/legacy.html),
    because seems more concise (not `random` & `gauss` as in the stdlib).
    """
    yield from (gauss(mu, sigma) for _ in range(n))

utility

vecleq(v: Iterable[Any], w: Iterable[Any]) -> Generator[bool]

Return if two vectors are equal.

\[ \vec{v}=\vec{w} \qquad \mathbb{K}^m\times\mathbb{K}^n\to\mathbb{B} \]
Source code in vector\lazy\utility.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def vecleq(v:Iterable[Any], w:Iterable[Any]) -> Generator[bool]:
    r"""Return if two vectors are equal.

    $$
        \vec{v}=\vec{w} \qquad \mathbb{K}^m\times\mathbb{K}^n\to\mathbb{B}
    $$
    """
    sentinel = object()
    for vi, wi in zip_longest(v, w, fillvalue=sentinel):
        if wi is sentinel:
            yield not bool(vi)
        elif vi is sentinel:
            yield not bool(wi)
        else:
            yield vi == wi

vecltrim(v: Iterable[Any], tol: Any | None = None) -> Generator[Any]

Remove all trailing near zero (abs(v_i)<=tol) coefficients.

\[ \begin{pmatrix} v_0 \\ \vdots \\ v_m \end{pmatrix} \ \text{where} \ m=\max\{\, j\mid |v_{j-1}|>\text{tol}\,\}\cup\{-1\} \qquad \mathbb{K}^n\to\mathbb{K}^{\leq n} \]

tol may also be None, then all coefficients that evaluate to False are trimmed.

Notes
  • Cutting of elements that are abs(v_i)<=tol instead of abs(v_i)<tol to allow cutting of elements that are exactly zero by trim(v, 0) instead of trim(v, sys.float_info.min).
Source code in vector\lazy\utility.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def vecltrim(v:Iterable[Any], tol:Any|None=None) -> Generator[Any]:
    r"""Remove all trailing near zero (`abs(v_i)<=tol`) coefficients.

    $$
        \begin{pmatrix}
            v_0 \\
            \vdots \\
            v_m
        \end{pmatrix} \ \text{where} \ m=\max\{\, j\mid |v_{j-1}|>\text{tol}\,\}\cup\{-1\} \qquad \mathbb{K}^n\to\mathbb{K}^{\leq n}
    $$

    `tol` may also be `None`,
    then all coefficients that evaluate to `False` are trimmed.

    Notes
    -----
    - Cutting of elements that are `abs(v_i)<=tol` instead of `abs(v_i)<tol` to
    allow cutting of elements that are exactly zero by `trim(v, 0)` instead
    of `trim(v, sys.float_info.min)`.
    """
    t = []
    for x in v:
        t.append(x)
        if (x if tol is None else abs(x)>tol):
            yield from t
            t.clear()

veclrshift(v: Iterable[Any], n: int, zero: Any = 0) -> Generator[Any]

Shift coefficients up.

\[ (v_{i-n})_i \qquad \begin{pmatrix} 0 \\ \vdots \\ 0 \\ v_0 \\ v_1 \\ \vdots \end{pmatrix} \qquad \mathbb{K}^m\to\mathbb{K}^{m+n} \]
Source code in vector\lazy\utility.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def veclrshift(v:Iterable[Any], n:int, zero:Any=0) -> Generator[Any]:
    r"""Shift coefficients up.

    $$
        (v_{i-n})_i \qquad \begin{pmatrix}
            0 \\
            \vdots \\
            0 \\
            v_0 \\
            v_1 \\
            \vdots
        \end{pmatrix} \qquad \mathbb{K}^m\to\mathbb{K}^{m+n}
    $$
    """
    yield from chain(repeat(zero, n), v)

vecllshift(v: Iterable[Any], n: int) -> Generator[Any]

Shift coefficients down.

\[ (v_{i+n})_i \qquad \begin{pmatrix} v_n \\ v_{n+1} \\ \vdots \end{pmatrix} \qquad \mathbb{K}^m\to\mathbb{K}^{\max\{m-n, 0\}} \]
Source code in vector\lazy\utility.py
70
71
72
73
74
75
76
77
78
79
80
81
def vecllshift(v:Iterable[Any], n:int) -> Generator[Any]:
    r"""Shift coefficients down.

    $$
        (v_{i+n})_i \qquad \begin{pmatrix}
            v_n \\
            v_{n+1} \\
            \vdots
        \end{pmatrix} \qquad \mathbb{K}^m\to\mathbb{K}^{\max\{m-n, 0\}}
    $$
    """
    yield from islice(v, n, None)

hilbertspace

veclconj(v: Iterable[Any]) -> Generator[Any]

Return the complex conjugate.

\[ \vec{v}^* \qquad \mathbb{K}^n\to\mathbb{K}^n \]

Tries to call a method conjugate on each element. If not found, simply keeps the element as is.

Source code in vector\lazy\hilbertspace.py
11
12
13
14
15
16
17
18
19
20
21
def veclconj(v:Iterable[Any]) -> Generator[Any]:
    r"""Return the complex conjugate.

    $$
        \vec{v}^* \qquad \mathbb{K}^n\to\mathbb{K}^n
    $$

    Tries to call a method `conjugate` on each element.
    If not found, simply keeps the element as is.
    """
    yield from map(try_conjugate, v)

vectorspace

veclpos(v: Iterable[Any]) -> Generator[Any]

Return the identity.

\[ +\vec{v} \qquad \mathbb{K}^n\to\mathbb{K}^n \]
Source code in vector\lazy\vectorspace.py
15
16
17
18
19
20
21
22
def veclpos(v:Iterable[Any]) -> Generator[Any]:
    r"""Return the identity.

    $$
        +\vec{v} \qquad \mathbb{K}^n\to\mathbb{K}^n
    $$
    """
    yield from map(pos, v)

veclneg(v: Iterable[Any]) -> Generator[Any]

Return the negation.

\[ -\vec{v} \qquad \mathbb{K}^n\to\mathbb{K}^n \]
Source code in vector\lazy\vectorspace.py
24
25
26
27
28
29
30
31
def veclneg(v:Iterable[Any]) -> Generator[Any]:
    r"""Return the negation.

    $$
        -\vec{v} \qquad \mathbb{K}^n\to\mathbb{K}^n
    $$
    """
    yield from map(neg, v)

vecladd(*vs: Iterable[Any]) -> Generator[Any]

Return the sum.

\[ \vec{v}_0+\vec{v}_1+\cdots \qquad \mathbb{K}^{n_0}\times\mathbb{K}^{n_1}\times\cdots\to\mathbb{K}^{\max_i n_i} \]
See also
  • for sum on a single coefficient: vecladdc
Source code in vector\lazy\vectorspace.py
33
34
35
36
37
38
39
40
41
42
43
44
def vecladd(*vs:Iterable[Any]) -> Generator[Any]:
    r"""Return the sum.

    $$
        \vec{v}_0+\vec{v}_1+\cdots \qquad \mathbb{K}^{n_0}\times\mathbb{K}^{n_1}\times\cdots\to\mathbb{K}^{\max_i n_i}
    $$

    See also
    --------
    - for sum on a single coefficient: [`vecladdc`][vector.lazy.vectorspace.vecladdc]
    """
    yield from map(partial(sum_default, default=MISSING), group_ordinal(*vs))

vecladdc(v: Iterable[Any], c: Any, i: int = 0, zero: Any = 0) -> Generator[Any]

Return the sum with a basis vector.

\[ \vec{v}+c\vec{e}_i \qquad \mathbb{K}^n\to\mathbb{K}^{\max\{n, i+1\}} \]

More efficient than vecladd(v, veclbasis(i, c)).

See also
  • for sum on more coefficients: vecladd
Source code in vector\lazy\vectorspace.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def vecladdc(v:Iterable[Any], c:Any, i:int=0, zero:Any=0) -> Generator[Any]:
    r"""Return the sum with a basis vector.

    $$
        \vec{v}+c\vec{e}_i \qquad \mathbb{K}^n\to\mathbb{K}^{\max\{n, i+1\}}
    $$

    More efficient than `vecladd(v, veclbasis(i, c))`.

    See also
    --------
    - for sum on more coefficients: [`vecladd`][vector.lazy.vectorspace.vecladd]
    """
    v = iter(v)
    yield from islice(chain(v, repeat(zero)), i)
    try:
        yield next(v) + c
    except StopIteration:
        yield +c
    yield from v

veclsub(v: Iterable[Any], w: Iterable[Any]) -> Generator[Any]

Return the difference.

\[ \vec{v}-\vec{w} \qquad \mathbb{K}^m\times\mathbb{K}^n\to\mathbb{K}^{\max\{m, n\}} \]
See also
  • for difference on a single coefficient: veclsubc
Source code in vector\lazy\vectorspace.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def veclsub(v:Iterable[Any], w:Iterable[Any]) -> Generator[Any]:
    r"""Return the difference.

    $$
        \vec{v}-\vec{w} \qquad \mathbb{K}^m\times\mathbb{K}^n\to\mathbb{K}^{\max\{m, n\}}
    $$

    See also
    --------
    - for difference on a single coefficient: [`veclsubc`][vector.lazy.vectorspace.veclsubc]
    """
    sentinel = object()
    for vi, wi in zip_longest(v, w, fillvalue=sentinel):
        if wi is sentinel:
            yield vi
        elif vi is sentinel:
            yield -wi
        else:
            yield vi - wi

veclsubc(v: Iterable[Any], c: Any, i: int = 0, zero: Any = 0) -> Generator[Any]

Return the difference with a basis vector.

\[ \vec{v}-c\vec{e}_i \qquad \mathbb{K}^n\to\mathbb{K}^{\max\{n, i+1\}} \]

More efficient than veclsub(v, veclbasis(i, c)).

See also
  • for difference on more coefficients: veclsub
Source code in vector\lazy\vectorspace.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
def veclsubc(v:Iterable[Any], c:Any, i:int=0, zero:Any=0) -> Generator[Any]:
    r"""Return the difference with a basis vector.

    $$
        \vec{v}-c\vec{e}_i \qquad \mathbb{K}^n\to\mathbb{K}^{\max\{n, i+1\}}
    $$

    More efficient than `veclsub(v, veclbasis(i, c))`.

    See also
    --------
    - for difference on more coefficients: [`veclsub`][vector.lazy.vectorspace.veclsub]
    """
    v = iter(v)
    yield from islice(chain(v, repeat(zero)), i)
    try:
        yield next(v) - c
    except StopIteration:
        yield -c
    yield from v

veclmul(v: Iterable[Any], a: Any) -> Generator[Any]

Return the product.

\[ \vec{v}a \qquad \mathbb{K}\times\mathbb{K}^n\to\mathbb{K}^n \]
Source code in vector\lazy\vectorspace.py
108
109
110
111
112
113
114
115
def veclmul(v:Iterable[Any], a:Any) -> Generator[Any]:
    r"""Return the product.

    $$
        \vec{v}a \qquad \mathbb{K}\times\mathbb{K}^n\to\mathbb{K}^n
    $$
    """
    yield from map(mul, v, repeat(a))

veclrmul(a: Any, v: Iterable[Any]) -> Generator[Any]

Return the product.

\[ a\vec{v} \qquad \mathbb{K}\times\mathbb{K}^n\to\mathbb{K}^n \]
Source code in vector\lazy\vectorspace.py
117
118
119
120
121
122
123
124
def veclrmul(a:Any, v:Iterable[Any]) -> Generator[Any]:
    r"""Return the product.

    $$
        a\vec{v} \qquad \mathbb{K}\times\mathbb{K}^n\to\mathbb{K}^n
    $$
    """
    yield from map(mul, repeat(a), v)

vecltruediv(v: Iterable[Any], a: Any) -> Generator[Any]

Return the true quotient.

\[ \frac{\vec{v}}{a} \qquad \mathbb{K}^n\times\mathbb{K}\to\mathbb{K}^n \]
Notes

Why called truediv instead of div?

  • div would 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, truediv and floordiv operations have to be provided, and none should be privileged over the other by getting the universal div name.
  • truediv/floordiv is unambiguous, like Python operators.
Source code in vector\lazy\vectorspace.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
def vecltruediv(v:Iterable[Any], a:Any) -> Generator[Any]:
    r"""Return the true quotient.

    $$
        \frac{\vec{v}}{a} \qquad \mathbb{K}^n\times\mathbb{K}\to\mathbb{K}^n
    $$

    Notes
    -----
    Why called `truediv` instead of `div`?

    - `div` would 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, `truediv`
    and `floordiv` operations have to be provided, and none should be
    privileged over the other by getting the universal `div` name.
    - `truediv`/`floordiv` is unambiguous, like Python `operator`s.
    """
    yield from map(truediv, v, repeat(a))

veclfloordiv(v: Iterable[Any], a: Any) -> Generator[Any]

Return the floor quotient.

\[ \left\lfloor\frac{\vec{v}}{a}\right\rfloor \qquad \mathbb{K}^n\times\mathbb{K}\to\mathbb{K}^n \]
Source code in vector\lazy\vectorspace.py
146
147
148
149
150
151
152
153
def veclfloordiv(v:Iterable[Any], a:Any) -> Generator[Any]:
    r"""Return the floor quotient.

    $$
        \left\lfloor\frac{\vec{v}}{a}\right\rfloor \qquad \mathbb{K}^n\times\mathbb{K}\to\mathbb{K}^n
    $$
    """
    yield from map(floordiv, v, repeat(a))

veclmod(v: Iterable[Any], a: Any) -> Generator[Any]

Return the remainder.

\[ \vec{v} \bmod a \qquad \mathbb{K}^n\times\mathbb{K}\to\mathbb{K}^n \]
Source code in vector\lazy\vectorspace.py
155
156
157
158
159
160
161
162
def veclmod(v:Iterable[Any], a:Any) -> Generator[Any]:
    r"""Return the remainder.

    $$
        \vec{v} \bmod a \qquad \mathbb{K}^n\times\mathbb{K}\to\mathbb{K}^n
    $$
    """
    yield from map(mod, v, repeat(a))

vecldivmod(v: Iterable[Any], a: Any) -> Generator[tuple[Any, Any]]

Return the floor quotient and remainder.

\[ \left\lfloor\frac{\vec{v}}{a}\right\rfloor, \ \left(\vec{v} \bmod a\right) \qquad \mathbb{K}^n\times\mathbb{K}\to\mathbb{K}^n\times\mathbb{K}^n \]
Source code in vector\lazy\vectorspace.py
164
165
166
167
168
169
170
171
172
def vecldivmod(v:Iterable[Any], a:Any) -> Generator[tuple[Any,Any]]:
    r"""Return the floor quotient and remainder.

    $$
        \left\lfloor\frac{\vec{v}}{a}\right\rfloor, \ \left(\vec{v} \bmod a\right) \qquad \mathbb{K}^n\times\mathbb{K}\to\mathbb{K}^n\times\mathbb{K}^n
    $$
    """
    for vi in v:
        yield divmod(vi, a)

elementwise

veclhadamard(*vs: Iterable[Any]) -> Generator[Any]

Return the elementwise product.

\[ \left((\vec{v}_0)_i\cdot(\vec{v}_1)_i\cdot\cdots\right)_i \qquad \mathbb{K}^{n_0}\times\mathbb{K}^{n_1}\times\cdots\to\mathbb{K}^{\min_i n_i} \]
Source code in vector\lazy\elementwise.py
16
17
18
19
20
21
22
23
def veclhadamard(*vs:Iterable[Any]) -> Generator[Any]:
    r"""Return the elementwise product.

    $$
        \left((\vec{v}_0)_i\cdot(\vec{v}_1)_i\cdot\cdots\right)_i \qquad \mathbb{K}^{n_0}\times\mathbb{K}^{n_1}\times\cdots\to\mathbb{K}^{\min_i n_i}
    $$
    """
    yield from map(partial(prod_default, default=MISSING), zip(*vs))

veclhadamardtruediv(v: Iterable[Any], w: Iterable[Any]) -> Generator[Any]

Return the elementwise true quotient.

\[ \left(\frac{v_i}{w_i}\right)_i \qquad \mathbb{K}^m\times\mathbb{K}^n\to\mathbb{K}^m \]
Source code in vector\lazy\elementwise.py
25
26
27
28
29
30
31
32
def veclhadamardtruediv(v:Iterable[Any], w:Iterable[Any]) -> Generator[Any]:
    r"""Return the elementwise true quotient.

    $$
        \left(\frac{v_i}{w_i}\right)_i \qquad \mathbb{K}^m\times\mathbb{K}^n\to\mathbb{K}^m
    $$
    """
    yield from map(truediv, v, chain(w, exception_generator(ZeroDivisionError)))

veclhadamardfloordiv(v: Iterable[Any], w: Iterable[Any]) -> Generator[Any]

Return the elementwise floor quotient.

\[ \left(\left\lfloor\frac{v_i}{w_i}\right\rfloor\right)_i \qquad \mathbb{K}^m\times\mathbb{K}^n\to\mathbb{K}^m \]
Source code in vector\lazy\elementwise.py
34
35
36
37
38
39
40
41
def veclhadamardfloordiv(v:Iterable[Any], w:Iterable[Any]) -> Generator[Any]:
    r"""Return the elementwise floor quotient.

    $$
        \left(\left\lfloor\frac{v_i}{w_i}\right\rfloor\right)_i \qquad \mathbb{K}^m\times\mathbb{K}^n\to\mathbb{K}^m
    $$
    """
    yield from map(floordiv, v, chain(w, exception_generator(ZeroDivisionError)))

veclhadamardmod(v: Iterable[Any], w: Iterable[Any]) -> Generator[Any]

Return the elementwise remainder.

\[ \left(v_i \bmod w_i\right)_i \qquad \mathbb{K}^m\times\mathbb{K}^n\to\mathbb{K}^m \]
Source code in vector\lazy\elementwise.py
43
44
45
46
47
48
49
50
def veclhadamardmod(v:Iterable[Any], w:Iterable[Any]) -> Generator[Any]:
    r"""Return the elementwise remainder.

    $$
        \left(v_i \bmod w_i\right)_i \qquad \mathbb{K}^m\times\mathbb{K}^n\to\mathbb{K}^m
    $$
    """
    yield from map(mod, v, chain(w, exception_generator(ZeroDivisionError)))

veclhadamarddivmod(v: Iterable[Any], w: Iterable[Any]) -> Generator[tuple[Any, Any]]

Return the elementwise floor quotient and remainder.

\[ \left(\left\lfloor\frac{v_i}{w_i}\right\rfloor\right)_i, \ \left(v_i \bmod w_i\right)_i \qquad \mathbb{K}^n\times\mathbb{K}^m\to\mathbb{K}^n\times\mathbb{K}^n \]
Source code in vector\lazy\elementwise.py
52
53
54
55
56
57
58
59
def veclhadamarddivmod(v:Iterable[Any], w:Iterable[Any]) -> Generator[tuple[Any,Any]]:
    r"""Return the elementwise floor quotient and remainder.

    $$
        \left(\left\lfloor\frac{v_i}{w_i}\right\rfloor\right)_i, \ \left(v_i \bmod w_i\right)_i \qquad \mathbb{K}^n\times\mathbb{K}^m\to\mathbb{K}^n\times\mathbb{K}^n
    $$
    """
    yield from map(divmod, v, chain(w, exception_generator(ZeroDivisionError)))

veclhadamardmin(*vs: Iterable[Any], key: Callable[[Any], Any] | None = None) -> Generator[Any]

Return the elementwise minimum.

\[ \left(\min((\vec{v}_0)_i,(\vec{v}_1)_i,\cdots)\right)_i \qquad \mathbb{K}^{n_0}\times\mathbb{K}^{n_1}\times\cdots\to\mathbb{K}^{\max_i n_i} \]
Source code in vector\lazy\elementwise.py
61
62
63
64
65
66
67
68
def veclhadamardmin(*vs:Iterable[Any], key:Callable[[Any],Any]|None=None) -> Generator[Any]:
    r"""Return the elementwise minimum.

    $$
        \left(\min((\vec{v}_0)_i,(\vec{v}_1)_i,\cdots)\right)_i \qquad \mathbb{K}^{n_0}\times\mathbb{K}^{n_1}\times\cdots\to\mathbb{K}^{\max_i n_i}
    $$
    """
    yield from map(partial(min, key=key), group_ordinal(*vs))

veclhadamardmax(*vs: Iterable[Any], key: Callable[[Any], Any] | None = None) -> Generator[Any]

Return the elementwise maximum.

\[ \left(\max((\vec{v}_0)_i,(\vec{v}_1)_i,\cdots)\right)_i \qquad \mathbb{K}^{n_0}\times\mathbb{K}^{n_1}\times\cdots\to\mathbb{K}^{\max_i n_i} \]
Source code in vector\lazy\elementwise.py
70
71
72
73
74
75
76
77
def veclhadamardmax(*vs:Iterable[Any], key:Callable[[Any],Any]|None=None) -> Generator[Any]:
    r"""Return the elementwise maximum.

    $$
        \left(\max((\vec{v}_0)_i,(\vec{v}_1)_i,\cdots)\right)_i \qquad \mathbb{K}^{n_0}\times\mathbb{K}^{n_1}\times\cdots\to\mathbb{K}^{\max_i n_i}
    $$
    """
    yield from map(partial(max, key=key), group_ordinal(*vs))