SciCompMod / memilio

Modular spatio-temporal models for epidemic and pandemic simulations
https://scicompmod.github.io/memilio/
Apache License 2.0
52 stars 15 forks source link

Use floating point types consistently #1018

Open reneSchm opened 2 months ago

reneSchm commented 2 months ago

Motivation / Current Behaviour

We did not consistently use ScalarType for some time, but now we added a FP ("floating point") template parameter to several classes. Instead of fixing inconsistencies we now have three contenders for a floating point type, each of which being almost exclusively used as double - hence it is not a current problem, but could definitely become one in the future. Below is an example where each type is present, but probably only one (FP) should be used.

We probably want to use FP where available and ScalarType where it is not. The difficulty is, that there may be components that require double explicitly.

Enhancement description

Decide which type to use where. Then make usage of that type consistent.

Additional context

template <typename FP = ScalarType, class... Categories>
class Populations : public CustomIndexArray<UncertainValue<FP>, Categories...>
{
public:

...

    void set_total(ScalarType value)
    {
        double current_population = get_total();
        if (fabs(current_population) < 1e-12) {
            double ysize = double(this->array().size());
            for (size_t i = 0; i < this->get_num_compartments(); i++) {
                this->array()[(Eigen::Index)i] = value / ysize;
            }
        }
        else {
            for (size_t i = 0; i < this->get_num_compartments(); i++) {
                this->array()[(Eigen::Index)i] *= value / current_population;
            }
        }
    }

...

};

Checklist

reneSchm commented 1 month ago

Here I will try to list problems of or around as well as implicit requirements on ScalarType or FP. Solutions or alternatives listed are to be understood as ideas, and should be discussed.