|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# ***************************************************************************** |
| 3 | +# Copyright (c) 2025, Intel Corporation |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without |
| 7 | +# modification, are permitted provided that the following conditions are met: |
| 8 | +# - Redistributions of source code must retain the above copyright notice, |
| 9 | +# this list of conditions and the following disclaimer. |
| 10 | +# - Redistributions in binary form must reproduce the above copyright notice, |
| 11 | +# this list of conditions and the following disclaimer in the documentation |
| 12 | +# and/or other materials provided with the distribution. |
| 13 | +# |
| 14 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 15 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 18 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 19 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 20 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 22 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 24 | +# THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | +# ***************************************************************************** |
| 26 | + |
| 27 | +""" |
| 28 | +Interface of the Error functions |
| 29 | +
|
| 30 | +Notes |
| 31 | +----- |
| 32 | +This module is a face or public interface file for the library |
| 33 | +it contains: |
| 34 | + - Interface functions |
| 35 | + - documentation for the functions |
| 36 | +
|
| 37 | +""" |
| 38 | + |
| 39 | +import dpnp.backend.extensions.ufunc._ufunc_impl as ufi |
| 40 | +from dpnp.dpnp_algo.dpnp_elementwise_common import DPNPUnaryFunc |
| 41 | + |
| 42 | +__all__ = ["erf"] |
| 43 | + |
| 44 | + |
| 45 | +class DPNPErf(DPNPUnaryFunc): |
| 46 | + """Class that implements a family of erf functions.""" |
| 47 | + |
| 48 | + def __init__( |
| 49 | + self, |
| 50 | + name, |
| 51 | + result_type_resolver_fn, |
| 52 | + unary_dp_impl_fn, |
| 53 | + docs, |
| 54 | + ): |
| 55 | + super().__init__( |
| 56 | + name, |
| 57 | + result_type_resolver_fn, |
| 58 | + unary_dp_impl_fn, |
| 59 | + docs, |
| 60 | + ) |
| 61 | + |
| 62 | + def __call__(self, x, out=None): |
| 63 | + return super().__call__(x, out=out) |
| 64 | + |
| 65 | + |
| 66 | +_ERF_DOCSTRING = r""" |
| 67 | +Returns the error function of complex argument. |
| 68 | +
|
| 69 | +It is defined as :math:`\frac{2}{\sqrt{\pi}} \int_{0}^{z} e^{-t^2} \, dt`. |
| 70 | +
|
| 71 | +For full documentation refer to :obj:`scipy.special.erf`. |
| 72 | +
|
| 73 | +Parameters |
| 74 | +---------- |
| 75 | +x : {dpnp.ndarray, usm_ndarray} |
| 76 | + Input array. |
| 77 | +out : {dpnp.ndarray, usm_ndarray}, optional |
| 78 | + Optional output array for the function values. |
| 79 | +
|
| 80 | +See Also |
| 81 | +-------- |
| 82 | +:obj:`dpnp.special.erfc` : Complementary error function. |
| 83 | +:obj:`dpnp.special.erfinv` : Inverse of the error function. |
| 84 | +:obj:`dpnp.special.erfcinv` : Inverse of the complementary error function. |
| 85 | +:obj:`dpnp.special.erfcx` : Scaled complementary error function. |
| 86 | +:obj:`dpnp.special.erfi` : Imaginary error function. |
| 87 | +
|
| 88 | +Notes |
| 89 | +----- |
| 90 | +The cumulative of the unit normal distribution is given by |
| 91 | +
|
| 92 | +.. math:: |
| 93 | + \Phi(z) = \frac{1}{2} \left[ |
| 94 | + 1 + \operatorname{erf} \left( |
| 95 | + \frac{z}{\sqrt{2}} |
| 96 | + \right) |
| 97 | + \right] |
| 98 | +
|
| 99 | +Examples |
| 100 | +-------- |
| 101 | +>>> import dpnp as np |
| 102 | +>>> x = np.linspace(-3, 3, num=5) |
| 103 | +>>> np.special.erf(x) |
| 104 | +array([[-0.99997791, -0.96610515, 0. , 0.96610515, 0.99997791]) |
| 105 | +
|
| 106 | +""" |
| 107 | + |
| 108 | +erf = DPNPErf( |
| 109 | + "erf", |
| 110 | + ufi._erf_result_type, |
| 111 | + ufi._erf, |
| 112 | + _ERF_DOCSTRING, |
| 113 | + # mkl_fn_to_call="_mkl_erf_to_call", |
| 114 | + # mkl_impl_fn="_erf", |
| 115 | +) |
0 commit comments