Skip to content

Commit 1a01815

Browse files
joyceerhlluabud
authored andcommitted
Show tensor dimensions in variable explorer (microsoft#14244)
1 parent ddfbd77 commit 1a01815

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

pythonFiles/tests/ipython/getJupyterVariableList.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from IPython import get_ipython as _VSCODE_get_ipython
66

77
# _VSCode_supportsDataExplorer will contain our list of data explorer supported types
8-
_VSCode_supportsDataExplorer = "['list', 'Series', 'dict', 'ndarray', 'DataFrame']"
8+
_VSCode_supportsDataExplorer = (
9+
"['list', 'Series', 'dict', 'ndarray', 'DataFrame', 'Tensor']"
10+
)
911

1012
# who_ls is a Jupyter line magic to fetch currently defined vars
1113
_VSCode_JupyterVars = _VSCODE_get_ipython().run_line_magic("who_ls", "")

pythonFiles/vscode_datascience_helpers/dataframes/vscodeGetVariableInfo.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
import builtins as _VSCODE_builtins
66
import vscodeDataFrameHelpers as _VSCODE_dataFrameHelpers
77

8+
9+
def _VSCODE_maybeParseTensorShape(var, result):
10+
try:
11+
vartype = type(var)
12+
if (hasattr(vartype, "__name__")) and vartype.__name__ == "Tensor":
13+
varshape = str(var.shape)
14+
start = varshape.index("[")
15+
end = varshape.index("]")
16+
if start > 0 and end > 0:
17+
res = "(" + varshape[start + 1 : end] + ")"
18+
result["shape"] = res
19+
except TypeError:
20+
pass
21+
22+
823
# Function to do our work. It will return the object
924
def _VSCODE_getVariableInfo(var):
1025
# Start out without the information
@@ -26,6 +41,7 @@ def _VSCODE_getVariableInfo(var):
2641
):
2742
result["shape"] = _VSCODE_shapeStr
2843
del _VSCODE_shapeStr
44+
_VSCODE_maybeParseTensorShape(var, result)
2945
except TypeError:
3046
pass
3147

pythonFiles/vscode_datascience_helpers/getJupyterVariableDataFrameInfo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import builtins as _VSCODE_builtins
66

77
# _VSCode_sub_supportsDataExplorer will contain our list of data explorer supported types
8-
_VSCode_supportsDataExplorer = "['list', 'Series', 'dict', 'ndarray', 'DataFrame']"
8+
_VSCode_supportsDataExplorer = (
9+
"['list', 'Series', 'dict', 'ndarray', 'DataFrame', 'Tensor']"
10+
)
911

1012
# In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable
1113
# Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable

src/client/datascience/jupyter/kernelVariables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const DocStringRegex = /.*?\[.*?;31mDocstring:.*?\[0m\s+(.*)/;
3434
const CountRegex = /.*?\[.*?;31mLength:.*?\[0m\s+(.*)/;
3535
const ShapeRegex = /^\s+\[(\d+) rows x (\d+) columns\]/m;
3636

37-
const DataViewableTypes: Set<string> = new Set<string>(['DataFrame', 'list', 'dict', 'ndarray', 'Series']);
37+
const DataViewableTypes: Set<string> = new Set<string>(['DataFrame', 'list', 'dict', 'ndarray', 'Series', 'Tensor']);
3838

3939
interface INotebookState {
4040
currentExecutionCount: number;

0 commit comments

Comments
 (0)