xtensor 实现 expand
#include <xtensor/xarray.hpp>
#include <xtensor/xbroadcast.hpp>
#include <xtensor/xio.hpp>
#include <xtensor/xview.hpp>
int main() {
// 创建一个形状为 (1, 3) 的 xtensor 数组
using namespace std;
xt::xarray<int> a = {{1, 2, 3}};
// 使用 xtensor 的广播机制将数组扩展为形状 (4, 3)
auto b = xt::broadcast(a, {4, 3});
// 输出原始数组的形状和内容
std::cout << "Input shape: \n";
auto a_shape = a.shape();
// std::cout << xt::adapt(a_shape) << std::endl;
std::cout << "Input array: " << a << std::endl;
// 输出扩展后的数组的形状和内容
std::cout << "Output shape: \n";
// cout << b.shape() << std::endl;
auto b_shape = b.shape();
// std::cout << xt::adapt(b_shape) << std::endl;
std::cout << "Output array: " << b << std::endl;
return 0;
}
g++ -I /home/xxx/modules/xtensor/include -I /home/xx/modules/xtl/include expand_test.cc -o expand_test