|
98 | 98 | "divide", |
99 | 99 | "ediff1d", |
100 | 100 | "fabs", |
| 101 | + "float_power", |
101 | 102 | "floor", |
102 | 103 | "floor_divide", |
103 | 104 | "fmax", |
@@ -1364,6 +1365,105 @@ def ediff1d(x1, to_end=None, to_begin=None): |
1364 | 1365 | ) |
1365 | 1366 |
|
1366 | 1367 |
|
| 1368 | +_FLOAT_POWER_DOCSTRING = """ |
| 1369 | +Calculates `x1_i` raised to `x2_i` for each element `x1_i` of the input array |
| 1370 | +`x1` with the respective element `x2_i` of the input array `x2`. |
| 1371 | +
|
| 1372 | +This differs from the power function in that boolean, integers, and float16 are |
| 1373 | +promoted to floats with a minimum precision of float32 so that the result is |
| 1374 | +always inexact. The intent is that the function will return a usable result for |
| 1375 | +negative powers and seldom overflow for positive powers. |
| 1376 | +
|
| 1377 | +Negative values raised to a non-integral value will return ``NaN``. To get |
| 1378 | +complex results, cast the input to complex, or specify the ``dtype`` to be one |
| 1379 | +of complex dtype. |
| 1380 | +
|
| 1381 | +For full documentation refer to :obj:`numpy.float_power`. |
| 1382 | +
|
| 1383 | +Parameters |
| 1384 | +---------- |
| 1385 | +x1 : {dpnp.ndarray, usm_ndarray, scalar} |
| 1386 | + First input array, expected to have floating-point data types. |
| 1387 | + Both inputs `x1` and `x2` can not be scalars at the same time. |
| 1388 | +x2 : {dpnp.ndarray, usm_ndarray, scalar} |
| 1389 | + Second input array, also expected to floating-point data types. |
| 1390 | + Both inputs `x1` and `x2` can not be scalars at the same time. |
| 1391 | +out : {None, dpnp.ndarray, usm_ndarray}, optional |
| 1392 | + Output array to populate. Array must have the correct shape and |
| 1393 | + the expected data type. |
| 1394 | + Default: ``None``. |
| 1395 | +order : {"C", "F", "A", "K"}, optional |
| 1396 | + Memory layout of the newly output array, if parameter `out` is ``None``. |
| 1397 | + Default: ``"K"``. |
| 1398 | +
|
| 1399 | +Returns |
| 1400 | +------- |
| 1401 | +out : dpnp.ndarray |
| 1402 | + An array containing the bases in `x1` raised to the exponents in `x2` |
| 1403 | + element-wise. |
| 1404 | +
|
| 1405 | +Limitations |
| 1406 | +----------- |
| 1407 | +Parameters `where` and `subok` are supported with their default values. |
| 1408 | +Keyword argument `kwargs` is currently unsupported. |
| 1409 | +Otherwise ``NotImplementedError`` exception will be raised. |
| 1410 | +
|
| 1411 | +See Also |
| 1412 | +-------- |
| 1413 | +:obj:`dpnp.power` : Power function that preserves type. |
| 1414 | +
|
| 1415 | +Examples |
| 1416 | +-------- |
| 1417 | +>>> import dpnp as np |
| 1418 | +
|
| 1419 | +Cube each element in an array: |
| 1420 | +
|
| 1421 | +>>> x1 = np.arange(6) |
| 1422 | +>>> x1 |
| 1423 | +array([0, 1, 2, 3, 4, 5]) |
| 1424 | +>>> np.float_power(x1, 3) |
| 1425 | +array([ 0., 1., 8., 27., 64., 125.]) |
| 1426 | +
|
| 1427 | +Raise the bases to different exponents: |
| 1428 | +
|
| 1429 | +>>> x2 = np.array([1.0, 2.0, 3.0, 3.0, 2.0, 1.0]) |
| 1430 | +>>> np.float_power(x1, x2) |
| 1431 | +array([ 0., 1., 8., 27., 16., 5.]) |
| 1432 | +
|
| 1433 | +The effect of broadcasting: |
| 1434 | +
|
| 1435 | +>>> x2 = np.array([[1, 2, 3, 3, 2, 1], [1, 2, 3, 3, 2, 1]]) |
| 1436 | +>>> x2 |
| 1437 | +array([[1, 2, 3, 3, 2, 1], |
| 1438 | + [1, 2, 3, 3, 2, 1]]) |
| 1439 | +>>> np.float_power(x1, x2) |
| 1440 | +array([[ 0., 1., 8., 27., 16., 5.], |
| 1441 | + [ 0., 1., 8., 27., 16., 5.]]) |
| 1442 | +
|
| 1443 | +Negative values raised to a non-integral value will result in ``NaN``: |
| 1444 | +
|
| 1445 | +>>> x3 = np.array([-1, -4]) |
| 1446 | +>>> np.float_power(x3, 1.5) |
| 1447 | +array([nan, nan]) |
| 1448 | +
|
| 1449 | +To get complex results, give the argument one of complex dtype, i.e. |
| 1450 | +``dtype=np.complex64``: |
| 1451 | +
|
| 1452 | +>>> np.float_power(x3, 1.5, dtype=np.complex64) |
| 1453 | +array([1.1924881e-08-1.j, 9.5399045e-08-8.j], dtype=complex64) |
| 1454 | +""" |
| 1455 | + |
| 1456 | +float_power = DPNPBinaryFunc( |
| 1457 | + "float_power", |
| 1458 | + ufi._float_power_result_type, |
| 1459 | + ti._pow, |
| 1460 | + _FLOAT_POWER_DOCSTRING, |
| 1461 | + mkl_fn_to_call=vmi._mkl_pow_to_call, |
| 1462 | + mkl_impl_fn=vmi._pow, |
| 1463 | + binary_inplace_fn=ti._pow_inplace, |
| 1464 | +) |
| 1465 | + |
| 1466 | + |
1367 | 1467 | _FLOOR_DOCSTRING = """ |
1368 | 1468 | Returns the floor for each element `x_i` for input array `x`. |
1369 | 1469 |
|
@@ -2468,6 +2568,7 @@ def modf(x1, **kwargs): |
2468 | 2568 | :obj:`dpnp.fmax` : Element-wise maximum of array elements. |
2469 | 2569 | :obj:`dpnp.fmin` : Element-wise minimum of array elements. |
2470 | 2570 | :obj:`dpnp.fmod` : Calculate the element-wise remainder of division. |
| 2571 | +:obj:`dpnp.float_power` : Power function that promotes integers to floats. |
2471 | 2572 |
|
2472 | 2573 | Examples |
2473 | 2574 | -------- |
|
0 commit comments