|
7 | 7 | # http://arrayfire.com/licenses/BSD-3-Clause
|
8 | 8 | ########################################################
|
9 | 9 |
|
| 10 | +""" |
| 11 | +BLAS functions for arrayfire. |
| 12 | +""" |
| 13 | + |
10 | 14 | from .library import *
|
11 | 15 | from .array import *
|
12 | 16 |
|
13 | 17 | def matmul(lhs, rhs, lhs_opts=MATPROP.NONE, rhs_opts=MATPROP.NONE):
|
| 18 | + """ |
| 19 | + Generalized matrix multiplication for two matrices. |
| 20 | +
|
| 21 | + Parameters |
| 22 | + ---------- |
| 23 | +
|
| 24 | + lhs : af.Array |
| 25 | + A 2 dimensional, real or complex arrayfire array. |
| 26 | +
|
| 27 | + rhs : af.Array |
| 28 | + A 2 dimensional, real or complex arrayfire array. |
| 29 | +
|
| 30 | + lhs_opts: optional: af.MATPROP. default: af.MATPROP.NONE. |
| 31 | + Can be one of |
| 32 | + - af.MATPROP.NONE - If no op should be done on `lhs`. |
| 33 | + - af.MATPROP.TRANS - If `lhs` has to be transposed before multiplying. |
| 34 | + - af.MATPROP.CTRANS - If `lhs` has to be hermitian transposed before multiplying. |
| 35 | +
|
| 36 | + rhs_opts: optional: af.MATPROP. default: af.MATPROP.NONE. |
| 37 | + Can be one of |
| 38 | + - af.MATPROP.NONE - If no op should be done on `rhs`. |
| 39 | + - af.MATPROP.TRANS - If `rhs` has to be transposed before multiplying. |
| 40 | + - af.MATPROP.CTRANS - If `rhs` has to be hermitian transposed before multiplying. |
| 41 | +
|
| 42 | + Returns |
| 43 | + ------- |
| 44 | +
|
| 45 | + out : af.Array |
| 46 | + Output of the matrix multiplication on `lhs` and `rhs`. |
| 47 | +
|
| 48 | + Note |
| 49 | + ----- |
| 50 | +
|
| 51 | + - The data types of `lhs` and `rhs` should be the same. |
| 52 | + - Batches are not supported. |
| 53 | +
|
| 54 | + """ |
14 | 55 | out = Array()
|
15 | 56 | safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
|
16 | 57 | lhs_opts.value, rhs_opts.value))
|
17 | 58 | return out
|
18 | 59 |
|
19 | 60 | def matmulTN(lhs, rhs):
|
| 61 | + """ |
| 62 | + Matrix multiplication after transposing the first matrix. |
| 63 | +
|
| 64 | + Parameters |
| 65 | + ---------- |
| 66 | +
|
| 67 | + lhs : af.Array |
| 68 | + A 2 dimensional, real or complex arrayfire array. |
| 69 | +
|
| 70 | + rhs : af.Array |
| 71 | + A 2 dimensional, real or complex arrayfire array. |
| 72 | +
|
| 73 | + Returns |
| 74 | + ------- |
| 75 | +
|
| 76 | + out : af.Array |
| 77 | + Output of the matrix multiplication on `transpose(lhs)` and `rhs`. |
| 78 | +
|
| 79 | + Note |
| 80 | + ----- |
| 81 | +
|
| 82 | + - The data types of `lhs` and `rhs` should be the same. |
| 83 | + - Batches are not supported. |
| 84 | +
|
| 85 | + """ |
20 | 86 | out = Array()
|
21 | 87 | safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
|
22 | 88 | MATPROP.TRANS.value, MATPROP.NONE.value))
|
23 | 89 | return out
|
24 | 90 |
|
25 | 91 | def matmulNT(lhs, rhs):
|
| 92 | + """ |
| 93 | + Matrix multiplication after transposing the second matrix. |
| 94 | +
|
| 95 | + Parameters |
| 96 | + ---------- |
| 97 | +
|
| 98 | + lhs : af.Array |
| 99 | + A 2 dimensional, real or complex arrayfire array. |
| 100 | +
|
| 101 | + rhs : af.Array |
| 102 | + A 2 dimensional, real or complex arrayfire array. |
| 103 | +
|
| 104 | + Returns |
| 105 | + ------- |
| 106 | +
|
| 107 | + out : af.Array |
| 108 | + Output of the matrix multiplication on `lhs` and `transpose(rhs)`. |
| 109 | +
|
| 110 | + Note |
| 111 | + ----- |
| 112 | +
|
| 113 | + - The data types of `lhs` and `rhs` should be the same. |
| 114 | + - Batches are not supported. |
| 115 | +
|
| 116 | + """ |
26 | 117 | out = Array()
|
27 | 118 | safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
|
28 | 119 | MATPROP.NONE.value, MATPROP.TRANS.value))
|
29 | 120 | return out
|
30 | 121 |
|
31 | 122 | def matmulTT(lhs, rhs):
|
| 123 | + """ |
| 124 | + Matrix multiplication after transposing both inputs. |
| 125 | +
|
| 126 | + Parameters |
| 127 | + ---------- |
| 128 | +
|
| 129 | + lhs : af.Array |
| 130 | + A 2 dimensional, real or complex arrayfire array. |
| 131 | +
|
| 132 | + rhs : af.Array |
| 133 | + A 2 dimensional, real or complex arrayfire array. |
| 134 | +
|
| 135 | + Returns |
| 136 | + ------- |
| 137 | +
|
| 138 | + out : af.Array |
| 139 | + Output of the matrix multiplication on `transpose(lhs)` and `transpose(rhs)`. |
| 140 | +
|
| 141 | + Note |
| 142 | + ----- |
| 143 | +
|
| 144 | + - The data types of `lhs` and `rhs` should be the same. |
| 145 | + - Batches are not supported. |
| 146 | +
|
| 147 | + """ |
32 | 148 | out = Array()
|
33 | 149 | safe_call(backend.get().af_matmul(ct.pointer(out.arr), lhs.arr, rhs.arr,
|
34 | 150 | MATPROP.TRANS.value, MATPROP.TRANS.value))
|
35 | 151 | return out
|
36 | 152 |
|
37 | 153 | def dot(lhs, rhs, lhs_opts=MATPROP.NONE, rhs_opts=MATPROP.NONE):
|
| 154 | + """ |
| 155 | + Dot product of two input vectors. |
| 156 | +
|
| 157 | + Parameters |
| 158 | + ---------- |
| 159 | +
|
| 160 | + lhs : af.Array |
| 161 | + A 1 dimensional, real or complex arrayfire array. |
| 162 | +
|
| 163 | + rhs : af.Array |
| 164 | + A 1 dimensional, real or complex arrayfire array. |
| 165 | +
|
| 166 | + lhs_opts: optional: af.MATPROP. default: af.MATPROP.NONE. |
| 167 | + Can be one of |
| 168 | + - af.MATPROP.NONE - If no op should be done on `lhs`. |
| 169 | + - No other options are currently supported. |
| 170 | +
|
| 171 | + rhs_opts: optional: af.MATPROP. default: af.MATPROP.NONE. |
| 172 | + Can be one of |
| 173 | + - af.MATPROP.NONE - If no op should be done on `rhs`. |
| 174 | + - No other options are currently supported. |
| 175 | +
|
| 176 | + Returns |
| 177 | + ------- |
| 178 | +
|
| 179 | + out : af.Array |
| 180 | + Output of dot product of `lhs` and `rhs`. |
| 181 | +
|
| 182 | + Note |
| 183 | + ----- |
| 184 | +
|
| 185 | + - The data types of `lhs` and `rhs` should be the same. |
| 186 | + - Batches are not supported. |
| 187 | +
|
| 188 | + """ |
38 | 189 | out = Array()
|
39 | 190 | safe_call(backend.get().af_dot(ct.pointer(out.arr), lhs.arr, rhs.arr,
|
40 | 191 | lhs_opts.value, rhs_opts.value))
|
|
0 commit comments