Created
September 21, 2016 12:10
-
-
Save hughperkins/fdf8e27daec983e69767ef6bbaf1db9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import print_function | |
| import numpy as np | |
| import PyTorch | |
| import PyTorchHelpers | |
| TorchClass = PyTorchHelpers.load_lua_class('TorchClass.lua', 'TorchClass') | |
| cl = TorchClass() | |
| v = list(range(10)) | |
| npv = np.asarray(v, dtype=np.float32) | |
| cl.set(npv) | |
| # cl.write() | |
| npv2 = npv * 2 | |
| cl.set(npv2) | |
| # cl.write() | |
| cl.set(npv * 3) | |
| # cl.write() | |
| print('') | |
| print('before allocating a simple array of zeros: cl.v\n', cl.v) | |
| print(np.zeros(10, dtype=np.float32)) | |
| print('') | |
| print('after: cl.v\n', cl.v) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| torch.setdefaulttensortype('torch.FloatTensor') | |
| local TorchClass = torch.class('TorchClass') | |
| function TorchClass:__init() | |
| print("<TorchClass> initialization") | |
| end | |
| function TorchClass:write() | |
| if self.v then | |
| print("<TorchClass> This is the value:") | |
| print(self.v) | |
| else | |
| print("<TorchClass> Value not defined") | |
| end | |
| end | |
| function TorchClass:set(vin) | |
| self.v = vin | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment