Expose torch.empty(sizes, *, names, ...) to Python
There are a few main components to this: Implement `tensor.names` in Python. - This results a `List[Optional[str]]`. In the future it'll return a `List[Optional[torch.Dimname]]` when we implement torch.Dimname objects, but now it is like this for testing. PythonArgParser learns how to handle `DimnameList?` - PythonArgParser stores an InternedStringsTable that maps interned PyObject* to at::Dimname objects. In cpp-land we use at::Dimname, in python land we work with strings. - PythonArgParser converts input Nones and strings to at::Dimname. - None gets converted to Dimname::wildcard() - PythonArgParser interns a python string if it is not interned (the mapping only stores interned strings). - If the interned string is not in the table, PythonArgParser parses it to get an at::Dimname and adds the (interned string, Dimname) mapping to the table. ![image](https://user-images.githubusercontent.com/5652049/59299353-7175c680-8c5a-11e9-8f57-220cce9cbec7.png) unpacking `optional<DimnameList>`. - We get an `optional<vector<Dimname>>` from `PythonArgs`. However, this needs to be converted to an `optional<ArrayRef<Dimname>>` (because that is what `at::empty` takes as an argument). - To do this, I added extra codegen to unwrap `optional<vector<Dimname>>` to `vector<Dimname>>`, convert that to `ArrayRef<Dimname>`, and then rewrap it to `optional<ArrayRef<Dimname>>`. Test Plan: - `python test/test_namedtensor.py -v` - New tests [namedtensor ci] gh-metadata: pytorch pytorch 21648 gh/zou3519/48/head
正在显示
torch/csrc/python_dimname.cpp
0 → 100644
torch/csrc/python_dimname.h
0 → 100644