Giter VIP home page Giter VIP logo

Comments (9)

bluescarni avatar bluescarni commented on July 23, 2024

A sparsity pattern is a vector of pairs. So when one inits a sparsity pattern with the syntax {{}}, what happens is that a vector of one value-initialized pair is created: [[0,0]] (because {} is value initialisation, and value initialisation for C++ integrals is equivalent to zero initialisation).

I don't see how we could detect such an occurrence (unless somehow repeated [[0,0]] patterns are invalid? Can't ever remember the details of the sparsity stuff...). Seems to me an unfortunate consequence of equating C++11's initialisation rules with vector-like initialisation (a-la python lists).

from pagmo2.

bluescarni avatar bluescarni commented on July 23, 2024

One possible way to prevent that syntax from working would be to use, instead of std::pair, a custom coded class which prohibits that type of initialization (but otherwise behaves exactly like std::pair).

from pagmo2.

darioizzo avatar darioizzo commented on July 23, 2024

Could we not check in here upon construction of a problem? https://github.com/esa/pagmo2/blob/master/include/pagmo/problem.hpp#L1215 ?

from pagmo2.

darioizzo avatar darioizzo commented on July 23, 2024

Ah ok, now I get your point a [0,0] is created

from pagmo2.

darioizzo avatar darioizzo commented on July 23, 2024

The error is still well phrased when raised, but I was thinking to the possibility of detecting it in check_hessians_sparsity(hs);
Now I understand why its impossible without changing drastically the representation of the sparisty ...

from pagmo2.

bluescarni avatar bluescarni commented on July 23, 2024

Here's a demo of what I mean:

https://godbolt.org/g/suXAtx

(try changing sparsity_pattern1 to sparsity_pattern2 in the main function)

from pagmo2.

darioizzo avatar darioizzo commented on July 23, 2024

Yeps. Nice solution, but I am not sure we want to override the std::pair .... there may be hidden consequences? Like that we have to implement a more complex my_pair class? Also we would need to have the python exp for my_pair ... Is it worth?

from pagmo2.

bluescarni avatar bluescarni commented on July 23, 2024

Personally I don't think it's worth it. It's an unfortunate syntactic quirk, but I'd rather warn about it in the tutorial or something like that.

from pagmo2.

bluescarni avatar bluescarni commented on July 23, 2024

Closing this for the time being, as we established it's not a bug and nobody wants to embark in re-implementing std::pair with the desired behaviour.

from pagmo2.

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.