<commit_before>/*
 * InitGaussianRandomWeights.cpp
 *
 *  Created on: Aug 9, 2011
 *      Author: kpeterson
 */

#include "InitGaussianRandomWeights.hpp"
#include "InitGaussianRandomWeightsParams.hpp"

namespace PV {

InitGaussianRandomWeights::InitGaussianRandomWeights(char const * name, HyPerCol * hc) {
   initialize_base();
   initialize(name, hc);
}

InitGaussianRandomWeights::InitGaussianRandomWeights() {
   initialize_base();
}

InitGaussianRandomWeights::~InitGaussianRandomWeights() {
   gaussianRandState = NULL; // Don't delete; base class deletes randState, which gaussianRandState is effectively a dynamic_cast of.
}

int InitGaussianRandomWeights::initialize_base() {
   gaussianRandState = NULL;
   return PV_SUCCESS;
}

int InitGaussianRandomWeights::initialize(char const * name, HyPerCol * hc) {
   int status = InitRandomWeights::initialize(name, hc);
   return status;
}

InitWeightsParams * InitGaussianRandomWeights::createNewWeightParams() {
   InitWeightsParams * tempPtr = new InitGaussianRandomWeightsParams(name, parentHyPerCol);
   return tempPtr;
}

int InitGaussianRandomWeights::initRNGs(bool isKernel) {
   assert(randState==NULL && gaussianRandState==NULL);
   int status = PV_SUCCESS;
   if (isKernel) {
      gaussianRandState = new GaussianRandom(callingConn->getParent(), callingConn->getNumDataPatches());
   }
   else {
      gaussianRandState = new GaussianRandom(callingConn->getParent(), callingConn->preSynapticLayer()->getLayerLoc(), true/*isExtended*/);
   }
   if (randState == NULL) {
      fprintf(stderr, "InitRandomWeights error in rank %d process: unable to create object of class Random.\n", callingConn->getParent()->columnId());
      exit(EXIT_FAILURE);
   }
   randState = (Random *) gaussianRandState;
   return status;
}


/**
 * randomWeights() fills the full-size patch with random numbers, whether or not the patch is shrunken.
 */
int InitGaussianRandomWeights::randomWeights(pvdata_t * patchDataStart, InitWeightsParams *weightParams, int patchIndex) {
   InitGaussianRandomWeightsParams *weightParamPtr = dynamic_cast<InitGaussianRandomWeightsParams*>(weightParams);

   if(weightParamPtr==NULL) {
      fprintf(stderr, "Failed to recast pointer to weightsParam!  Exiting...");
      exit(1);
   }

   const float mean = weightParamPtr->getMean();<commit_msg>Fixed a bug with initGaussianRandomWeights<commit_after>/*
 * InitGaussianRandomWeights.cpp
 *
 *  Created on: Aug 9, 2011
 *      Author: kpeterson
 */

#include "InitGaussianRandomWeights.hpp"
#include "InitGaussianRandomWeightsParams.hpp"

namespace PV {

InitGaussianRandomWeights::InitGaussianRandomWeights(char const * name, HyPerCol * hc) {
   initialize_base();
   initialize(name, hc);
}

InitGaussianRandomWeights::InitGaussianRandomWeights() {
   initialize_base();
}

InitGaussianRandomWeights::~InitGaussianRandomWeights() {
   gaussianRandState = NULL; // Don't delete; base class deletes randState, which gaussianRandState is effectively a dynamic_cast of.
}

int InitGaussianRandomWeights::initialize_base() {
   gaussianRandState = NULL;
   return PV_SUCCESS;
}

int InitGaussianRandomWeights::initialize(char const * name, HyPerCol * hc) {
   int status = InitRandomWeights::initialize(name, hc);
   return status;
}

InitWeightsParams * InitGaussianRandomWeights::createNewWeightParams() {
   InitWeightsParams * tempPtr = new InitGaussianRandomWeightsParams(name, parentHyPerCol);
   return tempPtr;
}

int InitGaussianRandomWeights::initRNGs(bool isKernel) {
   assert(randState==NULL && gaussianRandState==NULL);
   int status = PV_SUCCESS;
   if (isKernel) {
      gaussianRandState = new GaussianRandom(callingConn->getParent(), callingConn->getNumDataPatches());
   }
   else {
      gaussianRandState = new GaussianRandom(callingConn->getParent(), callingConn->preSynapticLayer()->getLayerLoc(), true/*isExtended*/);
   }

   if (gaussianRandState == NULL) {
      fprintf(stderr, "InitRandomWeights error in rank %d process: unable to create object of class Random.\n", callingConn->getParent()->columnId());
      exit(EXIT_FAILURE);
   }
   randState = (Random *) gaussianRandState;
   return status;
}


/**
 * randomWeights() fills the full-size patch with random numbers, whether or not the patch is shrunken.
 */
int InitGaussianRandomWeights::randomWeights(pvdata_t * patchDataStart, InitWeightsParams *weightParams, int patchIndex) {
   InitGaussianRandomWeightsParams *weightParamPtr = dynamic_cast<InitGaussianRandomWeightsParams*>(weightParams);

   if(weightParamPtr==NULL) {
      fprintf(stderr, "Failed to recast pointer to weightsParam!  Exiting...");
      exit(1);
   }

   const float mean = weightParamPtr->getMean();
{'fraction_non_alphanumeric': 0.10618336886993604, 'fraction_numerical': 0.00255863539445629, 'mean_word_length': 5.373641304347826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '4617167', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1362, 'n_words': 305}