Skip to content

merge from master #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1,216 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1216 commits
Select commit Hold shift + click to select a range
6080392
auto-generating sphinx docs
pytorchbot Apr 18, 2018
fabfaa5
auto-generating sphinx docs
pytorchbot Apr 18, 2018
b2d5e95
auto-generating sphinx docs
pytorchbot Apr 18, 2018
65ef768
auto-generating sphinx docs
pytorchbot Apr 18, 2018
9767afd
auto-generating sphinx docs
pytorchbot Apr 18, 2018
03a4891
auto-generating sphinx docs
pytorchbot Apr 18, 2018
04330ee
auto-generating sphinx docs
pytorchbot Apr 18, 2018
b53ba33
auto-generating sphinx docs
pytorchbot Apr 18, 2018
2195668
auto-generating sphinx docs
pytorchbot Apr 18, 2018
046a5c5
auto-generating sphinx docs
pytorchbot Apr 18, 2018
003474d
auto-generating sphinx docs
pytorchbot Apr 18, 2018
1806558
auto-generating sphinx docs
pytorchbot Apr 18, 2018
a6e793a
auto-generating sphinx docs
pytorchbot Apr 18, 2018
6b88cb6
auto-generating sphinx docs
pytorchbot Apr 18, 2018
8a06139
auto-generating sphinx docs
pytorchbot Apr 19, 2018
bad2077
auto-generating sphinx docs
pytorchbot Apr 19, 2018
f92dffa
auto-generating sphinx docs
pytorchbot Apr 19, 2018
5349821
auto-generating sphinx docs
pytorchbot Apr 19, 2018
078b2d6
auto-generating sphinx docs
pytorchbot Apr 19, 2018
3b67428
auto-generating sphinx docs
pytorchbot Apr 19, 2018
ba0cd15
auto-generating sphinx docs
pytorchbot Apr 19, 2018
6182476
auto-generating sphinx docs
pytorchbot Apr 19, 2018
cec7220
auto-generating sphinx docs
pytorchbot Apr 19, 2018
a27ce34
auto-generating sphinx docs
pytorchbot Apr 19, 2018
f4621ef
auto-generating sphinx docs
pytorchbot Apr 19, 2018
3e6a1c3
auto-generating sphinx docs
pytorchbot Apr 19, 2018
072d099
auto-generating sphinx docs
pytorchbot Apr 19, 2018
d9d6e80
auto-generating sphinx docs
pytorchbot Apr 19, 2018
bba5c8b
auto-generating sphinx docs
pytorchbot Apr 19, 2018
84d33d4
auto-generating sphinx docs
pytorchbot Apr 19, 2018
3c866e7
auto-generating sphinx docs
pytorchbot Apr 19, 2018
88bf2e8
auto-generating sphinx docs
pytorchbot Apr 19, 2018
1e03e5f
auto-generating sphinx docs
pytorchbot Apr 19, 2018
182c7e1
auto-generating sphinx docs
pytorchbot Apr 19, 2018
312b936
auto-generating sphinx docs
pytorchbot Apr 19, 2018
85ac0a3
auto-generating sphinx docs
pytorchbot Apr 19, 2018
a1a0105
auto-generating sphinx docs
pytorchbot Apr 19, 2018
8f7d3d7
auto-generating sphinx docs
pytorchbot Apr 19, 2018
1678541
auto-generating sphinx docs
pytorchbot Apr 19, 2018
78de798
auto-generating sphinx docs
pytorchbot Apr 19, 2018
91a4849
auto-generating sphinx docs
pytorchbot Apr 19, 2018
eec495b
auto-generating sphinx docs
pytorchbot Apr 19, 2018
ccf6733
auto-generating sphinx docs
pytorchbot Apr 19, 2018
53b1113
auto-generating sphinx docs
pytorchbot Apr 19, 2018
84d94a0
auto-generating sphinx docs
pytorchbot Apr 19, 2018
4a88a10
auto-generating sphinx docs
pytorchbot Apr 19, 2018
950d8d3
auto-generating sphinx docs
pytorchbot Apr 19, 2018
83dbee7
auto-generating sphinx docs
pytorchbot Apr 19, 2018
7b709de
auto-generating sphinx docs
pytorchbot Apr 19, 2018
c879f26
auto-generating sphinx docs
pytorchbot Apr 20, 2018
7a3b884
auto-generating sphinx docs
pytorchbot Apr 20, 2018
2aa3921
auto-generating sphinx docs
pytorchbot Apr 20, 2018
334caaf
auto-generating sphinx docs
pytorchbot Apr 20, 2018
6c0d800
auto-generating sphinx docs
pytorchbot Apr 20, 2018
620de87
auto-generating sphinx docs
pytorchbot Apr 20, 2018
f9ba450
auto-generating sphinx docs
pytorchbot Apr 20, 2018
d978d59
auto-generating sphinx docs
pytorchbot Apr 20, 2018
a266e7b
auto-generating sphinx docs
pytorchbot Apr 20, 2018
f2b88d1
auto-generating sphinx docs
pytorchbot Apr 20, 2018
36e17d3
auto-generating sphinx docs
pytorchbot Apr 20, 2018
74b97ec
auto-generating sphinx docs
pytorchbot Apr 20, 2018
be1121c
auto-generating sphinx docs
pytorchbot Apr 20, 2018
e47e9e3
auto-generating sphinx docs
pytorchbot Apr 20, 2018
9fa4a0c
auto-generating sphinx docs
pytorchbot Apr 20, 2018
0b24d71
auto-generating sphinx docs
pytorchbot Apr 20, 2018
fc2530e
auto-generating sphinx docs
pytorchbot Apr 20, 2018
18c8b2b
auto-generating sphinx docs
pytorchbot Apr 20, 2018
b00b818
auto-generating sphinx docs
pytorchbot Apr 20, 2018
781377b
auto-generating sphinx docs
pytorchbot Apr 20, 2018
5071fd2
auto-generating sphinx docs
pytorchbot Apr 20, 2018
92134d5
Small html change prevents text in div 'Run this command' from gettin…
Apr 20, 2018
906ce33
auto-generating sphinx docs
pytorchbot Apr 20, 2018
4126f19
auto-generating sphinx docs
pytorchbot Apr 21, 2018
d633aa1
Merge pull request #23 from ericnakagawa/master
soumith Apr 21, 2018
7ae4797
auto-generating sphinx docs
pytorchbot Apr 21, 2018
0467fa9
auto-generating sphinx docs
pytorchbot Apr 21, 2018
02b9caa
auto-generating sphinx docs
pytorchbot Apr 21, 2018
cb638f5
auto-generating sphinx docs
pytorchbot Apr 21, 2018
7644156
auto-generating sphinx docs
pytorchbot Apr 21, 2018
909f0f3
auto-generating sphinx docs
pytorchbot Apr 21, 2018
6440bb7
auto-generating sphinx docs
pytorchbot Apr 21, 2018
0f13f4d
auto-generating sphinx docs
pytorchbot Apr 21, 2018
2078a74
auto-generating sphinx docs
pytorchbot Apr 21, 2018
83b3496
auto-generating sphinx docs
pytorchbot Apr 21, 2018
b19db3a
auto-generating sphinx docs
pytorchbot Apr 21, 2018
7cb8dee
auto-generating sphinx docs
pytorchbot Apr 21, 2018
3274607
auto-generating sphinx docs
pytorchbot Apr 21, 2018
39dce3f
PyTorch 0.4.0 Migration Guide
ssnl Apr 22, 2018
976c5f4
add links to to()
ssnl Apr 22, 2018
4979277
typos
ssnl Apr 22, 2018
eb43a3d
torch.tensor
ssnl Apr 22, 2018
e6ec6f7
auto-generating sphinx docs
pytorchbot Apr 22, 2018
793024f
auto-generating sphinx docs
pytorchbot Apr 22, 2018
fdf2624
auto-generating sphinx docs
pytorchbot Apr 22, 2018
b4b67a0
auto-generating sphinx docs
pytorchbot Apr 22, 2018
ec446b1
auto-generating sphinx docs
pytorchbot Apr 22, 2018
0f3d8e5
auto-generating sphinx docs
pytorchbot Apr 22, 2018
e72d2ae
auto-generating sphinx docs
pytorchbot Apr 22, 2018
a2fb37a
auto-generating sphinx docs
pytorchbot Apr 22, 2018
164d7b0
auto-generating sphinx docs
pytorchbot Apr 22, 2018
325dffd
auto-generating sphinx docs
pytorchbot Apr 23, 2018
f42fcf3
remove incorrect warning on assigning to .data
ssnl Apr 23, 2018
e4792fd
auto-generating sphinx docs
pytorchbot Apr 23, 2018
349db0a
auto-generating sphinx docs
pytorchbot Apr 23, 2018
ecf4051
auto-generating sphinx docs
pytorchbot Apr 23, 2018
d40ae43
auto-generating sphinx docs
pytorchbot Apr 23, 2018
33e526c
auto-generating sphinx docs
pytorchbot Apr 23, 2018
e260ab3
auto-generating sphinx docs
pytorchbot Apr 23, 2018
2f4888e
auto-generating sphinx docs
pytorchbot Apr 23, 2018
c15a8d5
auto-generating sphinx docs
pytorchbot Apr 23, 2018
5954d29
auto-generating sphinx docs
pytorchbot Apr 23, 2018
91a4850
auto-generating sphinx docs
pytorchbot Apr 23, 2018
de78da4
auto-generating sphinx docs
pytorchbot Apr 23, 2018
74a5b22
auto-generating sphinx docs
pytorchbot Apr 23, 2018
e650d9b
auto-generating sphinx docs
pytorchbot Apr 23, 2018
6c01679
auto-generating sphinx docs
pytorchbot Apr 23, 2018
acacf39
add set/get_default_dtype, sizes tuple&varargs, and formats
ssnl Apr 24, 2018
35e9288
add back links in titles
ssnl Apr 24, 2018
fef288a
emphasize torch.tensor copy
ssnl Apr 24, 2018
dd2c9c5
link at top
ssnl Apr 24, 2018
04cbe59
auto-generating sphinx docs
pytorchbot Apr 24, 2018
1fdc6b1
update content
ssnl Apr 24, 2018
4768a9e
formatting
ssnl Apr 24, 2018
8894042
updates
ssnl Apr 24, 2018
bdf35f9
update and fix 1 rendering issue
ssnl Apr 24, 2018
1a9be50
fix linewrap
ssnl Apr 24, 2018
c10c0b6
hacky solution
ssnl Apr 24, 2018
76f4912
Merge pull request #24 from SsnL/0_4_migration
soumith Apr 24, 2018
9c49db2
To be consistent with the one yaer in ... post
ssnl Apr 24, 2018
912611a
Merge pull request #25 from SsnL/minor_fixes
soumith Apr 24, 2018
e598b79
auto-generating sphinx docs
pytorchbot Apr 24, 2018
4a04a2b
auto-generating sphinx docs
pytorchbot Apr 24, 2018
c2d80cf
auto-generating sphinx docs
pytorchbot Apr 24, 2018
2daac88
0.4.0 docs
soumith Apr 24, 2018
5448c51
regex for 0.4.0 docs
soumith Apr 24, 2018
df1fa6c
move around stable docs
soumith Apr 24, 2018
4da5d13
push 0.4.0 to wizard
soumith Apr 24, 2018
1624363
auto-generating sphinx docs
pytorchbot Apr 24, 2018
f999cba
Add windows matrix
zou3519 Apr 24, 2018
4dece98
Merge pull request #26 from zou3519/windows-matrix
soumith Apr 24, 2018
6da575a
Fix docs links in migration guide
zou3519 Apr 24, 2018
c99d2f1
auto-generating sphinx docs
pytorchbot Apr 24, 2018
7b8fcef
Merge pull request #27 from zou3519/fix-docs-links
soumith Apr 24, 2018
01d7fa7
auto-generating sphinx docs
pytorchbot Apr 24, 2018
50221b3
Fix redirects
zou3519 Apr 24, 2018
ebf62d3
Merge pull request #28 from zou3519/fix-redirects
soumith Apr 24, 2018
525f804
auto-generating sphinx docs
pytorchbot Apr 24, 2018
4c1359f
Fix page to recommend pip torchvision
zou3519 Apr 24, 2018
4d31a74
Merge pull request #29 from zou3519/pip-torchvision
soumith Apr 24, 2018
26938b2
auto-generating sphinx docs
pytorchbot Apr 24, 2018
6ad5f73
auto-generating sphinx docs
pytorchbot Apr 24, 2018
336b03e
auto-generating sphinx docs
pytorchbot Apr 25, 2018
60f2fe8
auto-generating sphinx docs
pytorchbot Apr 25, 2018
78f6e63
auto-generating sphinx docs
pytorchbot Apr 25, 2018
a5a9b0e
auto-generating sphinx docs
pytorchbot Apr 25, 2018
df39d93
auto-generating sphinx docs
pytorchbot Apr 25, 2018
a8c83a8
auto-generating sphinx docs
pytorchbot Apr 25, 2018
c04bb67
auto-generating sphinx docs
pytorchbot Apr 25, 2018
f127221
auto-generating sphinx docs
pytorchbot Apr 25, 2018
2b6f4a9
auto-generating sphinx docs
pytorchbot Apr 25, 2018
e5c1279
auto-generating sphinx docs
pytorchbot Apr 25, 2018
215f056
auto-generating sphinx docs
pytorchbot Apr 25, 2018
af93a6b
auto-generating sphinx docs
pytorchbot Apr 25, 2018
41312f0
auto-generating sphinx docs
pytorchbot Apr 25, 2018
0487759
auto-generating sphinx docs
pytorchbot Apr 25, 2018
fff7b71
auto-generating sphinx docs
pytorchbot Apr 25, 2018
ebeb22e
auto-generating sphinx docs
pytorchbot Apr 25, 2018
3e26b91
auto-generating sphinx docs
pytorchbot Apr 25, 2018
8e5d158
auto-generating sphinx docs
pytorchbot Apr 25, 2018
3b6c463
auto-generating sphinx docs
pytorchbot Apr 25, 2018
d3de572
move to torchvision-cpu packages
soumith Apr 25, 2018
c075d4e
auto-generating sphinx docs
pytorchbot Apr 25, 2018
9c66b05
auto-generating sphinx docs
pytorchbot Apr 25, 2018
77e88db
auto-generating sphinx docs
pytorchbot Apr 25, 2018
e0985c8
auto-generating sphinx docs
pytorchbot Apr 25, 2018
d1847db
auto-generating sphinx docs
pytorchbot Apr 25, 2018
150819b
auto-generating sphinx docs
pytorchbot Apr 26, 2018
148af2f
auto-generating sphinx docs
pytorchbot Apr 26, 2018
373b553
auto-generating sphinx docs
pytorchbot Apr 26, 2018
1ca32d9
auto-generating sphinx docs
pytorchbot Apr 26, 2018
eee475c
auto-generating sphinx docs
pytorchbot Apr 26, 2018
0062e47
auto-generating sphinx docs
pytorchbot Apr 26, 2018
109c673
auto-generating sphinx docs
pytorchbot Apr 26, 2018
b7f3b79
auto-generating sphinx docs
pytorchbot Apr 26, 2018
ea25f1a
auto-generating sphinx docs
pytorchbot Apr 26, 2018
e10bdc2
auto-generating sphinx docs
pytorchbot Apr 26, 2018
05d7639
auto-generating sphinx docs
pytorchbot Apr 26, 2018
f352d09
auto-generating sphinx docs
pytorchbot Apr 26, 2018
8482474
auto-generating sphinx docs
pytorchbot Apr 26, 2018
f63b085
auto-generating sphinx docs
pytorchbot Apr 26, 2018
16e3272
auto-generating sphinx docs
pytorchbot Apr 26, 2018
ddad16c
auto-generating sphinx docs
pytorchbot Apr 26, 2018
a07a1eb
auto-generating sphinx docs
pytorchbot Apr 26, 2018
26a1ebf
auto-generating sphinx docs
pytorchbot Apr 26, 2018
e00c12a
auto-generating sphinx docs
pytorchbot Apr 26, 2018
fe322de
auto-generating sphinx docs
pytorchbot Apr 26, 2018
ec856d5
auto-generating sphinx docs
pytorchbot Apr 26, 2018
bab9ad0
auto-generating sphinx docs
pytorchbot Apr 26, 2018
b0d1a19
auto-generating sphinx docs
pytorchbot Apr 26, 2018
bf48c6d
auto-generating sphinx docs
pytorchbot Apr 26, 2018
23b734d
auto-generating sphinx docs
pytorchbot Apr 26, 2018
1c2e5ea
auto-generating sphinx docs
pytorchbot Apr 26, 2018
518a38b
auto-generating sphinx docs
pytorchbot Apr 26, 2018
b29900f
Update migration guide on new constraints of module/buffer/parameter …
ssnl Apr 26, 2018
86d902b
auto-generating sphinx docs
pytorchbot Apr 26, 2018
6bbd370
Merge pull request #30 from SsnL/module_name_dot
soumith Apr 26, 2018
a3f0ba6
auto-generating sphinx docs
pytorchbot Apr 26, 2018
c806b22
auto-generating sphinx docs
pytorchbot Apr 26, 2018
ea22865
auto-generating sphinx docs
pytorchbot Apr 26, 2018
c49eb27
auto-generating sphinx docs
pytorchbot Apr 26, 2018
da235fc
auto-generating sphinx docs
pytorchbot Apr 26, 2018
68ffa50
auto-generating sphinx docs
pytorchbot Apr 26, 2018
cf16e62
auto-generating sphinx docs
pytorchbot Apr 26, 2018
f7707f9
auto-generating sphinx docs
pytorchbot Apr 27, 2018
75ef7c3
auto-generating sphinx docs
pytorchbot Apr 27, 2018
d6fdf2a
auto-generating sphinx docs
pytorchbot Apr 27, 2018
bddf5a5
auto-generating sphinx docs
pytorchbot Apr 27, 2018
7bf7645
auto-generating sphinx docs
pytorchbot Apr 27, 2018
458a6ea
auto-generating sphinx docs
pytorchbot Apr 27, 2018
4f9988f
auto-generating sphinx docs
pytorchbot Apr 27, 2018
029bfad
auto-generating sphinx docs
pytorchbot Apr 27, 2018
23f5c7c
auto-generating sphinx docs
pytorchbot Apr 27, 2018
0c869b5
auto-generating sphinx docs
pytorchbot Apr 27, 2018
8b0d5ac
auto-generating sphinx docs
pytorchbot Apr 27, 2018
54855fd
auto-generating sphinx docs
pytorchbot Apr 27, 2018
912cfbd
auto-generating sphinx docs
pytorchbot Apr 27, 2018
9251e70
auto-generating sphinx docs
pytorchbot Apr 27, 2018
07c8ea5
auto-generating sphinx docs
pytorchbot Apr 27, 2018
9e39e34
auto-generating sphinx docs
pytorchbot Apr 27, 2018
c263d21
auto-generating sphinx docs
pytorchbot Apr 27, 2018
0e385fa
auto-generating sphinx docs
pytorchbot Apr 28, 2018
700fad0
auto-generating sphinx docs
pytorchbot Apr 28, 2018
da74646
auto-generating sphinx docs
pytorchbot Apr 28, 2018
f7ea270
auto-generating sphinx docs
pytorchbot Apr 28, 2018
166c8ab
auto-generating sphinx docs
pytorchbot Apr 28, 2018
b38e77d
auto-generating sphinx docs
pytorchbot Apr 28, 2018
24de183
auto-generating sphinx docs
pytorchbot Apr 28, 2018
5a32af0
auto-generating sphinx docs
pytorchbot Apr 28, 2018
6094f1a
auto-generating sphinx docs
pytorchbot Apr 28, 2018
4ec09f3
auto-generating sphinx docs
pytorchbot Apr 28, 2018
98e743d
auto-generating sphinx docs
pytorchbot Apr 28, 2018
c52e4bd
auto-generating sphinx docs
pytorchbot Apr 28, 2018
758299d
auto-generating sphinx docs
pytorchbot Apr 28, 2018
92600ba
auto-generating sphinx docs
pytorchbot Apr 28, 2018
89ea9ff
auto-generating sphinx docs
pytorchbot Apr 28, 2018
95cc479
auto-generating sphinx docs
pytorchbot Apr 29, 2018
8317a0c
auto-generating sphinx docs
pytorchbot Apr 29, 2018
1dfb21a
auto-generating sphinx docs
pytorchbot Apr 29, 2018
f102294
auto-generating sphinx docs
pytorchbot Apr 29, 2018
f8b0651
auto-generating sphinx docs
pytorchbot Apr 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_site/
Gemfile.lock
14 changes: 12 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ sass:
sass_dir: _sass # default
style: compressed
safe: true
highlighter: rouge
markdown: kramdown
future: true
include:
- _static
- _images
- _modules
- _sources
- _tensor_str.html
Expand All @@ -30,3 +29,14 @@ exclude:

