Skip to content

Commit

Permalink
Indentation, whitespace, comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
timharley committed Mar 6, 2014
1 parent 30da8ed commit 07a4dbe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
14 changes: 7 additions & 7 deletions lib/TH/THRandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
#define m _MERSENNE_STATE_M
THGenerator* THGenerator_new()
{
THGenerator *self = THAlloc(sizeof(THGenerator));
self->left = 1;
self->initf = 0;
self->normal_is_valid = 0;
return self;
THGenerator *self = THAlloc(sizeof(THGenerator));
self->left = 1;
self->initf = 0;
self->normal_is_valid = 0;
return self;
}

void THGenerator_free(THGenerator *self)
{
THFree(self);
THFree(self);
}

unsigned long THRandom_seed(THGenerator *_generator)
Expand Down Expand Up @@ -161,7 +161,7 @@ static double __uniform__(THGenerator *_generator)
if (--(_generator->left) == 0)
THRandom_nextState(_generator);
y = *((_generator->next)++);

/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
Expand Down
6 changes: 4 additions & 2 deletions lib/TH/THRandom.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "THGeneral.h"

#define _MERSENNE_STATE_N 624
#define _MERSENNE_STATE_N 624
#define _MERSENNE_STATE_M 397
typedef struct THGenerator {
/* The initial seed. */
Expand All @@ -13,7 +13,7 @@ typedef struct THGenerator {
unsigned long *next;
unsigned long state[_MERSENNE_STATE_N]; /* the array for the state vector */
/********************************/

/* For normal distribution */
double normal_x;
double normal_y;
Expand All @@ -23,8 +23,10 @@ typedef struct THGenerator {

#define torch_Generator "torch.Generator"

/* Create a new random number generator stream */
TH_API THGenerator * THGenerator_new();

/* Free a random number generator stream */
TH_API void THGenerator_free(THGenerator *gen);

/* Initializes the random number generator with the current time (granularity: seconds) and returns the seed. */
Expand Down
18 changes: 9 additions & 9 deletions torchcwrap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,37 +91,37 @@ types.Tensor = {
types.Generator = {

helpname = function(arg)
return "Generator"
end,
return "Generator"
end,

declare = function(arg)
return string.format("THGenerator * arg%d;", arg.i)
end,
end,

check = function(arg, idx)
return string.format("(arg%d = luaT_toudata(L, %d, torch_Generator))", arg.i, idx)
end,
return string.format("(arg%d = luaT_toudata(L, %d, torch_Generator))", arg.i, idx)
end,

read = function(arg, idx)
end,

init = function(arg)
local text = {}
local text = {}
-- If no generator is supplied, pull the default out of the torch namespace.
table.insert(text, 'lua_getglobal(L,"torch");')
table.insert(text, string.format('arg%d = luaT_getfieldcheckudata(L, -1, "_gen", torch_Generator);', arg.i))
table.insert(text, 'lua_pop(L, 2);')
return table.concat(text, '\n')
end,

carg = function(arg)
return string.format('arg%d', arg.i)
end,

creturn = function(arg)
return string.format('arg%d', arg.i)
end,

precall = function(arg)
end,

Expand Down

0 comments on commit 07a4dbe

Please sign in to comment.