/***********************************************
Get the inner product of vectors from start row(sr), last rowLength-length
input: the number of subjects, the number of blocks, the start row, the number of voxels of masked matrix one that involved in the computing, the trials information, the first masked data array, the second masked data array
output: the partial similarity matrix based on the selected rows of first matrices and the whole second matrices
************************************************/
float* GetPartialInnerSimMatrixWithMasks(int nSubs, int nTrials, int sr, int rowLength, Trial* trials, RawMatrix** masked_matrices1, RawMatrix** masked_matrices2) // compute the correlation between masked matrices
{
  int i;
  int row1 = masked_matrices1[0]->row;
  int row2 = masked_matrices2[0]->row;  //rows should be the same across subjects since we are using the same mask file to filter out voxels
  float* values= new float[nTrials*rowLength*row2];
  float* simMatrix = new float[nTrials*nTrials];
  memset((void*)simMatrix, 0, nTrials*nTrials*sizeof(float));
  for (i=0; i<nTrials; i++)
  {
    int sc = trials[i].sc;
    int ec = trials[i].ec;
    int sid = trials[i].sid;
    int col = masked_matrices1[sid]->col; // the column of 1 and 2 should be the same, i.e. the number of TRs of a block; columns may be different, since different subjects have different TRs
    float* mat1 = masked_matrices1[sid]->matrix;
    float* mat2 = masked_matrices2[sid]->matrix;
    float* buf1 = new float[row1*col]; // col is more than what really need, just in case
    float* buf2 = new float[row2*col]; // col is more than what really need, just in case
    int ml1 = getBuf(sc, ec, row1, col, mat1, buf1);  // get the normalized matrix, return the length of time points to be computed
    int ml2 = getBuf(sc, ec, row2, col, mat2, buf2);  // get the normalized matrix, return the length of time points to be computed, m1==m2
    cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, rowLength, row2, ml1, 1.0, buf1+sr*ml1, ml1, buf2, ml2, 0.0, values+i*rowLength*row2, row2);
    delete[] buf1;
    delete[] buf2;
  }
  NormalizeCorrValues(values, nTrials, rowLength, row2, nSubs);
  GetDotProductUsingMatMul(simMatrix, values, nTrials, rowLength, row2);
  delete[] values;
  return simMatrix;
}
Exemplo n.º 2
0
/******************************
compute a corr-matrix based on trial, starting row and step
input: a trial struct, starting row id, step (the row of the correlation matrix, whose column is row), the raw matrix struct array
output: the corr-matrix struct
*******************************/
CorrMatrix* CorrMatrixComputation(Trial trial, int sr, int step, RawMatrix** matrices1, RawMatrix** matrices2)
{
  int sid = trial.sid;
  int sc = trial.sc;
  int ec = trial.ec;
  int row1 = matrices1[sid]->row;
  int row2 = matrices2[sid]->row;
  int col = matrices1[sid]->col;  // the column of 1 and 2 should be the same, i.e. the number of TRs of a block
  float* mat1 = matrices1[sid]->matrix;
  float* mat2 = matrices2[sid]->matrix;
  float* buf1 = new float[row1*col]; // col is more than what really need, just in case
  float* buf2 = new float[row2*col]; // col is more than what really need, just in case
  int ml1 = getBuf(sc, ec, row1, col, mat1, buf1);  // get the normalized matrix, return the length of time points to be computed
  int ml2 = getBuf(sc, ec, row2, col, mat2, buf2);  // get the normalized matrix, return the length of time points to be computed, m1==m2
  CorrMatrix* c_matrix = new CorrMatrix();
  c_matrix->sid = sid;
  c_matrix->tlabel = trial.label;
  c_matrix->sr = sr;
  c_matrix->step = step;
  c_matrix->nVoxels = row2; //
  float* corrs = new float[step*row2];
  cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, step, row2, ml1, 1.0, buf1+sr*ml1, ml1, buf2, ml2, 0.0, corrs, row2);
  c_matrix->matrix = corrs;
  delete[] buf1;
  delete[] buf2;
  return c_matrix;
}
Exemplo n.º 3
0
ossimDataObjectStatus ossimS16ImageData::validate() const
{
   if (getBuf() == NULL)
   {
      setDataObjectStatus(OSSIM_NULL);
      return OSSIM_NULL;
   }
   
   ossim_uint32 count = 0;
   const ossim_uint32 SIZE = getSize();
   const ossim_uint32 BOUNDS = getSizePerBand();
   const ossim_uint32 NUMBER_OF_BANDS = getNumberOfBands();
   
   for(ossim_uint32 band = 0; band < NUMBER_OF_BANDS; ++band)
   {
      ossim_sint16 np = (ossim_sint16)m_nullPixelValue[band];
      const ossim_sint16* p  = getSshortBuf(band);
      for (ossim_uint32 i=0; i<BOUNDS; i++)
      {
         // check if the band is null
         if (p[i] != np) count++;         
      }
   }
   
   if (!count)
      setDataObjectStatus(OSSIM_EMPTY);
   else if (count == SIZE)
      setDataObjectStatus(OSSIM_FULL);
   else
      setDataObjectStatus(OSSIM_PARTIAL);

   return getDataObjectStatus();
}
Exemplo n.º 4
0
void ossimU11ImageData::copyTileToNormalizedBuffer(ossim_uint32 band,
        float* buf) const
{
    if (!buf)
    {
        ossimSetError(getClassName(),
                      ossimErrorCodes::OSSIM_ERROR,
                      "ossimU11ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
                      __FILE__,
                      __LINE__);
        return;
    }
    if(!getBuf(band)) return;

    ossim_uint32 size = getSizePerBand();

    if(size > 0)
    {
        const ossim_uint16* s = getUshortBuf(band);  // source
        float* d = buf;   // destination

        for(ossim_uint32 index = 0; index < size; ++index)
        {
            *d = m_remapTable.normFromPix(static_cast<ossim_int32>(*s));
        }
    }
}
Exemplo n.º 5
0
// row here is nTops, get the inner product of vectors from start row(sr), last rowLength-length
float* GetPartialInnerSimMatrix(int row, int col, int nSubs, int nTrials, int sr, int rowLength, Trial* trials, RawMatrix** r_matrices) // only compute the correlation among the selected voxels
{
  int i;
  float* values = new float[nTrials*rowLength*row];
  float* simMatrix = new float[nTrials*nTrials];
  for (i=0; i<nTrials*nTrials; i++) simMatrix[i] = 0.0;
  for (i=0; i<nTrials; i++)
  {
    int sc = trials[i].sc;
    int ec = trials[i].ec;
    int sid = trials[i].sid;
    float* mat = r_matrices[sid]->matrix;
    //if (i==0 && sr==0) cout<<mat[1000*col]<<" "<<mat[1000*col+1]<<" "<<mat[1000*col+2]<<" "<<mat[1000*col+3]<<endl;
    //else if (i==0 && sr!=0) cout<<mat[0]<<" "<<mat[1]<<" "<<mat[2]<<" "<<mat[3]<<endl;
    float* buf = new float[row*col]; // col is more than what really need, just in case
    int ml = getBuf(sc, ec, row, col, mat, buf);  // get the normalized matrix, return the length of time points to be computed
    //cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, step, row, ml, 1.0, buf+sr*ml, ml, buf, ml, 0.0, corrs, row);
    cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, rowLength, row, ml, 1.0, buf+sr*ml, ml, buf, ml, 0.0, values+i*rowLength*row, row);
    delete[] buf;
  }
  NormalizeCorrValues(values, nTrials, rowLength, row, nSubs);
  GetDotProductUsingMatMul(simMatrix, values, nTrials, rowLength, row);
  delete[] values;
  return simMatrix;
}
Exemplo n.º 6
0
/*********************************************************
	Decompress Method
*********************************************************/
int Compression::decompress(void *dest, int destLen, int sourceLen)
{
	void *source = getBuf();
	int compressingMethod = gConfig->networkCompression;
	
	uLongf newSource = sourceLen;
	uLongf newDest = destLen;
	int ret = 0;
	if(sourceLen > 4) {
		if(compressingMethod == 1)
			ret = uncompress((Bytef*) dest, (uLongf*) &newDest, (const Bytef*)source, newSource);
		else if(compressingMethod == 2)
			ret = lzo1b_decompress((const Bytef*)source, newSource, (Bytef*) dest, &newDest, NULL);
		else if(compressingMethod == 3)
			ret = lzo1x_decompress((const Bytef*)source, newSource, (Bytef*) dest, &newDest, NULL);

		if(compressingMethod == 1) {
			if(ret != Z_OK) {
				if(ret == Z_MEM_ERROR){
					LOG("ERROR decompressing: memory error\n");
				}else if(ret == Z_BUF_ERROR){
					LOG("ERROR decompressing: buffer error\n");
				}else if(ret == Z_DATA_ERROR){
					LOG("ERROR decompressing: data error,\n");
				}
			}
		}
	}
	else {
		memcpy(dest, source, sourceLen);
	}
	return (int)newDest;
}
Exemplo n.º 7
0
void ossimU11ImageData::copyNormalizedBufferToTile(ossim_uint32 band,
        float* buf)
{
    if (!buf)
    {
        ossimSetError(getClassName(),
                      ossimErrorCodes::OSSIM_ERROR,
                      "ossimU11ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
                      __FILE__,
                      __LINE__);
        return;
    }

    ossim_uint32 size = getSizePerBand();

    if((size > 0)&&getBuf(band))
    {
        float* s = buf; // source
        ossim_uint16* d = getUshortBuf(band); // destination

        for(ossim_uint32 index = 0; index <  size; ++index)
        {
            *d = m_remapTable.pixFromNorm(*s);
            ++d;
            ++s;
        }
    }
}
Exemplo n.º 8
0
bool SMSSendRequestPacket::getPacketContents(int conversion,
                                             char* &senderPhone,
                                             char* &recipientPhone,
                                             int &dataLength,
                                             byte* &data)
{
   int position = REQUEST_HEADER_SIZE;
   dataLength = incReadShort(position);
   incReadByte(position); // smsType, currently not used here
   incReadString(position, senderPhone);
   incReadString(position, recipientPhone);
   data = getBuf() + position;
   char* tempBuf = new char[dataLength*6];
   // Check if we should convert the SMS
   if ( conversion == CONVERSION_TEXT ) {
      dataLength = 
        SMSConvUtil::gsmToMc2(tempBuf, (const char*)data, dataLength);
   } else {
      // Do not convert
      memcpy(tempBuf, data, dataLength);
   }
   // Swap
   data = reinterpret_cast<byte*>(tempBuf);
   return true;
}
Exemplo n.º 9
0
void USRTTask::_printStack( int bp )
{
  if( bp>=FIFOSIZE )
    printf("Error too big bp\n");
  printf("digraph G {\n");
  int i;
  if( bp<getHead()->sp ) 
    for( i=bp;i<getHead()->sp;i++ )
      dump( (task_t*)getBuf(getHead()->fifo[i],0LL) );
  else {
    for( i=getHead()->sp;i<FIFOSIZE;i++ )
      dump( (task_t*)getBuf(getHead()->fifo[i],0LL) );
    for( i=0;i<bp;i++ )
      dump( (task_t*)getBuf(getHead()->fifo[i],0LL) );
  }
  printf("}\n");
}
void CopyrightBoxReplyPacket::
getCopyrightHolder( CopyrightHolder& holder ) const {
   // load copyrights from packet

   BitBuffer buff( getBuf() + REPLY_HEADER_SIZE, 
                   MAX_PACKET_SIZE - REPLY_HEADER_SIZE );

   holder.load( buff );

}
Exemplo n.º 11
0
void ossimS16ImageData::fill(ossim_uint32 band, double value)
{
   void* s         = getBuf(band);

   if (s == NULL) return; // nothing to do...

   ossim_uint32 size_in_pixels = getSizePerBand();
   ossim_sint16* p = getSshortBuf(band);

   for (ossim_uint32 i=0; i<size_in_pixels; i++) p[i] = (ossim_sint16)value;

   // Set the status to unknown since we don't know about the other bands.
   setDataObjectStatus(OSSIM_STATUS_UNKNOWN);
}
Exemplo n.º 12
0
unsigned int VFSFileZip::read(void *dst, unsigned int bytes)
{
    VFS_GUARD_OPT(this);
    char *mem = (char*)getBuf();
    char *startptr = mem + _pos;
    char *endptr = mem + size();
    bytes = std::min((unsigned int)(endptr - startptr), bytes); // limit in case reading over buffer size
    if(_mode.find('b') == std::string::npos)
        strnNLcpy((char*)dst, (const char*)startptr, bytes); // non-binary == text mode
    else
        memcpy(dst, startptr, bytes); //  binary copy
    _pos += bytes;
    return bytes;
}
Exemplo n.º 13
0
void ossimS16ImageData::copyTileToNormalizedBuffer(ossim_uint32 band,
                                                   double* buf) const
{
   if (!buf)
   {
      ossimSetError(getClassName(),
                     ossimErrorCodes::OSSIM_ERROR,
                    "ossimS16ImageData::copyTileToNormalizedBuffer File %s line %d\nNull pointer passed to method!",
                    __FILE__,
                    __LINE__);
      return;
   }
   
   if(!getBuf(band)) return;
   
   const ossim_uint32 SIZE = getSizePerBand();
   
   if(SIZE)
   {
      const ossim_float64 RANGE = (getMaxPix(band)-getMinPix(band)+1);
      
      const ossim_sint16* s = getSshortBuf(band);  // source
      double* d = buf;   // destination
      
      for(ossim_uint32 index = 0; index < SIZE; ++index)
      {
         ossim_float64 p = s[index];
         
         if (p == m_nullPixelValue[band])
         {
            d[index] = 0.0;
         }
         else if (p >= m_maxPixelValue[band])
         {
            d[index] = 1.0;
         }
         else
         {
            //---
            // Normalize...
            // Note that this will shift any negatives to positive prior
            // to dividing.
            //---
            d[index] =
               ((p-m_minPixelValue[band]+1) / RANGE);
         }
      }
   }
}
CopyrightBoxReplyPacket:: 
CopyrightBoxReplyPacket( const CopyrightBoxRequestPacket* req,
                         const CopyrightHolder& copyrights ):
   ReplyPacket( MAX_PACKET_SIZE,
                Packet::PACKETTYPE_COPYRIGHTBOX_REPLY,
                req, 
                StringTable::OK )  {
   // write copyrights to packet

   BitBuffer buff( getBuf() + REPLY_HEADER_SIZE, 
                   MAX_PACKET_SIZE - REPLY_HEADER_SIZE );
   copyrights.save( buff, 2 ); // 2 = include supplier ids
   // update size according to the buffer
   setLength( REPLY_HEADER_SIZE + buff.getCurrentOffset() );
}
Exemplo n.º 15
0
void UART_isr(void)
{
	int Source=U0IIR; // have to cache the interrupt id register
					  // as the 'if' clause below were reading it
					  // and hence changing its contents.
	if (Source & BIT2) // RX Interrupt
	{
		putBuf(&RXBuffer,U0RBR);
	}
	if (Source & BIT1) // TX Interrupt
	{
		if (TXBuffer.count > 0)
			U0THR = getBuf(&TXBuffer);
	}
}
Exemplo n.º 16
0
/**
 * Send a serialized error back to the client.
 * For a header server, this means serializing the exception, and setting
 * an error flag in the header.
 */