plugins:
- jekyll-feed

highlighter: rouge
markdown: kramdown
kramdown:
# Use GitHub flavored markdown, including triple backtick fenced code blocks
input: GFM
# Jekyll 3 and GitHub Pages now only support rouge for syntax highlighting
syntax_highlighter: rouge
syntax_highlighter_opts:
# Use existing pygments syntax highlighting css
css_class: 'highlight'
300 changes: 187 additions & 113 deletions _data/wizard.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions _includes/primary-nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<li><a {% if page.id == 'about' %}class="active"{% endif %} href="/about/">About</a></li>
<li><a {% if page.id == 'blog' %}class="active"{% endif %} href="/blog/">Blog</a></li>
<li><a {% if page.id == 'support' %}class="active"{% endif %} href="/support/">Support</a></li>
<li><a {% if page.id == 'tutorials' %}class="active"{% endif %} href="http://pytorch.org/tutorials/">Tutorials</a></li>
<li><a {% if page.id == 'apps' %}class="active"{% endif %} href="https://discuss.pytorch.org">Discuss</a></li>
</ul>
1 change: 1 addition & 0 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<link rel="stylesheet" href="/static/css/main.css">
<link rel="stylesheet" href="/static/css/jekyll-github.css">
</head>
<body id="{{ page.id }}">

