本文整理汇总了C++中eigen::MatrixBase::colwise方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixBase::colwise方法的具体用法?C++ MatrixBase::colwise怎么用?C++ MatrixBase::colwise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::MatrixBase
的用法示例。
在下文中一共展示了MatrixBase::colwise方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: forward_propagation
void forward_propagation(Eigen::MatrixBase<Derived1> const &input,
Eigen::MatrixBase<Derived2> const &weight,
Eigen::MatrixBase<Derived3> const &bias,
Eigen::MatrixBase<Derived4> &output,
bool no_overlap = true,
UnaryFunc func = UnaryFunc())
{
static_assert(std::is_same<Derived1::Scalar, Derived2::Scalar>::value &&
std::is_same<Derived2::Scalar, Derived3::Scalar>::value &&
std::is_same<Derived4::Scalar, Derived4::Scalar>::value,
"Data type of matrix input, weight, bias and output should be the same");
if(input.rows() != 0 && weight.rows() != 0 &&
bias.rows() != 0){
if(no_overlap){
output.noalias() = weight * input;
}else{
output = weight * input;
}
using Scalar = typename Derived3::Scalar;
using MatType = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>;
using Mapper = Eigen::Map<const MatType, Eigen::Aligned>;
Mapper Map(&bias(0, 0), bias.size());
output.colwise() += Map;
func(output);
}
}
示例2:
Eigen::MatrixBase<Eigen::Matrix<typename matrix::Scalar, matrix::Rows + 1, matrix::Rows + 1>> get_rigid_transform(
const Eigen::MatrixBase<matrix>& a,
const Eigen::MatrixBase<matrix>& b)
{
Eigen::Matrix<typename matrix::Scalar, matrix::Rows + 1, matrix::Rows + 1> transform =
Eigen::Matrix<typename matrix::Scalar, matrix::Rows + 1, matrix::Rows + 1>::Identity();
auto centroid_a = a.colwise() - a.rowwise().mean();
auto centroid_b = b.colwise() - b.rowwise().mean();
auto svd = (centered_a * centered_b.transpose()).eval().jacobiSVD(Eigen::ComputeFullU | Eigen::ComputeFullV);
auto U = svd.matrixU();
auto V = svd.matrixV();
auto R = (V * U.transpose()).eval();
auto C = Eigen::Matrix<typename matrix::Scalar, matrix::Rows, matrix::Rows>::Identity().eval();
C(matrix::Rows - 1, matrix::Rows - 1) = R.determinant();
R = V * C * U.transpose();
auto T = -R * centroid_a + centroid_b;
transform.block<matrix::Rows, matrix::Rows>(0, 0) = R;
transform.block<matrix::Rows, 1>(0, matrix::Rows) = T;
return transform;
}
示例3: assert
void igl::copyleft::offset_surface(
const Eigen::MatrixBase<DerivedV> & V,
const Eigen::MatrixBase<DerivedF> & F,
const isolevelType isolevel,
const typename Derivedside::Scalar s,
const SignedDistanceType & signed_distance_type,
Eigen::PlainObjectBase<DerivedSV> & SV,
Eigen::PlainObjectBase<DerivedSF> & SF,
Eigen::PlainObjectBase<DerivedGV> & GV,
Eigen::PlainObjectBase<Derivedside> & side,
Eigen::PlainObjectBase<DerivedS> & S)
{
typedef typename DerivedV::Scalar Scalar;
typedef typename DerivedF::Scalar Index;
{
Eigen::AlignedBox<Scalar,3> box;
typedef Eigen::Matrix<Scalar,1,3> RowVector3S;
assert(V.cols() == 3 && "V must contain positions in 3D");
RowVector3S min_ext = V.colwise().minCoeff().array() - isolevel;
RowVector3S max_ext = V.colwise().maxCoeff().array() + isolevel;
box.extend(min_ext.transpose());
box.extend(max_ext.transpose());
igl::voxel_grid(box,s,1,GV,side);
}
const Scalar h =
(GV.col(0).maxCoeff()-GV.col(0).minCoeff())/((Scalar)(side(0)-1));
const Scalar lower_bound = isolevel-sqrt(3.0)*h;
const Scalar upper_bound = isolevel+sqrt(3.0)*h;
{
Eigen::Matrix<Index,Eigen::Dynamic,1> I;
Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,3> C,N;
igl::signed_distance(
GV,V,F,signed_distance_type,lower_bound,upper_bound,S,I,C,N);
}
igl::flood_fill(side,S);
DerivedS SS = S.array()-isolevel;
igl::copyleft::marching_cubes(SS,GV,side(0),side(1),side(2),SV,SF);
}
示例4: bounding_box
IGL_INLINE void igl::bounding_box(
const Eigen::MatrixBase<DerivedV>& V,
const typename DerivedV::Scalar pad,
Eigen::PlainObjectBase<DerivedBV>& BV,
Eigen::PlainObjectBase<DerivedBF>& BF)
{
using namespace std;
const int dim = V.cols();
const auto & minV = V.colwise().minCoeff().array()-pad;
const auto & maxV = V.colwise().maxCoeff().array()+pad;
// 2^n vertices
BV.resize((1<<dim),dim);
// Recursive lambda to generate all 2^n combinations
const std::function<void(const int,const int,int*,int)> combos =
[&BV,&minV,&maxV,&combos](
const int dim,
const int i,
int * X,
const int pre_index)
{
for(X[i] = 0;X[i]<2;X[i]++)
{
int index = pre_index*2+X[i];
if((i+1)<dim)
{
combos(dim,i+1,X,index);
}else
{
for(int d = 0;d<dim;d++)
{
BV(index,d) = (X[d]?minV[d]:maxV[d]);
}
}
}
};
Eigen::VectorXi X(dim);
combos(dim,0,X.data(),0);
switch(dim)
{
case 2:
BF.resize(4,2);
BF<<
3,1,
1,0,
0,2,
2,3;
break;
case 3:
BF.resize(12,3);
BF<<
2,0,6,
0,4,6,
5,4,0,
5,0,1,
6,4,5,
5,7,6,
3,0,2,
1,0,3,
3,2,6,
6,7,3,
5,1,3,
3,7,5;
break;
default:
assert(false && "Unsupported dimension.");
break;
}
}