• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ tensor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: print_2D_view

void print_2D_view(tensor<T, M>& a) {
	for (unsigned int i = 0; i<a.shape(0); i++){
		for (unsigned int j = 0; j<a.shape(1); j++)
			cout<<a(i, j)<<" ";
		cout<<endl;
	}
}
开发者ID:cvejoski,项目名称:CUDALab,代码行数:7,代码来源:exercise_1.cpp


示例2: time_step

void time_step(){
	reduce(&P_odd,even_to_odd);
	P_odd.normalize();
	drift(&P_odd, &N_tensor, 1000);
	reduce(&P_even,odd_to_even);
	P_even.normalize(); 	
	drift(&P_even, &N_tensor, 1000);
};
开发者ID:matthew-ackerman,项目名称:Evolution_7,代码行数:8,代码来源:grapher.cpp


示例3: fill_uniform

        void curand_generator::
        fill_uniform (
            tensor& data
        )
        {
            if (data.size() == 0)
                return;

            CHECK_CURAND(curandGenerateUniform((curandGenerator_t)handle, data.device(), data.size()));
        }
开发者ID:20337112,项目名称:dlib,代码行数:10,代码来源:curand_dlibapi.cpp


示例4: tensor

	tensor (const tensor<value_type, other_layout> &other)
		: tensor_expression_type<self_type> ()
		, extents_ (other.extents())
		, strides_ (other.extents())
		, data_    (other.extents().product())
	{
		copy(this->rank(), this->extents().data(),
				 this->data(), this->strides().data(),
				 other.data(), other.strides().data());
	}
开发者ID:boostorg,项目名称:ublas,代码行数:10,代码来源:tensor.hpp


示例5: print_3D_view

void print_3D_view(tensor<T, M>& a) {
	for (unsigned int k = 0; k<a.shape(0); k++) {
		cout<<"dimension 0: "<<k<<endl;
		for (unsigned int i = 0; i<a.shape(1); i++){
			for (unsigned int j = 0; j<a.shape(2); j++)
				cout<<a(k, i, j)<<" ";
			cout<<endl;
		}
	}
}
开发者ID:cvejoski,项目名称:CUDALab,代码行数:10,代码来源:exercise_1.cpp


示例6: sqrt

Foam::vector Foam::finiteRotation::eulerAngles(const tensor& rotT)
{
    // Create a vector containing euler angles (x = roll, y = pitch, z = yaw)
    vector eulerAngles;

    scalar& rollAngle = eulerAngles.x();
    scalar& pitchAngle = eulerAngles.y();
    scalar& yawAngle = eulerAngles.z();

    // Calculate roll angle
    rollAngle = atan2(rotT.yz(), rotT.zz());

    // Use mag to avoid negative value due to round-off
    // HJ, 24/Feb/2016
    // Bugfix: sqr. SS, 18/Apr/2016
    const scalar c2 = sqrt(sqr(rotT.xx()) + sqr(rotT.xy()));

    // Calculate pitch angle
    pitchAngle = atan2(-rotT.xz(), c2);

    const scalar s1 = sin(rollAngle);
    const scalar c1 = cos(rollAngle);

    // Calculate yaw angle
    yawAngle = atan2(s1*rotT.zx() - c1*rotT.yx(), c1*rotT.yy() - s1*rotT.zy());

    return eulerAngles;
}
开发者ID:CFMS,项目名称:foam-extend-foam-extend-3.2,代码行数:28,代码来源:finiteRotation.C


示例7: entropy

float entropy(const tensor<float, dim, device>& tensor, float totalSum = 1.f) {
  if (totalSum == 1.f) {
    return -tbblas::detail::transform_reduce(
        typename tbblas::detail::select_system<device>::system(),
        tensor.begin(), tensor.end(),
        entropy_float(), 0.f, thrust::plus<float>());
  } else {
    return -tbblas::detail::transform_reduce(
        typename tbblas::detail::select_system<device>::system(),
        tensor.begin(), tensor.end(),
        entropy_float_norm(totalSum), 0.f, thrust::plus<float>());
  }
}
开发者ID:e-thereal,项目名称:capputils,代码行数:13,代码来源:entropy.hpp


示例8: getNormalFromTangent

Vector getNormalFromTangent(const tensor<double, 3, 2> tangent)
{
    Vector xp;
    // upper right...
    xp[0] = -tangent.get(1, 2);  // x
    xp[1] = tangent.get(0, 2);   // y
    xp[2] = -tangent.get(0, 1);  // z
    // lower left...
    // xp[0] = tangent.get(2,1);
    // xp[1] = -tangent.get(2,0);
    // xp[2] = tangent.get(1,0);
    return xp;
}
开发者ID:ctlee,项目名称:gamer,代码行数:13,代码来源:SurfaceMesh.cpp


示例9: log10

    void log10 (
        tensor& dest,
        const tensor& src
    )
    {
        DLIB_CASSERT(dest.size() == src.size());

#ifdef DLIB_USE_CUDA
        cuda::log10(dest,src);
#else
        dest = log10(mat(src));
#endif
    }
开发者ID:markpp,项目名称:MTB,代码行数:13,代码来源:tensor_tools.cpp


示例10: fill_gaussian

        void curand_generator::
        fill_gaussian (
            tensor& data,
            float mean,
            float stddev
        )
        {
            if (data.size() == 0)
                return;

            CHECK_CURAND(curandGenerateNormal((curandGenerator_t)handle, 
                                        data.device(),
                                        data.size(),
                                        mean,
                                        stddev));
        }
开发者ID:20337112,项目名称:dlib,代码行数:16,代码来源:curand_dlibapi.cpp


示例11:

bool Foam::isoSurface::noTransform(const tensor& tt) const
{
    return
        (mag(tt.xx()-1) < mergeDistance_)
     && (mag(tt.yy()-1) < mergeDistance_)
     && (mag(tt.zz()-1) < mergeDistance_)
     && (mag(tt.xy()) < mergeDistance_)
     && (mag(tt.xz()) < mergeDistance_)
     && (mag(tt.yx()) < mergeDistance_)
     && (mag(tt.yz()) < mergeDistance_)
     && (mag(tt.zx()) < mergeDistance_)
     && (mag(tt.zy()) < mergeDistance_);
}
开发者ID:BarisCumhur,项目名称:OpenFOAM-dev,代码行数:13,代码来源:isoSurface.C


示例12: scale_rows

    void scale_rows (
        tensor& out,
        const tensor& m,
        const tensor& v
    )
    {
        DLIB_CASSERT(have_same_dimensions(out,m));
        DLIB_CASSERT(is_vector(v));
        if (m.size() == 0 && v.size() == 0)
            return;
        DLIB_CASSERT(m.size() != 0);
        DLIB_CASSERT(m.num_samples() == v.size());

#ifdef DLIB_USE_CUDA
        cuda::scale_rows(out, m, v);
#else
        out = scale_rows(mat(m), mat(v));
#endif
    }
开发者ID:markpp,项目名称:MTB,代码行数:19,代码来源:tensor_tools.cpp


示例13: GetInterpTensor

//******************************************************************************
//Name:  GetInterpTensor                                                       *
//                                                                             *
//Purpose:  get the interpolated tensor at an arbitrary position               *
//                                                                             *
//Takes: pointer to the position as packed in a tensor                         *
//******************************************************************************
tensor field::GetInterpTensor(tensor &pos)
{
   double position[3];
   tensor ret_val;

   for(int i = 0; i < 3; i++)  position[i] = pos.Val(i);

   ret_val <= GetInterpTensor(position);

   return ret_val;
}
开发者ID:gravmath,项目名称:Projects,代码行数:18,代码来源:field.cpp


示例14: scale_columns

    void scale_columns (
        tensor& out,
        const tensor& m,
        const tensor& v
    )
    {
        DLIB_CASSERT(have_same_dimensions(out,m));
        DLIB_CASSERT(is_vector(v));
        if (m.size() == 0 && v.size() == 0)
            return;
        DLIB_CASSERT(m.size() != 0);
        DLIB_CASSERT(m.size()/m.num_samples() == v.size());

#ifdef DLIB_USE_CUDA
        cuda::scale_columns(out, m, v);
#else
        DLIB_CASSERT(false, "shouldn't be called right now");
        out = scale_columns(mat(m), mat(v));
#endif
    }
开发者ID:markpp,项目名称:MTB,代码行数:20,代码来源:tensor_tools.cpp


示例15: SetTensor

//******************************************************************************
//Name:  SetTensor                                                             *
//                                                                             *
//Purpose:  Set the tensor portion of the field                                *
//                                                                             *
//Takes: takes a position in tensor form and the address of the tensor         *
//******************************************************************************
void field::SetTensor(const tensor &pos, const tensor &rval)
{

   int i;
   double position[3];

   for( i = 0; i < 3; i++) position[i] = pos.Val(i);

   SetTensor(position, rval);

}
开发者ID:gravmath,项目名称:Projects,代码行数:18,代码来源:field.cpp


示例16: db

void Foam::myVelocityFvPatchVectorField::updateCoeffs()
{
    if (this->updated())
    {
        return;
    }

    // Variablen/ Felder
    const volVectorField& u = db().lookupObject<volVectorField>("u");
    //fvPatchVectorField& u_b = *this;
    tmp<vectorField> tu_b = *this;
    vectorField& u_b = tu_b();

    const tmp<vectorField> tn = this->patch().nf();
    const vectorField& n = tn();

    tmp<volTensorField> tGradU = fvc::grad(u);
    const volTensorField gradU = tGradU();
    tmp<vectorField> tD = patch().delta();
    const vectorField& D = tD();
    const labelList& bcs = patch().faceCells();

    for(int i=0; i<patch().size(); i++) {

        const label bc = bcs[i];
        const vector normal = n[i];
        const tensor Jac_u = gradU[bc];
        const vector u_bc = u[bc];
        const vector Di = D[i];

        vector u_b_extrapolated;

        u_b_extrapolated.component(0) = u_bc.component(0) +
                                        Jac_u.component(tensor::XX) * Di.component(0) +
                                        Jac_u.component(tensor::XY) * Di.component(1) +
                                        Jac_u.component(tensor::XZ) * Di.component(2);

        u_b_extrapolated.component(1) = u_bc.component(1) +
                                        Jac_u.component(tensor::YX) * Di.component(0) +
                                        Jac_u.component(tensor::YY) * Di.component(1) +
                                        Jac_u.component(tensor::YZ) * Di.component(2);

        u_b_extrapolated.component(2) = u_bc.component(2) +
                                        Jac_u.component(tensor::ZX) * Di.component(0) +
                                        Jac_u.component(tensor::ZY) * Di.component(1) +
                                        Jac_u.component(tensor::ZZ) * Di.component(2);

        u_b[i] = u_b_extrapolated - (u_b_extrapolated & normal) * normal;

    }

    //Info << u_b << endl;

    fixedValueFvPatchVectorField::updateCoeffs();     // updated_ = true

}
开发者ID:JonasBuenger,项目名称:myFoamStuff,代码行数:56,代码来源:myVelocityFvPatchVectorField.C


示例17: error

//******************************************************************************
//Name:  SetTensor                                                             *
//                                                                             *
//Purpose:  Set the tensor portion of the field                                *
//                                                                             *
//Takes: takes a pointer to a position array and the address of the tensor     *
//******************************************************************************
void field::SetTensor(int *indices, const tensor &rval)
{
   int *index;
	int *r_index;
	int i, j, temp;
	double value;

//Error check
	if( rval.p->num_indices != (p->num_indices - 3) )
		error("SetTensor error:","cannot assign the tensor to a field point");

	for(i = 3; i < p->num_indices; i++)
	{
	  if( rval.p->range[i-3] != p->range[i] )
		  error("SetTensor error:","cannot assign the tensor to a field point");
	}

//set up the index array that indexes into the field and set the specified position
	index = new int[p->num_indices];
   for( i = 0; i < 3; i++) index[i] = indices[i];

//set up the index array that indexes into the rval tensor
	r_index = new int[rval.p->num_indices];

//set the field
	for(i = 0; i < rval.p->product; i++)
	{
		//pack the r_index array (see tensor::Contract)
		temp = 0;
		for(j = 0; j < rval.p->num_indices - 1; j++)
		{
		  r_index[j] = (i - i%rval.p->scales[j] - temp)/rval.p->scales[j];
		  temp += r_index[j] * rval.p->scales[j];
		}

		r_index[j] = (i - temp)/rval.p->scales[j];

		//complete the index array with the tensor indices
		for(j = 3; j < p->num_indices; j++) index[j] = r_index[j - 3];

      value = rval.Val(r_index);

      //put the rval tensors value into the field at specified position
      Set(value,index);
	}

  //Clean up
  delete [] index;
  delete [] r_index;

}
开发者ID:gravmath,项目名称:Projects,代码行数:58,代码来源:field.cpp


示例18: GetTensor

//******************************************************************************
//Name:  GetTensor                                                             *
//                                                                             *
//Purpose:  get the tensor portion of the field given the position             *
//                                                                             *
//Takes: position stored as a tensor                                           *
//******************************************************************************
tensor field::GetTensor(const tensor &pos)
{

   int i;
   double position[3];

   tensor temp;

   for( i = 0; i < 3; i++ ) position[i] = pos.Val(i);

   temp <= GetTensor(position);

   return temp;
}
开发者ID:gravmath,项目名称:Projects,代码行数:21,代码来源:field.cpp


示例19: scale_rows2

    void scale_rows2 (
        float beta, 
        tensor& out,
        const tensor& m1,
        const tensor& m2,
        const tensor& v1,
        const tensor& v2
    )
    {
        DLIB_CASSERT(have_same_dimensions(out,m1));
        DLIB_CASSERT(have_same_dimensions(out,m2));
        DLIB_CASSERT(have_same_dimensions(v1,v2));
        DLIB_CASSERT(is_vector(mat(v1))); 
        DLIB_CASSERT(v1.size() == m1.num_samples());

#ifdef DLIB_USE_CUDA
        cuda::scale_rows2(beta, out, m1, m2, v1, v2);
#else
        if (beta == 0)
            out = scale_rows(mat(m1) - scale_rows(mat(m2),mat(v1)), mat(v2));
        else
            out = beta*mat(out) + scale_rows(mat(m1) - scale_rows(mat(m2),mat(v1)), mat(v2));
#endif
    }
开发者ID:markpp,项目名称:MTB,代码行数:24,代码来源:tensor_tools.cpp


示例20: hypot

Foam::scalar Foam::finiteRotation::rotAngle(const tensor& rotT)
{
    // Alternative formulation: Daniel Schmode, 15/Feb/2009
    scalar x = rotT.zy() - rotT.yz();
    scalar y = rotT.xz() - rotT.zx();
    scalar z = rotT.yx() - rotT.xy();

    scalar r = hypot(x, hypot(y, z));
    scalar t = tr(rotT);

    return atan2(r, t - 1);
}
开发者ID:CFMS,项目名称:foam-extend-foam-extend-3.2,代码行数:12,代码来源:finiteRotation.C



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ tensor_type类代码示例发布时间:2022-05-31
下一篇:
C++ tendrils类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap