torch / cutorch

A CUDA backend for Torch7
Other
338 stars 208 forks source link

torch.random and torch.randn dont work #61

Closed soumith closed 9 years ago

soumith commented 9 years ago

when set default tensor type to CudaTensor, these two functions dont work

soumith commented 9 years ago

fixed via https://github.com/torch/cutorch/commit/e0b529c1d97a5ccf7d32d0028ef18a1fcf42608c

c0d3rman commented 9 years ago

torch.random is still broken for me.

require 'cutorch'
torch.setdefaulttensortype('torch.CudaTensor')
print(torch.random())

throws

/opt/torch/torch/install/bin/luajit: temp.lua:3: torch.CudaTensor does not implement the torch.random() function
soumith commented 9 years ago

@c0d3rman as a general good practice, do not set the default tensor type as torch.CudaTensor, there are a few API calls that are still broken. We have it on our roadmap to make cutorch completely API compatible with torch, but it is not finished.

In this particular case, you are trying to generate a single random number, not a tensor of random numbers, i.e. torch.random(10,5) will work for example.

c0d3rman commented 9 years ago

OK, thanks! I'm just adapting a library to use the GPU (specifically DeepQLearning). Figured it would make things a lot easier to just set the default tensor type. The torch.random() statement in their code is this:

return (torch.random! % Brain.net_outputs) + 1

For now I'll try to make all tensors CudaTensors manually.

soumith commented 9 years ago

oh wow, that's a great start. let me know if you get stuck somewhere.