MCPcopy
hub / github.com/numpy/numpy / einsum

Function einsum

numpy/_core/einsumfunc.py:1243–1647  ·  view source on GitHub ↗

einsum(subscripts, *operands, out=None, dtype=None, order='K', casting='safe', optimize=False) Evaluates the Einstein summation convention on the operands. Using the Einstein summation convention, many common multi-dimensional, linear algebraic array operations can be r

(*operands, out=None, optimize=False, **kwargs)

Source from the content-addressed store, hash-verified

1241# Rewrite einsum to handle different cases
1242@array_function_dispatch(_einsum_dispatcher, module='numpy')
1243def einsum(*operands, out=None, optimize=False, **kwargs):
1244 """
1245 einsum(subscripts, *operands, out=None, dtype=None, order='K',
1246 casting='safe', optimize=False)
1247
1248 Evaluates the Einstein summation convention on the operands.
1249
1250 Using the Einstein summation convention, many common multi-dimensional,
1251 linear algebraic array operations can be represented in a simple fashion.
1252 In *implicit* mode `einsum` computes these values.
1253
1254 In *explicit* mode, `einsum` provides further flexibility to compute
1255 other array operations that might not be considered classical Einstein
1256 summation operations, by disabling, or forcing summation over specified
1257 subscript labels.
1258
1259 See the notes and examples for clarification.
1260
1261 Parameters
1262 ----------
1263 subscripts : str
1264 Specifies the subscripts for summation as comma separated list of
1265 subscript labels. An implicit (classical Einstein summation)
1266 calculation is performed unless the explicit indicator '->' is
1267 included as well as subscript labels of the precise output form.
1268 operands : list of array_like
1269 These are the arrays for the operation.
1270 out : ndarray, optional
1271 If provided, the calculation is done into this array.
1272 dtype : {data-type, None}, optional
1273 If provided, forces the calculation to use the data type specified.
1274 Note that you may have to also give a more liberal `casting`
1275 parameter to allow the conversions. Default is None.
1276 order : {'C', 'F', 'A', 'K'}, optional
1277 Controls the memory layout of the output. 'C' means it should
1278 be C contiguous. 'F' means it should be Fortran contiguous,
1279 'A' means it should be 'F' if the inputs are all 'F', 'C' otherwise.
1280 'K' means it should be as close to the layout as the inputs as
1281 is possible, including arbitrarily permuted axes.
1282 Default is 'K'.
1283 casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
1284 Controls what kind of data casting may occur. Setting this to
1285 'unsafe' is not recommended, as it can adversely affect accumulations.
1286
1287 * 'no' means the data types should not be cast at all.
1288 * 'equiv' means only byte-order changes are allowed.
1289 * 'safe' means only casts which can preserve values are allowed.
1290 * 'same_kind' means only safe casts or casts within a kind,
1291 like float64 to float32, are allowed.
1292 * 'unsafe' means any data conversions may be done.
1293
1294 Default is 'safe'.
1295 optimize : {False, True, 'greedy', 'optimal'}, optional
1296 Controls if intermediate optimization should occur. No optimization
1297 will occur if False and True will default to the 'greedy' algorithm.
1298 Also accepts an explicit contraction list from the ``np.einsum_path``
1299 function. See ``np.einsum_path`` for more details. Defaults to False.
1300

Callers

nothing calls this directly

Calls 2

einsum_pathFunction · 0.85
bmm_einsumFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…