Expand Down
6 changes: 3 additions & 3 deletions docs/tensors.html → _layouts/redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1; url=master/tensors.html">
<meta http-equiv="refresh" content="1; url={{ page.redirect_url }}">
<script type="text/javascript">
window.location.href = "master/tensors.html"
window.location.href = "{{ page.redirect_url }}"
</script>
<title>Page Redirection</title>
</head>
<body>
If you are not redirected automatically, follow this <a href='master/tensors.html'>link to the latest documentation</a>.
If you are not redirected automatically, follow this <a href='{{ page.redirect_url }}'>link to the latest documentation</a>.
<br />
If you want to view documentation for a particular version, follow this <a href='versions.html'>link</a>.
</body>
Expand Down
53 changes: 29 additions & 24 deletions _posts/2017-5-11-Internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ typedef struct {
The `PyObject_HEAD` is a macro that brings in the code that implements an object's reference counting, and a pointer to the corresponding type object. So in this case, to implement a float, the only other "state" needed is the floating point value itself.

Now, let's see the struct for our `THPTensor` type:
```
```cpp
struct THPTensor {
PyObject_HEAD
THTensor *cdata;
Expand All @@ -65,7 +65,7 @@ struct THPTensor {
Pretty simple, right? We are just wrapping the underlying `TH` tensor by storing a pointer to it.

The key part is defining the "type object" for a new type. An example definition of a type object for our Python float takes the form:
```
```cpp
static PyTypeObject py_FloatType = {
PyVarObject_HEAD_INIT(NULL, 0)
"py.FloatObject", /* tp_name */
Expand Down Expand Up @@ -97,16 +97,16 @@ The type object for our `THPTensor` is `THPTensorType`, defined in `csrc/generic

As an example, let's take a look at the `tp_new` function we set in the `PyTypeObject`:

```
```cpp
PyTypeObject THPTensorType = {
PyVarObject_HEAD_INIT(NULL, 0)
...
THPTensor_(pynew), /* tp_new */
};
```
The `tp_new` function enables object creation. It is responsible for creating (as opposed to initializing) objects of that type and is equivalent to the `__new()__` method at the Python level. The C implementation is a static method that is passed the type being instantiated and any arguments, and returns a newly created object.
The `tp_new` function enables object creation. It is responsible for creating (as opposed to initializing) objects of that type and is equivalent to the `__new__()` method at the Python level. The C implementation is a static method that is passed the type being instantiated and any arguments, and returns a newly created object.

```
```cpp
static PyObject * THPTensor_(pynew)(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
HANDLE_TH_ERRORS
Expand All @@ -117,7 +117,7 @@ static PyObject * THPTensor_(pynew)(PyTypeObject *type, PyObject *args, PyObject
```
The first thing our new function does is allocate the `THPTensor`. It then runs through a series of initializations based off of the args passed to the function. For example, when creating a `THPTensor` *x* from another `THPTensor` *y*, we set the newly created `THPTensor`'s `cdata` field to be the result of calling `THTensor_(newWithTensor)` with the *y*'s underlying `TH` Tensor as an argument. Similar constructors exist for sizes, storages, NumPy arrays, and sequences.

** Note that we solely use `tp_new`, and not a combination of `tp_new` and `tp_init` (which corresponds to the `__init()__` function).
** Note that we solely use `tp_new`, and not a combination of `tp_new` and `tp_init` (which corresponds to the `__init__()` function).

The other important thing defined in Tensor.cpp is how indexing works. PyTorch Tensors support Python's **Mapping Protocol**. This allows us to do things like:
```python
Expand All @@ -136,7 +136,7 @@ The most important methods are `THPTensor_(getValue)` and `THPTensor_(setValue)`
---

We could spend a ton of time exploring various aspects of the `THPTensor` and how it relates to defining a new Python object. But we still need to see how the `THPTensor_(init)()` function is translated to the `THPIntTensor_init()` we used in our module initialization. How do we take our `Tensor.cpp` file that defines a "generic" Tensor and use it to generate Python objects for all the permutations of types? To put it another way, `Tensor.cpp` is littered with lines of code like:
```
```cpp
return THPTensor_(New)(THTensor_(new)(LIBRARY_STATE_NOARGS));
```
This illustrates both cases we need to make type-specific:
Expand All @@ -149,15 +149,15 @@ In other words, for all supported Tensor types, we need to "generate" source cod
One component building an Extension module using Setuptools is to list the source files involved in the compilation. However, our `csrc/generic/Tensor.cpp` file is not listed! So how does the code in this file end up being a part of the end product?

Recall that we are calling the `THPTensor*` functions (such as `init`) from the directory above `generic`. If we take a look in this directory, there is another file `Tensor.cpp` defined. The last line of this file is important:
```
```cpp
//generic_include TH torch/csrc/generic/Tensor.cpp
```
Note that this `Tensor.cpp` file is included in `setup.py`, but it is wrapped in a call to a Python helper function called `split_types`. This function takes as input a file, and looks for the "//generic_include" string in the file contents. If it is found, it generates a new output file for each Tensor type, with the following changes:

- The output file is renamed to `Tensor<Type>.cpp`
- The output file is slightly modified as follows:

```
```cpp
# Before:
//generic_include TH torch/csrc/generic/Tensor.cpp

Expand All @@ -166,7 +166,8 @@ Note that this `Tensor.cpp` file is included in `setup.py`, but it is wrapped in
#include "TH/THGenerate<Type>Type.h"
```
Including the header file on the second line has the side effect of including the source code in `Tensor.cpp` with some additional context defined. Let's take a look at one of the headers:
```

```cpp
#ifndef TH_GENERIC_FILE
#error "You must define TH_GENERIC_FILE before including THGenerateFloatType.h"
#endif
Expand All @@ -192,21 +193,22 @@ Including the header file on the second line has the side effect of including th
#undef TH_GENERIC_FILE
#endif
```

What this is doing is bringing in the code from the generic `Tensor.cpp` file and surrounding it with the following macro definitions. For example, we define real as a float, so any code in the generic Tensor implementation that refers to something as a real will have that real replaced with a float. In the corresponding file `THGenerateIntType.h`, the same macro would replace `real` with `int`.

These output files are returned from `split_types` and added to the list of source files, so we can see how the `.cpp` code for different types is created.

There are a few things to note here: First, the `split_types` function is not strictly necessary. We could wrap the code in `Tensor.cpp` in a single file, repeating it for each type. The reason we split the code into separate files is to speed up compilation. Second, what we mean when we talk about the type replacement (e.g. replace real with a float) is that the C preprocessor will perform these subsitutions during compilaiton. Merely surrounding the source code with these macros has no side effects until preprocessing.
There are a few things to note here: First, the `split_types` function is not strictly necessary. We could wrap the code in `Tensor.cpp` in a single file, repeating it for each type. The reason we split the code into separate files is to speed up compilation. Second, what we mean when we talk about the type replacement (e.g. replace real with a float) is that the C preprocessor will perform these substitutions during compilation. Merely surrounding the source code with these macros has no side effects until preprocessing.

### Generic Builds (Part Two)
---

Now that we have source files for all the Tensor types, we need to consider how the corresponding header declarations are created, and also how the conversions from `THTensor_(method)` and `THPTensor_(method)` to `TH<Type>Tensor_method` and `THP<Type>Tensor_method` work. For example, `csrc/generic/Tensor.h` has declarations like:
```
```cpp
THP_API PyObject * THPTensor_(New)(THTensor *ptr);
```
We use the same strategy for generating code in the source files for the headers. In `csrc/Tensor.h`, we do the following:
```
```cpp
#include "generic/Tensor.h"
#include <TH/THGenerateAllTypes.h>

Expand All @@ -216,26 +218,28 @@ We use the same strategy for generating code in the source files for the headers
This has the same effect, where we draw in the code from the generic header, wrapped with the same macro definitions, for each type. The only difference is that the resulting code is contained all within the same header file, as opposed to being split into multiple source files.

Lastly, we need to consider how we "convert" or "substitute" the function types. If we look in the same header file, we see a bunch of `#define` statements, including:
```
```cpp
#define THPTensor_(NAME) TH_CONCAT_4(THP,Real,Tensor_,NAME)
```
This macro says that any string in the source code matching the format `THPTensor_(NAME)` should be replaced with `THPRealTensor_NAME`, where Real is derived from whatever the symbol Real is `#define`'d to be at the time. Because our header code and source code is surrounded by macro definitions for all the types as seen above, after the preprocessor has run, the resulting code is what we would expect. The code in the `TH` library defines the same macro for `THTensor_(NAME)`, supporting the translation of those functions as well. In this way, we end up with header and source files with specialized code.
####Module Objects and Type Methods

#### Module Objects and Type Methods

Now we have seen how we have wrapped `TH`'s Tensor definition in `THP`, and generated THP methods such as `THPFloatTensor_init(...)`. Now we can explore what the above code actually does in terms of the module we are creating. The key line in `THPTensor_(init)` is:
```
```cpp
# THPTensorBaseStr, THPTensorType are also macros that are specific
# to each type
PyModule_AddObject(module, THPTensorBaseStr, (PyObject *)&THPTensorType);
```
This function registers our Tensor objects to the extension module, so we can use THPFloatTensor, THPIntTensor, etc. in our Python code.

Just being able to create Tensors isn't very useful - we need to be able to call all the methods that `TH` defines. A simple example shows calling the in-place `zero_` method on a Tensor.
```
```python
x = torch.FloatTensor(10)
x.zero_()
```
Let's start by seeing how we add methods to newly defined types. One of the fields in the "type object" is `tp_methods`. This field holds an array of method definitions (`PyMethodDef`s) and is used to associate methods (and their underlying C/C++ implementations) with a type. Suppose we wanted to define a new method on our `PyFloatObject` that replaces the value. We could implement this as follows:
```
```cpp
static PyObject * replace(PyFloatObject *self, PyObject *args) {
double val;
if (!PyArg_ParseTuple(args, "d", &val))
Expand All @@ -245,12 +249,12 @@ static PyObject * replace(PyFloatObject *self, PyObject *args) {
}
```
This is equivalent to the Python method:
```
```python
def replace(self, val):
self.ob_fval = fal
self.ob_fval = val
```
It is instructive to read more about how defining methods works in CPython. In general, methods take as the first parameter the instance of the object, and optionally parameters for the positional arguments and keyword arguments. This static function is registered as a method on our float:
```
```cpp
static PyMethodDef float_methods[] = {
{"replace", (PyCFunction)replace, METH_VARARGS,
"replace the value in the float"
Expand All @@ -261,9 +265,10 @@ static PyMethodDef float_methods[] = {
This registers a method called replace, which is implemented by the C function of the same name. The `METH_VARARGS` flag indicates that the method takes a tuple of arguments representing all the arguments to the function. This array is set to the `tp_methods` field of the type object, and then we can use the `replace` method on objects of that type.

We would like to be able to call all of the methods for `TH` tensors on our `THP` tensor equivalents. However, writing wrappers for all of the `TH` methods would be time-consuming and error prone. We need a better way to do this.

### PyTorch cwrap
---
PyTorch implements its own cwrap tool to wrap the `TH` Tensor methods for use in the Python backend. We define a `.cwrap` file containing a series of C method declarations in our custom YAML format (http://yaml.org). The cwrap tool takes this file and outputs `.cpp` source files containing the wrapped methods in a format that is compatible with our `THPTensor` Python object and the Python C extension method calling format. This tool is used to generate code to wrap not only `TH`, but also `CuDNN`. It is defined to be extensible.
PyTorch implements its own cwrap tool to wrap the `TH` Tensor methods for use in the Python backend. We define a `.cwrap` file containing a series of C method declarations in our custom [YAML format](http://yaml.org). The cwrap tool takes this file and outputs `.cpp` source files containing the wrapped methods in a format that is compatible with our `THPTensor` Python object and the Python C extension method calling format. This tool is used to generate code to wrap not only `TH`, but also `CuDNN`. It is defined to be extensible.

An example YAML "declaration" for the in-place `addmv_` function is as follows:
```
Expand All @@ -284,7 +289,7 @@ An example YAML "declaration" for the in-place `addmv_` function is as follows:
```
The architecture of the cwrap tool is very simple. It reads in a file, and then processes it with a series of **plugins.** See `tools/cwrap/plugins/__init__.py` for documentation on all the ways a plugin can alter the code.

The source code generation occurs in a series of passes. First, the YAML "declaration" is parsed and processed. Then the source code is generated piece-by-piece - adding things like argument checks and extractions, defining the method header, and the actual call to the underlying library such as `TH`. Finally, the cwrap tool allows for processing the entire file at a time. The resulting output for `addmv_` can be explored here: https://gist.github.com/killeent/c00de46c2a896335a52552604cc4d74b.
The source code generation occurs in a series of passes. First, the YAML "declaration" is parsed and processed. Then the source code is generated piece-by-piece - adding things like argument checks and extractions, defining the method header, and the actual call to the underlying library such as `TH`. Finally, the cwrap tool allows for processing the entire file at a time. The resulting output for `addmv_` can be [explored here](https://gist.github.com/killeent/c00de46c2a896335a52552604cc4d74b).

In order to interface with the CPython backend, the tool generates an array of `PyMethodDef`s that can be stored or appended to the `THPTensor`'s `tp_methods` field.

Expand Down Expand Up @@ -322,4 +327,4 @@ This is just a snapshot of parts of the build system for PyTorch. There is more
### Resources:
---

- https://docs.python.org/3.7/extending/index.html is invaluable for understanding how to write C/C++ Extension to Python
- <https://docs.python.org/3.7/extending/index.html> is invaluable for understanding how to write C/C++ Extension to Python
Loading