From 44c5456859a3da1c5f6166fea4e15cdb18f334de Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 8 Mar 2021 11:14:53 -0800 Subject: [PATCH 1/4] Add tensordot specification --- .../linear_algebra_functions.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/spec/API_specification/linear_algebra_functions.md b/spec/API_specification/linear_algebra_functions.md index 209a2f787..ca0c3dd76 100644 --- a/spec/API_specification/linear_algebra_functions.md +++ b/spec/API_specification/linear_algebra_functions.md @@ -279,6 +279,37 @@ TODO TODO +(function-tensordot)= +### tensordot(x1, x2, /, *, axes=2) + +Returns a tensor contraction of `x1` and `x2` over specific axes. + +- **x1**: _<array>_ + + - first input array. Must have a data type of either `float32` or `float64`. + +- **x2**: _<array>_ + + - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have a data type of either `float32` or `float64`. + +- **axes**: _Union\[ int, Tuple\[ Sequence\[ int ], Sequence\[ int ] ] ]_ + + - number of axes (dimensions) to contract or explicit sequences of axes (dimensions) for `x1` and `x2`, respectively. + + If `axes` is an `int` equal to `N`, then contraction must be performed over the last `N` axes of `x1` and the first `N` axes of `x2` in order. The size of each corresponding axis (dimension) must match. Must be nonnegative. + + - If `N` equals `0`, the result is the tensor (outer) product. + - If `N` equals `1`, the result is the tensor dot product. + - If `N` equals `2`, the result is the tensor double contraction (default). + + If `axes` is a tuple of two sequences `(x1_axes, x2_axes)`, the first sequence must apply to `x` and the second sequence to `x2`. Both sequences must have the same length. Each axis (dimension) `x1_axes[i]` for `x1` must have the same size as the respective axis (dimension) `x2_axes[i]` for `x2`. Each sequence must consist of unique (nonnegative) integers that specify valid axes for each respective array. + +#### Returns + +- **out**: _<array>_ + + - an array containing the tensor contraction whose shape consists of the non-contracted axes (dimensions) of the first array `x1`, followed by the non-contracted axes (dimensions) of the second array `x2`. The returned array must have a data type determined by {ref}`type-promotion`. + (function-trace)= ### trace(x, /, *, axis1=0, axis2=1, offset=0) From be58b0014cd76731cd6d71eb6a7da12629004b34 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 24 Mar 2021 02:26:08 -0700 Subject: [PATCH 2/4] Update data type requirements --- spec/API_specification/linear_algebra_functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/API_specification/linear_algebra_functions.md b/spec/API_specification/linear_algebra_functions.md index ca0c3dd76..3f2a95065 100644 --- a/spec/API_specification/linear_algebra_functions.md +++ b/spec/API_specification/linear_algebra_functions.md @@ -286,11 +286,11 @@ Returns a tensor contraction of `x1` and `x2` over specific axes. - **x1**: _<array>_ - - first input array. Must have a data type of either `float32` or `float64`. + - first input array. Must have a numeric data type. - **x2**: _<array>_ - - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have a data type of either `float32` or `float64`. + - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have a numeric data type. - **axes**: _Union\[ int, Tuple\[ Sequence\[ int ], Sequence\[ int ] ] ]_ From 6c26d72eee2c6d344c9016536cb740dc7f57ef77 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Wed, 24 Mar 2021 17:48:16 -0700 Subject: [PATCH 3/4] Update dtype requirements --- spec/API_specification/linear_algebra_functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/API_specification/linear_algebra_functions.md b/spec/API_specification/linear_algebra_functions.md index 3f2a95065..cc4489cf8 100644 --- a/spec/API_specification/linear_algebra_functions.md +++ b/spec/API_specification/linear_algebra_functions.md @@ -286,11 +286,11 @@ Returns a tensor contraction of `x1` and `x2` over specific axes. - **x1**: _<array>_ - - first input array. Must have a numeric data type. + - first input array. Should have a numeric data type. - **x2**: _<array>_ - - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Must have a numeric data type. + - second input array. Must be compatible with `x1` (see {ref}`broadcasting`). Should have a numeric data type. - **axes**: _Union\[ int, Tuple\[ Sequence\[ int ], Sequence\[ int ] ] ]_ From 7d7f61c7a3602aabb28281f59f46e73a0a41365e Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 5 Apr 2021 10:46:10 -0700 Subject: [PATCH 4/4] Fix missing header --- spec/API_specification/linear_algebra_functions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/API_specification/linear_algebra_functions.md b/spec/API_specification/linear_algebra_functions.md index cc4489cf8..781ae2806 100644 --- a/spec/API_specification/linear_algebra_functions.md +++ b/spec/API_specification/linear_algebra_functions.md @@ -284,6 +284,8 @@ TODO Returns a tensor contraction of `x1` and `x2` over specific axes. +#### Parameters + - **x1**: _<array>_ - first input array. Should have a numeric data type.