<commit_before>/*
 * ImagePvp.cpp
 */

#include "ImagePvp.hpp"

namespace PV {

ImagePvp::ImagePvp() {
   initialize_base();
}

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

ImagePvp::~ImagePvp() {
   if(frameStartBuf){
      free(frameStartBuf);
      frameStartBuf = NULL;
   }
   if(countBuf){
      free(countBuf);
      countBuf = NULL;
   }
}

int ImagePvp::initialize_base() {
   needFrameSizesForSpiking = true;
   frameStartBuf = NULL;
   countBuf = NULL;
   //pvpFilename = NULL;
   pvpFrameIdx = 0;
   //pvpBatchIdx = 0;
   return PV_SUCCESS;
}

int ImagePvp::initialize(const char * name, HyPerCol * hc) {
   int status = BaseInput::initialize(name, hc);

   PV_Stream * pvstream = NULL;
   if (getParent()->icCommunicator()->commRank()==0) {
      pvstream = PV::PV_fopen(inputPath, "rb", false/*verifyWrites*/);
   }
   int numParams = NUM_PAR_BYTE_PARAMS;
   int params[numParams];
   pvp_read_header(pvstream, getParent()->icCommunicator(), params, &numParams);
   PV::PV_fclose(pvstream); pvstream = NULL;
   fileNumFrames = params[INDEX_NBANDS]; 
   //fileNumBatches = params[INDEX_NBATCH];
   
   if(pvpFrameIdx < 0 || pvpFrameIdx >= fileNumFrames){
      std::cout << "ImagePvp:: pvpFrameIndex of " << pvpFrameIdx << " out of bounds, file contains " << fileNumFrames << " frames\n";
      exit(-1);
   }

   return status;
}

int ImagePvp::ioParamsFillGroup(enum ParamsIOFlag ioFlag) {
   int status = BaseInput::ioParamsFillGroup(ioFlag);
   //ioParam_pvpPath(ioFlag);
   ioParam_pvpFrameIdx(ioFlag);
   //ioParam_pvpBatchIdx(ioFlag);
   return status;
}

//void ImagePvp::ioParam_inputPath(enum ParamsIOFlag ioFlag) {<commit_msg>ImagePvp does a sanity check on whether inputPath is a pvp file<commit_after>/*
 * ImagePvp.cpp
 */

#include "ImagePvp.hpp"

namespace PV {

ImagePvp::ImagePvp() {
   initialize_base();
}

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

ImagePvp::~ImagePvp() {
   if(frameStartBuf){
      free(frameStartBuf);
      frameStartBuf = NULL;
   }
   if(countBuf){
      free(countBuf);
      countBuf = NULL;
   }
}

int ImagePvp::initialize_base() {
   needFrameSizesForSpiking = true;
   frameStartBuf = NULL;
   countBuf = NULL;
   //pvpFilename = NULL;
   pvpFrameIdx = 0;
   //pvpBatchIdx = 0;
   return PV_SUCCESS;
}

int ImagePvp::initialize(const char * name, HyPerCol * hc) {
   int status = BaseInput::initialize(name, hc);

   PV_Stream * pvstream = NULL;
   if (getParent()->icCommunicator()->commRank()==0) {
      pvstream = PV::PV_fopen(inputPath, "rb", false/*verifyWrites*/);
   }
   int numParams = NUM_PAR_BYTE_PARAMS;
   int params[numParams];
   pvp_read_header(pvstream, getParent()->icCommunicator(), params, &numParams);
   PV::PV_fclose(pvstream); pvstream = NULL;
   if (numParams != NUM_BIN_PARAMS || params[INDEX_HEADER_SIZE] != NUM_BIN_PARAMS*sizeof(int) || params[INDEX_NUM_PARAMS] != NUM_BIN_PARAMS) {
      std::cout << "ImagePvp:: inputPath \"" << inputPath << "\" is not a .pvp file.\n";
      exit(EXIT_FAILURE);
   }
   fileNumFrames = params[INDEX_NBANDS]; 
   //fileNumBatches = params[INDEX_NBATCH];
   
   if(pvpFrameIdx < 0 || pvpFrameIdx >= fileNumFrames){
      std::cout << "ImagePvp:: pvpFrameIndex of " << pvpFrameIdx << " out of bounds, file contains " << fileNumFrames << " frames\n";
      exit(EXIT_FAILURE);
   }

   return status;
}

int ImagePvp::ioParamsFillGroup(enum ParamsIOFlag ioFlag) {
   int status = BaseInput::ioParamsFillGroup(ioFlag);
   //ioParam_pvpPath(ioFlag);
   ioParam_pvpFrameIdx(ioFlag);
   //ioParam_pvpBatchIdx(ioFlag);
   return status;
}

//void ImagePvp::ioParam_inputPath(enum ParamsIOFlag ioFlag) {
{'fraction_non_alphanumeric': 0.1407961528185947, 'fraction_numerical': 0.0024044883783061713, 'mean_word_length': 3.998664886515354, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 11, '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': '4489195', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1336, 'n_words': 250}