PetaVision  Alpha
PatchGeometry.hpp
1 /*
2  * PatchGeometry.hpp
3  *
4  * Created on: Jul 21, 2017
5  * Author: Pete Schultz
6  */
7 
8 #ifndef PATCHGEOMETRY_HPP_
9 #define PATCHGEOMETRY_HPP_
10 
11 #include "components/Patch.hpp"
12 #include "include/PVLayerLoc.h"
13 #include <string>
14 #include <vector>
15 
16 namespace PV {
17 
54 
55  public:
67  std::string const &name,
68  int patchSizeX,
69  int patchSizeY,
70  int patchSizeF,
71  PVLayerLoc const *preLoc,
72  PVLayerLoc const *postLoc);
73 
76 
81  void setMargins(PVHalo const &preHalo, PVHalo const &postHalo);
82 
90 
95  int getPatchSizeX() const { return mPatchSizeX; }
96 
101  int getPatchSizeY() const { return mPatchSizeY; }
102 
108  int getPatchSizeF() const { return mPatchSizeF; }
109 
114  int getPatchSizeOverall() const { return mPatchSizeX * mPatchSizeY * mPatchSizeF; }
115 
117  PVLayerLoc const &getPreLoc() const { return mPreLoc; }
118 
120  PVLayerLoc const &getPostLoc() const { return mPostLoc; }
121 
126  int getNumPatchesX() const { return mNumPatchesX; }
127 
132  int getNumPatchesY() const { return mNumPatchesY; }
133 
138  int getNumPatchesF() const { return mNumPatchesF; }
139 
141  int getNumPatches() const { return getNumPatchesX() * getNumPatchesY() * getNumPatchesF(); }
142 
147  int getNumKernelsX() const { return mNumKernelsX; }
148 
153  int getNumKernelsY() const { return mNumKernelsY; }
154 
159  int getNumKernelsF() const { return mNumKernelsF; }
160 
162  int getNumKernels() const { return getNumKernelsX() * getNumKernelsY() * getNumKernelsF(); }
163 
165  Patch const &getPatch(int patchIndex) const { return mPatchVector[patchIndex]; }
166 
168  std::size_t getGSynPatchStart(int patchIndex) const { return mGSynPatchStart[patchIndex]; }
169 
171  std::vector<std::size_t> const &getGSynPatchStart() const { return mGSynPatchStart; }
172 
174  std::size_t getAPostOffset(int patchIndex) const { return mAPostOffset[patchIndex]; }
175 
177  long getUnshrunkenStart(int patchIndex) const { return mUnshrunkenStart[patchIndex]; }
178 
182  std::size_t getTransposeItemIndex(int kernelIndex, int itemInPatch) const {
183  return mTransposeItemIndex[kernelIndex][itemInPatch];
184  }
185 
187  std::vector<std::size_t> const &getAPostOffset() const { return mAPostOffset; }
188 
189  int getPatchStrideX() const { return mPatchStrideX; }
190  int getPatchStrideY() const { return mPatchStrideY; }
191  int getPatchStrideF() const { return mPatchStrideF; }
192 
197  int getLog2ScaleDiffX() const { return mLog2ScaleDiffX; }
198 
203  int getLog2ScaleDiffY() const { return mLog2ScaleDiffY; }
204 
210  bool getSelfConnectionFlag() const { return mSelfConnectionFlag; }
211 
212  static int calcPatchStartInPost(
213  int indexRestrictedPre,
214  int patchSize,
215  int numNeuronsPre,
216  int numNeuronsPost);
217 
218  private:
220  void initialize(
221  std::string const &name,
222  int patchSizeX,
223  int patchSizeY,
224  int patchSizeF,
225  PVLayerLoc const *preLoc,
226  PVLayerLoc const *postLoc);
227 
233  static int verifyPatchSize(int numPreRestricted, int numPostRestricted, int patchSize);
234 
239  void verifyPatchSize();
240 
245  void setPatchGeometry();
246 
251 
252  static void calcPatchData(
253  int index,
254  int numPreRestricted,
255  int preStartBorder,
256  int preEndBorder,
257  int numPostRestricted,
258  int postStartBorder,
259  int postEndBorder,
260  int patchSize,
261  int *patchDim,
262  int *patchStart,
263  int *postPatchStartRestricted,
264  int *postPatchStartExtended,
265  int *postPatchUnshrunkenStart);
266 
267  private:
268  int mPatchSizeX;
269  int mPatchSizeY;
270  int mPatchSizeF;
271  PVLayerLoc mPreLoc;
272  PVLayerLoc mPostLoc;
273  int mNumPatchesX;
274  int mNumPatchesY;
275  int mNumPatchesF;
276  int mNumKernelsX;
277  int mNumKernelsY;
278  int mNumKernelsF;
279 
280  std::vector<Patch> mPatchVector;
281  std::vector<std::size_t> mGSynPatchStart;
282  std::vector<std::size_t> mAPostOffset;
283  std::vector<long> mUnshrunkenStart;
284  std::vector<std::vector<int>> mTransposeItemIndex;
285 
286  int mPatchStrideX;
287  int mPatchStrideY;
288  int mPatchStrideF;
289 
290  int mLog2ScaleDiffX;
291  int mLog2ScaleDiffY;
292  bool mSelfConnectionFlag; // True if instantiated with preLoc and postLoc pointers equal
293 }; // end class PatchGeometry
294 
295 } // end namespace PV
296 
297 #endif // PATCHGEOMETRY_HPP_
PVLayerLoc const & getPostLoc() const
int getNumPatchesX() const
int getLog2ScaleDiffY() const
int getNumKernelsF() const
int getNumPatches() const
int getPatchSizeOverall() const
void setMargins(PVHalo const &preHalo, PVHalo const &postHalo)
int getPatchSizeX() const
std::size_t getGSynPatchStart(int patchIndex) const
int getLog2ScaleDiffX() const
void initialize(std::string const &name, int patchSizeX, int patchSizeY, int patchSizeF, PVLayerLoc const *preLoc, PVLayerLoc const *postLoc)
bool getSelfConnectionFlag() const
int getNumKernelsY() const
int getPatchSizeF() const
std::size_t getTransposeItemIndex(int kernelIndex, int itemInPatch) const
std::size_t getAPostOffset(int patchIndex) const
Patch const & getPatch(int patchIndex) const
int getNumKernelsX() const
void allocateDataStructures()
int getNumPatchesF() const
std::vector< std::size_t > const & getAPostOffset() const
int getPatchSizeY() const
void setTransposeItemIndices()
PatchGeometry(std::string const &name, int patchSizeX, int patchSizeY, int patchSizeF, PVLayerLoc const *preLoc, PVLayerLoc const *postLoc)
int getNumKernels() const
PVLayerLoc const & getPreLoc() const
int getNumPatchesY() const
long getUnshrunkenStart(int patchIndex) const
std::vector< std::size_t > const & getGSynPatchStart() const