PetaVision  Alpha
UniformRandomV.cpp
1 /*
2  * UniformRandomV.cpp
3  *
4  * Created on: Oct 26, 2016
5  * Author: pschultz
6  */
7 
8 #include "UniformRandomV.hpp"
9 #include "columns/HyPerCol.hpp"
10 #include "columns/Random.hpp"
11 #include "utils/PVLog.hpp"
12 
13 namespace PV {
14 
15 UniformRandomV::UniformRandomV() { initialize_base(); }
16 
17 UniformRandomV::UniformRandomV(char const *name, HyPerCol *hc) {
18  initialize_base();
19  initialize(name, hc);
20 }
21 
22 UniformRandomV::~UniformRandomV() {}
23 
24 int UniformRandomV::initialize_base() { return PV_SUCCESS; }
25 
26 int UniformRandomV::initialize(char const *name, HyPerCol *hc) {
27  int status = BaseInitV::initialize(name, hc);
28  return status;
29 }
30 
31 int UniformRandomV::ioParamsFillGroup(enum ParamsIOFlag ioFlag) {
32  int status = BaseInitV::ioParamsFillGroup(ioFlag);
33  ioParam_minV(ioFlag);
34  ioParam_maxV(ioFlag);
35  return status;
36 }
37 
38 void UniformRandomV::ioParam_minV(enum ParamsIOFlag ioFlag) {
39  parent->parameters()->ioParamValue(ioFlag, name, "minV", &minV, minV);
40 }
41 
42 void UniformRandomV::ioParam_maxV(enum ParamsIOFlag ioFlag) {
43  pvAssert(!parent->parameters()->presentAndNotBeenRead(name, "minV"));
44  parent->parameters()->ioParamValue(ioFlag, name, "maxV", &maxV, minV + 1.0f);
45 }
46 
47 void UniformRandomV::calcV(float *V, PVLayerLoc const *loc) {
48  PVLayerLoc flatLoc;
49  memcpy(&flatLoc, loc, sizeof(PVLayerLoc));
50  flatLoc.nf = 1;
51  Random randState{&flatLoc, false /*not extended*/};
52  const int nxny = flatLoc.nx * flatLoc.ny;
53  for (int b = 0; b < loc->nbatch; b++) {
54  float *VBatch = V + b * loc->nx * loc->ny * loc->nf;
55 #ifdef PV_USE_OPENMP_THREADS
56 #pragma omp parallel for
57 #endif
58  for (int xy = 0; xy < nxny; xy++) {
59  for (int f = 0; f < loc->nf; f++) {
60  int index = kIndex(xy, 0, f, nxny, 1, loc->nf);
61  VBatch[index] = randState.uniformRandom(xy, minV, maxV);
62  }
63  }
64  }
65 }
66 
67 } // end namespace PV
virtual void ioParam_minV(enum ParamsIOFlag ioFlag)
minV: The minimum value of the random distribution
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Definition: BaseInitV.cpp:34
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual void ioParam_maxV(enum ParamsIOFlag ioFlag)
maxV: The maximum value of the random distribution