Coder Social home page Coder Social logo

Iterating w/ speed in mind about grid_map HOT 4 CLOSED

stonier avatar stonier commented on September 3, 2024
Iterating w/ speed in mind

from grid_map.

Comments (4)

pfankhauser avatar pfankhauser commented on September 3, 2024 1

Here's also an updated version of your example for the fastest execution that I have been able to achieve yet:

grid_map::Matrix& data_layer_one = my_grid_map.get("layer_one");
grid_map::Matrix& data_layer_two = my_grid_map.get("layer_two");
for (grid_map::GridMapIterator iterator(my_grid_map); !iterator.isPastEnd(); ++iterator) {
  const int i = iterator.getLinearIndex();
  // do something with data_layer_one(i);
  // do something with data_layer_two(i);
}

Here we make use of the linear index access of Eigen matrices to maximize performance.

from grid_map.

pfankhauser avatar pfankhauser commented on September 3, 2024

Thanks for your comments. You are right that the performance can be increased when locally storing a reference or copy of the data layer. There's actually a node that runs a performance comparison:

rosrun grid_map_demos iterator_benchmark

In this example, we iterate through a grid map and copy the data from one layer into another if it is bigger in value. For a map of size 5000 x 5000 cells (25 mio. cells), the performance can be improved from the convenient usage of the iterator to the optimized usage from 1350 ms to 135 ms.

I have updated the documentation to highlight this here: https://github.com/ethz-asl/grid_map#iterators

Does this clarify your question?

from grid_map.

stonier avatar stonier commented on September 3, 2024

Does this clarify your question?

Yes, and thanks for the pointer about the getLinearIndex().

You might like to add a comment to the iterators demo program - many programmers (myself included in this situation) tend to go directly to code before documents when it comes to discovering how to do something specific.

from grid_map.

pfankhauser avatar pfankhauser commented on September 3, 2024

Yes, good idea, thanks.

from grid_map.

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.