Exemple #1
0
int main(int argc, char *argv[]) {
  if (argc != 2) {
    cout << "Parameters Error." << endl;
    cout << "Use: " << argv[0] << " xxxx.bmp" << endl;
    return 1;
  }

  bmpfile.open(argv[1], ios::in | ios::binary);
  if (bmpfile.is_open()) {
    bmpfile.read((char *)&FileHeader, sizeof(FileHeader));
    if (strncmp(FileHeader.bfType, "BM", 2) != 0) {
      cout << "Not a BMP File, or an Unsupported OS/2 BMP File." << endl;
      return 1;
    }
    bmpfile.read((char *)&InfoHeader, sizeof(InfoHeader));

    Output_FileHeader();
    Output_InfoHeader();

    vector<Pixel> *vec = ReadBitmap();

    int x, y;
    while (cin >> x >> y) {
      if (x == -1)
        break;
      PrintLocation(x, y, vec);
    }

    bmpfile.close();
    delete[] vec;
  } else {
/*
 * Description: rebuild the file using header info
 * Arguments: in - reference to ifstream to use
 * Return Value: none
 */
void HCTree::rebuild(ifstream& in){
  stack<HCNode*> myStack;
  byte flag;
  in.read((char*)&flag, sizeof(flag));
  
  /* loop until the stack size is 1 and flag meets separator*/
  while (myStack.size()>1 || flag != 0 ) {
    if (flag == 1) { // this is a leaf node
      byte symbol;
      in.read((char*)&symbol,sizeof(symbol));
      HCNode* newNode = new HCNode(0, symbol, 0, 0, 0);
      leaves[(int)symbol] = newNode;
      myStack.push(newNode);
    } else if(!myStack.empty()){ // this is a internal node
      HCNode* c1 = myStack.top();
      myStack.pop();
      HCNode* c0 = myStack.top();
      myStack.pop();
      HCNode* mergeNode = new HCNode(0, 0, c0, c1, 0);
      c0->p = mergeNode;
      c1->p = mergeNode;
      myStack.push(mergeNode);
    }
    in.read((char*)&flag, sizeof(flag));
  }
  root = myStack.top();
  myStack.pop();
}
Exemple #3
0
vector<Pixel> *ReadBitmap() {
  int offset = 0;
  int height = ToHumanRead(InfoHeader.biHeight);
  int width = ToHumanRead(InfoHeader.biWidth);

  int linebyte = width * ToHumanRead(InfoHeader.biBitCount) / 8;
  offset = linebyte % 4;
  if (offset != 0)
    offset = 4 - offset;
  cout << "Offset: " << offset << endl;

  vector<Pixel> *vec = new vector<Pixel>[ abs(height) ];

  bool isBottom = false;
  if (ToHumanRead(InfoHeader.biHeight) > 0) // read from bottom
  {
    isBottom = true;
  }
  for (int i = 0; i < abs(height); i++) {
    for (int j = 0; j < width; j++) {
      bmpfile.read((char *)&p, sizeof(p));
      if (!isBottom)
        vec[i].push_back(p);
      else
        vec[height - i - 1].push_back(p);
      drop_alpha();
    }
    for (int j = 0; j < offset; j++) {
      unsigned char null;
      bmpfile.read((char *)&null, sizeof(null));
    }
  }
  return vec;
}
UINT32 DICOMParser::GetUInt(ifstream& fileDICOM, const DICOM_eType eElementType, const UINT32 iElemLength, const bool bNeedsEndianConversion) {
  string value;
  UINT32 result;
  switch (eElementType) {
    case TYPE_Implicit :
    case TYPE_IS  : {
              value.resize(iElemLength);
              fileDICOM.read(&value[0],iElemLength);
              result = atoi(value.c_str());
              break;
            }
    case TYPE_UL  : {
              fileDICOM.read((char*)&result,4);
              if (bNeedsEndianConversion) result = EndianConvert::Swap<UINT32>(result);
              break;
            }
    case TYPE_US  : {
              short tmp;
              fileDICOM.read((char*)&tmp,2);
              if (bNeedsEndianConversion) tmp = EndianConvert::Swap<short>(tmp);
              result = tmp;
              break;
            }
    default : result = 0; break;
  }
  return result;
}
Exemple #5
0
void flag_orbits::read_file(ifstream &fp, int verbose_level)
{
	int f_v = (verbose_level >= 1);
	int i;
	
	if (f_v) {
		cout << "flag_orbits::read_file" << endl;
		}
	fp.read((char *) &nb_primary_orbits_lower, sizeof(int));
	fp.read((char *) &nb_primary_orbits_upper, sizeof(int));
	fp.read((char *) &nb_flag_orbits, sizeof(int));
	fp.read((char *) &pt_representation_sz, sizeof(int));

	Pt = NEW_int(nb_flag_orbits * pt_representation_sz);
	for (i = 0; i < nb_flag_orbits * pt_representation_sz; i++) {
		fp.read((char *) &Pt[i], sizeof(int));
		}
	Flag_orbit_node = NEW_OBJECTS(flag_orbit_node, nb_flag_orbits);
	for (i = 0; i < nb_flag_orbits; i++) {
		if (FALSE) {
			cout << "flag_orbits::read_file "
					"node " << i << " / " << nb_flag_orbits << endl;
			}
		Flag_orbit_node[i].Flag_orbits = this;
		Flag_orbit_node[i].flag_orbit_index = i;
		Flag_orbit_node[i].read_file(fp, 0 /*verbose_level */);
		}

	if (f_v) {
		cout << "flag_orbits::read_file finished" << endl;
		}
}
Exemple #6
0
void AnimPackage::read(ifstream &ifp)
{
	SECTION_DECLARATION_2
	fourcc = readUInt32(ifp);
	size = readUInt32(ifp);

	if (fourcc == ANPK) {
		READ_SECTION(INFO);

		uint32 numAnims = readUInt32(ifp);
		animList.resize(numAnims);
		size -= sizeof(uint32);
		size = (size+0x3) & ~0x3;
		char *buf = new char[size];
		ifp.read(buf, size);
		name = buf;
		delete[] buf;

		for (uint32 i = 0; i < numAnims; i++)
			animList[i].read_1(ifp);
	} else if (fourcc == ANP3) {
		char buf[24];
		ifp.read(buf, 24);
		name = buf;
		uint32 numAnims = readUInt32(ifp);
		animList.resize(numAnims);

		for (uint32 i = 0; i < numAnims; i++)
			animList[i].read_3(ifp);
	} else {
		cout << "no known ifp file\n";
	}
}
Exemple #7
0
Patch FileLoader::loadMvsPatch(ifstream &file) {
	vector<int> camIdx;
	int camNum;
	Vec3d center;
	Vec2d sphericalNormal;
	double fitness;
	double correlation;

	// read patch center
	loadMvsVec(file, center);
	// read patch spherical normal
	loadMvsVec(file, sphericalNormal);
	// load visible camera number
	file.read((char*) &camNum, sizeof(int));
	// load visible camera index
	for (int i = 0; i < camNum; ++i) {
		int idx;
		file.read((char*) &idx, sizeof(int));
		camIdx.push_back(idx);
	}
	// load fitness
	file.read((char*) &fitness, sizeof(double));
	// load correlation
	file.read((char*) &correlation, sizeof(double));
	return Patch(center, sphericalNormal, camIdx, fitness, correlation);
}
Exemple #8
0
	BitString::BitString(ifstream & input) {
		assert(input.good());
		input.read((char*)&length,sizeof(size_t));
		input.read((char*)&uintLength,sizeof(size_t));
		data = new uint[uintLength];
		input.read((char*)data,uintLength*sizeof(uint));
	}
void HealthClub::readDevice (ifstream & inFile)
{
	//assumption - the file is open and set on the right place
	int i;

	int Serial;
	inFile.read((char*)&Serial, sizeof(Serial));//reading the serial number of device
	Device::SetSerialNum(Serial);
	
	int totalDevice;
	inFile.read((char*)&totalDevice, sizeof(totalDevice)); //reading the total amount of devices in the club

	this->devices.setLogicSize(totalDevice); //allocating device* array
	this->devices.getArray() = new Device*[totalDevice];

	//creating the devices according the info in the file 
	for (i = 0; i<this->devices.getLogicSize(); i++)
	{
		int length = 3;
		char* type = new char [length+1]; //indicate the type of the current device
		inFile.read((char*)type,length); // read the type of current device from the file
		type[length]= '\0';
		if (strncmp(type,typeid(AerobicDevice).name()+6, length) == 0)
		{
			Device* d = new AerobicDevice (inFile); // create from the file new aerobic device
			this->devices.replaceCell(i,d);
		}
		else if (strncmp(type,typeid(PowerDevice).name()+6,length) == 0)
		{
			Device* d =  new PowerDevice (inFile); // create from the file new Power device
			this->devices.replaceCell(i,d);
		}
	}
}
Exemple #10
0
bool readClusterData(ifstream& inf, int* dataPts, int nPts, int nClusters, int ts_chunk, float** ctrs)
{
	if (!inf)
        return false;
	int value;
	float fvalue;
    for(int i=0; i < nPts; i++){
		//assert(inf);
		//if(!inf.eof()){
			inf.read(reinterpret_cast<char *>(&value), sizeof(int));
			//fprintf(stderr,"dataPts[%d]=%d\n",i,value);
			dataPts[i] = value;
			
		//}
	}

	//fprintf(stderr,"next_cluster\n");
	for (int j = 0; j < nClusters; j++){
		for (int d = 0; d < ts_chunk; d++) {
			inf.read(reinterpret_cast<char *>(&fvalue), sizeof(float));
			ctrs[j][d] = fvalue;
			//fprintf(stderr,"ctrs[%d][%d]=%f\n",j,d,ctrs[j][d]);
		}
	}

	return true;
}
Exemple #11
0
PAIS::Camera FileLoader::loadMvsCamera(ifstream &file) {
	int fileNameLength;
	char *fileName;
	Vec3d center;
	Vec2d focal;
	Vec4d quaternion;
	Vec2d principle;
	double radialDistortion;

	// read image file name length
	file.read( (char*) &fileNameLength, sizeof(int) );
	// read image file name
	fileName = new char [fileNameLength+1];
	file.read(fileName, fileNameLength);
	fileName[fileNameLength] = '\0';
	// read camera center
	loadMvsVec(file, center);
	// read camera focal length
	loadMvsVec(file, focal);
	// read camera principle point
	loadMvsVec(file, principle);
	// read rotation quaternion
	loadMvsVec(file, quaternion);
	// read radial distortion
	file.read((char*) &radialDistortion, sizeof(double));

	Camera cam(fileName, focal, principle, quaternion, center, radialDistortion);

	delete [] fileName;

	return cam;
}
void dumpDiffBaselines(ifstream &fin1, ifstream &fin2)
{
    Baseline baseline1;
    Baseline baseline2;
    Baseline diffBaseline;

    // read in all the baselines
    while (fin1.read((char*)&baseline1, sizeof baseline1))
    {
	baseline1.demarshall();

	fin2.read((char*)&baseline2, sizeof baseline2);
	baseline2.demarshall();

	diffBaseline.header = baseline1.header;

	// diff the values
	for (int i=0; i< baseline1.header.numberOfSubchannels; ++i)
	{
	    diffBaseline.baselineValues[i] = 
		baseline1.baselineValues[i] - baseline2.baselineValues[i];
	}

	diffBaseline.marshall();
	cout.write((char*)&diffBaseline, sizeof diffBaseline);

    }
}
Exemple #13
0
bool ch_image_ref::read(f_base * pf, ifstream & fin, long long t)
{
  lock_bk();
  unsigned long long ul;
  m_time[m_back] = t;
  fin.read((char*) &m_ifrm[m_back], sizeof(long long));
  //  cout << "Frame index " << m_ifrm[m_back] << endl;
  fin.read((char*) &ul, sizeof(unsigned long long));
  //  cout << "Compressed Frame size " << ul << endl;
  Mat bufm(1, (int) ul, CV_8UC1);
  fin.read((char*) bufm.data, (streamsize) ul);

  imdecode(bufm, CV_LOAD_IMAGE_ANYDEPTH, &m_img[m_back]);
  //  cout << "Resulting image size " << m_img[m_back].cols << "x" << m_img[m_back].rows << endl; 
  //  cout << "Exiting ch_image::read" << endl;
  lock_fr();

  unlock_fr();
  int tmp = m_front;
  m_front = m_back;
  m_back = tmp;

  unlock_bk();
  return true;
}
Exemple #14
0
/*
  Ta funkcija prebere binarno datoteko.
*/
void binarnoBranje()
{
    //odpiranje datoteke
    inputFile.open(filename.c_str(), ios::binary|ios::in);
    //ugotavljanje velikosti datoteke:
    inputFile.seekg(0,inputFile.end);
    long long fileSize = inputFile.tellg();
    //pointer nazaj na zacetek datoteke
    inputFile.seekg(0,inputFile.beg);

    //preracunanje koliko je koncnih bytov, za katere bo treba prilagoditi char array in stevilo iteracij
    long long endBytes = fileSize % writingSize, pos = 0, iterations = fileSize/writingSize;
    //branje
    while (iterations--)
    {
        inputFile.read(c, writingSize);
        pos+=writingSize;
        inputFile.seekg(pos, ios::beg);
    }
    //koncni byti
    delete[] c;
    c = new char[endBytes];
    inputFile.read(c, endBytes);
    //velikost c nastavimo nazaj na zacetek
    delete[] c;
    c = new char[writingSize];
}
Exemple #15
0
bool sfheader :: readWavHeader(ifstream &f, const char *name) {
	bool formatFound = false;
	unsigned char format[16];
	unsigned char data[12];
	f.read(data,12);
	if (!assertWarning(f.gcount() == 12,"Error reading header") ||
		!assertWarning(strncmp((char*)data, "RIFF", 4) == 0, "not RIFF file") ||
		!assertWarning(strncmp((char*)data+8, "WAVE", 4) == 0, "not WAV file"))
		return false;
	while (!f.eof()) {		// read chunks until data is found
		f.read(data,8);
		if (!assertWarning(f.gcount() == 8,"Error reading header"))
			return false;
		int chunkLength = sRead32LE(data+4);
		if (strncmp((char*)data, "data", 4) == 0) {
			if (!assertWarning(formatFound, "No format data in WAV file"))
				return false;
			init(chunkLength / (sizeof(audioSample) * sRead16LE(format+2)),
				 sRead32LE(format+4), sRead16LE(format), sRead16LE(format+2),
				 0, 0, name);
			return true;
		} else if (strncmp((char*)data, "fmt ", 4) == 0) {
			f.read(format,16);
			if (!assertWarning(f.gcount()==16, "Error in WAV format data") ||
				!assertWarning(sRead16LE(format) == WAV_LINEAR_PCM,
								"not WAV linear PCM format") ||
				!assertWarning(sRead16LE(format+14) == 16, "not 16 bit format"))
				return false;
			f.seekg(chunkLength-16, ios::cur);
			formatFound = true;
		} else
			f.seekg(chunkLength, ios::cur);
	}
	return assertWarning(false, "WAV data not found");
} // readWavHeader()
Exemple #16
0
void PNMFileUtils::extractToken(ifstream &inputStream,
                                char *token,
                                int maxSize)
{
  int count = 0;
  char ch;
  
  // skip whitespace and comments
  do
  {
    inputStream.read((char *)&ch, sizeof(char));
    // if a comment char is found then read till the next "\n"
    if(ch == '#')
      while(ch != '\n')
        inputStream.read((char *)&ch, sizeof(char *));
  }
  while(ch == ' ' || ch == '\t' || ch == '\n');
  
  // copy data into token
  do
  {
    if(count >= maxSize - 1)
      throw runtime_error("Token too large");
    token[count++] = ch;
    inputStream.read((char *)&ch, sizeof(char));
  }
  while(ch != ' ' && ch != '\t' && ch != '\n' && ch != '.');
  
  inputStream.putback(ch);
  token[count] = '\0';
}
Exemple #17
0
void strong_generators::read_from_file_binary(action *A, ifstream &fp, INT verbose_level)
{
	INT f_v = (verbose_level >= 1);
	INT i, l;

	if (f_v) {
		cout << "strong_generators::read_from_file_binary" << endl;
		}
	init(A, 0);
	fp.read((char *) &l, sizeof(INT));
	if (l != A->base_len) {
		cout << "strong_generators::read_from_file_binary l != A->base_len" << endl;
		exit(1);
		}
	tl = NEW_INT(A->base_len);
	for (i = 0; i < A->base_len; i++) {
		fp.read((char *) &tl[i], sizeof(INT));
		}
	gens = new vector_ge;
	gens->init(A);
	gens->read_from_file_binary(fp, verbose_level - 1);
	if (f_v) {
		cout << "strong_generators::read_from_file_binary done" << endl;
		}
}
Exemple #18
0
MyHeader sizeOfFile(ifstream &stream)
{
    int ndim = 0;
    stream.read((char*)&ndim, sizeof(ndim));
    
    int dim[3];
    stream.read((char*)&dim, sizeof(dim));

    MyHeader header;

    if (ndim == 1)
    {
         header.count = dim[0];
         header.width = 1;
         header.height = 1;
    }
    
    if (ndim == 4)
    {
        header.count  = dim[0] * dim[1];
        header.width  = dim[2];
        
        int wdim = 0;
        stream.read((char*)&wdim, sizeof(wdim));
        header.height = wdim;
    }
    
    return header;
}
void FacemarkKazemiImpl :: readLeaf(ifstream& is, vector<Point2f> &leaf)
{
    uint64_t size;
    is.read((char*)&size, sizeof(size));
    leaf.resize((size_t)size);
    is.read((char*)&leaf[0], leaf.size() * sizeof(Point2f));
}
Exemple #20
0
void DistanceField::retrieveZSlice(ifstream & fin, bool floatData, int resolutionX, int resolutionY, int resolutionZ, float * slice)
{
  double * buffer = (double*) malloc (sizeof(double) * (resolutionX+1) * (resolutionY+1)); // place for one slice

  float * distanceDataPos = slice;

  if (floatData)
    fin.read((char*)buffer, sizeof(float) * (resolutionX+1) * (resolutionY+1));
  else
    fin.read((char*)buffer, sizeof(double) * (resolutionX+1) * (resolutionY+1));

  char * bufferPos = (char*)buffer;
  int bufferPosInc = floatData ? sizeof(float) : sizeof(double);

  // copy data to the slice
  for(int j = 0; j <= resolutionY; j++)
    for(int i = 0; i <= resolutionX; i++)
    {
      if (floatData)
        *distanceDataPos = *(float*)bufferPos;
      else
        *distanceDataPos = *(double*)bufferPos;
      distanceDataPos++;
      bufferPos += bufferPosInc;
    }
}
		void getfh(ifstream& in){
			in.read((char*)&fh.bfType,sizeof(fh.bfType));
			in.read((char*)&fh.bfSize,sizeof(fh.bfSize));
			in.read((char*)&fh.bfReserved1,sizeof(fh.bfReserved1));
			in.read((char*)&fh.bfReserved2,sizeof(fh.bfReserved2));
			in.read((char*)&fh.bfOffBits,sizeof(fh.bfOffBits));
		}
void ParsedEncodedFile::parseTableFromFile(ifstream &encoded, unsigned int & j)
{
	j = 0;
	for (int i = 0; i < 256; i++)
	{
		FVPair fv;
		uint8_t value = i;
		uint16_t frequency;

		uint8_t frqMSB;
		encoded.read((char *)&frqMSB, 1);
		j++;
		uint8_t frqLSB;
		encoded.read((char *)&frqLSB, 1);
		j++;

		frequency = ((uint16_t)(frqMSB) << 8) | (uint16_t)(frqLSB);


		if (frequency == 0)
			continue;
		fv.frequency = frequency;
		fv.value = value;
		this->frequencyTable.push_back(fv);
	}
}
Exemple #23
0
void variant_file::read_temp_site(ifstream &tmp_file, string &CHROM, int &POS, vector< pair<int,int> > &GTs)
{
	stringstream chr;
	char tmp_char;
	while(true)
	{
		tmp_file.read(&tmp_char,sizeof(char));
		if (tmp_char == '\n')
			break;
		chr << tmp_char;
	}
	CHROM = chr.str();

	tmp_file.read((char*)&POS,sizeof(POS));

	char in_byte, tmp_gt;
	for(unsigned int ui=0; ui<GTs.size(); ui++)
	{
		tmp_file.read(&in_byte,sizeof(in_byte));
		tmp_gt = in_byte & 0x03;
		if (tmp_gt == 0x02)
			GTs[ui].second = -1;
		else
			GTs[ui].second = (int)tmp_gt;
		in_byte = in_byte >> 4;
		tmp_gt = in_byte & 0x03;
		if (tmp_gt == 0x02)
			GTs[ui].first = -1;
		else
			GTs[ui].first = (int)tmp_gt;
	}
}
Exemple #24
0
void variant_file::read_big_temp_site(ifstream &tmp_file, string &CHROM, int &POS, int &alleles, vector< pair<int,int> > &GTs)
{
	stringstream chr;
	char tmp_char;
	while(true)
	{
		tmp_file.read(&tmp_char,sizeof(char));
		if (tmp_char == '\n')
			break;
		chr << tmp_char;
	}
	CHROM = chr.str();

	tmp_file.read((char*)&POS,sizeof(POS));

	int8_t tmp_alleles;
	tmp_file.read((char*)&tmp_alleles,sizeof(tmp_alleles));
	alleles = (int)tmp_alleles;

	char in_byte = 0xFF;
	for(unsigned int ui=0; ui<GTs.size(); ui++)
	{
		tmp_file.read(&in_byte,sizeof(in_byte));
		if (in_byte == (char)0xFF)
			GTs[ui].first = -1;
		else
			GTs[ui].first = (int)in_byte;

		tmp_file.read(&in_byte,sizeof(in_byte));
		if (in_byte == (char)0xFF)
			GTs[ui].second = -1;
		else
			GTs[ui].second = (int)in_byte;
	}
}
Exemple #25
0
void cSound::LoadWAVInfo(ifstream &filename, string &name, 	unsigned int &size)
{
    char chunk[4];
    filename.read((char *)&chunk, 4);
    filename.read((char *)&size, 4);

    name = string(chunk, 4);
}
Exemple #26
0
bool readClusterHeader(ifstream& inf, int& num_clusters, int& ts_chunk)
{
	if (!inf)
        return false;
	inf.read(reinterpret_cast<char *>(&num_clusters), sizeof(int));
	inf.read(reinterpret_cast<char *>(&ts_chunk), sizeof(int));
	return true;
}
Exemple #27
0
/*
 *--------------------------------------------------------------------------------------
 *       Class:  BmpFileHeader
 *      Method:  BmpFileHeader
 * Description:  constructor
 *--------------------------------------------------------------------------------------
 */
BmpFileHeader::BmpFileHeader (ifstream &file)
{
    file.read ((char *) &bf_type, sizeof (Word));
    file.read ((char *) &bf_size, sizeof (Dword));
    file.read ((char *) &bf_reserved1, sizeof (Word));
    file.read ((char *) &bf_reserved2, sizeof (Word));
    file.read ((char *) &bf_off_bits, sizeof (Dword));
}  /* -----  end of method BmpFileHeader::BmpFileHeader  (constructor)  ----- */
void Spectrum::readFromFile(ifstream &file)
{
    //check that it is binary
    delete []data.peaks;
    file.read( (char*)this, sizeof(*this) );  //read into self
    data.peaks = new  PEAK_T[data.numPeaks]; //allocate memory for array
    file.read( (char*)data.peaks, data.numPeaks*sizeof(PEAK_T) );  //read in array
}
vector<NArray> TrainMB(ifstream& data_file_in, ifstream& label_file_in, bool print) {
  Scale data_size{28, 28, 1, mb_size};
  Scale label_size{10, 1, 1, mb_size};
  ConvInfo conv_info[2];
  conv_info[0].pad_height = conv_info[0].pad_width = 0;
  conv_info[0].stride_vertical = conv_info[0].stride_horizontal = 1;
  conv_info[1].pad_height = conv_info[1].pad_width = 2;
  conv_info[1].stride_vertical = conv_info[1].stride_horizontal = 1;
  PoolingInfo pool_info[2];
  pool_info[0].algorithm = PoolingInfo::Algorithm::kMax;
  pool_info[0].height = pool_info[0].width = 2;
  pool_info[0].stride_vertical = pool_info[0].stride_horizontal = 2;
  pool_info[1].algorithm = PoolingInfo::Algorithm::kMax;
  pool_info[1].height = pool_info[1].width = 3;
  pool_info[1].stride_vertical = pool_info[1].stride_horizontal = 3;

  NArray acts[9], sens[9], label;
  shared_ptr<float> data_ptr(new float[data_size.Prod()], [](float* ptr) { delete[] ptr; });
  shared_ptr<float> label_ptr(new float[label_size.Prod()], [](float* ptr) { delete[] ptr; });
  data_file_in.read(reinterpret_cast<char*>(data_ptr.get()), data_size.Prod() * sizeof(float));
  label_file_in.read(reinterpret_cast<char*>(label_ptr.get()), label_size.Prod() * sizeof(float));
  acts[0] = NArray::MakeNArray(data_size, data_ptr);
  label = NArray::MakeNArray(label_size, label_ptr);

  acts[1] = Convolution::ConvForward(acts[0], weights[0], bias[0], conv_info[0]);
  acts[2] = Convolution::ActivationForward(acts[1], ActivationAlgorithm::kRelu);
  acts[3] = Convolution::PoolingForward(acts[2], pool_info[0]);
  acts[4] = Convolution::ConvForward(acts[3], weights[1], bias[1], conv_info[1]);
  acts[5] = Convolution::ActivationForward(acts[4], ActivationAlgorithm::kRelu);
  acts[6] = Convolution::PoolingForward(acts[5], pool_info[1]);
  auto re_acts6 = acts[6].Reshape({acts[6].Size().Prod() / mb_size, mb_size});
  acts[7] = (weights[2] * re_acts6).NormArithmetic(bias[2], ArithmeticType::kAdd);
  acts[8] = Convolution::SoftmaxForward(acts[7].Reshape({10, 1, 1, mb_size}), SoftmaxAlgorithm::kInstance);

  sens[8] = acts[8] - label;

  // sens[7] = Convolution::SoftmaxBackward(sens[8], acts[8], SoftmaxAlgorithm::kInstance).Reshape({10, mb_size});
  sens[7] = sens[8].Reshape({10, mb_size});
  sens[6] = (weights[2].Trans() * sens[7]).Reshape(acts[6].Size());
  sens[5] = Convolution::PoolingBackward(sens[6], acts[6], acts[5], pool_info[1]);
  sens[4] = Convolution::ActivationBackward(sens[5], acts[5], acts[4], ActivationAlgorithm::kRelu);
  sens[3] = Convolution::ConvBackwardData(sens[4], acts[3], weights[1], conv_info[1]);
  sens[2] = Convolution::PoolingBackward(sens[3], acts[3], acts[2], pool_info[0]);
  sens[1] = Convolution::ActivationBackward(sens[2], acts[2], acts[1], ActivationAlgorithm::kRelu);

  if (print) {
    PrintTrainingAccuracy(acts[8], label);
  }

  vector<NArray> ret;
  ret.push_back(Convolution::ConvBackwardFilter(sens[1], acts[0], weights[0], conv_info[0]));
  ret.push_back(Convolution::ConvBackwardBias(sens[1]));
  ret.push_back(Convolution::ConvBackwardFilter(sens[4], acts[3], weights[1], conv_info[1]));
  ret.push_back(Convolution::ConvBackwardBias(sens[4]));
  ret.push_back(sens[7] * re_acts6.Trans());
  ret.push_back(sens[7].Sum(1));
  return ret;
}
void read(ifstream& fin, string& str)
{
	size_t len;
	fin.read((char *)&len, sizeof(size_t));
	
	str = string(len, '\0');
	for (size_t i = 0; i < len; i++)
		fin.read(&str[i], sizeof(char));
}