Example #1
0
cNetFileReceiver::~cNetFileReceiver()
{
	SAFE_DELETE_ARR(m_downloadPath);

	m_fileStream.close();
	m_fileStream.clear();

	SAFE_DELETE_ARR(m_downloadFileName);
}
void
myGPUUnstructuredGridVolumeRayCastMapper::initInteratorOnGPU (void)
{
    if (dIntegrator)
        return;

    setDevice ();

    myUnstructuredGridLinearRayIntegrator *integrator
        = (myUnstructuredGridLinearRayIntegrator *) this->RealRayIntegrator;
    myLinearRayIntegratorTransferFunction *transferFunc
        = integrator->getTransferFunc ();

    hIntegrator.UnitDistance = integrator->getUnitDistance ();
    hIntegrator.IndependentComponents = integrator->getIndependentComponents ();
    hIntegrator.NumIndependentComponents =
        integrator->getNumIndependentComponents ();

    SAFE_DELETE_ARR (hIntegrator.TransferFunctions);
    int numComp = this->Scalars->GetNumberOfComponents ();
    hIntegrator.TransferFunctions =
        new dLinearRayIntegratorTransferFunction[numComp];

    LOOP_I (numComp)
    {
        hIntegrator.TransferFunctions[i].NumControlPoints
            = transferFunc[i].NumControlPoints;

        ALLOC_CPY_ASSIGN (double, hIntegrator.TransferFunctions[i].ControlPoints,
                          hIntegrator.TransferFunctions[i].NumControlPoints,
                          transferFunc[i].ControlPoints,
                          hIntegrator.TransferFunctions[i].ControlPoints,
                          dMemUsageIntegrator);

        ALLOC_CPY_ASSIGN (myLinearRayIntegratorTransferFunction::acolor,
                          hIntegrator.TransferFunctions[i].Colors,
                          hIntegrator.TransferFunctions[i].NumControlPoints,
                          transferFunc[i].Colors,
                          hIntegrator.TransferFunctions[i].Colors,
                          dMemUsageIntegrator);
    }

    dMemAlloc < dLinearRayIntegratorTransferFunction >
    (&dTransferFunc, numComp, &dMemUsageIntegrator, deviceID);
    MEMCPY_H_to_D (dTransferFunc, hIntegrator.TransferFunctions,
                   sizeof (dLinearRayIntegratorTransferFunction) * numComp);

    SAFE_DELETE_ARR (hIntegrator.TransferFunctions);
    hIntegrator.TransferFunctions = dTransferFunc;

    dMemAlloc < dUnstructuredGridLinearRayIntegrator >
    (&dIntegrator, 1, &dMemUsageIntegrator, deviceID);
    MEMCPY_H_to_D (dIntegrator, &hIntegrator,
                   sizeof (dUnstructuredGridLinearRayIntegrator));

    dMemUsage += dMemUsageIntegrator;
}
  KinectInterfacePrimesense::~KinectInterfacePrimesense() {
    // Stop the openNI device
    for (uint32_t i = 0; i < NUM_STREAMS; i++) {
      if (frames_[i]) {
        frames_[i]->release();
      }
      if (streams_[i]) {
        streams_[i]->stop();
        streams_[i]->destroy();
      }
    }
    if (device_) {
      device_->close();
    }

    if (tp_) {
      tp_->stop();
    }
    SAFE_DELETE(tp_);
    SAFE_DELETE(device_listener_);
    if (depth_format_100um_) {
      SAFE_DELETE_ARR(depth_1mm_);
    }
    SAFE_DELETE_ARR(registered_rgb_);
    SAFE_DELETE_ARR(pts_uvd_);
    SAFE_DELETE_ARR(pts_world_);
    SAFE_DELETE_ARR(labels_);
    SAFE_DELETE(openni_funcs_);
    for (uint32_t i = 0; i < NUM_STREAMS; i++) {
      SAFE_DELETE(frames_[i]);
      SAFE_DELETE(streams_[i]);
    }
    SAFE_DELETE(device_);

    // Decrement the devices counter
    if (device_initialized_) {
      openni_static_lock_.lock();
      openni_devices_open_--;
      openni_static_lock_.unlock();
    }

    // Request a shutdown of the openNI framework
    shutdownOpenNIStatic();
  }
