Skip to content

Buffer size of strided adapters? #2548

Open
@jdh8

Description

@jdh8

I tried to adapt a splat tensor. However, xtensor threw a runtime error with message xbuffer_storage not resizable. It seems that xtensor expects that buffer size equals to tensor size. I don't think that would be the case with user-provided strides.

#include <xtensor/xadapt.hpp>
#include <xtensor/xio.hpp>
#include <array>

int main()
{
  const float data = 1;
  const std::array<int, 2> shape = { 2, 2 };
  const std::array<int, 2> strides = { 0, 0 };

  // Expected
  std::cout << xt::adapt(&data, 1, xt::no_ownership(), shape, strides) << '\n';

  // Actual working
  std::cout << xt::adapt(&data, 4, xt::no_ownership(), shape, strides) << '\n';
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions