Skip to content

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