Example #4
0
int cNetFileReceiver::SetDownloadPath(const TCHAR path[])
{
	SAFE_DELETE_ARR(m_downloadPath);

	m_downloadPath = new TCHAR[lstrlenW(path) + 1];

	lstrcpyW(m_downloadPath, path);


	return 0;
}
Example #5
0
 PSO<T>::~PSO() {
   if (swarm_) {
     for (uint32_t i = 0; i < swarm_size_; i++) {
       SAFE_DELETE(swarm_[i]);
     }
   }
   SAFE_DELETE_ARR(best_pos_global_);
   SAFE_DELETE_ARR(c_lo_);
   SAFE_DELETE_ARR(c_hi_);
   SAFE_DELETE_ARR(cur_c_min_);
   SAFE_DELETE_ARR(cur_c_max_);
   SAFE_DELETE_ARR(delta_c_);
   SAFE_DELETE_ARR(vel_max_);
   SAFE_DELETE_ARR(swarm_);
 }
Example #6
0
el::lib_tcp_srv_t::~lib_tcp_srv_t()
{
	if (NULL != this->peer_fd_infos){
		for (int i = 0; i < this->cli_fd_value_max; i++) {
			lib_tcp_peer_info_t& cfi = this->peer_fd_infos[i];
			if (FD_TYPE_UNUSED == cfi.get_fd_type()){
				continue;
			}
			cfi.close();
		}
		SAFE_DELETE_ARR(this->peer_fd_infos);
	}
	lib_file_t::close_fd(this->listen_fd);
}
RungeKuttaSolver::~RungeKuttaSolver()
{
    SAFE_DELETE_ARR( mTmpPos );
    SAFE_DELETE_ARR( mTmpV );
    SAFE_DELETE_ARR( mK1 );
    SAFE_DELETE_ARR( mK2 );
    SAFE_DELETE_ARR( mK3 );
    SAFE_DELETE_ARR( mK4 );
}
void
ParticleSystem::freeParticleStorage()
{
    SAFE_DELETE_ARR( mParticlePos );
    SAFE_DELETE_ARR( mParticleVelocity );
    SAFE_DELETE_ARR( mParticleInvMass );
    SAFE_DELETE_ARR( mParticleInfo );
    SAFE_DELETE_ARR( mFaceNormals );
    SAFE_DELETE_ARR( mVertexNormals );
}
Example #9
0
void raptor_decoder::process_decode(byte **rec_packets, int rev_n, byte* result_buffer, int lenth_buffer, int *lost_ESIs, int *lostcount)
{
	MATRIX_ALLOC(erc,rev_n,SYMBOL_SIZE,byte,0);
	int *ESIs=new int[rev_n];
	for(int i=0;i<rev_n;++i)
	{
		ESIs[i]=((int*)(rec_packets[i]))[0];
		memcpy((byte*)(erc[i]),(byte*)(rec_packets[i])+sizeof(int),SYMBOL_SIZE*sizeof(byte));
	}
//printf("ESI decode = \n"); for(int i=0;i<rev_n;++i)	printf("%d ",ESIs[i]);printf("\n");
	base_process_decode((byte**)erc,(int*)ESIs,rev_n,lost_ESIs,lostcount);
	get_decode_result((byte*)result_buffer,lenth_buffer);
	MATRIX_DEL(erc,rev_n);
	SAFE_DELETE_ARR(ESIs);
	return ;
}
Example #10
0
void raptor_decoder::GEcalculate(long long **AA, int _K, int _L, int _N, int _M, int _SYMBOL_SIZE, int r, byte** _intermid_index)
{//GEcalculate(Aw, erc1, _SYMBOL_SIZE, r);Aw:matrix build before: (_N+S+H) * _L, erc1: _N * _SYMBOL_SIZE
	const int lenth_row_L=INT_CEIL64(_L);
	int P=0;
	long long *temp = new long long[lenth_row_L];
	byte *tempo = NULL;
	int base_zero_line=0;
	int i=0;
	for (int jj=0; jj<_L; jj++)
	{
		tempo=NULL;
		memset((long long*)temp,0,lenth_row_L*sizeof(long long));
		for(i=jj; (i<_M) && (!GET_MATRIX_ij(AA,i,jj)); ++i);
		if (i==_M){
			error = 4;
			continue;
		}//all is 0, non-mark matrix
		base_zero_line=i;
		for(i=0;i<base_zero_line;++i)
		{
			if( GET_MATRIX_ij(AA,i,jj) )
			{
				memxor((byte*)(_intermid_index[i]),(byte*)(_intermid_index[base_zero_line]),_SYMBOL_SIZE);
				memxor((long long *)(AA[i]),(long long*)(AA[base_zero_line]),lenth_row_L*sizeof(long long));
			}
		}
		for(++i;i<_M;++i)
		{
			if( GET_MATRIX_ij(AA,i,jj) )
			{
				memxor((byte*)(_intermid_index[i]),(byte*)(_intermid_index[base_zero_line]),_SYMBOL_SIZE);
				memxor((char *)(AA[i]),(char*)(AA[base_zero_line]),lenth_row_L*sizeof(long long));
			}
		}
		memcpy((long long*)temp,(long long *)(AA[jj]),lenth_row_L*sizeof(long long));
		memcpy((long long*)(AA[jj]),(long long*)(AA[base_zero_line]),lenth_row_L*sizeof(long long));
		memcpy((long long*)(AA[base_zero_line]),(long long*)temp,lenth_row_L*sizeof(long long));

		tempo = (byte*)(_intermid_index[jj]);
		_intermid_index[jj] = (byte*)(_intermid_index[base_zero_line]);
		_intermid_index[base_zero_line] = (byte*)(tempo);
	}
	SAFE_DELETE_ARR(temp);
	//discarded _M-_L rows to get the result
	return ;
}
Example #11
0
void FishPlayer::SaveImg()
{
	static int MASK1 = GetTickCount();
	static int MASK2 = MASK1 + rand();

	UINT t = GetTickCount();
	UINT crc = AECrc32(&t, sizeof(t), 0);
	t = m_ImgSize;
	crc = AECrc32(&t, sizeof(t), crc);
	t = ++MASK1;
	crc = AECrc32(&t, sizeof(t), crc);
	t = ++MASK2;
	crc = AECrc32(&t, sizeof(t), crc);
	char xx[50];
	sprintf_s(xx, sizeof(xx), "%u_%u.jpg", GetID(), crc);
	FTPUpload::Inst()->UploadToFTP(m_pImgData, m_ImgSize, xx, GetID(), crc);
	
	SAFE_DELETE_ARR(m_pImgData);
}
void
myGPUUnstructuredGridVolumeRayCastMapper::allocateImageMemory ()
{
    double oldMemUsage = dMemUsage;
    setDevice ();

    // Host part
    SAFE_DELETE_ARR (this->Image);
    this->Image = new unsigned char[ImageMemorySizeTotal];
    memset (this->Image, 0, sizeof (unsigned char) * ImageMemorySizeTotal);

    // Device part
    SAFE_DELETE_CUDA (dImage);
    dMemAlloc < unsigned char >(&dImage, ImageMemorySizeTotal, &dMemUsage,
                                deviceID);
    dMemSetZero < unsigned char >(&dImage, ImageMemorySizeTotal, deviceID);

    printf ("[GPU BunykRayCast] %.2f MB was allocated for the Image.\n",
            (dMemUsage - oldMemUsage) / (_1M_));
}
Example #13
0
bool FishPlayer::AddImgData(USHORT idx, USHORT size, byte *pData)
{
	if (m_pImgData && (idx + size) <= m_ImgSize && (m_UploadSize + size) <= m_ImgSize)
	{
		memcpy(m_pImgData + idx, pData, size);
		m_UploadSize += size;
		//上传完成
		if (m_UploadSize == m_ImgSize)
		{
			SaveImg();
		}
		return true;
	}
	else
	{
		SAFE_DELETE_ARR(m_pImgData);
		InnerFishLog(L"上传失败.");
		return false;
	}
}
Example #14
0
void Log(const CHAR *pcStr, ...)
{
	va_list var;
	va_start(var, pcStr);
	UINT nCount = _vscprintf(pcStr, var);
	CHAR *pBuffer = new CHAR[nCount + 1];
	if (pBuffer)
	{
		vsprintf_s(pBuffer, nCount + 1, pcStr, var);
		if (g_Handler == null)
		{
			wcout << pBuffer << endl;
			OutputDebugStringA(pBuffer);
			OutputDebugStringA("\n");
		}
		else
			g_Handler->LogHandlerA(pBuffer);

		SAFE_DELETE_ARR(pBuffer);
	}
	va_end(var);
}
void PixelProcessing::ProcessTexture(Texture* texture)
{
	const UINT width = texture->GetSurfaceWidth();
	const UINT height = texture->GetSurfaceHeight();

	DWORD *srf = (DWORD*)texture->LockRect();
	DWORD *tempSrf = new DWORD[texture->GetSurfaceWidth()*texture->GetSurfaceHeight()];

	for (int y=0; y<(int)height; y++)
	{
		for (int x=0; x<(int)width; x++)
		{
			ProcessPixel(&srf[y*width+x], &tempSrf[y*width+x]);
		}
	}

	for (int i=0; i<(int)(height*width); i++)
		srf[i] = tempSrf[i];

	texture->UnlockRect();
	SAFE_DELETE_ARR(tempSrf);
}
Example #16
0
void raptor_decoder::at_DecoderCalculate(int _K, int _Lp, long long **_B, byte **erc1, int _N, int _M, int _L, int _SYMBOL_SIZE, int** _U, int* _ESIs, int r, byte**y )
{	//input: B,the matrix of the 'A', erc1: the ereasuing blocks, _U: tiples that made before, also should be knowing, _ESIs, index pointer of erc1, _N is lenth of _ESIs
/*The order in which Gaussian elimination is performed to form the decoding schedule has no bearing on whether or not the decoding is successful. However, the speed of the decoding depends heavily on the order in which Gaussian elimination is performed. (Furthermore, maintaining a sparse representation of A is crucial, although this is not described here). The remainder of this section describes an order in which Gaussian elimination could be performed that is relatively efficient.*/

	int* d=(int*)(_U[0]);
	int* a=(int*)(_U[1]);
	int* b=(int*)(_U[2]);
	const int lenth_row_L=INT_CEIL64(_L);
	elim_stack *mtr_op=new elim_stack[_M*_L];;//elimination process
	long long mtr_op_size=0;
	at_AAcalculate( _B, _K, _ESIs, _N, _L, _M, d, a, b, _Lp, (elim_stack*)mtr_op, &mtr_op_size);
	if(get_err_bit()==4)
	{
		return ;
	}
	MATRIX_ALLOC(cdc, _M, _SYMBOL_SIZE, byte, 0 );
	byte **intermid_index = new byte*[_M];//Lx1(pointer array)
	at_Desymbol_process((elim_stack*)mtr_op, mtr_op_size, (byte**)cdc, (byte**)erc1, _SYMBOL_SIZE, _M, _N, (byte**)intermid_index);
	for (int j=0; j<_K; j++)
		Lncalculate(_Lp, intermid_index, d[j], a[j], b[j], _L, _SYMBOL_SIZE, (byte*)(y[j]));
	MATRIX_DEL(cdc,_M);
	SAFE_DELETE_ARR(intermid_index);
	return ;
}
Example #17
0
  bool Texture::saveImToFile(const std::string& filename, const uint8_t* im, 
    const uint32_t width, const uint32_t height, const bool save_flipped, 
    const uint32_t num_channels) {
    freeimage_init_lock_.lock();
    if (!freeimage_init_) {
      freeimage_init_lock_.unlock();
      throw std::wruntime_error("Texture::Texture() - ERROR: Please call "
        "initTextureSystem() before loading textures from file!");
    }
    freeimage_init_lock_.unlock();

    // NEW CODE USING THE FREEIMAGE LIBRARY
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;  //image format

	  // if still unknown, try to guess the file format from the file extension
	  if (fif == FIF_UNKNOWN) {
      fif = FreeImage_GetFIFFromFilename(filename.c_str());
    }
	  // if still unkown, return failure
	  if (fif == FIF_UNKNOWN) {
      throw wruntime_error(wstring(L"saveRGBToFile() - ERROR: Cannot deduce "
        L"format of the filename: ") + string_util::ToWideString(filename));
    }

    if (!FreeImage_FIFSupportsWriting(fif)) {
      throw std::wruntime_error("saveRGBToFile() - ERROR: Freeimage does not "
        "support writing to this image format!");
      return false;
    }

    BYTE* fi_bits = NULL;
    uint8_t* im_rev = NULL;

    // Unfortunately, Freeimage has a bug:
    // http://sourceforge.net/p/freeimage/bugs/172/
    // It ignores the mask properties and so the red and blue channels (24bpp)
    // get flipped.  Unfortunately, we have to swap them around.
    // As of 4/26/2013 this issue still isn't fixed.
    switch (num_channels) {
    case 0:
      throw std::wruntime_error("saveImToFile() - ERROR: num_channels == 0");
    case 1:
      fi_bits = (BYTE*)im;
      break;
    case 2:
    case 3:
      im_rev = new uint8_t[width * height * num_channels];
      for (uint32_t i = 0; i < width * height * num_channels; i+=num_channels) {
        for (uint32_t j = 0; j < num_channels; j++) {
          im_rev[i + j] = im[i + (num_channels - 1 - j)];
        }
      }
      fi_bits = (BYTE*)im_rev;
      break;
    default:
      throw std::wruntime_error("saveImToFile() - ERROR: num_channels > 0."
        " Saving images with alpha not yet supported.");
    }
    uint32_t pitch = num_channels * width;
    uint32_t bpp = 8 * num_channels;
    uint32_t red_mask = 0x0000FF;  // Free image likes the mask backwards?
    uint32_t green_mask = 0x00FF00;
    uint32_t blue_mask = 0xFF0000;
    FIBITMAP* fi_bit_map = FreeImage_ConvertFromRawBits(fi_bits, width, height,
      pitch, bpp, red_mask, blue_mask, green_mask, save_flipped);
    bool ret = false;
    if (fi_bit_map) {
      ret = (bool)FreeImage_Save(fif, fi_bit_map, filename.c_str(), 
        JPEG_QUALITYSUPERB);
    }
    if (fi_bit_map) {
      FreeImage_Unload(fi_bit_map);
    }

    SAFE_DELETE_ARR(im_rev);
    return ret;
  }
