Comments (10)
you can assign views to views, like
xt::view(channels, 0) = xt::view(....)
from xtensor.
you can assign views to views, like
xt::view(channels, 0) = xt::view(....)
I can't get something like this to work. See #2748. Any ideas?
from xtensor.
channels
needs to be an evaluated expression for having this work.
from xtensor.
you can assign views to views, like
xt::view(channels, 0) = xt::view(....)
If I get this correctly, it compiles, but crashes on assignment:
auto channels = xt::empty<uint16_t>({ 4, activeAreaImageHeight * activeAreaImageWidth / 4 });
auto ch0 = xt::view(activeAreaImageR1, xt::range(0, 2));
auto ch01d = xt::reshape_view(ch0, { activeAreaImageHeight * activeAreaImageWidth / 4 });
xt::view(channels, 0) = ch0;
channels
needs to be an evaluated expression for having this work.
Sorry, I probably didn't get the idea, because this does not work:
auto channels = xt::eval(xt::empty<uint16_t>({ 4, activeAreaImageHeight * activeAreaImageWidth / 4 }));
channels[0] = xt::eval(xt::view(activeAreaImageR1, xt::range(0, 2)));
With any combinations of xt::eval it tells me this:
from xtensor.
The first snippet should not build since you still try to assign to a view on an unevaluated expression.
Regading the second one, be carefull that operator[]
in xtensor is different from operator[]
in numpy, see https://github.com/compiler-research/xeus-cpp/actions/runs/6892192995/job/18748906995?pr=19 for the different ways to access elements in xensor expressions. The following should work:
auto channels = xt::eval(xt::empty<uint16_t>({ 4, activeAreaImageHeight * activeAreaImageWidth / 4 }));
xt::view(channels, 0) = xt::eval(xt::view(activeAreaImageR1, xt::range(0, 2)));
(assuming the shapes are compatible).
from xtensor.
The first snippet should not build since you still try to assign to a view on an unevaluated expression.
First variant compiles, but crashes on execution of last line.
see https://github.com/compiler-research/xeus-cpp/actions/runs/6892192995/job/18748906995?pr=19
Wrong link, probably?
This compiles (added reshape), but crashes on execution
auto channels = xt::eval(xt::empty<uint16_t>({ 4, activeAreaImageHeight * activeAreaImageWidth / 4 }));
xt::view(channels, 0) = xt::eval(xt::reshape_view(xt::view(activeAreaImageR1, xt::range(0, 2)), { activeAreaImageHeight * activeAreaImageWidth / 4 }));
from xtensor.
Wrong link, probably?
Indeed, sorry for that, here is the correct one: https://xtensor.readthedocs.io/en/latest/expression.html#element-access
This compiles (added reshape), but crashes on execution
Can you print the shapes of both expressions in the last statement? No need for xt::eval
on the right hand side.
from xtensor.
Can you print the shapes of both expressions in the last statement? No need for
xt::eval
on the right hand side.
If I got you correctly (sorry if no), this
auto channels = xt::eval(xt::empty<uint16_t>({ 4, activeAreaImageHeight * activeAreaImageWidth / 4 }));
auto reshapedView = xt::reshape_view(xt::view(activeAreaImageR1, xt::range(0, 2)), { activeAreaImageHeight * activeAreaImageWidth / 4 });
auto shape1 = reshapedView.shape();
auto shape2 = xt::view(channels, 0).shape();
from xtensor.
OK, so the shpaes are compatible, I would try the following:
auto channels = xt::eval(xt::empty<uint16_t>({ 4, activeAreaImageHeight * activeAreaImageWidth / 4 }));
auto image_view = xt::eval(xt::view(activeAreaImageR1, xt::range(0, 2)));
auto reshapedView = xt::reshape_view(image_view, { activeAreaImageHeight * activeAreaImageWidth / 4 });
xt::view(channels, 0) = reshaped_view;
and the following:
auto channels = xt::eval(xt::empty<uint16_t>({ 4, activeAreaImageHeight * activeAreaImageWidth / 4 }));
auto image_view = xt::eval(xt::view(activeAreaImageR1, xt::range(0, 2)));
auto reshapedView = xt::eval(xt::reshape_view(image_view, { activeAreaImageHeight * activeAreaImageWidth / 4 }));
xt::view(channels, 0) = reshaped_view;
to see where it crashes. You should also check how activeAreaImageR1
is initialized, and its shape.
from xtensor.
This
auto channels = xt::eval(xt::empty<uint16_t>({ 4, activeAreaImageHeight * activeAreaImageWidth / 4 })); auto image_view = xt::eval(xt::view(activeAreaImageR1, xt::range(0, 2))); auto reshapedView = xt::reshape_view(image_view, { activeAreaImageHeight * activeAreaImageWidth / 4 }); xt::view(channels, 0) = reshaped_view;
And this:
auto channels = xt::eval(xt::empty<uint16_t>({ 4, activeAreaImageHeight * activeAreaImageWidth / 4 })); auto image_view = xt::eval(xt::view(activeAreaImageR1, xt::range(0, 2))); auto reshapedView = xt::eval(xt::reshape_view(image_view, { activeAreaImageHeight * activeAreaImageWidth / 4 })); xt::view(channels, 0) = reshaped_view;
on this line:
auto reshapedView = xt::eval(xt::reshape_view(image_view, { activeAreaImageHeight * activeAreaImageWidth / 4 }));
You should also check how
activeAreaImageR1
is initialized, and its shape.
Full code:
uint16_t* sourceBuffer = new uint16_t[sourceFileInfo->metadata->dataSize / sizeof(uint16_t)];
FILE* fileptr;
fileptr = fopen(filePath.toStdString().c_str(), "rb");
if (fileptr == nullptr) return;
fseek(fileptr, sourceFileInfo->metadata->dataOffset, SEEK_SET);
fread(sourceBuffer, sizeof(uint16_t), sourceFileInfo->metadata->dataSize / sizeof(uint16_t), fileptr);
fclose(fileptr);
std::vector shape = { sourceFileInfo->metadata->dataSize / sizeof(uint16_t) };
QList<int> activeArea = sourceFileInfo->metadata->activeArea;
int activeAreaImageHeight = activeArea[2] - activeArea[0];
int activeAreaImageWidth = activeArea[3] - activeArea[1];
auto source = xt::adapt(sourceBuffer, sourceFileInfo->metadata->dataSize / sizeof(uint16_t), xt::no_ownership(), shape);
source.reshape({ sourceFileInfo->metadata->imageHeight, sourceFileInfo->metadata->imageWidth });
auto activeAreaImage = xt::view(source, xt::range(activeArea[0], activeArea[2]), xt::range(activeArea[1], activeArea[3]));
auto activeAreaImageR1 = xt::view(activeAreaImage, xt::all(), 2);
xt::reshape_view(activeAreaImageR1, { -1 });
xt::xarray<uint16_t> activeAreaImageR2 = xt::view(activeAreaImage, xt::range(1, 2));
xt::reshape_view(activeAreaImageR2, { -1 });
and then the code with problems from original question
from xtensor.
Related Issues (20)
- [Bug] Error when using vstack with mixed shape type HOT 1
- Can't find functions finding the maximum and minimum values and indices of the entire matrix HOT 3
- Adding `xt::reshape` like `reshape` intrinsic in Fortran HOT 11
- View sizes mismatch when assigning view to another view HOT 5
- `xt::real(...)` crashes the program when printed to `cout` HOT 1
- [C++20] Module and Concepts HOT 2
- update for xsimd 13 HOT 4
- arm64 build timing out on test_xblockwise_reducer.cpp HOT 1
- [Performance] Sub-optimal performance on means of strided axes
- Linear algebra operators HOT 1
- Buggy behaviour of non-contiguous xadaptor and scalar assignment
- saturation arithmetic?
- Tensor View Operations Slower Than Manual Looping
- How can I compile xtensor with gcc-7.5 HOT 5
- Avoiding template explosion on views HOT 4
- Performance issue possibly related to returning C-style adaptor from function
- Non-conformant testing of template-template-args c++ standard feature HOT 1
- transpose slower than numpy
- xt::variance crashes HOT 2
- Unexpected value of `xt::get_rank<xt::xtensor_adaptor>`.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xtensor.