|
33 | 33 | from ._elementwise_common import UnaryElementwiseFunc |
34 | 34 | from ._type_utils import ( |
35 | 35 | _acceptance_fn_negative, |
| 36 | + _acceptance_fn_reciprocal, |
36 | 37 | ) |
37 | 38 |
|
38 | 39 | # U01: ==== ABS (x) |
|
1042 | 1043 | ) |
1043 | 1044 | del _tanh_docstring |
1044 | 1045 |
|
| 1046 | +# U36: ==== TRUNC (x) |
| 1047 | +_trunc_docstring = r""" |
| 1048 | +trunc(x, /, \*, out=None, order='K') |
| 1049 | +
|
| 1050 | +Returns the truncated value for each element `x_i` for input array `x`. |
| 1051 | +
|
| 1052 | +The truncated value of the scalar `x` is the nearest integer i which is |
| 1053 | +closer to zero than `x` is. In short, the fractional part of the |
| 1054 | +signed number `x` is discarded. |
| 1055 | +
|
| 1056 | +Args: |
| 1057 | + x (usm_ndarray): |
| 1058 | + Input array, expected to have a boolean or real-valued data type. |
| 1059 | + out (Union[usm_ndarray, None], optional): |
| 1060 | + Output array to populate. |
| 1061 | + Array must have the correct shape and the expected data type. |
| 1062 | + order ("C","F","A","K", optional): |
| 1063 | + Memory layout of the new output array, if parameter |
| 1064 | + `out` is ``None``. |
| 1065 | + Default: "K". |
| 1066 | +
|
| 1067 | +Returns: |
| 1068 | + usm_ndarray: |
| 1069 | + An array containing the result of element-wise division. The data type |
| 1070 | + of the returned array is determined by the Type Promotion Rules. |
| 1071 | +""" |
| 1072 | +trunc = UnaryElementwiseFunc( |
| 1073 | + "trunc", ti._trunc_result_type, ti._trunc, _trunc_docstring |
| 1074 | +) |
| 1075 | +del _trunc_docstring |
| 1076 | + |
| 1077 | +# U37: ==== CBRT (x) |
| 1078 | +_cbrt_docstring_ = r""" |
| 1079 | +cbrt(x, /, \*, out=None, order='K') |
| 1080 | +
|
| 1081 | +Computes the cube-root for each element `x_i` for input array `x`. |
| 1082 | +
|
| 1083 | +Args: |
| 1084 | + x (usm_ndarray): |
| 1085 | + Input array, expected to have a real-valued floating-point data type. |
| 1086 | + out (Union[usm_ndarray, None], optional): |
| 1087 | + Output array to populate. |
| 1088 | + Array have the correct shape and the expected data type. |
| 1089 | + order ("C","F","A","K", optional): |
| 1090 | + Memory layout of the new output array, if parameter |
| 1091 | + `out` is ``None``. |
| 1092 | + Default: "K". |
| 1093 | +
|
| 1094 | +Returns: |
| 1095 | + usm_ndarray: |
| 1096 | + An array containing the element-wise cube-root. |
| 1097 | + The data type of the returned array is determined by |
| 1098 | + the Type Promotion Rules. |
| 1099 | +""" |
| 1100 | + |
| 1101 | +cbrt = UnaryElementwiseFunc( |
| 1102 | + "cbrt", ti._cbrt_result_type, ti._cbrt, _cbrt_docstring_ |
| 1103 | +) |
| 1104 | +del _cbrt_docstring_ |
| 1105 | + |
| 1106 | +# U38: ==== EXP2 (x) |
| 1107 | +_exp2_docstring_ = r""" |
| 1108 | +exp2(x, /, \*, out=None, order='K') |
| 1109 | +
|
| 1110 | +Computes the base-2 exponential for each element `x_i` for input array `x`. |
| 1111 | +
|
| 1112 | +Args: |
| 1113 | + x (usm_ndarray): |
| 1114 | + Input array, expected to have a floating-point data type. |
| 1115 | + out (Union[usm_ndarray, None], optional): |
| 1116 | + Output array to populate. |
| 1117 | + Array have the correct shape and the expected data type. |
| 1118 | + order ("C","F","A","K", optional): |
| 1119 | + Memory layout of the new output array, if parameter |
| 1120 | + `out` is ``None``. |
| 1121 | + Default: "K". |
| 1122 | +
|
| 1123 | +Returns: |
| 1124 | + usm_ndarray: |
| 1125 | + An array containing the element-wise base-2 exponentials. |
| 1126 | + The data type of the returned array is determined by |
| 1127 | + the Type Promotion Rules. |
| 1128 | +""" |
| 1129 | + |
| 1130 | +exp2 = UnaryElementwiseFunc( |
| 1131 | + "exp2", ti._exp2_result_type, ti._exp2, _exp2_docstring_ |
| 1132 | +) |
| 1133 | +del _exp2_docstring_ |
| 1134 | + |
| 1135 | +# U39: ==== RSQRT (x) |
| 1136 | +_rsqrt_docstring_ = r""" |
| 1137 | +rsqrt(x, /, \*, out=None, order='K') |
| 1138 | +
|
| 1139 | +Computes the reciprocal square-root for each element `x_i` for input array `x`. |
| 1140 | +
|
| 1141 | +Args: |
| 1142 | + x (usm_ndarray): |
| 1143 | + Input array, expected to have a real-valued floating-point data type. |
| 1144 | + out (Union[usm_ndarray, None], optional): |
| 1145 | + Output array to populate. |
| 1146 | + Array have the correct shape and the expected data type. |
| 1147 | + order ("C","F","A","K", optional): |
| 1148 | + Memory layout of the new output array, if parameter |
| 1149 | + `out` is ``None``. |
| 1150 | + Default: "K". |
| 1151 | +
|
| 1152 | +Returns: |
| 1153 | + usm_ndarray: |
| 1154 | + An array containing the element-wise reciprocal square-root. |
| 1155 | + The returned array has a floating-point data type determined by |
| 1156 | + the Type Promotion Rules. |
| 1157 | +""" |
| 1158 | + |
| 1159 | +rsqrt = UnaryElementwiseFunc( |
| 1160 | + "rsqrt", ti._rsqrt_result_type, ti._rsqrt, _rsqrt_docstring_ |
| 1161 | +) |
| 1162 | +del _rsqrt_docstring_ |
| 1163 | + |
1045 | 1164 | # U40: ==== PROJ (x) |
1046 | 1165 | _proj_docstring = r""" |
1047 | 1166 | proj(x, /, \*, out=None, order='K') |
|
1098 | 1217 | ) |
1099 | 1218 | del _signbit_docstring |
1100 | 1219 |
|
| 1220 | +# U42: ==== RECIPROCAL (x) |
| 1221 | +_reciprocal_docstring = r""" |
| 1222 | +reciprocal(x, /, \*, out=None, order='K') |
| 1223 | +
|
| 1224 | +Computes the reciprocal of each element `x_i` for input array `x`. |
| 1225 | +
|
| 1226 | +Args: |
| 1227 | + x (usm_ndarray): |
| 1228 | + Input array, expected to have a floating-point data type. |
| 1229 | + out (Union[usm_ndarray, None], optional): |
| 1230 | + Output array to populate. |
| 1231 | + Array have the correct shape and the expected data type. |
| 1232 | + order ("C","F","A","K", optional): |
| 1233 | + Memory layout of the new output array, if parameter |
| 1234 | + `out` is ``None``. |
| 1235 | + Default: "K". |
| 1236 | +
|
| 1237 | +Returns: |
| 1238 | + usm_ndarray: |
| 1239 | + An array containing the element-wise reciprocals. |
| 1240 | + The returned array has a floating-point data type determined |
| 1241 | + by the Type Promotion Rules. |
| 1242 | +""" |
| 1243 | + |
| 1244 | +reciprocal = UnaryElementwiseFunc( |
| 1245 | + "reciprocal", |
| 1246 | + ti._reciprocal_result_type, |
| 1247 | + ti._reciprocal, |
| 1248 | + _reciprocal_docstring, |
| 1249 | + acceptance_fn=_acceptance_fn_reciprocal, |
| 1250 | +) |
| 1251 | +del _reciprocal_docstring |
| 1252 | + |
1101 | 1253 | # U43: ==== ANGLE (x) |
1102 | 1254 | _angle_docstring = r""" |
1103 | 1255 | angle(x, /, \*, out=None, order='K') |
|
0 commit comments