void HeaderServerChannel::HeaderRequest::sendError(
    std::exception_ptr ep,
    std::string exCode,
    MessageChannel::SendCallback* cb) {

  try {
    std::rethrow_exception(ep);
  } catch (const TApplicationException& ex) {
    channel_->header_->setHeader("ex", exCode);
    std::unique_ptr<folly::IOBuf> exbuf(
        serializeError(channel_->header_->getProtocolId(), ex, getBuf()));
    sendReply(std::move(exbuf), cb);
  } catch (const std::exception& ex) {
    // Other types are unimplemented.
    DCHECK(false);
  }
}
Exemplo n.º 17
0
int Compression::compress(void *input, int nByte)
{
	void *output = getBuf();
	int compressingMethod = gConfig->networkCompression;
	
	uLongf CompBuffSize = 0;
	if(compressingMethod == 1)
		CompBuffSize = (uLongf)(nByte + (nByte * 0.1) + 12);
	else
		CompBuffSize = (uLongf)(nByte + (nByte/1024 * 16 ) + 16);

	unsigned char * workingMemory = NULL;
	if(compressingMethod == 2)
		workingMemory = (unsigned char*)malloc(LZO1B_MEM_COMPRESS);
	else if(compressingMethod == 3)
		workingMemory = (unsigned char*)malloc(LZO1X_1_15_MEM_COMPRESS);
	int ret = 0;
	if(nByte > 4) {
		int compressLevel = 1;
		if(compressingMethod == 1)
			ret = compress2((Bytef *) output, &CompBuffSize, (Bytef *) input, nByte, compressLevel);
		else if(compressingMethod == 2)
			ret = lzo1b_compress((Bytef *) input, nByte, (Bytef *) output, &CompBuffSize, workingMemory, compressLevel);
		else if(compressingMethod == 3)
			ret = lzo1x_1_15_compress((Bytef *) input, nByte, (Bytef *) output, &CompBuffSize, workingMemory);

		if(compressingMethod == 1) {
			if(ret != Z_OK) {
				if(ret == Z_MEM_ERROR){
					LOG("ERROR compressing: memory error\n");
				}else if(ret == Z_BUF_ERROR){
					LOG("ERROR compressing: buffer error\n");					
				}else if(ret == Z_STREAM_ERROR){
					LOG("ERROR compressing: compressLevel not (1-9), %d\n", compressLevel);
				}
			}
		}
	}
	else {
		memcpy(output, input, nByte);
		CompBuffSize = nByte;
	}
	if(compressingMethod == 2 || compressingMethod == 3)
		free(workingMemory);
	return CompBuffSize;
}
Exemplo n.º 18
0
void ossimS16ImageData::setValue(ossim_int32 x, ossim_int32 y, double color)
{
   if(getBuf() != NULL && isWithin(x, y))
   {
      //***
      // Compute the offset into the buffer for (x,y).  This should always
      // come out positive.
      //***
      ossim_uint32 ux = static_cast<ossim_uint32>(x - m_origin.x);
      ossim_uint32 uy = static_cast<ossim_uint32>(y - m_origin.y);

      ossim_uint32 offset = uy * m_spatialExtents[0] + ux;
      
      for(ossim_uint32 band = 0; band < m_numberOfDataComponents; band++)
      {
         ossim_sint16* buf = getSshortBuf(band)+offset;
         *buf = (ossim_sint16)color;
      }
   }
}
Exemplo n.º 19
0
// row here is nTops, most of the time is function is not practical due to out of memory
float* GetInnerSimMatrix(int row, int col, int nTrials, Trial* trials, RawMatrix** r_matrices) // only compute the correlation among the selected voxels
{
  int i;
  float* values = new float[nTrials*row*row];
  float* simMatrix = new float[nTrials*nTrials];
  for (i=0; i<nTrials*nTrials; i++) simMatrix[i] = 0.0;
  for (i=0; i<nTrials; i++)
  {
    int sc = trials[i].sc;
    int ec = trials[i].ec;
    int sid = trials[i].sid;
    float* mat = r_matrices[sid]->matrix;
    float* buf = new float[row*col]; // col is more than what really need, just in case
    int ml = getBuf(sc, ec, row, col, mat, buf);  // get the normalized matrix, return the length of time points to be computed
    cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, row, row, ml, 1.0, buf, ml, buf, ml, 0.0, values+i*row*row, row);
    delete[] buf;
  }
  GetDotProductUsingMatMul(simMatrix, values, nTrials, row, row);
  delete[] values;
  return simMatrix;
}
Exemplo n.º 20
0
void HeaderServerChannel::HeaderRequest::sendReplyWithStreams(
    std::unique_ptr<folly::IOBuf>&& data,
    std::unique_ptr<StreamManager>&& manager,
    MessageChannel::SendCallback* sendCallback) {

  if (clientExpectsStreams_) {
    CHECK(outOfOrder_);

    Stream* stream = nullptr;
    try {
      stream = new Stream(channel_,
                          seqId_,
                          transforms_,
                          headers_,
                          streamTimeout_,
                          getBuf()->clone(),
                          std::move(manager),
                          sendCallback);

      channel_->header_->setSequenceNumber(seqId_);
      channel_->header_->setTransforms(transforms_);
      channel_->sendStreamingMessage(stream,
                                     std::move(data),
                                     HEADER_FLAG_STREAM_BEGIN);

      // since this function is never called across threads
      // streamPtrReturn_ will always remain valid
      *streamPtrReturn_ = stream;
    } catch (const std::exception& e) {
      LOG(ERROR) << "Failed to send message: " << e.what();
      delete stream;
    }

  } else {
    manager->cancel();
    sendReply(std::move(data));
  }
}
Exemplo n.º 21
0
bool
SMSSendRequestPacket::getPacketContents(int conversion,
                                        char* &senderPhone,
                                        char* &recipientPhone,
                                        int &dataLength,
                                        byte* &data,
                                        int& smsNumber,
                                        int& nbrParts,
                                        int& partNbr)
{
   int position = REQUEST_HEADER_SIZE;
   dataLength = incReadShort(position);
   incReadByte(position); // skip smsType
   incReadString(position, senderPhone);
   incReadString(position, recipientPhone);
   data = getBuf() + position;
   position += dataLength;
   char* tempBuf = new char[dataLength*6];
   // Check if we should convert the SMS
   if ( conversion == CONVERSION_TEXT ) {
      dataLength = 
        SMSConvUtil::gsmToMc2(tempBuf, (const char*)data, dataLength);
   } else {
      // Do not convert
      memcpy(tempBuf, data, dataLength);
   }
   // Swap
   data = reinterpret_cast<byte*>(tempBuf);
   if ( position < (int)getLength() ) {
      smsNumber = incReadByte(position);
      nbrParts  = incReadByte(position);
      partNbr   = incReadByte(position);
   } else {
      smsNumber = nbrParts = partNbr = -1;
   }
   return true;
}
Exemplo n.º 22
0
int L4Handler::onWriteEx()
{
    bool full = ((getBuf()->available() == 0) ? true : false);
    int length;
    
    while ((length = getBuf()->blockSize()) > 0 )
    {
        int n = getStream()->write(getBuf()->begin(), length);
        if ( D_ENABLED( DL_LESS ) )
                LOG_D ((getLogger(), "[%s] L4Handler: write [%d of %d]", getLogId(), n, length ));
        
        if (n > 0)
            getBuf()->pop_front(n);
        else if ( n == 0 )
            break;
        else // if (n < 0)
        {
            closeBothConnection();
            return -1;
        }
    }
    
    if (getBuf()->available() != 0)
    {
        if (full)
            m_pL4conn->continueRead();
    
        if ( getBuf()->empty() )
        {
            suspendWrite();
            if ( D_ENABLED( DL_LESS ) )
            {
                LOG_D(( getLogger(), "[%s] [L4conn] m_pL4conn->continueRead",
                    getLogId() ));
            }
        }
    }
        
    return 0;
}
int ExynosJpegDecoder::getInBuf(char **pcBuf, int *piInputSize)
{
    return getBuf(t_bFlagCreateInBuf, &t_stJpegInbuf, pcBuf, piInputSize, \
                        NUM_JPEG_DEC_IN_PLANES, NUM_JPEG_DEC_IN_PLANES);
}
int ExynosJpegDecoder::getOutBuf(char **pcBuf, int *piOutputSize, int iSize)
{
    return getBuf(t_bFlagCreateOutBuf, &t_stJpegOutbuf, pcBuf, piOutputSize, iSize, t_iPlaneNum);
}
Exemplo n.º 25
0
char egetc()
{
	return getBuf(&RXBuffer);
}
Exemplo n.º 26
0
void *
BufPair::getBufData(ATADataPacketHeader::PolarizationCode pol)
{
	Buffer *buf = getBuf(pol);
	return (buf->getData());
}
Exemplo n.º 27
0
 /**
  * Wrap sqlite3_column_blob and sqlite3_column_bytes to return a new Blob.
  * @param column The column.
  * @return The new Blob.
  */
 Blob
 getBlob(int column) { return Blob(getBuf(column), getSize(column)); }