Git Product home page Git Product logo

Comments (3)

wdeconinck avatar wdeconinck commented on August 16, 2024 2

The idea is that the Field only holds an Array, Metadata and a reference to the FunctionSpace.
Anything like field.levels() is just a shorthand for getting it out of the Metadata via field.metadata().getInt("levels") .
It should indeed be noted that this is not a cheap operation and that you may instead like to:
const idx_t levels = field.levels(); and use levels inside the computational loop, or you can use the array-view's shape function. Even if it was stored as an extra variable, Field contains a FieldImpl* pointer and such indirection will also not be good for performance.
It is also possibly better to extract loop bounds before the computational loop for compilers to have a better chance at optimising.

@odlomax , w.r.t. horizontal indices, this is indeed also in the metadata, and there's a short-hand to get it out:

std::vector<idx_t> Field::horizontal_dimensions() const {
        std::vector<idx_t> h_dim{0};
        metadata().get("horizontal_dimension", h_dim);
        return h_dim;
}

Note that there could be more than 1 horizontal dimension.

from atlas.

odlomax avatar odlomax commented on August 16, 2024

I think the difficulty with having a member variable is that you now have two unsynchronised values which represent levels, i.e. metadata.getInt("levels") and an int in the field object.

Perhaps the performant yet readable solution is to have metadata which defines the horizontal and vertical dimensions of the field, i.e.,

const auto horizDim = metadata.getInt("horizontal dimension", 0);
const auto vertDim = metadata.getInt("vertical dimension", 1);

// could implement `Field::horizontalDim()` and `Field::verticalDim()` to simplify

for (auto horiz = idx_t{0}; horiz < fieldView.shape(horizDim); ++horiz) {
  for (auto vert = idx_t{0}; vert < fieldView.shape(vertDim); ++vert) {
    // some stuff with fieldView(horiz, vert)...
  }
}

@wdeconinck, I think this is something that was discussed last year in Boulder, right?

from atlas.

mo-joshuacolclough avatar mo-joshuacolclough commented on August 16, 2024

Thank you for the comprehensive response @wdeconinck.

Even if it was stored as an extra variable, Field contains a FieldImpl* pointer and such indirection will also not be good for performance.

I hadn't considered this.. In general then it is best to pull this information out of a field prior to looping.
I'll close this issue for now as it's clear that this was the intended design.

from atlas.

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.