xtensor-stack / xtensor

C++ tensors with broadcasting and lazy computing
BSD 3-Clause "New" or "Revised" License
3.33k stars 398 forks source link

construct an xview of fortran-managed memory #311

Closed phaustin closed 7 years ago

phaustin commented 7 years ago

I'm forced to call c++ from a fortran main program and am wondering if there is there a way to construct an xview from a pointer to contiguous memory and a set of strides.

JohanMabille commented 7 years ago

We provide adaptors for containers that provide an STL-container-like interface but not for pointers to contiguous memory yet. I'm adding this as a feature request.

JohanMabille commented 7 years ago

When #313 is merged, you can do:

#include "xtensor/xadapt.hpp"

// If p is a dynamically allocated array of size s, and the memory is managed by Fortran:
auto adapted = xt::xadapt(p, s, no_ownership(), shape, layout_type::column_major);
// You can used adapted as any other xexpression ...

If shape is an std::array<std::size_t, N>, xadapt returns an xtensor_adaptor, otherwise it returns an xarray_adaptor.

SylvainCorlay commented 7 years ago

@phaustin FYI the PR has been merged.

phaustin commented 7 years ago

Excellent, will be able to use this in a shortcourse I'm teaching next month on multicore-python

SylvainCorlay commented 7 years ago

There will be a release in the next few days with that. We are going to use it in xtensor-python and xtensor-julia.

JohanMabille commented 7 years ago

xtensor 0.10.2 is out and contains this feature.