<commit_before>/**
 * This file tests copying to boundary regions while applying mirror boundary conditions.
 * formerly called test_borders.cpp
 *
 */

#undef DEBUG_PRINT

#include "../src/layers/HyPerLayer.hpp"
#include "../src/layers/Example.hpp"
#include "../src/io/io.h"


const int numFeatures = 2;

int main(int argc, char * argv[])
{
   PVLayerLoc sLoc, bLoc;
   PVLayerCube * sCube, * bCube;

   PV::HyPerCol * hc = new PV::HyPerCol("test_mirror_BCs column", argc, argv);
   PV::Example * l = new PV::Example("test_mirror_BCs layer", hc);

   //FILE * fd = stdout;
   int nf  = numFeatures;
   int nB = 4;
   int nS = 8;
   int syex = ( nS + 2*nB ) * nf;
   int sy = nS * nf;

   sLoc.nxGlobal = sLoc.nyGlobal = nS; // shouldn't be used
   sLoc.kx0 = sLoc.ky0 = 0; // shouldn't be used
   sLoc.nx = sLoc.ny = nS;
   sLoc.nPad = nB;
   sLoc.nBands = nf;

   bLoc = sLoc;

   sCube = pvcube_new(&sLoc, (nS+2*nB)*(nS+2*nB)*nf);
   bCube = sCube;

   // fill interior with non-extended index of each neuron
   // leave border values at zero to start with
   int kFirst = nB;
   int kLast = nS + nB;
   for (int ky = kFirst; ky < kLast; ky++) {
      for (int kx = kFirst; kx < kLast; kx++) {
         for (int kf = 0; kf < nf; kf++) {
            int kex = ky * syex + kx * nf + kf;
            int k = (ky-kFirst) * sy + (kx-kFirst) * nf + kf;
            sCube->data[kex] = k;
#ifdef DEBUG_PRINT
            printf("sCube val = %5i:, kex = %5i:, k = %5i\n", (int) sCube->data[kex], kex, k);
#endif
        }
      }
   }

   // this is the function we're testing...
   for (int borderId = 1; borderId < NUM_NEIGHBORHOOD; borderId++){
      l->mirrorInteriorToBorder(borderId, sCube, bCube);
   }

#ifdef DEBUG_PRINT
   // write out extended cube values
   int nx = 2*nB + nS;
   int ny = nx;
   for (int kf = 0; kf < nf; kf++) {
      for (int ky = 0; ky < ny; ky++) {
         for (int kx = 0; kx < nx; kx++) {
            int kex = ky * syex + kx * nf + kf;
            printf("%5i ", (int) sCube->data[kex]);
         }
         printf("\n");
      }
      printf("\n");
   }
#endif

   // check values at mirror indices
   // uses a completely different algorithm than mirrorInteriorToBorder

   // northwest
   for (int ky = kFirst; ky < kFirst+nB; ky++) {
      int kymirror = kFirst - 1 - (ky - kFirst);
      for (int kx = kFirst; kx < kFirst+nB; kx++) {
         int kxmirror = kFirst - 1 - (kx - kFirst);
         for (int kf = 0; kf < nf; kf++) {
            int kex = ky * syex + kx * nf + kf;
            int k = (ky-kFirst) * sy + (kx-kFirst) * nf + kf;
            int kmirror = kymirror * syex + kxmirror * nf + kf;
            int mirrorVal = bCube->data[kmirror];
            if ( mirrorVal != k) {
               printf("ERROR:northwest mirror value at %i from %i = %i, should be %i\n", kmirror, kex, mirrorVal, k);
               exit(1);<commit_msg>fixed test_mirror_BCs so that nx, ny, nf are always read in from params.test file<commit_after>/**
 * This file tests copying to boundary regions while applying mirror boundary conditions.
 * formerly called test_borders.cpp
 *
 */

#undef DEBUG_PRINT
#define DEBUG_PRINT

#include "../src/layers/HyPerLayer.hpp"
#include "../src/layers/Example.hpp"
#include "../src/io/io.h"


//const int numFeatures = 1;

int main(int argc, char * argv[])
{
   PVLayerLoc sLoc, bLoc;
   PVLayerCube * sCube, * bCube;

   PV::HyPerCol * hc = new PV::HyPerCol("test_mirror_BCs column", argc, argv);
   PV::Example * l = new PV::Example("test_mirror_BCs layer", hc);

   //FILE * fd = stdout;
   int nf  = l->clayer->loc.nBands;
   int nB = l->clayer->loc.nPad; //4;
   int nS = l->clayer->loc.nx; // 8;
   int syex = ( nS + 2*nB ) * nf;
   int sy = nS * nf;
   int nx = 2*nB + nS;
   int ny = nx;

   sLoc.nxGlobal = sLoc.nyGlobal = nS; // shouldn't be used
   sLoc.kx0 = sLoc.ky0 = 0; // shouldn't be used
   sLoc.nx = sLoc.ny = nS;
   sLoc.nPad = nB;
   sLoc.nBands = nf;

   bLoc = sLoc;

   sCube = pvcube_new(&sLoc, (nS+2*nB)*(nS+2*nB)*nf);
   bCube = sCube;

   // fill interior with non-extended index of each neuron
   // leave border values at zero to start with
   int kFirst = nB;
   int kLast = nS + nB;
   for (int ky = kFirst; ky < kLast; ky++) {
      for (int kx = kFirst; kx < kLast; kx++) {
         for (int kf = 0; kf < nf; kf++) {
            int kex = ky * syex + kx * nf + kf;
            int k = (ky-kFirst) * sy + (kx-kFirst) * nf + kf;
            sCube->data[kex] = k;
#ifdef DEBUG_PRINT
            printf("sCube val = %5i:, kex = %5i:, k = %5i\n", (int) sCube->data[kex], kex, k);
#endif
        }
      }
   }

#ifdef DEBUG_PRINT
   // write out extended cube values
   for (int kf = 0; kf < nf; kf++) {
      for (int ky = 0; ky < ny; ky++) {
         for (int kx = 0; kx < nx; kx++) {
            int kex = ky * syex + kx * nf + kf;
            printf("%5i ", (int) sCube->data[kex]);
         }
         printf("\n");
      }
      printf("\n");
   }
#endif

   // this is the function we're testing...
   for (int borderId = 1; borderId < NUM_NEIGHBORHOOD; borderId++){
      l->mirrorInteriorToBorder(borderId, sCube, bCube);
   }

#ifdef DEBUG_PRINT
   // write out extended cube values
   for (int kf = 0; kf < nf; kf++) {
      for (int ky = 0; ky < ny; ky++) {
         for (int kx = 0; kx < nx; kx++) {
            int kex = ky * syex + kx * nf + kf;
            printf("%5i ", (int) sCube->data[kex]);
         }
         printf("\n");
      }
      printf("\n");
   }
#endif

   // check values at mirror indices
   // uses a completely different algorithm than mirrorInteriorToBorder

   // northwest
   for (int ky = kFirst; ky < kFirst+nB; ky++) {
      int kymirror = kFirst - 1 - (ky - kFirst);
      for (int kx = kFirst; kx < kFirst+nB; kx++) {
         int kxmirror = kFirst - 1 - (kx - kFirst);
         for (int kf = 0; kf < nf; kf++) {
            int kex = ky * syex + kx * nf + kf;
            int k = (ky-kFirst) * sy + (kx-kFirst) * nf + kf;
            int kmirror = kymirror * syex + kxmirror * nf + kf;
            int mirrorVal = bCube->data[kmirror];
            if ( mirrorVal != k) {
               printf("ERROR:northwest mirror value at %i from %i = %i, should be %i\n", kmirror, kex, mirrorVal, k);
               exit(1);
{'fraction_non_alphanumeric': 0.15488, 'fraction_numerical': 0.008, 'mean_word_length': 2.056723716381418, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '892053', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2421, 'n_words': 709}