'Ways to find where a function is defined on a github repo without having to do a manual search?
I've been looking at the pytorch repo. In particular, I'm trying to find where this function is defined: https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/core/TensorBase.h#L505-L506
It's declared here in the header file but I can't seem to find where it's actually defined. Is there a quick way I can do this for a github repo?
Solution 1:[1]
You can search a lot of things without downloading the repo by using github search bar :
If you want full vscode search abilities, you can also use this marvelous project : https://github1s.com/pytorch/pytorch
Edit #1: It have been brought to my attention, that you can have a similar effect by pressing the dot on you keyboard from -any- github repository directly ;) Enjoy !
Edit #2 : I also learnt that there is also this : https://gitpod.io/#{repository github url} that you can use to read and edit your own repo. Wow, the things we discover every days !
Solution 2:[2]
I don't think github has any such functionality and the search function often times doesn't work well for me.
However, depending on the specific case, there are some heuristic methods using the web interface that are quicker than scrolling through the search results.
For example in this case, have a look at the git blame for the line. The commit putting the declaration there should also have put the definition somewhere, usually.
In this case you will get this commit, which by a quick search on the page shows you that there is a macro for explicit specialization definitions of the function template in this file.
I also couldn't find a definition of the primary template with a quick look. Presumably the function is supposed to be explicitly specialized for all types it is used with.
Solution 3:[3]
The best way I know is to get a local copy with git clone and use git grep -n <fn_name> from the root of the directory (or wherever the source code is stored, either is fine). That will list all instances of the last argument and what file and line number it appears on, so it's typically pretty easy to tell which is the definition because it will have a { instead of a ; at the end.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | user17732522 |
| Solution 3 | Catcow |

