Changeset 1130 for cpp/frams/model


Ignore:
Timestamp:
04/16/21 15:55:34 (3 years ago)
Author:
Maciej Komosinski
Message:

Used std::min(), std::max() explicitly to avoid compiler confusion. Used std::size() explicitly instead of the equivalent macro

Location:
cpp/frams/model
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/autoname.cpp

    r973 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
    55#include "autoname.h"
    6 #include "common/nonstd_stl.h"
     6#include <algorithm>
    77#include <ctype.h>
    88
     
    100100        if (model.getPartCount() > 0)
    101101        {
    102                 cialo = min((int)(sqrt(double(model.getPartCount()) - 1) * NAME_BODYLEN), NAME_MAXLENBODY - 1);
     102                cialo = std::min((int)(sqrt(double(model.getPartCount()) - 1) * NAME_BODYLEN), NAME_MAXLENBODY - 1);
    103103                poz = 0;
    104104                for (i = 0; i <= cialo; i++) // budowanie "opisu" ciala
     
    106106                        nextpoz = ((model.getPartCount()) * (i + 1)) / (cialo + 1) - 1;
    107107                        w = 1.0;
    108                         for (; poz <= nextpoz; poz++) w = max(w, model.getPart(poz)->mass);
    109                         tmpc[i] = Sp[min(int((w - 1.0) * NAME_BODYMASS), int(sizeof(Sp)) - 2)];
     108                        for (; poz <= nextpoz; poz++) w = std::max(w, model.getPart(poz)->mass);
     109                        tmpc[i] = Sp[std::min(int((w - 1.0) * NAME_BODYMASS), int(sizeof(Sp)) - 2)];
    110110                }
    111111                tmpc[i] = 0;
     
    117117        if (model.getNeuroCount() > 0)
    118118        {
    119                 mozg = min((int)(sqrt((double)model.getNeuroCount()) * NAME_BRAINLEN), NAME_MAXLENBRAIN - 1);
     119                mozg = std::min((int)(sqrt((double)model.getNeuroCount()) * NAME_BRAINLEN), NAME_MAXLENBRAIN - 1);
    120120                poz = 0;
    121121                for (i = 0; i <= mozg; i++) // budowanie "opisu" mozgu
     
    123123                        nextpoz = (model.getNeuroCount() * (i + 1)) / (mozg + 1) - 1;
    124124                        wint = 0;
    125                         for (; poz <= nextpoz; poz++) wint = max(wint, model.getNeuro(poz)->getInputCount());
    126                         tmpm[i] = Sam[min(int(wint * NAME_BRAININP), int(sizeof(Sam)) - 2)];
     125                        for (; poz <= nextpoz; poz++) wint = std::max(wint, model.getNeuro(poz)->getInputCount());
     126                        tmpm[i] = Sam[std::min(int(wint * NAME_BRAININP), int(sizeof(Sam)) - 2)];
    127127                }
    128128                tmpm[i] = 0;
  • cpp/frams/model/model.h

    r1118 r1130  
    1313#include <frams/util/advlist.h>
    1414#include <frams/util/usertags.h>
     15#include <common/nonstd_stl.h>
    1516
    1617extern ParamEntry f0_model_paramtab[];
  • cpp/frams/model/similarity/EMD/emd.c

    r1064 r1130  
    1919#include <stdlib.h>
    2020#include <math.h>
     21#include <algorithm>
    2122
    2223#include "emd.h"
     
    100101{
    101102  int itr;
    102   int max_n = max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have.
     103  int max_n = std::max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have.
    103104  double totalCost;
    104105  float w;
     
    211212{
    212213  int i, j;
    213   int max_n = max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have.
     214  int max_n = std::max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have.
    214215  double sSum, dSum, diff;
    215216  feature_t *P1, *P2;
     
    474475{
    475476    int i, j, k;
    476     int max_n = max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have.
     477    int max_n = std::max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have.
    477478    double xMin;
    478479    int steps;
     
    555556{
    556557  int i, steps;
    557   int max_n = max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have.
     558  int max_n = std::max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have.
    558559  node2_t **CurX, *NewX;
    559560  char *IsUsed=new char[2*max_n];
     
    652653{
    653654  int i, j, found, minI, minJ;
    654   int max_n = max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have.
     655  int max_n = std::max(_n1, _n2); //max_n was introduced in r1062 instead of the #defined constant MAX_SIG_SIZE1=1000 in the original implementation. max_n is better than the constant, but it would be even better to use either _n1 or _n2, if we only knew what size each individual array should precisely have.
    655656  double deltaMin, oldVal, diff;
    656657  double** Delta = new double*[_n1];
  • cpp/frams/model/similarity/measure-distribution.cpp

    r1125 r1130  
    7979        //int size = sampled.getPartCount();
    8080        //if (size < (int) sqrt((double) std::numeric_limits<int>::max())) //prevent exceeding int limits
    81         //      samples_taken = min(samples_num, size*size);
     81        //      samples_taken = std::min(samples_num, size*size);
    8282
    8383        rndgen.seed(55); //For determinism. Otherwise the descriptors (that choose samples pseudo-randomly) for the same Model can yield different values and so the dissimilarity between the object and its copy will not be 0.
Note: See TracChangeset for help on using the changeset viewer.