Multiplies matrix `a` by vector `b`, producing `a` * `b`. The matrix `a` must, following any transpositions, be a tensor of rank >= 2, and we must have `shape(b) = shape(a)[:-2] + [shape(a)[-1]]`. Both `a` and `b` must be of the same type. The supported types are: `float16`, `float32`, `fl
(a,
b,
transpose_a=False,
adjoint_a=False,
a_is_sparse=False,
b_is_sparse=False,
name=None)
| 2756 | |
| 2757 | @tf_export("linalg.matvec") |
| 2758 | def matvec(a, |
| 2759 | b, |
| 2760 | transpose_a=False, |
| 2761 | adjoint_a=False, |
| 2762 | a_is_sparse=False, |
| 2763 | b_is_sparse=False, |
| 2764 | name=None): |
| 2765 | """Multiplies matrix `a` by vector `b`, producing `a` * `b`. |
| 2766 | |
| 2767 | The matrix `a` must, following any transpositions, be a tensor of rank >= 2, |
| 2768 | and we must have `shape(b) = shape(a)[:-2] + [shape(a)[-1]]`. |
| 2769 | |
| 2770 | Both `a` and `b` must be of the same type. The supported types are: |
| 2771 | `float16`, `float32`, `float64`, `int32`, `complex64`, `complex128`. |
| 2772 | |
| 2773 | Matrix `a` can be transposed or adjointed (conjugated and transposed) on |
| 2774 | the fly by setting one of the corresponding flag to `True`. These are `False` |
| 2775 | by default. |
| 2776 | |
| 2777 | If one or both of the inputs contain a lot of zeros, a more efficient |
| 2778 | multiplication algorithm can be used by setting the corresponding |
| 2779 | `a_is_sparse` or `b_is_sparse` flag to `True`. These are `False` by default. |
| 2780 | This optimization is only available for plain matrices/vectors (rank-2/1 |
| 2781 | tensors) with datatypes `bfloat16` or `float32`. |
| 2782 | |
| 2783 | For example: |
| 2784 | |
| 2785 | ```python |
| 2786 | # 2-D tensor `a` |
| 2787 | # [[1, 2, 3], |
| 2788 | # [4, 5, 6]] |
| 2789 | a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3]) |
| 2790 | |
| 2791 | # 1-D tensor `b` |
| 2792 | # [7, 9, 11] |
| 2793 | b = tf.constant([7, 9, 11], shape=[3]) |
| 2794 | |
| 2795 | # `a` * `b` |
| 2796 | # [ 58, 64] |
| 2797 | c = tf.matvec(a, b) |
| 2798 | |
| 2799 | |
| 2800 | # 3-D tensor `a` |
| 2801 | # [[[ 1, 2, 3], |
| 2802 | # [ 4, 5, 6]], |
| 2803 | # [[ 7, 8, 9], |
| 2804 | # [10, 11, 12]]] |
| 2805 | a = tf.constant(np.arange(1, 13, dtype=np.int32), |
| 2806 | shape=[2, 2, 3]) |
| 2807 | |
| 2808 | # 2-D tensor `b` |
| 2809 | # [[13, 14, 15], |
| 2810 | # [16, 17, 18]] |
| 2811 | b = tf.constant(np.arange(13, 19, dtype=np.int32), |
| 2812 | shape=[2, 3]) |
| 2813 | |
| 2814 | # `a` * `b` |
| 2815 | # [[ 86, 212], |
nothing calls this directly
no test coverage detected