|
54 | 54 | dpnp_matrix_power,
|
55 | 55 | dpnp_matrix_rank,
|
56 | 56 | dpnp_multi_dot,
|
| 57 | + dpnp_norm, |
57 | 58 | dpnp_pinv,
|
58 | 59 | dpnp_qr,
|
59 | 60 | dpnp_slogdet,
|
@@ -491,7 +492,7 @@ def multi_dot(arrays, *, out=None):
|
491 | 492 | """
|
492 | 493 | Compute the dot product of two or more arrays in a single function call.
|
493 | 494 |
|
494 |
| - For full documentation refer to :obj:`numpy.multi_dot`. |
| 495 | + For full documentation refer to :obj:`numpy.linalg.multi_dot`. |
495 | 496 |
|
496 | 497 | Parameters
|
497 | 498 | ----------
|
@@ -602,60 +603,109 @@ def pinv(a, rcond=1e-15, hermitian=False):
|
602 | 603 | return dpnp_pinv(a, rcond=rcond, hermitian=hermitian)
|
603 | 604 |
|
604 | 605 |
|
605 |
| -def norm(x1, ord=None, axis=None, keepdims=False): |
| 606 | +def norm(x, ord=None, axis=None, keepdims=False): |
606 | 607 | """
|
607 | 608 | Matrix or vector norm.
|
608 | 609 |
|
609 |
| - This function is able to return one of eight different matrix norms, |
610 |
| - or one of an infinite number of vector norms (described below), depending |
611 |
| - on the value of the ``ord`` parameter. |
| 610 | + For full documentation refer to :obj:`numpy.linalg.norm`. |
612 | 611 |
|
613 | 612 | Parameters
|
614 | 613 | ----------
|
615 |
| - input : array_like |
616 |
| - Input array. If `axis` is None, `x` must be 1-D or 2-D, unless `ord` |
617 |
| - is None. If both `axis` and `ord` are None, the 2-norm of |
618 |
| - ``x.ravel`` will be returned. |
619 |
| - ord : optional |
620 |
| - Order of the norm (see table under ``Notes``). inf means numpy's |
621 |
| - `inf` object. The default is None. |
622 |
| - axis : optional. |
| 614 | + x : {dpnp.ndarray, usm_ndarray} |
| 615 | + Input array. If `axis` is ``None``, `x` must be 1-D or 2-D, unless |
| 616 | + `ord` is ``None``. If both `axis` and `ord` are ``None``, the 2-norm |
| 617 | + of ``x.ravel`` will be returned. |
| 618 | + ord : {int, float, inf, -inf, "fro", "nuc"}, optional |
| 619 | + Norm type. inf means dpnp's `inf` object. The default is ``None``. |
| 620 | + axis : {None, int, 2-tuple of ints}, optional |
623 | 621 | If `axis` is an integer, it specifies the axis of `x` along which to
|
624 | 622 | compute the vector norms. If `axis` is a 2-tuple, it specifies the
|
625 | 623 | axes that hold 2-D matrices, and the matrix norms of these matrices
|
626 |
| - are computed. If `axis` is None then either a vector norm (when `x` |
627 |
| - is 1-D) or a matrix norm (when `x` is 2-D) is returned. The default |
628 |
| - is None. |
| 624 | + are computed. If `axis` is ``None`` then either a vector norm (when |
| 625 | + `x` is 1-D) or a matrix norm (when `x` is 2-D) is returned. |
| 626 | + The default is ``None``. |
629 | 627 | keepdims : bool, optional
|
630 |
| - If this is set to True, the axes which are normed over are left in the |
631 |
| - result as dimensions with size one. With this option the result will |
632 |
| - broadcast correctly against the original `x`. |
| 628 | + If this is set to ``True``, the axes which are normed over are left in |
| 629 | + the result as dimensions with size one. With this option the result |
| 630 | + will broadcast correctly against the original `x`. |
633 | 631 |
|
634 | 632 | Returns
|
635 | 633 | -------
|
636 |
| - n : float or ndarray |
| 634 | + out : dpnp.ndarray |
637 | 635 | Norm of the matrix or vector(s).
|
638 |
| - """ |
639 | 636 |
|
640 |
| - x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) |
641 |
| - if x1_desc: |
642 |
| - if ( |
643 |
| - not isinstance(axis, int) |
644 |
| - and not isinstance(axis, tuple) |
645 |
| - and axis is not None |
646 |
| - ): |
647 |
| - pass |
648 |
| - elif keepdims is not False: |
649 |
| - pass |
650 |
| - elif ord not in [None, 0, 3, "fro", "f"]: |
651 |
| - pass |
652 |
| - else: |
653 |
| - result_obj = dpnp_norm(x1, ord=ord, axis=axis) |
654 |
| - result = dpnp.convert_single_elem_array_to_scalar(result_obj) |
| 637 | + Examples |
| 638 | + -------- |
| 639 | + >>> import dpnp as np |
| 640 | + >>> a = np.arange(9) - 4 |
| 641 | + >>> a |
| 642 | + array([-4, -3, -2, -1, 0, 1, 2, 3, 4]) |
| 643 | + >>> b = a.reshape((3, 3)) |
| 644 | + >>> b |
| 645 | + array([[-4, -3, -2], |
| 646 | + [-1, 0, 1], |
| 647 | + [ 2, 3, 4]]) |
| 648 | +
|
| 649 | + >>> np.linalg.norm(a) |
| 650 | + array(7.745966692414834) |
| 651 | + >>> np.linalg.norm(b) |
| 652 | + array(7.745966692414834) |
| 653 | + >>> np.linalg.norm(b, 'fro') |
| 654 | + array(7.745966692414834) |
| 655 | + >>> np.linalg.norm(a, np.inf) |
| 656 | + array(4.) |
| 657 | + >>> np.linalg.norm(b, np.inf) |
| 658 | + array(9.) |
| 659 | + >>> np.linalg.norm(a, -np.inf) |
| 660 | + array(0.) |
| 661 | + >>> np.linalg.norm(b, -np.inf) |
| 662 | + array(2.) |
| 663 | +
|
| 664 | + >>> np.linalg.norm(a, 1) |
| 665 | + array(20.) |
| 666 | + >>> np.linalg.norm(b, 1) |
| 667 | + array(7.) |
| 668 | + >>> np.linalg.norm(a, -1) |
| 669 | + array(0.) |
| 670 | + >>> np.linalg.norm(b, -1) |
| 671 | + array(6.) |
| 672 | + >>> np.linalg.norm(a, 2) |
| 673 | + array(7.745966692414834) |
| 674 | + >>> np.linalg.norm(b, 2) |
| 675 | + array(7.3484692283495345) |
| 676 | +
|
| 677 | + >>> np.linalg.norm(a, -2) |
| 678 | + array(0.) |
| 679 | + >>> np.linalg.norm(b, -2) |
| 680 | + array(1.8570331885190563e-016) # may vary |
| 681 | + >>> np.linalg.norm(a, 3) |
| 682 | + array(5.8480354764257312) # may vary |
| 683 | + >>> np.linalg.norm(a, -3) |
| 684 | + array(0.) |
| 685 | +
|
| 686 | + Using the `axis` argument to compute vector norms: |
| 687 | +
|
| 688 | + >>> c = np.array([[ 1, 2, 3], |
| 689 | + ... [-1, 1, 4]]) |
| 690 | + >>> np.linalg.norm(c, axis=0) |
| 691 | + array([ 1.41421356, 2.23606798, 5. ]) |
| 692 | + >>> np.linalg.norm(c, axis=1) |
| 693 | + array([ 3.74165739, 4.24264069]) |
| 694 | + >>> np.linalg.norm(c, ord=1, axis=1) |
| 695 | + array([ 6., 6.]) |
| 696 | +
|
| 697 | + Using the `axis` argument to compute matrix norms: |
| 698 | +
|
| 699 | + >>> m = np.arange(8).reshape(2,2,2) |
| 700 | + >>> np.linalg.norm(m, axis=(1,2)) |
| 701 | + array([ 3.74165739, 11.22497216]) |
| 702 | + >>> np.linalg.norm(m[0, :, :]), np.linalg.norm(m[1, :, :]) |
| 703 | + (array(3.7416573867739413), array(11.224972160321824)) |
655 | 704 |
|
656 |
| - return result |
| 705 | + """ |
657 | 706 |
|
658 |
| - return call_origin(numpy.linalg.norm, x1, ord, axis, keepdims) |
| 707 | + dpnp.check_supported_arrays_type(x) |
| 708 | + return dpnp_norm(x, ord, axis, keepdims) |
659 | 709 |
|
660 | 710 |
|
661 | 711 | def qr(a, mode="reduced"):
|
|
0 commit comments