Example #18
0
int cNetFileReceiver::Update(cNetMessage* pRecvMsg)
{
	if (pRecvMsg == nullptr) return -1;


	cBinaryReader br(pRecvMsg);

	UINT msgType = pRecvMsg->Header->MsgType;


	if (msgType == NetMsgType::RQ_FileSend)
	{
		Stop();


		TCHAR filePath[2048];
		br.ReadString(filePath);

		m_leftByteSize = br.Read<int>();


		bool readyForRecv = m_bOnRecv;


		if (readyForRecv)
		{
			// 파일 이름 추출
			int filePathLen = lstrlenW(filePath);

			TCHAR fileName[2048] = { '\0', };
			int startCopyIdx = 0;

			for (startCopyIdx = filePathLen - 1; startCopyIdx >= 0; --startCopyIdx)
			{
				if (filePath[startCopyIdx] == TEXT('\\') || filePath[startCopyIdx] == TEXT('/'))
				{
					++startCopyIdx;
					break;
				}
			}

			if (startCopyIdx < 0) startCopyIdx = 0;

			for (int i = startCopyIdx; i <= filePathLen; ++i)
			{
				fileName[i - startCopyIdx] = filePath[i];
			}


			// 파일 생성
			SAFE_DELETE_ARR(m_downloadFileName);
			m_downloadFileName = new TCHAR[min(lstrlenW(m_downloadPath) + lstrlenW(fileName) + 2, 4096)];

			swprintf_s(m_downloadFileName, 4096, L"%s%s", m_downloadPath, fileName);

			m_fileStream.open(m_downloadFileName);

			if (m_fileStream.is_open() == false)
			{
				Util::Log("수신할 파일 생성 실패");


				readyForRecv = false; // 파일 생성 실패
			}
		}
		else
		{
			Util::Log("파일 수신 거부함");
		}


		// 다운로드 여부 응답
		cBinaryWriter bw;
		bw.Write(readyForRecv ? NetDefine::YES : NetDefine::NO);

		cNetMessage* pMsg = NetMsgUtil::MakeMessage(NetMsgType::RP_FileSend, &bw);

		m_pNetSender->PushSendMsg(pMsg);
	}
	else if (msgType == NetMsgType::NF_FileSendData)
	{
		bool bSuccess = true;


		// 파일 다운로드 진행
		int seqNum = br.Read<int>();
		int byteSize = br.Read<int>();
		char* fileData = new char[byteSize];

		br.ReadBytes(fileData, byteSize);

		if (m_fileStream.is_open())
		{
			Util::Log("파일 수신 %d 성공", seqNum);


			bSuccess = true;

			m_fileStream.write(fileData, byteSize);


			m_leftByteSize -= byteSize; // 남은 바이트 수 갱신

			if (m_leftByteSize <= 0) // 다운로드 완료
			{
				// 다운로드 성공여부 응답
				cBinaryWriter bw;
				bw.Write(NetDefine::SUCCESS);

				cNetMessage* pMsg = NetMsgUtil::MakeMessage(NetMsgType::RP_FileSendEnd, &bw);

				m_pNetSender->PushSendMsg(pMsg);


				m_fileStream.close();
				m_fileStream.clear();
			}
		}
		else
		{
			Util::Log("파일 수신 %d 실패", seqNum);


			bSuccess = false;
		}

		SAFE_DELETE_ARR(fileData);


		// 파일 다운로드 상황 응답
		cBinaryWriter bw;
		bw.Write(seqNum);
		bw.Write(byteSize);
		bw.Write(bSuccess ? NetDefine::SUCCESS : NetDefine::FAIL);

		cNetMessage* pMsg = NetMsgUtil::MakeMessage(NetMsgType::RP_FileSendData, &bw);

		m_pNetSender->PushSendMsg(pMsg);
	}
	else if (msgType == NetMsgType::NF_FileSendEnd)
	{
		Stop();


		bool bSuccess = true;


		BYTE goodBad = br.Read<BYTE>();

		if (goodBad == NetDefine::SUCCESS)
		{
			Util::Log("파일 수신 완료");


			bSuccess = true;
		}
		else
		{
			Util::Log("파일 수신 실패");


			bSuccess = false;
		}


		if (m_leftByteSize > 0) bSuccess = false;


		// 다운로드 성공여부 응답
		cBinaryWriter bw;
		bw.Write(bSuccess ? NetDefine::SUCCESS : NetDefine::FAIL);

		cNetMessage* pMsg = NetMsgUtil::MakeMessage(NetMsgType::RP_FileSendEnd, &bw);

		m_pNetSender->PushSendMsg(pMsg);
	}


	return 0;
}
Example #19
0
TcpConnection::~TcpConnection()
{
    SAFE_DELETE_ARR(_buffer);
    debug_log("connection destroyed.");
}
Example #20
0
void raptor_decoder::base_process_decode(byte **erc,int *_ESIs, int rev_n, int *lost_ESIs, int *lostcount)
{//input should be blocks array erc and the index of erc ESIs, which marks all the position of sub-block of whole block, 
	//if decoding process fail, then we just give the blocks that still could be used, otherwise, we could recover all the packets
/*
input: 
	byte array: erc, encoding packets
	int array: _ESIs, ESIs marks of encoding packets
	int : rev_n, the size of _ESIs and erc 
*/	
	*lostcount=0;
	if(rev_n < N)
	{
		error = 5;
		rev_block = (byte**)erc;
		clear_fail_decode();
		ESIs = (int*)_ESIs;
		byte *flag_source_empty = new byte[K];
		memset((byte*)(flag_source_empty),0,K*sizeof(byte));
		for(int i=0;i<rev_n;++i)
		{
			if(ESIs[i]<K)
			{
				memcpy((byte*)(source_block[ESIs[i]]),(byte*)(rev_block[i]),SYMBOL_SIZE*sizeof(byte));
				add_fail_decode();
				flag_source_empty[ESIs[i]]=1;
			}
		}
		for(int i=0;i<K;++i)
		{
			if(!(flag_source_empty[i]))
			{
				lost_ESIs[*lostcount]=i;++(*lostcount);
				memset((byte*)(source_block[i]),0,SYMBOL_SIZE*sizeof(byte));
			}
		}
		SAFE_DELETE_ARR(flag_source_empty);
	}
	else
	{//attention: size of ESIs should no more than N
		rev_block = (byte**)erc;
		MATRIX_COPY(backup_block,rev_block,N,SYMBOL_SIZE,byte);
		clear_fail_decode();
		ESIs = (int*)_ESIs;
		(this->*pDecoderCalculate)(K, Lp, (long long **)B, (byte **)rev_block, N, M, L, SYMBOL_SIZE, (int**)U, (int*)ESIs, 0, (byte**)source_block);
		//dealing with the possibly that the decode is fail
		if(get_err_bit())
		{
			byte *flag_source_empty = new byte[K];
			memset((byte*)(flag_source_empty),0,K*sizeof(byte));
			for(int i=0;i<N;++i)
			{
				if(ESIs[i]<K)
				{
					memcpy((byte*)(source_block[ESIs[i]]),(byte*)(backup_block[i]),SYMBOL_SIZE*sizeof(byte));
					add_fail_decode();
					flag_source_empty[ESIs[i]]=1;
				}
			}
			for(int i=0;i<K;++i)
			{
				if(!(flag_source_empty[i]))
				{
					lost_ESIs[*lostcount]=i;++(*lostcount);
//					memset((byte*)(source_block[i]),0,SYMBOL_SIZE*sizeof(byte));
				}
			}
			SAFE_DELETE_ARR(flag_source_empty);
		}
	}
	return ;
}
Example #21
0
  void JoinTable::init(TorchData& input) {
    if (input.type() != TorchDataType::TABLE_DATA) {
      throw std::runtime_error("JoinTable::forwardProp() - "
        "Table expected!");
    }
    Table& in = (Table&)input;

    if (in.tableSize() == 0) {
      throw std::runtime_error("JoinTable::forwardProp() - "
        "Empty input Table!");
    }

    // Check that it is a table of FloatTensors
    for (uint32_t i = 0; i < in.tableSize(); i++) {
      if (in(i)->type() != TENSOR_DATA) {
        throw std::runtime_error("JoinTable::forwardProp() - "
          "Table of float tensors expected!");
      }
    }

    uint32_t dim = TO_TENSOR_PTR(in(0))->dim();
    if (dim <= dimension_) {
      throw std::runtime_error("JoinTable::forwardProp() - "
        "Input is smaller than join dimension!");
    }
    uint32_t jdim = dim - dimension_ - 1;  // dimension_=0 is the top dim

    // Make sure the dimensions OTHER than the join dimension are all the same
    for (uint32_t d = 0; d < dim; d++) {
      if (d != jdim) {
        for (uint32_t j = 1; j < in.tableSize(); j++) {
          if (TO_TENSOR_PTR(in(j))->size()[d] != TO_TENSOR_PTR(in(0))->size()[d]) {
            throw std::runtime_error("JoinTable::forwardProp() - "
              "Size mismatch!");
          }
        }
        if (output != NULL && TO_TENSOR_PTR(output)->size()[d] != 
          TO_TENSOR_PTR(in(0))->size()[d]) {
            SAFE_DELETE(output);
        }
      }
    }

    uint32_t nelems_jdim = 0;
    for (uint32_t j = 1; j < in.tableSize(); j++) {
      nelems_jdim += TO_TENSOR_PTR(in(j))->size()[jdim];
    }

    if (output != NULL &&
      TO_TENSOR_PTR(output)->size()[jdim] != nelems_jdim) {
      SAFE_DELETE(output);
    }

    if (output == NULL) {
      uint32_t* size = new uint32_t[dim];
      memcpy(size, TO_TENSOR_PTR(in(0))->size(), sizeof(size[0]) * dim);
      size[dimension_] = nelems_jdim;
      output = new Tensor<float>(dim, size);
      SAFE_DELETE_ARR(size);
    }
  }