簡體   English   中英

xtensor:選擇具有特定字符串列值的行

[英]xtensor: Select rows with specific string column values

我正在采用一種方法來查找具有特定整數值的行( xtensor: Select rows with specific column values )。 adapatation 在 2D xtensor 的第一列中查找字符串值,而不是整數值。

嘗試使用 xt::equal() 時出現編譯錯誤,如下所示。 編譯錯誤是“ binary '+': 'std::basic_string<char,std::char_traits,std::allocator>' 沒有定義此運算符或轉換為文件 xtype_traits.hpp 中預定義運算符可接受的類型"

當 n1 是一個簡單的整數列表時,我不明白為什么編譯器會因為 std::string 問題而拒絕這一行:{1, 0, 0, 0, 0}

#include <vector>
#include <iostream>
#include <string>
#include <numeric>
#include <limits>
#undef max 
#undef min
#define NOMINMAX
#include <xtensor/xtensor.hpp>
#include <xtensor/xview.hpp>
#include <xtensor/xio.hpp>

xt::xtensor <std::string, 2> xtAudit =
{ {"Cell1", "A1", "B1"},
 {"Cell2", "A2", "B2"},
 {"Cell3", "A3", "B3"},
 {"Cell4", "A4", "B4"},
 {"Cell5", "A5", "B5"} };

std::string strCell = "Cell1"; 
auto test1 = xt::equal(xt::view(xtAudit, xt::all(), xt::keep(0)), strCell);
std::cout << test1 << std::endl;

auto n1 = xt::sum(test1, 1);
std::cout << n1 << std::endl;

auto idx1 = xt::flatten_indices(xt::argwhere(xt::equal(n1, 1))); // compile error here with xt::equal()
std::cout << idx1 << std::endl;

auto b1 = xt::view(xtAudit, xt::keep(idx1), xt::all());
std::cout << b1 << std::endl;

直到編譯錯誤的輸出是(我通過注釋掉導致編譯錯誤的行以及其他錯誤來得到這些):

{{true}, {false}, {false}, {false}, {false}}

{1, 0, 0, 0, 0}

對我來說,它看起來可能有一些錯誤。 我不明白為什么test1應該有任何記憶基於std::string之間的相等運算符。 該錯誤似乎與操作的惰性有關 要解決此問題,您可以使用

auto n1 = xt::eval(xt::sum(test1, 1));

我建議您向 xtensor 提交錯誤報告。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM