Questions tagged [xtensor]

xtensor is a C++ library meant for numerical analysis with multi-dimensional array expressions.

xtensor is a C++ library meant for numerical analysis with multi-dimensional array expressions.

xtensor provides

  • an extensible expression system enabling lazy broadcasting.
  • an API following the idioms of the C++ standard library.
  • tools to manipulate array expressions and build upon xtensor.

Containers of xtensor are inspired by NumPy, the Python array programming library. Adaptors for existing data structures to be plugged into our expression system can easily be written.

In fact, xtensor can be used to process NumPy data structures inplace using Python’s buffer protocol.[1]

Resources


[1] | Reference - http://quantstack.net/xtensor

84 questions
7
votes
2 answers

How to convert an xarray to std::vector?

The docs make it quite clear on how to adapt a std::vector to a tensor object. https://xtensor.readthedocs.io/en/latest/adaptor.html std::vector v = {1., 2., 3., 4., 5., 6. }; std::vector shape = { 2, 3 }; auto a1 = xt::adapt(v,…
Tom
  • 1,235
  • 9
  • 22
7
votes
2 answers

Set include-path for header only library installed with conda

I was recently advised to check out conda as a package manager. Unfortunately I don't succeed in finding how to make my compiler find a header-only library installed with conda? Ideally I would like to not having to manually specify a path to my…
Tom de Geus
  • 5,625
  • 2
  • 33
  • 77
5
votes
2 answers

how to fill xtensor array with data using a pointer

I am trying to create a xtensor array from a blob data in caffe library. A pointer to data is returned using the function mutable_cpu_data() in caffe for example by float* data = output->mutable_cpu_data();. Is this possible with xtensor? If yes,…
max
  • 2,627
  • 1
  • 24
  • 44
5
votes
1 answer

example usage of xt::where for xtensor C++

I am new to the xtensor. I am wondering how one would use the output from xt::where. In python, for example assuming imap is an nd array, np.where(imap>=4) returns two arrays with indices and can be assigned directly using the = operator. Please let…
Achyut Sarma
  • 119
  • 7
4
votes
1 answer

Numpy vs Eigen vs Xtensor Linear Algebra Benchmark Oddity

I recently was trying to compare different python and C++ matrix libraries against each other for their linear algebra performance in order to see which one(s) to use in an upcoming project. While there are multiple types of linear algebra…
stillQuestioning
  • 105
  • 3
  • 10
4
votes
1 answer

xtensor's "operator/" slower than numpy's "/"

I'm trying to transfer some code I've previously written in python into C++, and I'm currently testing xtensor to see if it can be faster than numpy for doing what I need it to. One of my functions takes a square matrix d and a scalar alpha, and…
abic011
  • 43
  • 5
4
votes
1 answer

Copying views in xtensor

Is there a function similar to numpy copy for copying views? If not, what is the simplest way to deep copy complex views? The copy constructor still points to the same internal values, which is fine most of the times, but there are times when a deep…
Hajdu Gábor
  • 329
  • 1
  • 12
3
votes
1 answer

How to build header only C++ library within Bazel workspace?

I'm working on a C++ project and I need Numpy like arrays and functionalities in C++. I found some alternatives like xtensor, NumCpp etc. These are header only libraries. The problem is I'm experimenting with Bazel for the first time so, I don't…
Jema
  • 65
  • 1
  • 9
3
votes
1 answer

xtensor and xsimd: improve performance on reduction

I'm trying to get the same performance with xtensor on the reduction operations (e.g. sum of elements) as in NumPy. I enable xsimd for parallel computing, but it has no effect. The following is the benchmark code: #include #include…
Ashot Matevosyan
  • 2,349
  • 1
  • 9
  • 11
3
votes
1 answer

Performance of xtensor types vs. NumPy for simple reduction

I was trying out xtensor-python and started by writing a very simple sum function, after using the cookiecutter setup and enabling SIMD intrinsics with xsimd. inline double sum_pytensor(xt::pytensor &m) { return xt::sum(m)(); } inline…
Eric Hansen
  • 1,749
  • 2
  • 19
  • 39
3
votes
2 answers

Assigning in high-dimensional Xtensor arrays

I am using the Xtensor library for C++. I have a xt::zeros({n, n, 3}) array and I would like to assign the its i, j, element an xt::xarray{ , , } so that it would store a 3D dimensional vector at each (i, j). However the documentation does not…
msx
  • 555
  • 1
  • 5
  • 11
2
votes
1 answer

Move C-style array into `xt::array` from xtensor

I am using stb image library to load a image into C-style contiguous array. I want to move this array into a xtensor style xtensor or xarray with xt::adapt. Here is the demonstration code: // It must be C-stype array because stb is C…
Lion Lai
  • 1,862
  • 2
  • 20
  • 41
2
votes
1 answer

Xtensor random::randn returning number number below lower bound and above upper bound

I am trying to generate random numbers of shape {10} and range between -0.5 and 0.5 #include #include #include int main() { xt::xarray a = xt::random::randn({10}, -0.5, 0.5); …
2
votes
1 answer

xtensor: assigning view to double

I'm trying to implement a rolling mean ala pandas via the xtensor library. However I'm unable to assign the expression xt::mean(x_window) to the double result[i]. #include #include #include #include…
marital_weeping
  • 618
  • 5
  • 18
2
votes
1 answer

xtensor equivalent of numpy a[a>3] = 1

Title says it - what is the xtensor equivalent of numpy's # set all elements > 3 to 1 sometensor[sometensor > 3] = 1 ? It looks like xt::filter works: xt::filter(sometensor, sometensor > 3) = 1 But it also looks like the numpy version is much…
Colin
  • 3,670
  • 1
  • 25
  • 36
1
2 3 4 5 6