当前位置: 首页>>代码示例>>C++>>正文


C++ Matrix2类代码示例

本文整理汇总了C++中Matrix2的典型用法代码示例。如果您正苦于以下问题:C++ Matrix2类的具体用法?C++ Matrix2怎么用?C++ Matrix2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Matrix2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cast_and_apply

    void cast_and_apply(Function& f, Matrix1& first, Matrix2& second)
    {
        typedef typename Matrix2::value_type value_type;
        typedef typename Matrix2::dense_type dense_type;
        typedef typename Matrix2::sparse_type sparse_type;
        typedef	typename Matrix2::scalar_type scalar_type;

        if (second.is_true_scalar()) { // kanske bara ta in värdet ist
            const scalar_type& sc = dynamic_cast<const scalar_type&> (second);
            Operator<Function, Matrix1, const scalar_type> op;
            op(f, first, sc);
        }
        else if (second.is_dense()) {
            const dense_type& d = dynamic_cast<const dense_type&> (second);
            Operator<Function, Matrix1, const dense_type> op;
            op(f, first, d);
        }
        else if (second.is_sparse()) {
            const sparse_type& s = dynamic_cast<const sparse_type&> (second);
            Operator<Function, Matrix1, const sparse_type> op;
            op(f, first, s);
        }
        else {
            Operator<Function, Matrix1, const Matrix2> op;
            op(f, first, second);
        }
    }
开发者ID:nilsbore,项目名称:logical,代码行数:27,代码来源:matrix_operations.hpp

示例2: ifft2_1D

Matrix ifft2_1D(const Matrix2& mat)
{
	fftw_complex*   data_in;
	fftw_complex*   ifft;
	fftw_plan       plan_b;
	data_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * mat.imge.size1());
	ifft    = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * mat.imge.size1());
	plan_b = fftw_plan_dft_1d(mat.imge.size1(), data_in, ifft,
							  FFTW_BACKWARD,  FFTW_ESTIMATE);
	for(int i = 0, k = 0; i < mat.imge.size1(); ++i)
	{
		data_in[k][0] = mat.real(i, 0);
		data_in[k][1] = mat.imge(i, 0);
		k++;
	}
	/* perform FFT */
	fftw_execute(plan_b);
	double normal_val = 1.0 / (mat.imge.size1() * mat.imge.size2());
	Matrix out(mat.imge.size1(), mat.imge.size2());
	for(int i = 0, k = 0; i < mat.imge.size1(); ++i)
	{
		for(int j = 0; j < mat.imge.size2(); ++j)
		{
			out(i, j) = ifft[k][0] * normal_val;
			k++;
		}
	}
	fftw_destroy_plan(plan_b);
	fftw_free(data_in);
	fftw_free(ifft);
	return out;
}
开发者ID:maleiwhat,项目名称:vectorizing-project,代码行数:32,代码来源:main.cpp

示例3: matrixByMatrix

ResultType matrixByMatrix(const Matrix1& a1, const Matrix2& a2)
{
  ResultType result(a1.numberOfRows(),a2.numberOfColumns(),true);
  if(a1.numberOfColumns()!=a2.numberOfRows())
    throw std::range_error("operator chomp::vectalg::matrixByMatrix: incompatible matrix dimensions");

  for(int i=0;i<result.numberOfColumns();++i)
  {
    typename ResultType::iterator b=result.begin()+i, e=result.end()+i;
    typename Matrix1::const_iterator j=a1.begin();
    while(b!=e)
    {
      typename Matrix2::const_iterator b1=a2.begin()+i, e1=a2.end()+i;
      typename ResultType::ScalarType x = TypeTraits<typename ResultType::ScalarType>::zero();
      while(b1!=e1)
      {
        x += (*j) * (*b1);
        ++j;
        b1+=a2.rowStride();
      }
      *b=x;
      b+=result.rowStride();
    }
  }

  return result;
}
开发者ID:caosuomo,项目名称:rads,代码行数:27,代码来源:algebraicOperations.hpp

示例4: RandomiseDirectionVector

 Vector2 RandomiseDirectionVector(const Vector2 &direction, float halfAngle)
 {
    float angle = RandFloatSigned() * halfAngle;
    Matrix2 rotation;
    rotation.FromRotation(angle);
    return rotation * direction;
 }
开发者ID:CrazyNinja,项目名称:Neural-Network,代码行数:7,代码来源:Random.cpp

示例5: cyclic_eigen_jacobi

    std::size_t cyclic_eigen_jacobi( const Matrix1& A, Matrix2& V, Otor o, std::size_t max_rot = 80, const T eps = T( 1.0e-10 ) )
    {
        typedef typename Matrix1::value_type value_type;
        typedef typename Matrix1::size_type size_type;
        auto const compare_func = [eps]( const value_type lhs, const value_type rhs ) { return std::abs(lhs-rhs) < eps; };
        assert( A.row() == A.col() );
        //assert( is_symmetric( A, compare_func ) );

        size_type i     = 0;
        auto a          = A;
        auto const n    = a.row();
        auto const one  = value_type( 1 );
        auto const zero = value_type( 0 );
        // @V = diag{1, 1, ..., 1}
        V.resize( n, n );
        V = zero;
        std::fill( V.diag_begin(), V.diag_end(), one );

        for ( ; i != max_rot; ++i )
        {
            if ( !(i&7) && eigen_jacobi_private::norm(a) == zero )
            {
                break;
            }

            for ( size_type p = 0; p != n; ++p )
                for ( size_type q = p+1; q != n; ++q )
                    eigen_jacobi_private::rotate(a, V, p, q);
        }

        std::copy( a.diag_begin(), a.diag_end(), o );
        return i*n*n;
    }
开发者ID:,项目名称:,代码行数:33,代码来源:

示例6:

 inline Vector2<T_Scalar> operator*(const Vector2<T_Scalar>& v, const Matrix2<T_Scalar>& m)
 {
   Vector2<T_Scalar> t;
   t.x() = v.x()*m.e(0,0) + v.y()*m.e(1,0);
   t.y() = v.x()*m.e(0,1) + v.y()*m.e(1,1);
   return t;
 }
开发者ID:TomasHurban,项目名称:DP_Hairs_simulation_and_visualization,代码行数:7,代码来源:Matrix2.hpp

示例7: testaxpycblasConsistency

bool testaxpycblasConsistency  (LELA::Context<Ring, Modules1> &ctx1,
				LELA::Context<Ring, Modules2> &ctx2,
				const char *text,
				const typename Ring::Element &a,
				const Matrix1 &A1, const Matrix2 &A2,
				const Matrix3 &A3, const Matrix4 &A4)
{

        ostringstream str;
        str << "Testing " << text << " axpy consistency" << std::ends;
        commentator.start (str.str ().c_str ());

	std::ostream &report = commentator.report (Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION);

        bool pass = true;

	typename Matrix3::ContainerType A6 (A1.rowdim (), A1.coldim ());

	BLAS3::copy(ctx1, A1, A6);

        typename Matrix2::ContainerType A7 (A2.rowdim (), A2.coldim ());
        typename Matrix4::ContainerType A8 (A2.rowdim (), A2.coldim ());

	BLAS3::copy(ctx1, A2, A7);
	BLAS3::copy(ctx1, A2, A8);

        report << "Matrix A_1: "<< std::endl;
	BLAS3::write (ctx1, report, A1);

        report << "Matrix A_2: "<< std::endl;
	BLAS3::write (ctx1, report, A7);

	BLAS3::axpy (ctx1, a, A1, A7);

        report << "Matrix a A_1 + A_2: " << std::endl;;
	BLAS3::write (ctx1, report, A7);

        report << "Matrix A_1: "<< std::endl;
	BLAS3::write (ctx1, report, A6);

        report << "Matrix A_2: "<< std::endl;
	BLAS3::write (ctx1, report, A8);

	BLAS3::axpy (ctx2, a, A6, A8);

        report << "Matrix a A_3 + A_4: " << std::endl;
	BLAS3::write (ctx2, report, A8);

        if (!BLAS3::equal (ctx1, A7, A8))
	{
		commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR)
			<< "ERROR: a A_1 + A_2  !=  a A_3 + A_4 " << std::endl;
		pass = false;
	}

        commentator.stop (MSG_STATUS (pass));

        return pass;
}
开发者ID:malex984,项目名称:LELA-Spielwiese,代码行数:59,代码来源:test-blas-cblas-module.C

示例8: e

 //-----------------------------------------------------------------------------
 Matrix2 operator-(const Matrix2& m) const
 {
   Matrix2 t;
   for(int i=0; i<2; ++i)
     for(int j=0; j<2; ++j)
       t.e(j,i) = e(j,i) - m.e(j,i);
   return t;
 }
开发者ID:TomasHurban,项目名称:DP_Hairs_simulation_and_visualization,代码行数:9,代码来源:Matrix2.hpp

示例9:

Point2D Point2D::rotateby(Matrix2 rm) {

    double new_x = rm.m11()*x() + rm.m12()*y();
    double new_y = rm.m21()*x() + rm.m22()*y();

    return Point2D(new_x, new_y);

};
开发者ID:mauroalberti,项目名称:geoSurfDEM,代码行数:8,代码来源:spatial.cpp

示例10: getTransposed

 //-----------------------------------------------------------------------------
 Matrix2 getTransposed() const
 {
   Matrix2 m;
   for(int i=0; i<2; ++i)
     for(int j=0; j<2; ++j)
       m.e(j,i) = e(i,j);
   return m;
 }
开发者ID:TomasHurban,项目名称:DP_Hairs_simulation_and_visualization,代码行数:9,代码来源:Matrix2.hpp

示例11: Eigenvalues

void Eigenvalues(const Matrix2& A,Complex& lambda1,Complex& lambda2)
{
  Real trace=A.trace();
  Real det=A.determinant();
  Complex temp2 = Sqr(trace) - 4.0*det;
  Complex temp = Sqrt(temp2);
  lambda1 = 0.5*(Complex(trace) + temp);
  lambda2 = 0.5*(Complex(trace) - temp);
}
开发者ID:krishauser,项目名称:KrisLibrary,代码行数:9,代码来源:LinearAlgebra.cpp

示例12: transpose

// Calculations
static int transpose(lua_State *L) 
{
  int n = lua_gettop(L);  // Number of arguments
  if (n != 1) 
    return luaL_error(L, "Got %d arguments expected 1 (self)", n); 
    
  Matrix2* matrix = checkMatrix2(L);    
  Matrix2_push(L,1, new Matrix2(matrix->getTranspose()));
  return 1;
}
开发者ID:ordovician,项目名称:LusionEngine,代码行数:11,代码来源:LuaMatrix2.cpp

示例13: transformVector

static int transformVector(lua_State *L) 
{
  int n = lua_gettop(L);  // Number of arguments
  if (n != 2) 
    return luaL_error(L, "Got %d arguments expected 2 (self, point)", n); 
    
  Matrix2* matrix = checkMatrix2(L);
  Vector2 v = Vector2_pull(L,2);  
  Vector2_push(L, matrix->transformVector(v));
  return 1;
}
开发者ID:ordovician,项目名称:LusionEngine,代码行数:11,代码来源:LuaMatrix2.cpp

示例14: diff

 //-----------------------------------------------------------------------------
 T_Scalar diff(const Matrix2& other) const
 {
   T_Scalar err = 0;
   for(int i=0; i<2; ++i)
     for(int j=0; j<2; ++j)
       if (e(j,i) > other.e(j,i)) // avoid fabs/abs
         err += e(j,i) - other.e(j,i);
       else
         err += other.e(j,i) - e(j,i);
   return err;
 }
开发者ID:TomasHurban,项目名称:DP_Hairs_simulation_and_visualization,代码行数:12,代码来源:Matrix2.hpp

示例15: testEigenDecomposition

/**
 * Example of a test. To be completed.
 *
 */
bool testEigenDecomposition()
{
    unsigned int nbok = 0;
    unsigned int nb = 0;

    typedef EigenDecomposition<2,double> Eigen2;
    typedef Eigen2::Vector Vector2;
    typedef Eigen2::Matrix Matrix2;

    trace.beginBlock ( "Testing block ..." );
    // [4 1]
    // [1 2]
    Matrix2 A;
    A.setComponent( 0, 0, 4 );
    A.setComponent( 0, 1, 1 );
    A.setComponent( 1, 0, 1 );
    A.setComponent( 1, 1, 2 );
    Matrix2 P;
    Vector2 v;
    Eigen2::getEigenDecomposition( A, P, v );
    trace.info() << "Input matrix: " << A << std::endl;
    trace.info() << "Eigenvectors: " << P << std::endl;
    trace.info() << "Eigenvalues: " << v << std::endl;
    Vector2 V0 = P.column( 0 );
    Vector2 V1 = P.column( 1 );
    Vector2 V0_exp( 0.3826834323650898, -0.9238795325112868 );
    Vector2 V1_exp( 0.9238795325112868, 0.3826834323650898);
    double v0_exp = 1.585786437626905;
    double v1_exp = 4.414213562373095;
    double error_V0 = (V0-V0_exp).norm();
    double error_V1 = (V1-V1_exp).norm();
    double error_v0 = fabs( v[0] - v0_exp );
    double error_v1 = fabs( v[1] - v1_exp );
    trace.info() << "error_V0 = " << error_V0 << std::endl;
    trace.info() << "error_V1 = " << error_V1 << std::endl;
    trace.info() << "error_v0 = " << error_v0 << std::endl;
    trace.info() << "error_v1 = " << error_v1 << std::endl;
    double epsilon = 1e-10;
    ++nb, nbok += error_V0 < epsilon ? 1 : 0;
    trace.info() << "(" << nbok << "/" << nb << ") "
                 << "error_V0 < epsilon, i.e. " <<  error_V0 << " < " << epsilon << std::endl;
    ++nb, nbok += error_V1 < epsilon ? 1 : 0;
    trace.info() << "(" << nbok << "/" << nb << ") "
                 << "error_V1 < epsilon, i.e. " <<  error_V1 << " < " << epsilon << std::endl;
    ++nb, nbok += error_v0 < epsilon ? 1 : 0;
    trace.info() << "(" << nbok << "/" << nb << ") "
                 << "error_v0 < epsilon, i.e. " <<  error_v0 << " < " << epsilon << std::endl;
    ++nb, nbok += error_v1 < epsilon ? 1 : 0;
    trace.info() << "(" << nbok << "/" << nb << ") "
                 << "error_v1 < epsilon, i.e. " <<  error_v1 << " < " << epsilon << std::endl;
    trace.endBlock();

    return nbok == nb;
}
开发者ID:Victor-Ostromoukhov,项目名称:DGtal,代码行数:58,代码来源:testEigenDecomposition.cpp


注:本文中的Matrix2类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。