示例#1
0
// virtual
LLIOPipe::EStatus LLURLRequest::process_impl(
	const LLChannelDescriptors& channels,
	buffer_ptr_t& buffer,
	bool& eos,
	LLSD& context,
	LLPumpIO* pump)
{
	PUMP_DEBUG;
	LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST);
	//llinfos << "LLURLRequest::process_impl()" << llendl;
	if(!buffer || !mDetail) return STATUS_ERROR;

	// we're still waiting or prcessing, check how many
	// bytes we have accumulated.
	const S32 MIN_ACCUMULATION = 100000;
	if (pump && mDetail->mByteAccumulator > MIN_ACCUMULATION)
	{
		 // This is a pretty sloppy calculation, but this
		 // tries to make the gross assumption that if data
		 // is coming in at 56kb/s, then this transfer will
		 // probably succeed. So, if we're accumlated
		 // 100,000 bytes (MIN_ACCUMULATION) then let's
		 // give this client another 2s to complete.
		 const F32 TIMEOUT_ADJUSTMENT = 2.0f;
		 mDetail->mByteAccumulator = 0;
		 pump->adjustTimeoutSeconds(TIMEOUT_ADJUSTMENT);
		 lldebugs << "LLURLRequest adjustTimeoutSeconds for request: " << mDetail->mURL << llendl;
		 if (mState == STATE_INITIALIZED)
		 {
			  llinfos << "LLURLRequest adjustTimeoutSeconds called during upload" << llendl;
		 }
	}

	switch(mState)
	{
	case STATE_INITIALIZED:
	{
		PUMP_DEBUG;
		// We only need to wait for input if we are uploading
		// something.
		if(((HTTP_PUT == mAction) || (HTTP_POST == mAction)) && !eos)
		{
			// we're waiting to get all of the information
			return STATUS_BREAK;
		}

		// *FIX: bit of a hack, but it should work. The configure and
		// callback method expect this information to be ready.
		mDetail->mResponseBuffer = buffer.get();
		mDetail->mChannels = channels;
		if(!configure())
		{
			return STATUS_ERROR;
		}
		mState = STATE_WAITING_FOR_RESPONSE;

		// *FIX: Maybe we should just go to the next state now...
		return STATUS_BREAK;
	}
	case STATE_WAITING_FOR_RESPONSE:
	case STATE_PROCESSING_RESPONSE:
	{
		PUMP_DEBUG;
		LLIOPipe::EStatus status = STATUS_BREAK;
		mDetail->mCurlRequest->perform();
		while(1)
		{
			CURLcode result;
			bool newmsg = mDetail->mCurlRequest->getResult(&result);
			if(!newmsg)
			{
				// keep processing
				break;
			}

			mState = STATE_HAVE_RESPONSE;
			context[CONTEXT_REQUEST][CONTEXT_TRANSFERED_BYTES] = mRequestTransferedBytes;
			context[CONTEXT_RESPONSE][CONTEXT_TRANSFERED_BYTES] = mResponseTransferedBytes;
			lldebugs << this << "Setting context to " << context << llendl;
			switch(result)
			{
				case CURLE_OK:
				case CURLE_WRITE_ERROR:
					// NB: The error indication means that we stopped the
					// writing due the body limit being reached
					if(mCompletionCallback && pump)
					{
						LLURLRequestComplete* complete = NULL;
						complete = (LLURLRequestComplete*)
							mCompletionCallback.get();
						complete->responseStatus(
								result == CURLE_OK
									? STATUS_OK : STATUS_STOP);
						LLPumpIO::links_t chain;
						LLPumpIO::LLLinkInfo link;
						link.mPipe = mCompletionCallback;
						link.mChannels = LLBufferArray::makeChannelConsumer(
							channels);
						chain.push_back(link);
						pump->respond(chain, buffer, context);
						mCompletionCallback = NULL;
					}
					break;
				case CURLE_FAILED_INIT:
				case CURLE_COULDNT_CONNECT:
					status = STATUS_NO_CONNECTION;
					break;
				default:
					llwarns << "URLRequest Error: " << result
							<< ", "
							<< LLCurl::strerror(result)
							<< ", "
							<< (mDetail->mURL.empty() ? "<EMPTY URL>" : mDetail->mURL)
							<< llendl;
					status = STATUS_ERROR;
					break;
			}
		}
		return status;
	}
	case STATE_HAVE_RESPONSE:
		PUMP_DEBUG;
		// we already stuffed everything into channel in in the curl
		// callback, so we are done.
		eos = true;
		context[CONTEXT_REQUEST][CONTEXT_TRANSFERED_BYTES] = mRequestTransferedBytes;
		context[CONTEXT_RESPONSE][CONTEXT_TRANSFERED_BYTES] = mResponseTransferedBytes;
		lldebugs << this << "Setting context to " << context << llendl;
		return STATUS_DONE;

	default:
		PUMP_DEBUG;
		context[CONTEXT_REQUEST][CONTEXT_TRANSFERED_BYTES] = mRequestTransferedBytes;
		context[CONTEXT_RESPONSE][CONTEXT_TRANSFERED_BYTES] = mResponseTransferedBytes;
		lldebugs << this << "Setting context to " << context << llendl;
		return STATUS_ERROR;
	}
}
TEST(TMatrix, copied_matrix_is_equal_to_source_one)
{
  TMatrix<int> m(5);
  TMatrix<int> m1(m);
  EXPECT_EQ(m, m1);
}
示例#3
0
// virtual
LLSDRPCClient::~LLSDRPCClient()
{
	LLMemType m1(LLMemType::MTYPE_IO_SD_CLIENT);
}
示例#4
0
template<typename MatrixType> void integer_type_tests(const MatrixType& m)
{
  typedef typename MatrixType::Index Index;
  typedef typename MatrixType::Scalar Scalar;

  VERIFY(NumTraits<Scalar>::IsInteger);
  enum { is_signed = (Scalar(-1) > Scalar(0)) ? 0 : 1 };
  VERIFY(int(NumTraits<Scalar>::IsSigned) == is_signed);

  typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;

  Index rows = m.rows();
  Index cols = m.cols();

  // this test relies a lot on Random.h, and there's not much more that we can do
  // to test it, hence I consider that we will have tested Random.h
  MatrixType m1(rows, cols),
             m2 = MatrixType::Random(rows, cols),
             m3(rows, cols),
             mzero = MatrixType::Zero(rows, cols);

  typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
  SquareMatrixType identity = SquareMatrixType::Identity(rows, rows),
                   square = SquareMatrixType::Random(rows, rows);
  VectorType v1(rows),
             v2 = VectorType::Random(rows),
             vzero = VectorType::Zero(rows);

  do {
    m1 = MatrixType::Random(rows, cols);
  } while(m1 == mzero || m1 == m2);

  do {
    v1 = VectorType::Random(rows);
  } while(v1 == vzero || v1 == v2);

  VERIFY_IS_APPROX(               v1,    v1);
  VERIFY_IS_NOT_APPROX(           v1,    2*v1);
  VERIFY_IS_APPROX(               vzero, v1-v1);
  VERIFY_IS_APPROX(               m1,    m1);
  VERIFY_IS_NOT_APPROX(           m1,    2*m1);
  VERIFY_IS_APPROX(               mzero, m1-m1);

  VERIFY_IS_APPROX(m3 = m1,m1);
  MatrixType m4;
  VERIFY_IS_APPROX(m4 = m1,m1);

  m3.real() = m1.real();
  VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), static_cast<const MatrixType&>(m1).real());
  VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), m1.real());

  // check == / != operators
  VERIFY(m1==m1);
  VERIFY(m1!=m2);
  VERIFY(!(m1==m2));
  VERIFY(!(m1!=m1));
  m1 = m2;
  VERIFY(m1==m2);
  VERIFY(!(m1!=m2));

  // check linear structure

  Scalar s1;
  do {
    s1 = ei_random<Scalar>();
  } while(s1 == 0);

  VERIFY_IS_EQUAL(m1+m1,                   2*m1);
  VERIFY_IS_EQUAL(m1+m2-m1,                m2);
  VERIFY_IS_EQUAL(m1*s1,                   s1*m1);
  VERIFY_IS_EQUAL((m1+m2)*s1,              s1*m1+s1*m2);
  m3 = m2; m3 += m1;
  VERIFY_IS_EQUAL(m3,                      m1+m2);
  m3 = m2; m3 -= m1;
  VERIFY_IS_EQUAL(m3,                      m2-m1);
  m3 = m2; m3 *= s1;
  VERIFY_IS_EQUAL(m3,                      s1*m2);

  // check matrix product.

  VERIFY_IS_APPROX(identity * m1, m1);
  VERIFY_IS_APPROX(square * (m1 + m2), square * m1 + square * m2);
  VERIFY_IS_APPROX((m1 + m2).transpose() * square, m1.transpose() * square + m2.transpose() * square);
  VERIFY_IS_APPROX((m1 * m2.transpose()) * m1, m1 * (m2.transpose() * m1));
}
void SquareMatrix3TestCase::testTransformation(){

    //test toQuaternion
    RotMat3x3d m1;
    Quat4d q1L;
    Quat4d q1R(0.0, -0.6, 0.0, -0.8);
    m1(0,0) = -0.28;
    m1(0,1) =  0;
    m1(0,2) =  0.96;
    m1(1,0) =  0.0;
    m1(1,1) = -1.0;
    m1(1,2) =  0.0;
    m1(2,0) = 0.96;
    m1(2,1) = 0;
    m1(2,2) = 0.28;
    q1L = m1.toQuaternion();
    //CPPUNIT_ASSERT( q1L == q1R);    

    RotMat3x3d m2;
    Quat4d q2L(0.4, -0.6, 0.3, -0.8);
    Quat4d q2R;
    q2L.normalize();

    m2 = q2L.toRotationMatrix3();    
    q2R = m2.toQuaternion();
    CPPUNIT_ASSERT( q2L == q2R);    
    
    //test toEuler
    Vector3d v1L;
    Vector3d v1R(M_PI/4.0, M_PI/4.0, M_PI/4.0);
    RotMat3x3d m3;
    double root2Over4 = sqrt(2)/4.0;
    m3(0,0) = 0.5 - root2Over4;
    m3(0,1) = 0.5 + root2Over4;
    m3(0,2) = 0.5;
    m3(1,0) = -0.5 -root2Over4;
    m3(1,1) = -0.5 + root2Over4;
    m3(1,2) = 0.5;
    m3(2,0) = 0.5;
    m3(2,1) = -0.5;
    m3(2,2) = sqrt(2)/2.0;    
    v1L = m3.toEulerAngles();
    CPPUNIT_ASSERT( v1L == v1R);

    //test diagonalize

    RotMat3x3d m4;    
    RotMat3x3d a;
    Vector3d w;
    RotMat3x3d m5L;
    RotMat3x3d m5R;
    m4(0, 0) = 3.0;
    m4(0, 1) = 4.0;
    m4(0, 2) = 5.0;
    m4(1, 0) = 4.0;
    m4(1, 1) = 5.0;
    m4(1, 2) = 6.0;    
    m4(2, 0) = 5.0;
    m4(2, 1) = 6.0;
    m4(2, 2) = 7.0; 
    a = m4;
    
    RotMat3x3d::diagonalize(a, w, m5L);

    m5R(0, 0) = 0.789067 ;
    m5R(0, 1) = -0.408248;
    m5R(0, 2) = 0.459028;
    m5R(1, 0) = 0.090750;
    m5R(1, 1) = 0.816497;
    m5R(1, 2) = 0.570173;    
    m5R(2, 0) = -0.607567;
    m5R(2, 1) = -0.408248 ;
    m5R(2, 2) = 0.681319; 

    CPPUNIT_ASSERT(m5L == m5R);
}
示例#6
0
int main() try 
{
    // Several ways to create and initialize band matrices:

    // Create with uninitialized values
    tmv::BandMatrix<double> m1(6,6,1,2);
    for(int i=0;i<m1.nrows();i++) 
        for(int j=0;j<m1.ncols();j++) 
            if (i<=j+m1.nlo() && j<=i+m1.nhi())
                m1(i,j) = 3.*i-j*j+7.; 
    std::cout<<"m1 =\n"<<m1;
    //! m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )

    // Create with all 2's.
    tmv::BandMatrix<double> m2(6,6,1,3,2.);
    std::cout<<"m2 =\n"<<m2;
    //! m2 =
    //! 6  6  
    //! ( 2  2  2  2  0  0 )
    //! ( 2  2  2  2  2  0 )
    //! ( 0  2  2  2  2  2 )
    //! ( 0  0  2  2  2  2 )
    //! ( 0  0  0  2  2  2 )
    //! ( 0  0  0  0  2  2 )

    // A BandMatrix can be non-square:
    tmv::BandMatrix<double> m3(6,8,1,3,2.);
    std::cout<<"m3 =\n"<<m3;
    //! m3 =
    //! 6  8  
    //! ( 2  2  2  2  0  0  0  0 )
    //! ( 2  2  2  2  2  0  0  0 )
    //! ( 0  2  2  2  2  2  0  0 )
    //! ( 0  0  2  2  2  2  2  0 )
    //! ( 0  0  0  2  2  2  2  2 )
    //! ( 0  0  0  0  2  2  2  2 )

    // Create from given elements:
    double mm[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
    tmv::BandMatrix<double,tmv::ColMajor> m4(6,6,2,1);
    std::copy(mm,mm+20,m4.colmajor_begin());
    std::cout<<"m4 (ColMajor) =\n"<<m4;
    //! m4 (ColMajor) =
    //! 6  6  
    //! ( 1  4  0  0  0  0 )
    //! ( 2  5  8  0  0  0 )
    //! ( 3  6  9  12  0  0 )
    //! ( 0  7  10  13  16  0 )
    //! ( 0  0  11  14  17  19 )
    //! ( 0  0  0  15  18  20 )
    tmv::BandMatrix<double,tmv::RowMajor> m5(6,6,2,1);
    std::copy(mm,mm+20,m5.rowmajor_begin());
    std::cout<<"m5 (RowMajor) =\n"<<m5;
    //! m5 (RowMajor) =
    //! 6  6  
    //! ( 1  2  0  0  0  0 )
    //! ( 3  4  5  0  0  0 )
    //! ( 6  7  8  9  0  0 )
    //! ( 0  10  11  12  13  0 )
    //! ( 0  0  14  15  16  17 )
    //! ( 0  0  0  18  19  20 )
    tmv::BandMatrix<double,tmv::DiagMajor> m6(6,6,2,1);
    std::copy(mm,mm+20,m6.diagmajor_begin());
    std::cout<<"m6 (DiagMajor) =\n"<<m6;
    //! m6 (DiagMajor) =
    //! 6  6  
    //! ( 10  16  0  0  0  0 )
    //! ( 5  11  17  0  0  0 )
    //! ( 1  6  12  18  0  0 )
    //! ( 0  2  7  13  19  0 )
    //! ( 0  0  3  8  14  20 )
    //! ( 0  0  0  4  9  15 )

    // Can make from the banded portion of a regular Matrix:
    tmv::Matrix<double> xm(6,6);
    for(int i=0;i<xm.nrows();i++) 
        for(int j=0;j<xm.ncols();j++) 
            xm(i,j) = 5.*i-j*j+3.; 
    tmv::BandMatrix<double> m7(xm,3,2);
    std::cout<<"m7 =\n"<<m7;
    //! m7 =
    //! 6  6  
    //! ( 3  2  -1  0  0  0 )
    //! ( 8  7  4  -1  0  0 )
    //! ( 13  12  9  4  -3  0 )
    //! ( 18  17  14  9  2  -7 )
    //! ( 0  22  19  14  7  -2 )
    //! ( 0  0  24  19  12  3 )
    // Or from a wider BandMatrix:
    tmv::BandMatrix<double> m8(m7,3,0);
    std::cout<<"m8 =\n"<<m8;
    //! m8 =
    //! 6  6  
    //! ( 3  0  0  0  0  0 )
    //! ( 8  7  0  0  0  0 )
    //! ( 13  12  9  0  0  0 )
    //! ( 18  17  14  9  0  0 )
    //! ( 0  22  19  14  7  0 )
    //! ( 0  0  24  19  12  3 )

    // Shortcuts to Bi- and Tri-diagonal matrices:
    tmv::Vector<double> v1(5,1.);
    tmv::Vector<double> v2(6,2.);
    tmv::Vector<double> v3(5,3.);
    tmv::BandMatrix<double> m9 = LowerBiDiagMatrix(v1,v2);
    tmv::BandMatrix<double> m10 = UpperBiDiagMatrix(v2,v3);
    tmv::BandMatrix<double> m11 = TriDiagMatrix(v1,v2,v3);
    std::cout<<"LowerBiDiagMatrix(v1,v2) =\n"<<m9;
    //! LowerBiDiagMatrix(v1,v2) =
    //! 6  6  
    //! ( 2  0  0  0  0  0 )
    //! ( 1  2  0  0  0  0 )
    //! ( 0  1  2  0  0  0 )
    //! ( 0  0  1  2  0  0 )
    //! ( 0  0  0  1  2  0 )
    //! ( 0  0  0  0  1  2 )
    std::cout<<"UpperBiDiagMatrix(v2,v3) =\n"<<m10;
    //! UpperBiDiagMatrix(v2,v3) =
    //! 6  6  
    //! ( 2  3  0  0  0  0 )
    //! ( 0  2  3  0  0  0 )
    //! ( 0  0  2  3  0  0 )
    //! ( 0  0  0  2  3  0 )
    //! ( 0  0  0  0  2  3 )
    //! ( 0  0  0  0  0  2 )
    std::cout<<"TriDiagMatrix(v1,v2,v3) =\n"<<m11;
    //! TriDiagMatrix(v1,v2,v3) =
    //! 6  6  
    //! ( 2  3  0  0  0  0 )
    //! ( 1  2  3  0  0  0 )
    //! ( 0  1  2  3  0  0 )
    //! ( 0  0  1  2  3  0 )
    //! ( 0  0  0  1  2  3 )
    //! ( 0  0  0  0  1  2 )


    // Norms, etc. 

    std::cout<<"Norm1(m1) = "<<Norm1(m1)<<std::endl;
    //! Norm1(m1) = 30
    std::cout<<"Norm2(m1) = "<<Norm2(m1)<<std::endl;
    //! Norm2(m1) = 24.0314
    std::cout<<"NormInf(m1) = "<<NormInf(m1)<<std::endl;
    //! NormInf(m1) = 28
    std::cout<<"NormF(m1) = "<<NormF(m1)<<" = "<<Norm(m1)<<std::endl;
    //! NormF(m1) = 32.0312 = 32.0312
    std::cout<<"MaxAbsElement(m1) = "<<MaxAbsElement(m1)<<std::endl;
    //! MaxAbsElement(m1) = 12
    std::cout<<"Trace(m1) = "<<Trace(m1)<<std::endl;
    //! Trace(m1) = 32
    std::cout<<"Det(m1) = "<<Det(m1)<<std::endl;
    //! Det(m1) = 67635


    // Views:

    std::cout<<"m1 =\n"<<m1;
    //! m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )
    std::cout<<"m1.diag() = "<<m1.diag()<<std::endl;
    //! m1.diag() = 6  ( 7  9  9  7  3  -3 )
    std::cout<<"m1.diag(1) = "<<m1.diag(1)<<std::endl;
    //! m1.diag(1) = 5  ( 6  6  4  0  -6 )
    std::cout<<"m1.diag(-1) = "<<m1.diag(-1)<<std::endl;
    //! m1.diag(-1) = 5  ( 10  12  12  10  6 )
    std::cout<<"m1.subBandMatrix(0,3,0,3,1,1) =\n"<<
        m1.subBandMatrix(0,3,0,3,1,1);
    //! m1.subBandMatrix(0,3,0,3,1,1) =
    //! 3  3  
    //! ( 7  6  0 )
    //! ( 10  9  6 )
    //! ( 0  12  9 )
    std::cout<<"m1.transpose() =\n"<<m1.transpose();
    //! m1.transpose() =
    //! 6  6  
    //! ( 7  10  0  0  0  0 )
    //! ( 6  9  12  0  0  0 )
    //! ( 3  6  9  12  0  0 )
    //! ( 0  1  4  7  10  0 )
    //! ( 0  0  -3  0  3  6 )
    //! ( 0  0  0  -9  -6  -3 )

    // rowRange, colRange shrink both dimensions of the matrix to include only
    // the portions that are in those rows or columns:
    std::cout<<"m1.rowRange(0,4) =\n"<<m1.rowRange(0,4);
    //! m1.rowRange(0,4) =
    //! 4  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    std::cout<<"m1.colRange(1,4) =\n"<<m1.colRange(1,4);
    //! m1.colRange(1,4) =
    //! 5  3  
    //! ( 6  3  0 )
    //! ( 9  6  1 )
    //! ( 12  9  4 )
    //! ( 0  12  7 )
    //! ( 0  0  10 )
    std::cout<<"m1.diagRange(0,2) =\n"<<m1.diagRange(0,2);
    //! m1.diagRange(0,2) =
    //! 6  6  
    //! ( 7  6  0  0  0  0 )
    //! ( 0  9  6  0  0  0 )
    //! ( 0  0  9  4  0  0 )
    //! ( 0  0  0  7  0  0 )
    //! ( 0  0  0  0  3  -6 )
    //! ( 0  0  0  0  0  -3 )
    std::cout<<"m1.diagRange(-1,1) =\n"<<m1.diagRange(-1,1);
    //! m1.diagRange(-1,1) =
    //! 6  6  
    //! ( 7  0  0  0  0  0 )
    //! ( 10  9  0  0  0  0 )
    //! ( 0  12  9  0  0  0 )
    //! ( 0  0  12  7  0  0 )
    //! ( 0  0  0  10  3  0 )
    //! ( 0  0  0  0  6  -3 )


    // Fortran Indexing:

    tmv::BandMatrix<double,tmv::FortranStyle> fm1 = m1;
    std::cout<<"fm1 = m1 =\n"<<fm1;
    //! fm1 = m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )
    std::cout<<"fm1(1,1) = "<<fm1(1,1)<<std::endl;
    //! fm1(1,1) = 7
    std::cout<<"fm1(4,3) = "<<fm1(4,3)<<std::endl;
    //! fm1(4,3) = 12
    std::cout<<"fm1.subBandMatrix(1,3,1,3,1,1) =\n"<<
        fm1.subBandMatrix(1,3,1,3,1,1);
    //! fm1.subBandMatrix(1,3,1,3,1,1) =
    //! 3  3  
    //! ( 7  6  0 )
    //! ( 10  9  6 )
    //! ( 0  12  9 )
    std::cout<<"fm1.rowRange(1,4) =\n"<<fm1.rowRange(1,4);
    //! fm1.rowRange(1,4) =
    //! 4  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    std::cout<<"fm1.colRange(2,4) =\n"<<fm1.colRange(2,4);
    //! fm1.colRange(2,4) =
    //! 5  3  
    //! ( 6  3  0 )
    //! ( 9  6  1 )
    //! ( 12  9  4 )
    //! ( 0  12  7 )
    //! ( 0  0  10 )
    std::cout<<"fm1.diagRange(0,1) =\n"<<fm1.diagRange(0,1);
    //! fm1.diagRange(0,1) =
    //! 6  6  
    //! ( 7  6  0  0  0  0 )
    //! ( 0  9  6  0  0  0 )
    //! ( 0  0  9  4  0  0 )
    //! ( 0  0  0  7  0  0 )
    //! ( 0  0  0  0  3  -6 )
    //! ( 0  0  0  0  0  -3 )
    std::cout<<"fm1.diagRange(-1,0) =\n"<<fm1.diagRange(-1,0);
    //! fm1.diagRange(-1,0) =
    //! 6  6  
    //! ( 7  0  0  0  0  0 )
    //! ( 10  9  0  0  0  0 )
    //! ( 0  12  9  0  0  0 )
    //! ( 0  0  12  7  0  0 )
    //! ( 0  0  0  10  3  0 )
    //! ( 0  0  0  0  6  -3 )


    // Matrix arithmetic:

    tmv::BandMatrix<double> m1pm2 = m1 + m2;
    std::cout<<"m1 + m2 =\n"<<m1pm2;
    //! m1 + m2 =
    //! 6  6  
    //! ( 9  8  5  2  0  0 )
    //! ( 12  11  8  3  2  0 )
    //! ( 0  14  11  6  -1  2 )
    //! ( 0  0  14  9  2  -7 )
    //! ( 0  0  0  12  5  -4 )
    //! ( 0  0  0  0  8  -1 )
    // Works correctly even if matrices are stored in different order:
    tmv::BandMatrix<double> m5pm6 = m5 + m6; 
    std::cout<<"m5 + m6 =\n"<<m5pm6;
    //! m5 + m6 =
    //! 6  6  
    //! ( 11  18  0  0  0  0 )
    //! ( 8  15  22  0  0  0 )
    //! ( 7  13  20  27  0  0 )
    //! ( 0  12  18  25  32  0 )
    //! ( 0  0  17  23  30  37 )
    //! ( 0  0  0  22  28  35 )
    // Also expands the number of off-diagonals appropriately as needed:
    tmv::BandMatrix<double> m2pm4 = m2 + m4; 
    std::cout<<"m2 + m4 =\n"<<m2pm4;
    //! m2 + m4 =
    //! 6  6  
    //! ( 3  6  2  2  0  0 )
    //! ( 4  7  10  2  2  0 )
    //! ( 3  8  11  14  2  2 )
    //! ( 0  7  12  15  18  2 )
    //! ( 0  0  11  16  19  21 )
    //! ( 0  0  0  15  20  22 )

    m1 *= 2.;
    std::cout<<"m1 *= 2 =\n"<<m1;
    //! m1 *= 2 =
    //! 6  6  
    //! ( 14  12  6  0  0  0 )
    //! ( 20  18  12  2  0  0 )
    //! ( 0  24  18  8  -6  0 )
    //! ( 0  0  24  14  0  -18 )
    //! ( 0  0  0  20  6  -12 )
    //! ( 0  0  0  0  12  -6 )

    m2 += m1;
    std::cout<<"m2 += m1 =\n"<<m2;
    //! m2 += m1 =
    //! 6  6  
    //! ( 16  14  8  2  0  0 )
    //! ( 22  20  14  4  2  0 )
    //! ( 0  26  20  10  -4  2 )
    //! ( 0  0  26  16  2  -16 )
    //! ( 0  0  0  22  8  -10 )
    //! ( 0  0  0  0  14  -4 )

    tmv::Vector<double> v = xm.col(0);
    std::cout<<"v = "<<v<<std::endl;
    //! v = 6  ( 3  8  13  18  23  28 )
    std::cout<<"m1 * v = "<<m1*v<<std::endl;
    //! m1 * v = 6  ( 216  396  432  60  162  108 )
    std::cout<<"v * m1 = "<<v*m1<<std::endl;
    //! v * m1 = 6  ( 202  492  780  832  396  -768 )

    // Matrix * matrix product also expands bands appropriately:
    tmv::BandMatrix<double> m1m2 = m1 * m2; 
    std::cout<<"m1 * m2 =\n"<<m1m2;
    //! m1 * m2 =
    //! 6  6  
    //! ( 488  592  400  136  0  12 )
    //! ( 716  952  704  264  -8  -8 )
    //! ( 528  948  904  272  -56  -32 )
    //! ( 0  624  844  464  -320  -104 )
    //! ( 0  0  520  452  -80  -332 )
    //! ( 0  0  0  264  12  -96 )

    // Can mix BandMatrix with other kinds of matrices:
    std::cout<<"xm * m1 =\n"<<xm*m1;
    //! xm * m1 =
    //! 6  6  
    //! ( 82  48  -120  -348  -336  396 )
    //! ( 252  318  180  -128  -276  216 )
    //! ( 422  588  480  92  -216  36 )
    //! ( 592  858  780  312  -156  -144 )
    //! ( 762  1128  1080  532  -96  -324 )
    //! ( 932  1398  1380  752  -36  -504 )
    tmv::UpperTriMatrix<double> um(xm);
    std::cout<<"um + m1 =\n"<<um+m1;
    //! um + m1 =
    //! 6  6  
    //! ( 17  14  5  -6  -13  -22 )
    //! ( 20  25  16  1  -8  -17 )
    //! ( 0  24  27  12  -9  -12 )
    //! ( 0  0  24  23  2  -25 )
    //! ( 0  0  0  20  13  -14 )
    //! ( 0  0  0  0  12  -3 )
    tmv::LowerTriMatrix<double> lm(xm);
    lm *= m8;
    std::cout<<"lm *= m8 =\n"<<lm;
    //! lm *= m8 =
    //! 6  6  
    //! ( 9  0  0  0  0  0 )
    //! ( 80  49  0  0  0  0 )
    //! ( 252  192  81  0  0  0 )
    //! ( 534  440  252  81  0  0 )
    //! ( 744  774  500  224  49  0 )
    //! ( 954  1064  782  396  120  9 )
    tmv::DiagMatrix<double> dm(xm);
    m1 *= dm;
    std::cout<<"m1 *= dm =\n"<<m1;
    //! m1 *= dm =
    //! 6  6  
    //! ( 42  84  54  0  0  0 )
    //! ( 60  126  108  18  0  0 )
    //! ( 0  168  162  72  -42  0 )
    //! ( 0  0  216  126  0  -54 )
    //! ( 0  0  0  180  42  -36 )
    //! ( 0  0  0  0  84  -18 )
    return 0;
} catch (tmv::Error& e) {
    std::cerr<<e<<std::endl;
    return 1;
}
示例#7
0
文件: testmm.cpp 项目: 8l/connectal
int main(int argc, const char **argv)
{
  fprintf(stderr, "%s %s\n", __DATE__, __TIME__);
  bool sane = 1;
#define LARGE_MAT
#ifdef LARGE_MAT
#ifdef BSIM
  int A = 64;
  int B = 256;
#else
  int A = 256;
  int B = 2048;
#endif
  if (argc > 1) {
    B = strtoul(argv[1], 0, 0);
    A = 2*B;
  }
  srand(A*B);
  cv::Mat m1(A,B,CV_32F);
  cv::Mat m2(B,A,CV_32F);
  for(int a = 0; a < A; a++){
    for(int b = 0; b < B; b++){
      float v = (float)(rand() % 10);
      m2.at<float>(b,a) = (A*B)+v;
      m1.at<float>(a,b) = v;
    }
  }
#else
  cv::Mat m1 = (cv::Mat_<float>(4,8) <<
		11,12,13,14,15,16,17,18,
		21,22,23,24,25,26,27,28,
		31,32,33,34,35,36,37,38,
		41,42,43,44,45,46,47,48
		);
  cv::Mat m2 = (cv::Mat_<float>(8,4) <<
		51,62,53,54,
		55,56,57,58,
		61,62,63,64,
		65,66,67,68,
		71,72,73,74,
		75,76,77,78,
		81,82,83,84,
		85,86,87,88
		);
#endif

#ifndef CUDA_PERF_TEST
#ifdef MATRIX_NT
  mmdevice = new MmRequestNTProxy(IfcNames_MmRequestNTS2H);
#else
#ifdef MATRIX_TN
  mmdevice = new MmRequestTNProxy(IfcNames_MmRequestTNS2H);
#endif
#endif
  MmIndication *mmdeviceIndication = new MmIndication(IfcNames_MmIndicationH2S);
  //TimerRequestProxy *timerdevice = new TimerRequestProxy(IfcNames_TimerRequestPortalS2H);
  TimerIndication timerdeviceIndication(IfcNames_TimerIndicationH2S);
    DmaManager *dma = platformInit();

  if(sem_init(&mul_sem, 1, 0)){
    fprintf(stderr, "failed to init mul_sem\n");
    return -1;
  }

  long req_freq = 100000000;
  long freq = 0;
  setClockFrequency(0, req_freq, &freq);
  fprintf(stderr, "Requested FCLK[0]=%ld actually %ld\n", req_freq, freq);

  matAllocator = new PortalMatAllocator(dma);
  FILE *octave_file = fopen("foo.m", "w");

  fprintf(stderr, "OpenCV matmul\n");
  portalTimerStart(0);
  cv::Mat  m3 = m1 * m2;
  //uint64_t opencv_hw_cycles = portalTimerLap(0);

  PortalMat tm3;
  fprintf(stderr, "Naive matmul\n");
  portalTimerStart(0);
  tm3.naive_mul(m1,m2, octave_file);
  //uint64_t naive_hw_cycles = portalTimerLap(0);

  if (1) {
    fprintf(stderr, "DumpMat\n");
    dumpMatOctave<float>("m1",  "%10.5f", m1,  octave_file);
    dumpMatOctave<float>("m2",  "%10.5f", m2,  octave_file);
    dumpMatOctave<float>("m3",  "%10.5f", m3,  octave_file);
    dumpMatOctave<float>("tm3", "%10.5f", tm3, octave_file);
    fclose(octave_file);
    sane = tm3.compare(m3, 0, 0, 0.0001, 0, false);
    fprintf(stderr, "sane=%d\n", sane);
    fflush(stdout);
  }

#ifdef MATRIX_TN
  fprintf(stderr, "pm1t\n");
  PortalMat pm1t(m1.t());
  fprintf(stderr, "pm2\n");
  PortalMat pm2(m2);
  pm1t.reference();
  pm2.reference();
#else
#ifdef MATRIX_NT
  fprintf(stderr, "pm1\n");
  PortalMat pm1(m1);
  fprintf(stderr, "pm2t\n");
  PortalMat pm2t(m2.t());
  pm1.reference();
  pm2t.reference();
#endif
#endif
  PortalMat pm3;
  pm3.create(m1.rows, m2.cols, CV_32F);
  pm3.reference();

  // we invoke .reference on the matrices in advance 
  // in order to avoid counting the elapsed time for
  // performance analysis.  This is not strictly necessary
  // as all the portalmat methods make sure a valid 
  // reference is available before invoking the hardware

  pthread_t dbgtid;
  fprintf(stderr, "creating debug thread\n");

  if(pthread_create(&dbgtid, NULL,  dbgThread, NULL)){
   fprintf(stderr, "error creating debug thread\n");
   exit(1);
  }

  fprintf(stderr, "HW matmul\n");
  portalTimerStart(0);
#ifdef MATRIX_TN
  pm3.multf(pm1t, pm2, mmdeviceIndication);
#else
#ifdef MATRIX_NT
  pm3.multf(pm1, pm2t, mmdeviceIndication);
#endif
#endif
#if 0
  //uint64_t hw_cycles = portalTimerLap(0); 
  uint64_t read_beats = hostMemServerIndication.getMemoryTraffic(ChannelType_Read);
  uint64_t write_beats = hostMemServerIndication.getMemoryTraffic(ChannelType_Write);
  float read_util = (float)read_beats/(float)mmdeviceIndication->ccnt;
  float write_util = (float)write_beats/(float)mmdeviceIndication->ccnt;
  float read_bw = read_util * N_VALUE * 4 * (float)freq / 1.0e9;
  float write_bw = write_util * N_VALUE * 4 * (float)freq / 1.0e9;
  float macs = m1.rows * m2.rows * m2.cols;
  fprintf(stderr, "Bus frequency %f MHz\n", (float)freq / 1.0e6);
  fprintf(stderr, "memory read  beats %f utilization %f (beats/cycle), bandwidth %f (GB/s)\n", (float)read_beats, read_util, read_bw);
  fprintf(stderr, "memory write beats %f utilization %f (beats/cycle), bandwidth %f (GB/s)\n", (float)write_beats, write_util, write_bw);
  fprintf(stderr, "Throughput %f macs/cycle %f GFLOP/s\n",
	  (float)macs / (float)mmdeviceIndication->ccnt,
	  2.0 * (float)macs / (float)mmdeviceIndication->ccnt * freq / 1.0e9);
  fprintf(stderr, "Time %f cycles, opencv matmul %f cycles (speedup %f), naive matmul %f cycles (speedup %f)\n",
	  (float)mmdeviceIndication->ccnt,
	  (float)opencv_hw_cycles, (float)opencv_hw_cycles/(float)mmdeviceIndication->ccnt,
	  (float)naive_hw_cycles, (float)naive_hw_cycles/(float)mmdeviceIndication->ccnt);
#endif

  if (0) {
    dumpMat<float>("pm3", "%5.1f", pm3);
    dumpMat<float>(" m3", "%5.1f", m3);
  }
  bool eq = pm3.compare(m3);
#else // CUDA_PERF_TEST
  cv::Mat cm3(m1.rows,m2.cols, CV_32F);
  cuda_mm(m1, m2, cm3);
  cv::Mat  m3 = m1 * m2;
  bool eq = compare(m3, cm3, 0.01);
#endif // CUDA_PERF_TEST
  fprintf(stderr, "XXXXXXXXXXXXXXXXXXXXXXXXXX eq=%d\n", eq);
  return(!(eq&&sane));
}
示例#8
0
void
McGrip::assembleTorqueMatrices(int refJointNum, int thisJointNum, int nextJointNum,
                               double tx, double ty,
                               double theta, double theta_n,
                               Matrix &B, Matrix &a)
{
  DBGP("\nRef: " << refJointNum << " Proximal: "
       << thisJointNum << " Distal: " << nextJointNum);

  if (thisJointNum == refJointNum) {
    DBGP(">>> - cos(theta/2) = " << - cos(theta / 2.0));
  }

  //translation tx ty from refJoint to thisJoint
  Matrix t(2, 1);
  t.elem(0, 0) = tx; t.elem(1, 0) = ty;

  //joint angles theta and theta_n
  //remember in our math convention flexion rotation is negative
  Matrix Rtheta(Matrix::ROTATION2D(-theta));
  //we will flip the sign of everything later to make it agree with graspit

  //this is the first term in the chain
  //actually contains the resultant force direction
  Matrix m1(1, 2);

  //proximal insertion point
  if (nextJointNum >= 0) {
    m1.elem(0, 0) = cos(theta) - cos(theta / 2.0);
    m1.elem(0, 1) = -sin(theta) + sin(theta / 2.0);
  } else {
    m1.elem(0, 0) = -cos(theta / 2.0);
    m1.elem(0, 1) =  sin(theta / 2.0);
  }

  Matrix free_term(1, 1);
  matrixMultiply(m1, t, free_term);

  Matrix b_terms(1, 2);
  matrixMultiply(m1, Rtheta, b_terms);

  B.elem(refJointNum, thisJointNum) += b_terms.elem(0, 0);
  DBGP("Proximal effect: " << b_terms.elem(0, 0));
  B.elem(refJointNum, 6) += b_terms.elem(0, 1);
  a.elem(refJointNum, 0) += free_term.elem(0, 0);

  //distal insertion point
  if (nextJointNum >= 0) {
    m1.elem(0, 0) =  cos(theta + theta_n / 2.0) - cos(theta);
    m1.elem(0, 1) = -sin(theta + theta_n / 2.0) + sin(theta);

    Matrix S(Matrix::ZEROES<Matrix>(2, 3));
    S.elem(0, 0) = S.elem(1, 1) = S.elem(1, 2) = 1.0;

    matrixMultiply(m1, t, free_term);

    matrixMultiply(m1, Rtheta, b_terms);
    Matrix b_terms_ext(1, 3);
    matrixMultiply(b_terms, S, b_terms_ext);

    B.elem(refJointNum, nextJointNum) += b_terms_ext.elem(0, 0);
    DBGP("Distal effect: " << b_terms_ext.elem(0, 0));
    B.elem(refJointNum, 6) += b_terms_ext.elem(0, 1);
    B.elem(refJointNum, 7) += b_terms_ext.elem(0, 2);
    a.elem(refJointNum, 0) += free_term.elem(0, 0);
  }

  //mid-link change
  if (nextJointNum >= 0) {
    DBGP("Proximal -1.0 and distal +1.0");
    B.elem(refJointNum, thisJointNum) += -1.0;
    B.elem(refJointNum, nextJointNum) +=  1.0;
  }
}
示例#9
0
int main()
{
    typedef int V;
    typedef std::multiset<int> M;
    {
        V ar1[] =
        {
        };
        V ar2[] =
        {
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        m1.swap(m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        V ar1[] =
        {
        };
        V ar2[] =
        {
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        m1.swap(m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        V ar1[] =
        {
            1,
            2,
            3,
            4
        };
        V ar2[] =
        {
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        m1.swap(m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        V ar1[] =
        {
            1,
            2,
            3,
            4
        };
        V ar2[] =
        {
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        m1.swap(m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
}
示例#10
0
void LLURLRequestComplete::responseStatus(LLIOPipe::EStatus status)
{
	LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST);
	mRequestStatus = status;
}
示例#11
0
int main(int, char** argv)
{
    verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false;

    try
    {
        CIMMethod m1(CIMName ("getHostName"), CIMTYPE_STRING);
        m1.addQualifier(CIMQualifier(CIMName ("stuff"), true));
        m1.addQualifier(CIMQualifier(CIMName ("stuff2"), true));
        m1.addParameter(CIMParameter(CIMName ("ipaddress"), CIMTYPE_STRING));


        // Tests for Qualifiers
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.getQualifierCount() == 2);

        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);

        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND);

        Uint32 posQualifier;
        posQualifier = m1.findQualifier(CIMName ("stuff"));
        PEGASUS_TEST_ASSERT(posQualifier != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(posQualifier < m1.getQualifierCount());

        m1.removeQualifier(posQualifier);
        PEGASUS_TEST_ASSERT(m1.getQualifierCount() == 1);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);

        // Tests for Parameters
        PEGASUS_TEST_ASSERT(m1.findParameter(
            CIMName ("ipaddress")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.findParameter(
            CIMName ("noparam"))  == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.getParameterCount()  == 1);
        CIMParameter cp = m1.getParameter(
            m1.findParameter(CIMName ("ipaddress")));
        PEGASUS_TEST_ASSERT(cp.getName() == CIMName ("ipaddress"));

        m1.removeParameter (m1.findParameter (
            CIMName (CIMName ("ipaddress"))));
        PEGASUS_TEST_ASSERT (m1.getParameterCount ()  == 0);
        m1.addParameter (CIMParameter (CIMName ("ipaddress"),
                                       CIMTYPE_STRING));
        PEGASUS_TEST_ASSERT (m1.getParameterCount ()  == 1);

        // throws OutOfBounds
        try
        {
            m1.removeParameter (1);
        }
        catch (IndexOutOfBoundsException & oob)
        {
            if (verbose)
            {
                PEGASUS_STD (cout) << "Caught expected exception: "
                                   << oob.getMessage () << PEGASUS_STD (endl);
            }
        }

        CIMMethod m2(CIMName ("test"), CIMTYPE_STRING);
        m2.setName(CIMName ("getVersion"));
        PEGASUS_TEST_ASSERT(m2.getName() == CIMName ("getVersion"));

        m2.setType(CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(m2.getType() == CIMTYPE_STRING);

        m2.setClassOrigin(CIMName ("test"));
        PEGASUS_TEST_ASSERT(m2.getClassOrigin() == CIMName ("test"));

        m2.setPropagated(true);
        PEGASUS_TEST_ASSERT(m2.getPropagated() == true);

        const CIMMethod cm1(m1);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuf")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT((cm1.getParameterCount() != 3));
        PEGASUS_TEST_ASSERT(cm1.findParameter(
            CIMName ("ipaddress")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuff")) == PEG_NOT_FOUND);

        CIMQualifier q = m1.getQualifier(posQualifier);
        CIMConstParameter ccp = cm1.getParameter(
                    cm1.findParameter(CIMName ("ipaddress")));
        PEGASUS_TEST_ASSERT(cm1.getName() == CIMName ("getHostName"));
        PEGASUS_TEST_ASSERT(cm1.getType() == CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(cm1.getClassOrigin() == CIMName ("test")));
        PEGASUS_TEST_ASSERT(!cm1.getPropagated() == true);
        PEGASUS_TEST_ASSERT(!m1.identical(m2));

        // throws OutOfBounds
        try
        {
            CIMConstParameter p = cm1.getParameter(cm1.findParameter(
                                        CIMName ("ipaddress")));
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        // throws OutOfBounds
        try
        {
            CIMConstQualifier q1 = cm1.getQualifier(cm1.findQualifier(
                                        CIMName ("abstract")));
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        if (verbose)
        {
            XmlWriter::printMethodElement(m1);
            XmlWriter::printMethodElement(cm1);
        }
        Buffer out;
        XmlWriter::appendMethodElement(out, cm1);
        MofWriter::appendMethodElement(out, cm1);

        Boolean nullMethod = cm1.isUninitialized();
        PEGASUS_TEST_ASSERT(!nullMethod);

        CIMMethod m3 = m2.clone();
        m3 = cm1.clone();

        CIMMethod m4;
        CIMMethod m5(m4);

        CIMConstMethod ccm1(CIMName ("getHostName"),CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(ccm1.getParameterCount() == 3));

        PEGASUS_TEST_ASSERT(ccm1.getName() == CIMName ("getHostName"));
        PEGASUS_TEST_ASSERT(ccm1.getType() == CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(ccm1.getClassOrigin() == CIMName ("test")));
        PEGASUS_TEST_ASSERT(!ccm1.getPropagated() == true);
        PEGASUS_TEST_ASSERT(!(ccm1.getParameterCount() == 3));
        PEGASUS_TEST_ASSERT(ccm1.getQualifierCount() == 0);
        PEGASUS_TEST_ASSERT(ccm1.findQualifier(
            CIMName ("Stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(ccm1.findParameter(
            CIMName ("ipaddress")) == PEG_NOT_FOUND);

        if (verbose)
        {
            XmlWriter::printMethodElement(m1);
            XmlWriter::printMethodElement(ccm1);
        }

        XmlWriter::appendMethodElement(out, ccm1);

        CIMConstMethod ccm2(ccm1);
        CIMConstMethod ccm3;

        ccm3 = ccm1.clone();
        ccm1 = ccm3;
        PEGASUS_TEST_ASSERT(ccm1.identical(ccm3));
        PEGASUS_TEST_ASSERT(ccm1.findQualifier(
            CIMName ("stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(ccm1.findParameter(
            CIMName ("ipaddress")) == PEG_NOT_FOUND);

        nullMethod = ccm1.isUninitialized();
        PEGASUS_TEST_ASSERT(!nullMethod);

        // throws OutOfBounds
        try
        {
            //CIMParameter p = m1.getParameter(
            //     m1.findParameter(CIMName ("ipaddress")));
            CIMConstParameter p = ccm1.getParameter(0);
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        // throws OutOfBounds
        try
        {
            CIMConstQualifier q1 = ccm1.getQualifier(0);
        }
        catch(IndexOutOfBoundsException&)
        {
        }
    }
    catch(Exception& e)
    {
        cerr << "Exception: " << e.getMessage() << endl;
    }

    // Test for add second qualifier with same name.
    // Should do exception

    cout << argv[0] << " +++++ passed all tests" << endl;

    return 0;
}
示例#12
0
// virtual
LLURLRequestComplete::~LLURLRequestComplete()
{
	LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST);
}
示例#13
0
/**
 * LLURLRequestComplete
 */
LLURLRequestComplete::LLURLRequestComplete() :
	mRequestStatus(LLIOPipe::STATUS_ERROR)
{
	LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST);
}
示例#14
0
bool LLURLRequest::configure()
{
	LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST);
	bool rv = false;
	S32 bytes = mDetail->mResponseBuffer->countAfter(
   		mDetail->mChannels.in(),
		NULL);
	switch(mAction)
	{
	case HTTP_HEAD:
		mDetail->mCurlRequest->setopt(CURLOPT_HEADER, 1);
		mDetail->mCurlRequest->setopt(CURLOPT_NOBODY, 1);
		mDetail->mCurlRequest->setopt(CURLOPT_FOLLOWLOCATION, 1);
		rv = true;
		break;
	case HTTP_GET:
		mDetail->mCurlRequest->setopt(CURLOPT_HTTPGET, 1);
		mDetail->mCurlRequest->setopt(CURLOPT_FOLLOWLOCATION, 1);

		// Set Accept-Encoding to allow response compression
		mDetail->mCurlRequest->setoptString(CURLOPT_ENCODING, "");
		rv = true;
		break;

	case HTTP_PUT:
		// Disable the expect http 1.1 extension. POST and PUT default
		// to turning this on, and I am not too sure what it means.
		addHeader("Expect:");

		mDetail->mCurlRequest->setopt(CURLOPT_UPLOAD, 1);
		mDetail->mCurlRequest->setopt(CURLOPT_INFILESIZE, bytes);
		rv = true;
		break;

	case HTTP_POST:
		// Disable the expect http 1.1 extension. POST and PUT default
		// to turning this on, and I am not too sure what it means.
		addHeader("Expect:");

		// Disable the content type http header.
		// *FIX: what should it be?
		addHeader("Content-Type:");

		// Set the handle for an http post
		mDetail->mCurlRequest->setPost(NULL, bytes);

		// Set Accept-Encoding to allow response compression
		mDetail->mCurlRequest->setoptString(CURLOPT_ENCODING, "");
		rv = true;
		break;

	case HTTP_DELETE:
		// Set the handle for an http post
		mDetail->mCurlRequest->setoptString(CURLOPT_CUSTOMREQUEST, "DELETE");
		rv = true;
		break;

	case HTTP_MOVE:
		// Set the handle for an http post
		mDetail->mCurlRequest->setoptString(CURLOPT_CUSTOMREQUEST, "MOVE");
		// *NOTE: should we check for the Destination header?
		rv = true;
		break;

	default:
		llwarns << "Unhandled URLRequest action: " << mAction << llendl;
		break;
	}
	if(rv)
	{
		mDetail->mCurlRequest->sendRequest(mDetail->mURL);
	}
	return rv;
}
int main()
{
    hierarchical_mutex m1(42);
    hierarchical_mutex m2(2000);
    
}
int main(int argc, char *argv[]) {
    bool dump = false;
    std::string format = "ESRI Shapefile";
    std::string geom;

    static struct option long_options[] = {
        {"dump",         no_argument, 0, 'd'},
        {"format", required_argument, 0, 'f'},
        {"geom",   required_argument, 0, 'g'},
        {"help",         no_argument, 0, 'h'},
        {0, 0, 0, 0}
    };

    while (1) {
        int c = getopt_long(argc, argv, "df:g:h", long_options, 0);
        if (c == -1)
            break;

        switch (c) {
        case 'd':
            dump = true;
            break;
        case 'f':
            format = optarg;
            break;
        case 'g':
            geom = optarg;
            break;
        case 'h': {
            std::cout << "Usage: " << argv[0] << " [OPTIONS] SEGFILE1 SEGFILE2\n";
            print_help();
            exit(return_code_ok);
        }
        default:
            break;
        }
    }

    if (optind != argc - 2) {
        std::cerr << "Usage: " << argv[0] << " [OPTIONS] SEGFILE1 SEGFILE2\n";
        exit(return_code_cmdline);
    }

    segvec removed_segments;
    segvec added_segments;

    try {
        InputFile file1(argv[optind]);
        InputFile file2(argv[optind+1]);

        osmium::util::TypedMemoryMapping<osmium::UndirectedSegment> m1(file1.size() / sizeof(osmium::UndirectedSegment), false, file1.fd());
        osmium::util::TypedMemoryMapping<osmium::UndirectedSegment> m2(file2.size() / sizeof(osmium::UndirectedSegment), false, file2.fd());

        std::set_difference(m1.cbegin(), m1.cend(), m2.cbegin(), m2.cend(), std::back_inserter(removed_segments));
        std::set_difference(m2.cbegin(), m2.cend(), m1.cbegin(), m1.cend(), std::back_inserter(added_segments));
    } catch (std::runtime_error& e) {
        std::cerr << e.what() << "\n";
        exit(return_code_fatal);
    }

    if (dump) {
        std::cout << "Removed:\n";
        for (const auto& segment : removed_segments) {
            std::cout << "  " << segment << "\n";
        }

        std::cout << "Added:\n";
        for (const auto& segment : added_segments) {
            std::cout << "  " << segment << "\n";
        }
    } else if (!geom.empty()) {
        output_ogr(geom, format, removed_segments, added_segments);
    }
}
示例#17
0
// virtual
LLIOPipe::EStatus LLSDRPCServer::process_impl(
	const LLChannelDescriptors& channels,
	buffer_ptr_t& buffer,
	bool& eos,
	LLSD& context,
	LLPumpIO* pump)
{
	PUMP_DEBUG;
	LLMemType m1(LLMemType::MTYPE_IO_SD_SERVER);
//	lldebugs << "LLSDRPCServer::process_impl" << llendl;
	// Once we have all the data, We need to read the sd on
	// the the in channel, and respond on  the out channel
	if(!eos) return STATUS_BREAK;
	if(!pump || !buffer) return STATUS_PRECONDITION_NOT_MET;

	std::string method_name;
	LLIOPipe::EStatus status = STATUS_DONE;

	switch(mState)
	{
	case STATE_DEFERRED:
		PUMP_DEBUG;
		if(ESDRPCS_DONE != deferredResponse(channels, buffer.get()))
		{
			buildFault(
				channels,
				buffer.get(),
				FAULT_GENERIC,
				"deferred response failed.");
		}
		mState = STATE_DONE;
		return STATUS_DONE;

	case STATE_DONE:
//		lldebugs << "STATE_DONE" << llendl;
		break;
	case STATE_CALLBACK:
//		lldebugs << "STATE_CALLBACK" << llendl;
		PUMP_DEBUG;
		method_name = mRequest[LLSDRPC_METHOD_SD_NAME].asString();
		if(!method_name.empty() && mRequest.has(LLSDRPC_PARAMETER_SD_NAME))
		{
			if(ESDRPCS_DONE != callbackMethod(
				   method_name,
				   mRequest[LLSDRPC_PARAMETER_SD_NAME],
				   channels,
				   buffer.get()))
			{
				buildFault(
					channels,
					buffer.get(),
					FAULT_GENERIC,
					"Callback method call failed.");
			}
		}
		else
		{
			// this should never happen, since we should not be in
			// this state unless we originally found a method and
			// params during the first call to process.
			buildFault(
				channels,
				buffer.get(),
				FAULT_GENERIC,
				"Invalid LLSDRPC sever state - callback without method.");
		}
		pump->clearLock(mLock);
		mLock = 0;
		mState = STATE_DONE;
		break;
	case STATE_NONE:
//		lldebugs << "STATE_NONE" << llendl;
	default:
	{
		// First time we got here - process the SD request, and call
		// the method.
		PUMP_DEBUG;
		LLBufferStream istr(channels, buffer.get());
		mRequest.clear();
		LLSDSerialize::fromNotation(
			mRequest,
			istr,
			buffer->count(channels.in()));

		// { 'method':'...', 'parameter': ... }
		method_name = mRequest[LLSDRPC_METHOD_SD_NAME].asString();
		if(!method_name.empty() && mRequest.has(LLSDRPC_PARAMETER_SD_NAME))
		{
			ESDRPCSStatus rv = callMethod(
				method_name,
				mRequest[LLSDRPC_PARAMETER_SD_NAME],
				channels,
				buffer.get());
			switch(rv)
			{
			case ESDRPCS_DEFERRED:
				mPump = pump;
				mLock = pump->setLock();
				mState = STATE_DEFERRED;
				status = STATUS_BREAK;
				break;

			case ESDRPCS_CALLBACK:
			{
				mState = STATE_CALLBACK;
				LLPumpIO::LLLinkInfo link;
				link.mPipe = LLIOPipe::ptr_t(this);
				link.mChannels = channels;
				LLPumpIO::links_t links;
				links.push_back(link);
				pump->respond(links, buffer, context);
				mLock = pump->setLock();
				status = STATUS_BREAK;
				break;
			}
			case ESDRPCS_DONE:
				mState = STATE_DONE;
				break;
			case ESDRPCS_ERROR:
			default:
				buildFault(
					channels,
					buffer.get(),
					FAULT_GENERIC,
					"Method call failed.");
				break;
			}
		}
		else
		{
			// send a fault
			buildFault(
				channels,
				buffer.get(),
				FAULT_GENERIC,
				"Unable to find method and parameter in request.");
		}
		break;
	}
	}

	PUMP_DEBUG;
	return status;
}
示例#18
0
template<typename MatrixType> void basicStuff(const MatrixType& m)
{
  typedef typename MatrixType::Index Index;
  typedef typename MatrixType::Scalar Scalar;
  typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;

  Index rows = m.rows();
  Index cols = m.cols();

  // this test relies a lot on Random.h, and there's not much more that we can do
  // to test it, hence I consider that we will have tested Random.h
  MatrixType m1 = MatrixType::Random(rows, cols),
             m2 = MatrixType::Random(rows, cols),
             m3(rows, cols),
             mzero = MatrixType::Zero(rows, cols),
             identity = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
                              ::Identity(rows, rows),
             square = Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>::Random(rows, rows);
  VectorType v1 = VectorType::Random(rows),
             v2 = VectorType::Random(rows),
             vzero = VectorType::Zero(rows);

  Scalar x = ei_random<Scalar>();

  Index r = ei_random<Index>(0, rows-1),
        c = ei_random<Index>(0, cols-1);

  m1.coeffRef(r,c) = x;
  VERIFY_IS_APPROX(x, m1.coeff(r,c));
  m1(r,c) = x;
  VERIFY_IS_APPROX(x, m1(r,c));
  v1.coeffRef(r) = x;
  VERIFY_IS_APPROX(x, v1.coeff(r));
  v1(r) = x;
  VERIFY_IS_APPROX(x, v1(r));
  v1[r] = x;
  VERIFY_IS_APPROX(x, v1[r]);

  VERIFY_IS_APPROX(               v1,    v1);
  VERIFY_IS_NOT_APPROX(           v1,    2*v1);
  VERIFY_IS_MUCH_SMALLER_THAN(    vzero, v1);
  if(!NumTraits<Scalar>::IsInteger)
    VERIFY_IS_MUCH_SMALLER_THAN(  vzero, v1.norm());
  VERIFY_IS_NOT_MUCH_SMALLER_THAN(v1,    v1);
  VERIFY_IS_APPROX(               vzero, v1-v1);
  VERIFY_IS_APPROX(               m1,    m1);
  VERIFY_IS_NOT_APPROX(           m1,    2*m1);
  VERIFY_IS_MUCH_SMALLER_THAN(    mzero, m1);
  VERIFY_IS_NOT_MUCH_SMALLER_THAN(m1,    m1);
  VERIFY_IS_APPROX(               mzero, m1-m1);

  // always test operator() on each read-only expression class,
  // in order to check const-qualifiers.
  // indeed, if an expression class (here Zero) is meant to be read-only,
  // hence has no _write() method, the corresponding MatrixBase method (here zero())
  // should return a const-qualified object so that it is the const-qualified
  // operator() that gets called, which in turn calls _read().
  VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::Zero(rows,cols)(r,c), static_cast<Scalar>(1));

  // now test copying a row-vector into a (column-)vector and conversely.
  square.col(r) = square.row(r).eval();
  Matrix<Scalar, 1, MatrixType::RowsAtCompileTime> rv(rows);
  Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> cv(rows);
  rv = square.row(r);
  cv = square.col(r);
  
  VERIFY_IS_APPROX(rv, cv.transpose());

  if(cols!=1 && rows!=1 && MatrixType::SizeAtCompileTime!=Dynamic)
  {
    VERIFY_RAISES_ASSERT(m1 = (m2.block(0,0, rows-1, cols-1)));
  }

  if(cols!=1 && rows!=1)
  {
    VERIFY_RAISES_ASSERT(m1[0]);
    VERIFY_RAISES_ASSERT((m1+m1)[0]);
  }

  VERIFY_IS_APPROX(m3 = m1,m1);
  MatrixType m4;
  VERIFY_IS_APPROX(m4 = m1,m1);

  m3.real() = m1.real();
  VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), static_cast<const MatrixType&>(m1).real());
  VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), m1.real());

  // check == / != operators
  VERIFY(m1==m1);
  VERIFY(m1!=m2);
  VERIFY(!(m1==m2));
  VERIFY(!(m1!=m1));
  m1 = m2;
  VERIFY(m1==m2);
  VERIFY(!(m1!=m2));
}
示例#19
0
int main()
{
    typedef std::pair<const int, double> V;
    {
    typedef std::multimap<int, double> M;
    {
        V ar1[] =
        {
        };
        V ar2[] =
        {
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        V ar1[] =
        {
        };
        V ar2[] =
        {
            V(5, 5),
            V(6, 6),
            V(7, 7),
            V(8, 8),
            V(9, 9),
            V(10, 10),
            V(11, 11),
            V(12, 12)
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        V ar1[] =
        {
            V(1, 1),
            V(2, 2),
            V(3, 3),
            V(4, 4)
        };
        V ar2[] =
        {
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        V ar1[] =
        {
            V(1, 1),
            V(2, 2),
            V(3, 3),
            V(4, 4)
        };
        V ar2[] =
        {
            V(5, 5),
            V(6, 6),
            V(7, 7),
            V(8, 8),
            V(9, 9),
            V(10, 10),
            V(11, 11),
            V(12, 12)
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        typedef test_allocator<V> A;
        typedef test_compare<std::less<int> > C;
        typedef std::multimap<int, double, C, A> M;
        V ar1[] =
        {
            V(1, 1),
            V(2, 2),
            V(3, 3),
            V(4, 4)
        };
        V ar2[] =
        {
            V(5, 5),
            V(6, 6),
            V(7, 7),
            V(8, 8),
            V(9, 9),
            V(10, 10),
            V(11, 11),
            V(12, 12)
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2));
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
        assert(m1.key_comp() == C(2));
        assert(m1.get_allocator() == A(1));
        assert(m2.key_comp() == C(1));
        assert(m2.get_allocator() == A(2));
    }
    {
        typedef other_allocator<V> A;
        typedef test_compare<std::less<int> > C;
        typedef std::multimap<int, double, C, A> M;
        V ar1[] =
        {
            V(1, 1),
            V(2, 2),
            V(3, 3),
            V(4, 4)
        };
        V ar2[] =
        {
            V(5, 5),
            V(6, 6),
            V(7, 7),
            V(8, 8),
            V(9, 9),
            V(10, 10),
            V(11, 11),
            V(12, 12)
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2));
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
        assert(m1.key_comp() == C(2));
        assert(m1.get_allocator() == A(2));
        assert(m2.key_comp() == C(1));
        assert(m2.get_allocator() == A(1));
    }
    }
#if __cplusplus >= 201103L
    {
    typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
    {
        V ar1[] =
        {
        };
        V ar2[] =
        {
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        V ar1[] =
        {
        };
        V ar2[] =
        {
            V(5, 5),
            V(6, 6),
            V(7, 7),
            V(8, 8),
            V(9, 9),
            V(10, 10),
            V(11, 11),
            V(12, 12)
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        V ar1[] =
        {
            V(1, 1),
            V(2, 2),
            V(3, 3),
            V(4, 4)
        };
        V ar2[] =
        {
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        V ar1[] =
        {
            V(1, 1),
            V(2, 2),
            V(3, 3),
            V(4, 4)
        };
        V ar2[] =
        {
            V(5, 5),
            V(6, 6),
            V(7, 7),
            V(8, 8),
            V(9, 9),
            V(10, 10),
            V(11, 11),
            V(12, 12)
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
    }
    {
        typedef min_allocator<V> A;
        typedef test_compare<std::less<int> > C;
        typedef std::multimap<int, double, C, A> M;
        V ar1[] =
        {
            V(1, 1),
            V(2, 2),
            V(3, 3),
            V(4, 4)
        };
        V ar2[] =
        {
            V(5, 5),
            V(6, 6),
            V(7, 7),
            V(8, 8),
            V(9, 9),
            V(10, 10),
            V(11, 11),
            V(12, 12)
        };
        M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A());
        M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A());
        M m1_save = m1;
        M m2_save = m2;
        swap(m1, m2);
        assert(m1 == m2_save);
        assert(m2 == m1_save);
        assert(m1.key_comp() == C(2));
        assert(m1.get_allocator() == A());
        assert(m2.key_comp() == C(1));
        assert(m2.get_allocator() == A());
    }
    }
#endif
}
示例#20
0
void test()
{
    //tests
    DRMatrix m1(DRMatrix::identity());
    float mat[] = {1.0f, 0.0f, 0.0f, 0.0f,
                   0.0f, 1.0f, 0.0f, 0.0f,
                   0.0f, 0.0f, 1.0f, 0.0f,
                   0.0f, 0.0f, 0.0f, 1.0f};
    if(memcmp(m1, mat, sizeof(float)*16) != 0)
        LOG_WARNING("matrix identity isn't valid");
    DRMatrix m2 = m1.rotationX(30.0f);
    DRMatrix m3 = DRMatrix::axis(DRVector3(1.0f, 0.0f, 0.0f),
                                 DRVector3(0.0f, 1.0f, 0.0f),
                                 DRVector3(0.0f, 0.0f, 1.0));
    if(memcmp(m1, m3, sizeof(float)*16) != 0)
        LOG_WARNING("matrix axis isn't valid");
    
    DREngineLog.writeMatrixToLog(m1);
    DREngineLog.writeMatrixToLog(m2);
    DREngineLog.writeMatrixToLog(m3);
    
    DRVector3 rot1(1.0f, 0.0f, 0.0f);
    m2 = DRMatrix::rotationY(90.0f);
    rot1 = rot1.transformCoords(m2);
    DREngineLog.writeVector3ToLog(rot1, "1/0/0 90 Grad um y-Achse rotiert");
    rot1 = rot1.transformCoords(m2.invert());
    DREngineLog.writeVector3ToLog(rot1, "zurueckrotiert, 1/0/0 erwartet!");
    
    DREngineLog.writeToLog("RekursionTest: %d", rekursionTest(0));
    
    
    //Speicher test
/*  LOG_INFO("Speichertest");
    std::list<void*> pointer;
    void* t = NULL;
    u32 count = 0;
    do
    {
        t = malloc(16384);
        if(t) pointer.push_back(t);
        count++;
        if(count > 192073)
            break;
    } while(t);
    
    DRLog.writeToLog("count: %d, %u kByte wurden reserviert!", count, count*16384/1024);
    
    for(std::list<void*>::iterator it = pointer.begin(); it != pointer.end(); it++)
        free(*it);
    pointer.clear();
   //* */
    
    // Unit test
    printf("\n");
    Unit parsec(1.0, PARSEC);
    Unit lj = parsec.convertTo(LIGHTYEAR);
    DREngineLog.writeToLog("%s -> %s", parsec.print().data(), lj.print().data());    
    lj = Unit(1.0, LIGHTYEAR);
    parsec = lj.convertTo(PARSEC);
    DREngineLog.writeToLog("%s -> %s", lj.print().data(), parsec.print().data());    
    Unit ae = lj.convertTo(AE);
    DREngineLog.writeToLog("%s -> %s", lj.print().data(), ae.print().data());    
    ae = parsec.convertTo(AE);
    DREngineLog.writeToLog("%s -> %s", parsec.print().data(), ae.print().data());    
    parsec = ae.convertTo(PARSEC);
    DREngineLog.writeToLog("%s -> %s", ae.print().data(), parsec.print().data());    
    Unit m = parsec.convertTo(M);
    DREngineLog.writeToLog("%s -> %s", parsec.print().data(), m.print().data());    
    Unit kpc(1.0, KILOPARSEC);
    m = kpc.convertTo(M);
    DREngineLog.writeToLog("%s -> %s", kpc.print().data(), m.print().data());    
    m = Unit(1.0, M);
    kpc = m.convertTo(KILOPARSEC);
    DREngineLog.writeToLog("%s -> %s", m.print().data(), kpc.print().data());    
    printf("\n");
    
    Unit aes(0.005, AE);
    DREngineLog.writeToLog("%s -> %s", aes.print().data(), aes.convertTo(KM).print().data());
    
    //Vector Unit Test
    Vector3Unit u1(100, 200, 70, M), u2(1, 0, 0, KILOPARSEC), u3(100, 20, 17, LIGHTYEAR);
    u1.print("u1");
    u2.print("u2");
    u3.print("u3");
    
    u1 *= Unit(20, KM);
    u1.print("u1* 20 km");
    
    Vector3Unit(u1 + u2).print("u1+u2");
    Vector3Unit(u2+u3).print("u2+u3");
    Vector3Unit(u1*Unit(1, LIGHTYEAR)).print("u1*1 Lichtjahr");
    
    DRVector3 v(1.0f, 7.0f, 2.0f);
    DREngineLog.writeVector3ToLog(v, "init");
    v = v.normalize();
    DREngineLog.writeVector3ToLog(v, "normalized");
    v *= 7.0f;
    DREngineLog.writeVector3ToLog(v, "multiplikator");
    
    // ----------------------------------  ReferenzHolder Test --------------------------------
    
    DREngineLog.writeToLog("DRIndexReferenzHolder test");
    DRIndexReferenzHolder referenzHolder(10);
    uint tests[10];
    tests[0] = referenzHolder.getFree();
    referenzHolder.add(tests[0]);
    tests[1] = referenzHolder.getFree();
    
    DREngineLog.writeToLog("index1 (0): %d, index2 (1): %d", tests[0], tests[1]);
    referenzHolder.remove(tests[0]);
    tests[2] = referenzHolder.getFree();
    referenzHolder.remove(tests[1]);
    tests[3] = referenzHolder.getFree();
    DREngineLog.writeToLog("index3 (2): %d, index4 (1): %d", tests[2], tests[3]);
    for(int i = 0; i < 5; i++)
        tests[4+i] = referenzHolder.getFree();
    referenzHolder.remove(tests[7]);
    tests[9] = referenzHolder.getFree();
    DREngineLog.writeToLog("index10: (6): %d", tests[9]);
    
    DRTextureManager::Instance().test();
    
    // Random Test
    
}
示例#21
0
template<typename Scalar,typename StorageIndex> void sparse_vector(int rows, int cols)
{
  double densityMat = (std::max)(8./(rows*cols), 0.01);
  double densityVec = (std::max)(8./(rows), 0.1);
  typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
  typedef Matrix<Scalar,Dynamic,1> DenseVector;
  typedef SparseVector<Scalar,0,StorageIndex> SparseVectorType;
  typedef SparseMatrix<Scalar,0,StorageIndex> SparseMatrixType;
  Scalar eps = 1e-6;

  SparseMatrixType m1(rows,rows);
  SparseVectorType v1(rows), v2(rows), v3(rows);
  DenseMatrix refM1 = DenseMatrix::Zero(rows, rows);
  DenseVector refV1 = DenseVector::Random(rows),
              refV2 = DenseVector::Random(rows),
              refV3 = DenseVector::Random(rows);

  std::vector<int> zerocoords, nonzerocoords;
  initSparse<Scalar>(densityVec, refV1, v1, &zerocoords, &nonzerocoords);
  initSparse<Scalar>(densityMat, refM1, m1);

  initSparse<Scalar>(densityVec, refV2, v2);
  initSparse<Scalar>(densityVec, refV3, v3);

  Scalar s1 = internal::random<Scalar>();

  // test coeff and coeffRef
  for (unsigned int i=0; i<zerocoords.size(); ++i)
  {
    VERIFY_IS_MUCH_SMALLER_THAN( v1.coeff(zerocoords[i]), eps );
    //VERIFY_RAISES_ASSERT( v1.coeffRef(zerocoords[i]) = 5 );
  }
  {
    VERIFY(int(nonzerocoords.size()) == v1.nonZeros());
    int j=0;
    for (typename SparseVectorType::InnerIterator it(v1); it; ++it,++j)
    {
      VERIFY(nonzerocoords[j]==it.index());
      VERIFY(it.value()==v1.coeff(it.index()));
      VERIFY(it.value()==refV1.coeff(it.index()));
    }
  }
  VERIFY_IS_APPROX(v1, refV1);
  
  // test coeffRef with reallocation
  {
    SparseVectorType v4(rows);
    DenseVector v5 = DenseVector::Zero(rows);
    for(int k=0; k<rows; ++k)
    {
      int i = internal::random<int>(0,rows-1);
      Scalar v = internal::random<Scalar>();
      v4.coeffRef(i) += v;
      v5.coeffRef(i) += v;
    }
    VERIFY_IS_APPROX(v4,v5);
  }

  v1.coeffRef(nonzerocoords[0]) = Scalar(5);
  refV1.coeffRef(nonzerocoords[0]) = Scalar(5);
  VERIFY_IS_APPROX(v1, refV1);

  VERIFY_IS_APPROX(v1+v2, refV1+refV2);
  VERIFY_IS_APPROX(v1+v2+v3, refV1+refV2+refV3);

  VERIFY_IS_APPROX(v1*s1-v2, refV1*s1-refV2);

  VERIFY_IS_APPROX(v1*=s1, refV1*=s1);
  VERIFY_IS_APPROX(v1/=s1, refV1/=s1);

  VERIFY_IS_APPROX(v1+=v2, refV1+=refV2);
  VERIFY_IS_APPROX(v1-=v2, refV1-=refV2);

  VERIFY_IS_APPROX(v1.dot(v2), refV1.dot(refV2));
  VERIFY_IS_APPROX(v1.dot(refV2), refV1.dot(refV2));

  VERIFY_IS_APPROX(m1*v2, refM1*refV2);
  VERIFY_IS_APPROX(v1.dot(m1*v2), refV1.dot(refM1*refV2));
  {
    int i = internal::random<int>(0,rows-1);
    VERIFY_IS_APPROX(v1.dot(m1.col(i)), refV1.dot(refM1.col(i)));
  }


  VERIFY_IS_APPROX(v1.squaredNorm(), refV1.squaredNorm());
  
  VERIFY_IS_APPROX(v1.blueNorm(), refV1.blueNorm());

  // test aliasing
  VERIFY_IS_APPROX((v1 = -v1), (refV1 = -refV1));
  VERIFY_IS_APPROX((v1 = v1.transpose()), (refV1 = refV1.transpose().eval()));
  VERIFY_IS_APPROX((v1 += -v1), (refV1 += -refV1));
  
  // sparse matrix to sparse vector
  SparseMatrixType mv1;
  VERIFY_IS_APPROX((mv1=v1),v1);
  VERIFY_IS_APPROX(mv1,(v1=mv1));
  VERIFY_IS_APPROX(mv1,(v1=mv1.transpose()));
  
  // check copy to dense vector with transpose
  refV3.resize(0);
  VERIFY_IS_APPROX(refV3 = v1.transpose(),v1.toDense()); 
  VERIFY_IS_APPROX(DenseVector(v1),v1.toDense()); 

  // test conservative resize
  {
    std::vector<StorageIndex> inc;
    if(rows > 3)
      inc.push_back(-3);
    inc.push_back(0);
    inc.push_back(3);
    inc.push_back(1);
    inc.push_back(10);

    for(std::size_t i = 0; i< inc.size(); i++) {
      StorageIndex incRows = inc[i];
      SparseVectorType vec1(rows);
      DenseVector refVec1 = DenseVector::Zero(rows);
      initSparse<Scalar>(densityVec, refVec1, vec1);

      vec1.conservativeResize(rows+incRows);
      refVec1.conservativeResize(rows+incRows);
      if (incRows > 0) refVec1.tail(incRows).setZero();

      VERIFY_IS_APPROX(vec1, refVec1);

      // Insert new values
      if (incRows > 0)
        vec1.insert(vec1.rows()-1) = refVec1(refVec1.rows()-1) = 1;

      VERIFY_IS_APPROX(vec1, refVec1);
    }
  }

}
示例#22
0
文件: matrixTest.cpp 项目: zz2014/NAC
void matrixTest()
{
  Matrix m1(3,3);
  m1(1,1)=1; m1(1,2)=2;  m1(1,3)=3;
  m1(2,1)=4; m1(2,2)=5;  m1(2,3)=6;
  m1(3,1)=7; m1(3,2)=8;  m1(3,3)=9;

  Vector v(3);
  v(1)=2; v(2)=3; v(3)=1;

  Vector r(3);
  r = m1*v;


  const Vector cv(r);

  Vector vexpected(3);
  vexpected(1)=11; vexpected(2)=29; vexpected(3)=47;

  r.sub(vexpected);

  TEST(r.betrag() < 0.0001);

  TEST(fabs(cv(1)-vexpected(1)) < 0.0001);

  const Matrix cm(m1);
  
  TEST(fabs(m1(1,1)-cm(1,1)) < 0.0001);

  Matrix m2(3,2);
  m2(1,1)=1; m2(1,2)=2;
  m2(2,1)=4; m2(2,2)=5;
  m2(3,1)=7; m2(3,2)=8;

  Matrix mr(m1*m2);
  
  Matrix mexpected(3,2);
  mexpected(1,1)=30; mexpected(1,2)=36;
  mexpected(2,1)=66; mexpected(2,2)=81;
  mexpected(3,1)=102; mexpected(3,2)=126;

  int i,j;
  for(i=1;i<3;++i)
    for(j=1;j<2;++j)
    {
      TEST(fabs(mr(i,j)-mexpected(i,j)) < 0.0001);
    }

  try
  {
    mr(3,3);
    falsch();
  }
  catch(float nan)
  {
    if(nan==nan)
    {
      falsch();
    }
  }

  try
  {
    cv(7);
    falsch();
  }
  catch(float nan)
  {
    if(nan==nan)
    {
      falsch();
    }
  }

  TEST(fabs(v.skalarprodukt(vexpected)-156) < 0.0001);
}
示例#23
0
文件: test.cpp 项目: vabc3/EOJ
string Travel(const string& d)
{	
	return m1(d);
}
int main(int argc, char *argv[])
{
    /*int arg=1;
    QTime time;

    float values[9] = {1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f,9.0f};

    Matrix3 mat(values);

    cout << mat << endl;

    cout << mat.transpose() << endl;*/

   /* time.restart();
    QString img=argv[arg++];
    Terrain* t=generationImage(img);
    std::cout << "Terrain from image generated : " << time.restart() << "ms." << std::endl;//*/

     /* time.restart();
      Terrain* t=generationProcedural();
      std::cout << "Terrain generated : " << time.restart() << "ms." << std::endl;
     //*/


    /*time.restart();
    QString obj=argv[arg++];
    generateMesh(t,obj,300);
    std::cout << "Mesh generated : " << time.restart() << "ms." << std::endl;//*/

    /*time.restart();
    QString destination=argv[arg++];
    shoot(t,destination);
    std::cout << "Image generated from ray launching : " << time.restart() << "ms." << std::endl;//*/

   /* time.restart();
    QString destination=argv[arg++];

    shootMulti(t,destination,100);
    std::cout << "100 images generated from ray launching : " << time.restart() << "ms." << std::endl;//*/

    //delete t;

    /*Vector3D centre(1.0f,0.0f,0.0f);
    Vector3D centre2(.5f,.5f,0.0f);

    Vector3D origine(-3.0f,0.0f,0.0f);
    Vector3D direction(1.0f,0.0f,0.0f);

    Vector3D soleil(-10000.0f,0.0f,0.0f);

    CSGSphere sphere(centre, 1.0f);
    CSGSphere sphere2(centre2, 0.75f);


    CSGDifference uni(&sphere,&sphere2);

    Camera cam(origine, direction,1.0);

    QImage result = cam.printScreen(uni, soleil, 900, 900);

    QString nameImage = "C:/Users/etu/Desktop/sphereTest.png";
    result.save(nameImage);



    MeshBuilder mb;
    TableauVoxel tab(500,500,500,10.0/500,Vector3D(-5,-5,-5),uni);
    //TableauVoxel tab(3,3,3,10,Vector3D(0,0,0));
    //tab(1,1,1)=1;
    QString name2 = "C:/Users/etu/Desktop/voxel.obj";
    Mesh m=mb.voxel(tab,name2);
    mb.saveMesh(name2,m);*/

    QList<Vector3D> points = Vector3D::randHemisphere(1000);
    QList<Vector3D> points2 = Vector3D::rotateScaleTranslate(points, Vector3D(0,0,0), 1, Vector3D(0,0.5,0.5).normalized());
    QList<int> topo;
    QList<Vector3D> normales;
    Mesh m1(points, topo, normales, "ololo");
    Mesh m2(points2, topo, normales, "ololo2");

    MeshBuilder m;
    m.saveMesh("m1.obj", m1);
    m.saveMesh("m3.obj", m2);

    return 0;
}
TEST(TMatrix, can_create_copied_matrix)
{
  TMatrix<int> m(5);

  ASSERT_NO_THROW(TMatrix<int> m1(m));
}
示例#26
0
template<typename MatrixType> void householder(const MatrixType& m)
{
  typedef typename MatrixType::Index Index;
  static bool even = true;
  even = !even;
  /* this test covers the following files:
     Householder.h
  */
  Index rows = m.rows();
  Index cols = m.cols();

  typedef typename MatrixType::Scalar Scalar;
  typedef typename NumTraits<Scalar>::Real RealScalar;
  typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
  typedef Matrix<Scalar, internal::decrement_size<MatrixType::RowsAtCompileTime>::ret, 1> EssentialVectorType;
  typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
  typedef Matrix<Scalar, Dynamic, MatrixType::ColsAtCompileTime> HBlockMatrixType;
  typedef Matrix<Scalar, Dynamic, 1> HCoeffsVectorType;

  typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, MatrixType::RowsAtCompileTime> TMatrixType;
  
  Matrix<Scalar, EIGEN_SIZE_MAX(MatrixType::RowsAtCompileTime,MatrixType::ColsAtCompileTime), 1> _tmp((std::max)(rows,cols));
  Scalar* tmp = &_tmp.coeffRef(0,0);

  Scalar beta;
  RealScalar alpha;
  EssentialVectorType essential;

  VectorType v1 = VectorType::Random(rows), v2;
  v2 = v1;
  v1.makeHouseholder(essential, beta, alpha);
  v1.applyHouseholderOnTheLeft(essential,beta,tmp);
  VERIFY_IS_APPROX(v1.norm(), v2.norm());
  if(rows>=2) VERIFY_IS_MUCH_SMALLER_THAN(v1.tail(rows-1).norm(), v1.norm());
  v1 = VectorType::Random(rows);
  v2 = v1;
  v1.applyHouseholderOnTheLeft(essential,beta,tmp);
  VERIFY_IS_APPROX(v1.norm(), v2.norm());

  MatrixType m1(rows, cols),
             m2(rows, cols);

  v1 = VectorType::Random(rows);
  if(even) v1.tail(rows-1).setZero();
  m1.colwise() = v1;
  m2 = m1;
  m1.col(0).makeHouseholder(essential, beta, alpha);
  m1.applyHouseholderOnTheLeft(essential,beta,tmp);
  VERIFY_IS_APPROX(m1.norm(), m2.norm());
  if(rows>=2) VERIFY_IS_MUCH_SMALLER_THAN(m1.block(1,0,rows-1,cols).norm(), m1.norm());
  VERIFY_IS_MUCH_SMALLER_THAN(internal::imag(m1(0,0)), internal::real(m1(0,0)));
  VERIFY_IS_APPROX(internal::real(m1(0,0)), alpha);

  v1 = VectorType::Random(rows);
  if(even) v1.tail(rows-1).setZero();
  SquareMatrixType m3(rows,rows), m4(rows,rows);
  m3.rowwise() = v1.transpose();
  m4 = m3;
  m3.row(0).makeHouseholder(essential, beta, alpha);
  m3.applyHouseholderOnTheRight(essential,beta,tmp);
  VERIFY_IS_APPROX(m3.norm(), m4.norm());
  if(rows>=2) VERIFY_IS_MUCH_SMALLER_THAN(m3.block(0,1,rows,rows-1).norm(), m3.norm());
  VERIFY_IS_MUCH_SMALLER_THAN(internal::imag(m3(0,0)), internal::real(m3(0,0)));
  VERIFY_IS_APPROX(internal::real(m3(0,0)), alpha);

  // test householder sequence on the left with a shift

  Index shift = internal::random<Index>(0, std::max<Index>(rows-2,0));
  Index brows = rows - shift;
  m1.setRandom(rows, cols);
  HBlockMatrixType hbm = m1.block(shift,0,brows,cols);
  HouseholderQR<HBlockMatrixType> qr(hbm);
  m2 = m1;
  m2.block(shift,0,brows,cols) = qr.matrixQR();
  HCoeffsVectorType hc = qr.hCoeffs().conjugate();
  HouseholderSequence<MatrixType, HCoeffsVectorType> hseq(m2, hc);
  hseq.setLength(hc.size()).setShift(shift);
  VERIFY(hseq.length() == hc.size());
  VERIFY(hseq.shift() == shift);

  MatrixType m5 = m2;
  m5.block(shift,0,brows,cols).template triangularView<StrictlyLower>().setZero();
  VERIFY_IS_APPROX(hseq * m5, m1); // test applying hseq directly
  m3 = hseq;
  VERIFY_IS_APPROX(m3 * m5, m1); // test evaluating hseq to a dense matrix, then applying

  // test householder sequence on the right with a shift

  TMatrixType tm2 = m2.transpose();
  HouseholderSequence<TMatrixType, HCoeffsVectorType, OnTheRight> rhseq(tm2, hc);
  rhseq.setLength(hc.size()).setShift(shift);
  VERIFY_IS_APPROX(rhseq * m5, m1); // test applying rhseq directly
  m3 = rhseq;
  VERIFY_IS_APPROX(m3 * m5, m1); // test evaluating rhseq to a dense matrix, then applying
}
示例#27
0
LLSDRPCClient::LLSDRPCClient() :
	mState(STATE_NONE),
	mQueue(EPBQ_PROCESS)
{
	LLMemType m1(LLMemType::MTYPE_IO_SD_CLIENT);
}
示例#28
0
bool explore_game2(std::set<GameState> &known,std::set<GameState> &to_explore,std::set<GameState> &leafs,int depth)
{
   // Performs one round of iteration towards the solution
   //
   // known - set of visited game states 
   // to_explore - set of input states to play
   // leafs - set of new game states generated by possible moves on 'to_explore'
   
   // iterator over states to_explore 
   std::set<GameState>::iterator it;
   
   // Flag to monitor if a move took place
   bool moved=false;
   
   // Iterate over each input state that has not yet been played
   for (it=to_explore.begin();it!=to_explore.end();it++)
   {
      // If the input state has already been played, skip it
      std::set<GameState>::iterator i0 = known.find(*it);
      if (i0!=known.end()) continue;
      
      // Generate three new game states m1,m2,m3 
      // which result from playing move 0,1,2 on the input state
      // If any of the states will end the game, stop iterating and return false

      GameState m1(*it,0);
      if (m1.isValid()==false) return false;

      GameState m2(*it,1);
      if (m2.isValid()==false) return false;

      GameState m3(*it,2);
      if (m3.isValid()==false) return false;
            
      // If the resulting state is novel, add it to the output set of leaf states
      // which will be explored in the next iteration, and flag that a move
      // has taken place
      std::set<GameState>::iterator i1=known.find(m1);
      // if m1 is not in 'known' set
      if (i1==known.end())
      {
         leafs.insert(m1);
         moved=true;
      }
      
      std::set<GameState>::iterator i2=known.find(m2);   
      // if m2 is not in 'known' set
      if (i2==known.end())
      {
         leafs.insert(m2);
         moved=true;
      }
      
      std::set<GameState>::iterator i3=known.find(m3);
      // if m3 is not in 'known' set
      if (i3==known.end())
      {
         leafs.insert(m3);
         moved=true;
      }
   }
   
   // returns 'true' if another iteration is justified and 'false' otherwise   
   return moved;
}
示例#29
0
// virtual
LLIOPipe::EStatus LLSDRPCClient::process_impl(
	const LLChannelDescriptors& channels,
	buffer_ptr_t& buffer,
	bool& eos,
	LLSD& context,
	LLPumpIO* pump)
{
	PUMP_DEBUG;
	LLMemType m1(LLMemType::MTYPE_IO_SD_CLIENT);
	if((STATE_NONE == mState) || (!pump))
	{
		// You should have called the call() method already.
		return STATUS_PRECONDITION_NOT_MET;
	}
	EStatus rv = STATUS_DONE;
	switch(mState)
	{
	case STATE_READY:
	{
		PUMP_DEBUG;
//		lldebugs << "LLSDRPCClient::process_impl STATE_READY" << llendl;
		buffer->append(
			channels.out(),
			(U8*)mRequest.c_str(),
			mRequest.length());
		context[CONTEXT_DEST_URI_SD_LABEL] = mURI;
		mState = STATE_WAITING_FOR_RESPONSE;
		break;
	}
	case STATE_WAITING_FOR_RESPONSE:
	{
		PUMP_DEBUG;
		// The input channel has the sd response in it.
		//lldebugs << "LLSDRPCClient::process_impl STATE_WAITING_FOR_RESPONSE"
		//		 << llendl;
		LLBufferStream resp(channels, buffer.get());
		LLSD sd;
		LLSDSerialize::fromNotation(sd, resp, buffer->count(channels.in()));
		LLSDRPCResponse* response = (LLSDRPCResponse*)mResponse.get();
		if (!response)
		{
			mState = STATE_DONE;
			break;
		}
		response->extractResponse(sd);
		if(EPBQ_PROCESS == mQueue)
		{
			LLPumpIO::chain_t chain;
			chain.push_back(mResponse);
			pump->addChain(chain, DEFAULT_CHAIN_EXPIRY_SECS);
		}
		else
		{
			pump->respond(mResponse.get());
		}
		mState = STATE_DONE;
		break;
	}
	case STATE_DONE:
	default:
		PUMP_DEBUG;
		llinfos << "invalid state to process" << llendl;
		rv = STATUS_ERROR;
		break;
	}
	return rv;
}
示例#30
0
void LLURLRequest::setCallback(LLURLRequestComplete* callback)
{
	LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST);
	mCompletionCallback = callback;
	mDetail->mCurlRequest->setHeaderCallback(&headerCallback, (void*)callback);
}