类型转换std::vector <double>到Eigen::VectorXd?

时间:2018-08-01 16:45:40

标签: c++ visual-studio vector casting eigen3

我一直在网上寻找答案;但是,没有提供的解决了我的问题。

到目前为止,我已经尝试过

#include <Eigen/Dense>
#include <vector>
/*More code goes here*/
...
std::vector<double> _0to99;
/*putting values into the vector*/
Eigen::VectorXi X = Eigen::Map<Eigen::VectorXi>(_0to99.data(), _0to99.size());

但是,Visual Studio告诉我这个错误:

没有构造函数“ Eigen :: Map :: Map [with PlainObjectType = Eigen :: Matrix,MapOptions = 0,StrideType = Eigen :: Stride <0,0>]”的实例与参数列表匹配

'<函数样式转换>':无法从“初始化列表”转换为“ Eigen :: Map>”

任何帮助将不胜感激!祝你有美好的一天!

1 个答案:

答案 0 :(得分:-2)

正如我在https://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.htmlhttps://eigen.tuxfamily.org/dox/classEigen_1_1Map.html中所看到的那样,您的问题是您正在给Eigen :: Map对象的构造函数(其第二个参数是Stride对象)提供一个size_t值。

我认为您想将_0to99.size()作为Eigen :: Map对象的大小的参数传递。所以...解决方案很简单。

// Adds LTV-enabled information to the PDF document.
private ByteArrayOutputStream addLtv(final IOcspClient ocspClient,
                                     final ByteArrayOutputStream docStream)
        throws IOException, GeneralSecurityException {
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    final InputStream signedStream = new ByteArrayInputStream(docStream.toByteArray());
    final PdfReader reader = new PdfReader(signedStream);
    final PdfDocument document =
            new PdfDocument(reader, new PdfWriter(outputStream), new StampingProperties().useAppendMode());
    final LtvVerification verification = new LtvVerification(document);
    final SignatureUtil signatureUtil = new SignatureUtil(document);

    final List<String> signatureNames = signatureUtil.getSignatureNames();
    final String sigName = signatureNames.get(signatureNames.size() - 1);
    final PdfPKCS7 signature = signatureUtil.verifySignature(sigName);

    final CrlClientOnline crl = new CrlClientOnline();
    if (!signature.isTsp()) {
        for (final String name: signatureNames) {
            addVerificationInfo(ocspClient, verification, crl, name);
        }
    } else {
        addVerificationInfo(ocspClient, verification, crl, sigName);
    }

    document.close();

    return outputStream;
}

private void addVerificationInfo(final IOcspClient ocspClient, final LtvVerification verification,
                                 final CrlClientOnline crl,
                                 final String name) throws IOException, GeneralSecurityException {
    verification.addVerification(
            name, ocspClient, crl,
            LtvVerification.CertificateOption.WHOLE_CHAIN,
            LtvVerification.Level.OCSP_CRL,
            LtvVerification.CertificateInclusion.NO);
}

_0to99.size()后的逗号告诉编译器您要调用具有三个参数的Eigen :: Map对象的构造函数。

#include <Eigen/Dense>
#include <vector>
/*More code goes here*/
...
std::vector<double> _0to99;
/*putting values into the vector*/
Eigen::VectorXi X = Eigen::Map<Eigen::VectorXi>(_0to99.data(), _0to99.size(),);

第三个参数的默认值。


最后,我想如果您想使用双打,则希望使用Eigen :: VectorXd而不是Eigen :: VectorXi。