GithubHelp home page GithubHelp logo

Assignment of Expression to Tensor of Incorrect Dimensions - Strange Error - Numpy Unable to Allocate very Large Array about xtensor-python HOT 4 OPEN

stellarpower avatar stellarpower commented on May 24, 2024
Assignment of Expression to Tensor of Incorrect Dimensions - Strange Error - Numpy Unable to Allocate very Large Array

from xtensor-python.

Comments (4)

tdegeus avatar tdegeus commented on May 24, 2024

Most functions do not have compile-time checks for this. There could indeed be static assertions for many functions that are easy or less easy to write, but for the moment this is not xtensor's policy. There are run-time assertions I believe. You could compile with XTENSOR_ENABLE_ASSERT which should fire a runtime error : https://xtensor.readthedocs.io/en/latest/dev-build-options.html#build

As background information, it seems that upon construction the 2d return array tries to read the second dimension of vector. Since it is not part of vector's memory you simply get rubbish.

from xtensor-python.

stellarpower avatar stellarpower commented on May 24, 2024

Yes sorry, the C-T checking was just an aside; this example just illustrates why I like it and why it generates frustration to leave things to runtime.

I am using xtensor and the python module from conda-forge, updated the above with versions.

Just realised whilst describing this to a friend - is this a problem with the shape types? I assume the insane size NumPy wants to allocate is due to junk on the stack. Has it run pat the end of the std::array, expecting it to have two elements, but as a vector expression, size() is returning an array with just one? If so, I'd expect whichever side is responsible (python or BLAS) to be checking both for dimensional consistency of the shape, but also that the length of the shape (i.e. number of dimensions) is suitable.

from xtensor-python.

stellarpower avatar stellarpower commented on May 24, 2024

I also noted there's nothing stopping me from writing:

xt::pytensor<int, 1> a(...);
xt::pytensor<int, 2> b(...);
a = b;

Or equally the same with regular xtensors. I'd assumed that as they're templated this should be illegal - is everything checked at runtime rather than compile-time then?

from xtensor-python.

tdegeus avatar tdegeus commented on May 24, 2024

Indeed!

Personally, I'm not strictly against adding compile-time assertions. However, it would increase compile time, and I find this already somewhat long on many occasions. For me run-time assertions offer enough safety : I just run once with xtensor assertions and then never again. However, if you are willing to make the case of compile-time assertions and think about implementation I will for sure not stop you ;)

from xtensor-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.