Skip to content

beignet.special

beignet.special.error_erf

error_erf(input, *, out=None)

Error function.

Parameters:

Name Type Description Default
input Tensor

Input tensor.

required
out Tensor

Output tensor.

None

Returns:

Type Description
Tensor
Source code in src/beignet/special/_error_erf.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def error_erf(input: Tensor, *, out: Tensor | None = None) -> Tensor:
    r"""
    Error function.

    Parameters
    ----------
    input : Tensor
        Input tensor.

    out : Tensor, optional
        Output tensor.

    Returns
    -------
    Tensor
    """
    output = 1.0 - error_erfc(input)

    if out is not None:
        out.copy_(output)

        return out

    return output

beignet.special.error_erfc

error_erfc(input, *, out=None)

Complementary error function.

Parameters:

Name Type Description Default
input Tensor

Input tensor.

required
out Tensor

Output tensor.

None

Returns:

Type Description
Tensor
Source code in src/beignet/special/_error_erfc.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def error_erfc(input: Tensor, *, out: Tensor | None = None) -> Tensor:
    r"""
    Complementary error function.

    Parameters
    ----------
    input : Tensor
        Input tensor.

    out : Tensor, optional
        Output tensor.

    Returns
    -------
    Tensor
    """
    output = torch.exp(-(input**2)) * faddeeva_w(1.0j * input)

    if out is not None:
        out.copy_(output)

        return out

    return output

beignet.special.error_erfi

error_erfi(input, *, out=None)

Imaginary error function.

Parameters:

Name Type Description Default
input Tensor

Input tensor.

required
out Tensor

Output tensor.

None

Returns:

Type Description
Tensor
Source code in src/beignet/special/_error_erfi.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def error_erfi(input: Tensor, *, out: Tensor | None = None) -> Tensor:
    r"""
    Imaginary error function.

    Parameters
    ----------
    input : Tensor
        Input tensor.

    out : Tensor, optional
        Output tensor.

    Returns
    -------
    Tensor
    """
    output = -1.0j * error_erf(1.0j * input)

    if out is not None:
        out.copy_(output)

        return out

    return output

Dawson and Fresnel Integrals

beignet.special.dawson_integral_f

dawson_integral_f(input, *, out=None)

Dawson’s integral.

Parameters:

Name Type Description Default
input Tensor

Input tensor.

required
out Tensor

Output tensor.

None

Returns:

Type Description
Tensor
Source code in src/beignet/special/_dawson_integral_f.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def dawson_integral_f(input: Tensor, *, out: Tensor | None = None) -> Tensor:
    r"""
    Dawson’s integral.

    Parameters
    ----------
    input : Tensor
        Input tensor.

    out : Tensor, optional
        Output tensor.

    Returns
    -------
    Tensor
    """
    output = math.sqrt(torch.pi) / 2.0 * torch.exp(-(input**2)) * error_erfi(input)

    if out is not None:
        out.copy_(output)

        return out

    return output

beignet.special.faddeeva_w

faddeeva_w(input, *, out=None)

Faddeeva function.

Parameters:

Name Type Description Default
input Tensor

Input tensor.

required
out Tensor

Output tensor.

None

Returns:

Type Description
Tensor
Source code in src/beignet/special/_faddeeva_w.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def faddeeva_w(input: Tensor, *, out: Tensor | None = None) -> Tensor:
    r"""
    Faddeeva function.

    Parameters
    ----------
    input : Tensor
        Input tensor.

    out : Tensor, optional
        Output tensor.

    Returns
    -------
    Tensor
    """

    if not torch.is_complex(input):
        input = torch.complex(input, torch.zeros_like(input))

    # use symmetries to map to upper right quadrant of complex plane
    imag_negative = input.imag < 0.0
    input = torch.where(input.imag < 0.0, -input, input)
    real_negative = input.real < 0.0
    input = torch.where(input.real < 0.0, -input.conj(), input)

    x = input.real
    y = input.imag

    if not (((x >= 0.0) & (y >= 0.0)) | torch.isnan(x) | torch.isnan(y)).all():
        raise ValueError("failed to map input to x >= 0, y >= 0")

    output = _voigt_v(x, y, n=11) + 1j * _voigt_l(x, y, n=11)

    # compute real and imaginary parts separately to so we handle infs
    # without unnecessary nans
    expz2 = torch.complex(
        2 * torch.exp(-x.pow(2) + y.pow(2)) * torch.cos(-2 * x * y),
        2 * torch.exp(-x.pow(2) + y.pow(2)) * torch.sin(-2 * x * y),
    )
    output = torch.where(imag_negative, expz2 - output, output)
    output = torch.where(real_negative, output.conj(), output, out=out)

    if out is not None:
        out.copy_(output)
        return out
    else:
        return output