Modules in pytorch

username: km_proton
cooked: <p>torch.tensor()<br>
torch.utils.data.dataloader()<br>
my question is if we consider torch as .py file then contadicts to second statement that if utils is a class then dataloader is function then what is data . If we consider torch as package then functions cannot be inside a package (functions can only be inside a .py file) it contradicts to first statement . i have been reserching about this in many sites and forums but i was not able to find answer . could you please tell me the solution along with what happens when you import torch (what happens when you import torch like where is it being placed). is tensor a function present in <strong>init</strong> please explain the working when you import pytorch to the modules and files present inside pytorch(along with answer to this question)</p>

username: chetan06
cooked: <p>You can go  to the <a href="https://github.com/pytorch/pytorch/tree/master/torch/utils/data" rel="nofollow noopener">official github</a> page and can get a clear answer. Actually torch is the main package, then utils is a subpackage under it, data is subpackage under utils and then dataloader is finally the class.</p>
<p>You should note that a package can have subpackages as well as classes , so tensor is a class under torch and utils is a package under the same package</p>

username: km_proton
cooked: <p><a class="mention" href="/u/chetan06">@chetan06</a>  sorry if i am disturbing you .  i would like to ask you one question<br>
1.if i import torch then if there is a file called tensor.py which contains the (assume) class tensor1 then if i need to call the class tensor1 is it enough to call tensor1() or should i call tensor.tensor1</p>

username: chetan06
cooked: <p>I think tensor1() is enough. as<br>
When you write</p>
<pre><code class="lang-auto">from torch.utils.data import DataLoader
</code></pre>
<p>then you write the class Dataloader in file dataloader.py within the package torch.util.data.</p>
<p>I think I  have made myself clear, if not feel free to ask</p>

username: km_proton
cooked: <p><a class="mention" href="/u/chetan06">@chetan06</a><br>
no i am a beginer to python all i am thaught by my instructors is if you want to use  a function fn1 present in a file called file.py present in another package pkg1 then use should<br>
import pkg1<br>
pkg1.file.fn1<br>
this is all i know about python i dont know if there is any tutorial explaining how to use classes present in a module (i dont know about importing classes)</p>
<p>what i have come to observe is in pytorch if there is a class cls1 present in file file.py which is present in package pkg1 to use class cls1 we<br>
import pk1<br>
pkg1.cls1<br>
we omit file.py (ie we omit file.py insted of writting pkg1.file.cls1 we write as above)<br>
correct me if i am wrong and please tell what i have written above is true<br>
i wonder why using function requires prefixing file name and using class doesnot</p>

username: chetan06
cooked: <p>Actually I have used other language and the same is followed there too so I thought that way. But later when I saw the torch github page , that also confirmed that file_name should be omitted. In case the confusion persists you can once try it yourself</p>

username: km_proton
cooked: <p>i have never imported a class before if we import a function it returns a value (like int,bool,string,or float)<br>
but what happens when you call a class does it returns any value ?</p>

username: chetan06
cooked: <p>You do not use a class…class is a blueprint…you make object out of that class and use that. I recommend you to once go through the object oriented programming concept.</p>

username: km_proton
cooked: <p>we use torch.tensor() right so tensor() is a class right so what happens when you call tensor() is it like calling a function like fn() . a function returns a value like bool,int,float,string ect but what does class return (a class has subfunction inside and attributes inside without specifically calling a method or attribute how can it return a value) . i am asking this because i couldnot find any tutorial usefull like i have watched oops tutorials of techwithtim,edureka,moshhamidani,coreschafer,sendex,telusko ect but no explains the concept that classes can be called . moreover i cannot afford to study in universities thats why i am asking here</p>

username: chetan06
cooked: <p>Class is a user defined datatype. Likewise the primitive datatypes like int, float, etc. it is also a datatype but user defined one. So I ask you a question: What does int return?? Think…Absolutely nothing actually we use int to define the objects.<br>
int a;  // this is followed in many languages like C++, java, etc.<br>
And with int’s object we can perform a lot many operation.<br>
In the same way, class is a datatype which without its meaning has no significance, it is just the blueprint on which its objects are made and they acquire behaviour. So class returns nothing. They are just to make objects.</p>
<p>For example, we make a class student. Student is a general name. Now its object will have specific names, ids but almost same functions…that is they study, etc.</p>
<p>I think you have read object oriented concepts in python that’s why its difficult for you to get it. I read it in java and C++ so don’t panic just go slow and feel free to ask again.</p>

username: km_proton
cooked: <p>yes i can get your point but actually if we call fn() it executes that fn and the fn returns the value and the value is the value of that fn likewise what i am asking is if i call a fn what it would return that would be stored as the value of that class (you may tell me the fn inside it but if there are two fns)<br>
no my question was actually there are two function inside tensor class  def <strong>deepcopy</strong>(self, memo):   and    def <strong>reduce_ex</strong>(self, proto):<br>
so if i call a class like torch.tensor() what does it returns does it returns first one or second one</p>