Coder Social home page Coder Social logo

Comments (4)

paboyle avatar paboyle commented on July 18, 2024

Isn't the array template fixed size one dimensional [compile time templated]?

Might work for Nd type indices, but not generally usable; secondly the boost array has really nice
multi-dimensional features and subslicing extents. So it would merge multi1d,2d,3d to Nd neatly
and give subslicing. Just annoyed it hasn't made it into a standard and don't like dependency on boost.

Another thought is that in general I'm getting quite annoyed that vector resize loops
over dimension calling default constructor, giving slow resize. Will benchmark this again,
but for a while I tried (incorrectly) to call reserve and prevent the loop.

If I remember right, it is an implementation issue: the loop is implemented by
i) calling the default constructor once on a temporary if not is_pod.
ii) looping over the whole array using the copy constructor for each element
passing it the temporary.
iii) in the case where the default constructor does nothing, is_pod still says not plain old
data, the empty constructor does nothing to the temporary, but then it loops over the whole
volume copying the temporary that contains junk.

This is avoidable with an "is_pod" enable_if in valarray (and possibly vector haven't checked); but
std::complex is forcing it to still use the slow resize were I to use valarray because it triggers and "is_pod" failure.

So, at some point I may be forced to roll my own "simple" array container that suppresses
initialisation of arrays to junk in resize and initial allocate when is_pod==false.

Question is then whether I make it a multi-dim like boost arrays, or fix to vector like 1d.

from grid.

paboyle avatar paboyle commented on July 18, 2024

This is the sort of offending loop, that creates a default object and issues a loop
of length the allocation EVEN if the default contstructor is trival and thus filling with random junk.
The implementation should be guarded with enable_if<has_trivial_constructor<value_type> > to
avoid the loop when the constructor is empty.

void
resize(size_type __new_size, value_type __x = value_type())
{
if (__new_size < size())
_M_erase_at_end(this->_M_impl._M_start + __new_size);
else
insert(end(), __new_size - size(), __x);
}

from grid.

paboyle avatar paboyle commented on July 18, 2024

sorry for brain dumping Matt -- origin of misunderstanding -- my comments in the
TODO were intended to mean Boost's MultiArray:

http://www.boost.org/doc/libs/1_58_0/libs/multi_array/doc/

which is a very interesting interface.

from grid.

mspraggs avatar mspraggs commented on July 18, 2024

Ah sure, I see what you mean. Yeah std::array won't help for multi-dimensional arrays.

from grid.

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.