Comments (1)
@zdevito the bernoulli
function has three variants:
x = torch.Tensor(10)
x.bernoulli_(0.5) # sample from bernoulli distribution with p=0.5 over all elements in x
y_float = torch.Tensor(10).uniform_()
x.bernoulli_(y) # sample from bernoulli distribution with p sourced from the corresponding value in y at each index
y_double = torch.DoubleTensor(10).uniform_()
x.bernoulli_(y) # variant of above, with double precision tensor source for p
The 2nd and 3rd variants explicitly have float
and double
Tensor arguments.
Now, for whatever reason (I didn't look into why), consider the following:
x = torch.DoubleTensor(10)
y = torch.Tensor(10)
z = torch.Tensor(10).uniform_()
torch.bernoulli(z, out=y) # ok!
torch.bernoulli(z, out=x) # invalid args, z/x must have same type
So essentially what the macros are doing is making it so that the functions generated for the first declaration call the float tensor bernoulli function when the type is CUDA_FLOAT, and the double tensor bernoulli function when the type is CUDA_DOUBLE. In the second declaration, where we don't have an output, this works. Its unclear to me without further digging why this is so, it seems that we should be able to have any output type Tensor for bernoulli...
from pytorch.
Related Issues (20)
- ported cwrap declaration changes from pytorch trunk
- Add overloaded operators to Tensor
- TensorRandom.cwrap: cpu, cuda normal functions have different options HOT 1
- topk and other have ambiguous overloads due to 'default' HOT 1
- Sort through and regularize the list of special-replacements for constants
- implement wrap_dim checking
- actually return multiple arguments using std::pair instead of just returning the first one... HOT 1
- Port a printf function to work directly from C++ HOT 1
- Add support for THNN/THCNN HOT 1
- Add non-legacy mechanism for defining operators
- Add bindings for CUDNN
- Handle before_call places correctly. HOT 1
- Add copy logic HOT 1
- Remove lt_t variants HOT 1
- What is `snapshot.py` in your blog? HOT 1
- Tensor -> Tensor/TensorImpl HOT 1
- TensorRandom.cwrap has duplicates to handle removing Generator HOT 2
- THSize/THStride handling
- THCState and multi-gpu handling HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytorch.