小编Fyt*_*tch的帖子

是`template <typename>;`legal C++?

GCCClangtemplate<typename>;在全球范围内是否是C++中的有效声明存在分歧.

我希望在C++标准中不允许它,因为模板化属于声明语句,而不是表达式语句,因此也不属于null语句(语句;).

那么,这是Clang中的一个错误吗?

c++ grammar templates declaration language-lawyer

16
推荐指数
2
解决办法
915
查看次数

使用本征和std :: vector的SIGSEGV

我知道将Eigen类型与动态内存结合使用时会出现对齐问题。因此,我决定Eigen::DontAlign 根据此页面禁用向量化,但是以下代码仍在执行时一致地引发SIGSEGV。如果有人可以阐明为什么会发生,我会很高兴。从我的角度来看,使用Eigen::DontAlign应该使我摆脱了对齐的复杂性。

#include <Eigen/Dense>
#include <vector>

int main()
{
    using vec_t = Eigen::Matrix< double, 4, 1, Eigen::DontAlign >;
    std::vector< vec_t > foo;
    foo.emplace_back( 0.0, 0.0, 0.0, 1.0 );
    vec_t vec{ -4.0, 1.0, 3.0, 1.0 };
    foo.push_back( vec );
}
Run Code Online (Sandbox Code Playgroud)

GDB输出:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000408bed in Eigen::internal::evaluator<Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 1, 2, 4, 1> > >::packet<0, double __vector(4)>(long long, long long) const (this=0x22fa90, row=0, col=0)
    at C:/Dev/Eigen/Eigen/src/Core/CoreEvaluators.h:197
197           return ploadt<PacketType, LoadMode>(m_data + row + col * …
Run Code Online (Sandbox Code Playgroud)

c++ vectorization memory-alignment eigen c++11

5
推荐指数
1
解决办法
715
查看次数

如何有效地转置非方形矩阵?

我做了一个矩阵类,我想实现一个转置方法:

template<typename T>
void Matrix<T>::Transpose()
{
    // for square matrices
    if(this->Width() == this->Height())
    {
        for(std::size_t y = 1; y < this->Height(); ++y)
        {
            for(std::size_t x = 0; x < y; ++x)
            {
                // the function operator is used to access the entries of the matrix
                std::swap((*this)(x, y), (*this)(y, x));
            }
        }
    }
    else
    {
        // TODO
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是如何在不分配全新矩阵(该类用于大密集矩阵)的情况下实现非平方矩阵的转置方法,而是在其中.还有办法吗?

c++ performance matrix linear-algebra

3
推荐指数
1
解决办法
672
查看次数