Revert size to be unsigned for ArrayRef
authorRoland Schulz <roland.schulz@intel.com>
Wed, 6 Feb 2019 00:08:49 +0000 (16:08 -0800)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 7 Feb 2019 10:42:09 +0000 (11:42 +0100)
Given the decision for std::span to be signed this became
inconsistent with future C++ while already being inconsistent
with std::vector. The goal of the original change, to have
signed variables for all arithmetic including loop indices,
can be achieve by using ssize everwhere arithmethic is used.
ssize is both available as free function (also for std::vector)
and member function.

Related #2826

Change-Id: Icc5d0f9561c610cbce34c575d268171e9890ca9c

43 files changed:
docs/dev-manual/language-features.rst
src/gromacs/awh/biasstate.cpp
src/gromacs/awh/biaswriter.cpp
src/gromacs/awh/coordstate.cpp
src/gromacs/awh/correlationhistory.cpp
src/gromacs/awh/correlationtensor.h
src/gromacs/awh/tests/biasstate.cpp
src/gromacs/domdec/collect.cpp
src/gromacs/domdec/domdec_topology.cpp
src/gromacs/domdec/partition.cpp
src/gromacs/domdec/redistribute.cpp
src/gromacs/ewald/tests/pmetestcommon.cpp
src/gromacs/fileio/readinp.cpp
src/gromacs/fileio/tngio.cpp
src/gromacs/gmxana/gmx_densorder.cpp
src/gromacs/gmxana/gmx_eneconv.cpp
src/gromacs/gmxana/gmx_hydorder.cpp
src/gromacs/gmxana/gmx_make_ndx.cpp
src/gromacs/gmxana/gmx_nmeig.cpp
src/gromacs/gmxana/gmx_trjcat.cpp
src/gromacs/gmxana/thermochemistry.cpp
src/gromacs/gmxpreprocess/readir.cpp
src/gromacs/math/tests/testarrayrefs.h
src/gromacs/mdlib/calc_verletbuf.cpp
src/gromacs/mdlib/constr.h
src/gromacs/mdlib/force.cpp
src/gromacs/mdlib/forcerec.cpp
src/gromacs/mdlib/qmmm.cpp
src/gromacs/mdlib/updategroups.cpp
src/gromacs/mdlib/updategroupscog.cpp
src/gromacs/mdlib/vsite.cpp
src/gromacs/mdrun/multisim.cpp
src/gromacs/mdtypes/state.cpp
src/gromacs/pbcutil/pbc.cpp
src/gromacs/pulling/pull.cpp
src/gromacs/pulling/pull_rotation.cpp
src/gromacs/pulling/pullutil.cpp
src/gromacs/selection/tests/selectioncollection.cpp
src/gromacs/selection/tests/toputils.cpp
src/gromacs/topology/index.cpp
src/gromacs/topology/mtop_util.cpp
src/gromacs/topology/topology.cpp
src/gromacs/utility/arrayref.h

index 0caf0b7163270f48f407595247d92f9e75cf9569..9967416dfc532ca5da9d0a42b32759d10e555be4 100644 (file)
@@ -62,6 +62,8 @@ a release.
   ``dynamic_cast``. For emphasizing type (e.g. intentional integer division)
   use constructor syntax. For creating real constants use the user-defined literal
   _real (e.g. 2.5_real instead of static_cast<real>(2.5)).
+* Use signed integers for arithmetic (including loop indices). Use ssize
+  (available as free function and member of ArrayRef) to avoid casting.
 * Avoid overloading functions unless all variants really do the same
   thing, just with different types. Instead, consider making the
   function names more descriptive.
index 26ac4af4f3764d55ec82af5d0621a672f1263893..8145e4d5e6e4cfefe16a54cfb28f5381819634d8 100644 (file)
@@ -77,7 +77,7 @@ namespace gmx
 
 void BiasState::getPmf(gmx::ArrayRef<float> pmf) const
 {
-    GMX_ASSERT(pmf.size() == index(points_.size()), "pmf should have the size of the bias grid");
+    GMX_ASSERT(pmf.size() == points_.size(), "pmf should have the size of the bias grid");
 
     /* The PMF is just the negative of the log of the sampled PMF histogram.
      * Points with zero target weight are ignored, they will mostly contain noise.
@@ -171,7 +171,7 @@ void sumPmf(gmx::ArrayRef<PointState>  pointState,
 
     /* Take log again to get (non-normalized) PMF */
     double normFac = 1.0/numSharedUpdate;
-    for (gmx::index i = 0; i < pointState.size(); i++)
+    for (gmx::index i = 0; i < pointState.ssize(); i++)
     {
         if (pointState[i].inTargetRegion())
         {
@@ -493,7 +493,7 @@ double BiasState::moveUmbrella(const std::vector<DimParams> &dimParams,
         at steps when the reference value has been moved. E.g. if the ref. value
         is set every step to (coord dvalue +/- delta) would give zero force.
      */
-    for (gmx::index d = 0; d < biasForce.size(); d++)
+    for (gmx::index d = 0; d < biasForce.ssize(); d++)
     {
         /* Average of the current and new force */
         biasForce[d] = 0.5*(biasForce[d] + newForce[d]);
@@ -796,7 +796,7 @@ void labelCoveredPoints(const std::vector<bool> &visited,
                         int                      coverRadius,
                         gmx::ArrayRef<int>       covered)
 {
-    GMX_ASSERT(covered.size() >= numPoints, "covered should be at least as large as the grid");
+    GMX_ASSERT(covered.ssize() >= numPoints, "covered should be at least as large as the grid");
 
     bool haveFirstNotVisited = false;
     int  firstNotVisited     = -1;
index d31ac315c16cf8976bd3c975a001e2538eacddd9..e6e605ea4ed2dfdc51eb6b655906e76d53379b69 100644 (file)
@@ -221,14 +221,14 @@ static void normalizeBlock(AwhEnergyBlock *block, const Bias &bias)
             break;
         case Normalization::FreeEnergy:
             /* Normalize free energy values by subtracting the minimum value */
-            for (gmx::index index = 0; index < data.size(); index++)
+            for (gmx::index index = 0; index < data.ssize(); index++)
             {
                 if (bias.state().points()[index].inTargetRegion() && data[index] < minValue)
                 {
                     minValue = data[index];
                 }
             }
-            for (gmx::index index = 0; index < data.size(); index++)
+            for (gmx::index index = 0; index < data.ssize(); index++)
             {
                 if (bias.state().points()[index].inTargetRegion())
                 {
@@ -263,7 +263,7 @@ void BiasWriter::transferMetaDataToWriter(gmx::index         metaDataIndex,
                                           const Bias        &bias)
 {
     gmx::ArrayRef<float> data = block_[getVarStartBlock(AwhOutputEntryType::MetaData)].data();
-    GMX_ASSERT(metaDataIndex < data.size(), "Attempt to transfer AWH meta data to block for index out of range");
+    GMX_ASSERT(metaDataIndex < data.ssize(), "Attempt to transfer AWH meta data to block for index out of range");
 
     /* Transfer the point data of this variable to the right block(s) */
     switch (metaDataType)
index 8173431b9648671b1e07ebc6ed3bd98455ff26bb..29ebe7d7c3d7fe21a4092110b76c5523df909bfc 100644 (file)
@@ -109,7 +109,7 @@ int getSampleFromDistribution(ArrayRef<const double> distr,
 
     cumulativeDistribution[0] = distr[0];
 
-    for (gmx::index i = 1; i < distr.size(); i++)
+    for (gmx::index i = 1; i < distr.ssize(); i++)
     {
         cumulativeDistribution[i] = cumulativeDistribution[i - 1] + distr[i];
     }
index 195e3d265e0832bba60c2c95de362810f6786a33..aa36bb3e5c903716a8ec0d498d96233422cb27a5 100644 (file)
@@ -134,7 +134,7 @@ void updateCorrelationGridHistory(CorrelationGridHistory *correlationGridHistory
         }
     }
 
-    GMX_RELEASE_ASSERT(bufferIndex == blockDataBuffer.size(), "We should store exactly as many elements as the buffer size");
+    GMX_RELEASE_ASSERT(bufferIndex == blockDataBuffer.ssize(), "We should store exactly as many elements as the buffer size");
 }
 
 void CorrelationBlockData::restoreFromHistory(const CorrelationBlockDataHistory                  &blockHistory,
index 0072d49b944a97c1056e3b42c80a29f1c13a4c81..6d2716e5d618be56aebfa85316c63d30c1bd9283 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -116,7 +116,7 @@ class CorrelationBlockData
         void addData(double                      weight,
                      gmx::ArrayRef<const double> data)
         {
-            GMX_ASSERT(data.size() == gmx::index(coordData_.size()), "Size of data should match the size of coordData");
+            GMX_ASSERT(data.size() == coordData_.size(), "Size of data should match the size of coordData");
 
             blockSumWeight_       += weight;
             blockSumSquareWeight_ += weight*weight;
index 2d65d5be682fc0041b2786ffc16b816bfd35f65c..1dae643d0f9349ae9829aa94a43169097022d07d 100644 (file)
@@ -159,7 +159,7 @@ TEST_P(BiasStateTest, InitializesFromFile)
      * The target is (index + 1)/120.
      */
     double msdPmf    = 0;
-    for (index i = 0; i < points.size(); i++)
+    for (index i = 0; i < points.ssize(); i++)
     {
         msdPmf += gmx::square(points[i].logPmfSum() - points[0].logPmfSum() + 0.5*i) / points.size();
         EXPECT_DOUBLE_EQ(points[i].target(), (i + 1)/120.0);
index 5b9c6d5c07dd55b6770b79c548416fbc9c4333a7..1091872a53a5bfeee588cc0e7a9f183b36b1176c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -119,7 +119,7 @@ static void dd_collect_cg(gmx_domdec_t  *dd,
             fprintf(debug, "Initial charge group distribution: ");
             for (int rank = 0; rank < dd->nnodes; rank++)
             {
-                fprintf(debug, " %td", ma->domainGroups[rank].atomGroups.size());
+                fprintf(debug, " %td", ma->domainGroups[rank].atomGroups.ssize());
             }
             fprintf(debug, "\n");
         }
index 1e9b1c4ef8cec662e6d3fdd307d2bbcd85d0098f..23b7bce5ef8f18afd23bfb12c24ac87409bb0159 100644 (file)
@@ -1141,7 +1141,7 @@ static void combine_blocka(t_blocka                           *dest,
         dest->nalloc_a = over_alloc_large(dest->nra+na);
         srenew(dest->a, dest->nalloc_a);
     }
-    for (gmx::index s = 1; s < src.size(); s++)
+    for (gmx::index s = 1; s < src.ssize(); s++)
     {
         for (int i = dest->nr + 1; i < src[s].excl.nr + 1; i++)
         {
@@ -1168,7 +1168,7 @@ static void combine_idef(t_idef                             *dest,
     for (ftype = 0; ftype < F_NRE; ftype++)
     {
         int n = 0;
-        for (gmx::index s = 1; s < src.size(); s++)
+        for (gmx::index s = 1; s < src.ssize(); s++)
         {
             n += src[s].idef.il[ftype].nr;
         }
@@ -1190,7 +1190,7 @@ static void combine_idef(t_idef                             *dest,
             const int  nral1 = 1 + NRAL(ftype);
             const int  ftv   = ftype - c_ftypeVsiteStart;
 
-            for (gmx::index s = 1; s < src.size(); s++)
+            for (gmx::index s = 1; s < src.ssize(); s++)
             {
                 const t_ilist &ils = src[s].idef.il[ftype];
 
@@ -1226,12 +1226,12 @@ static void combine_idef(t_idef                             *dest,
                 }
 
                 /* Set nposres to the number of original position restraints in dest */
-                for (gmx::index s = 1; s < src.size(); s++)
+                for (gmx::index s = 1; s < src.ssize(); s++)
                 {
                     nposres -= src[s].idef.il[ftype].nr/2;
                 }
 
-                for (gmx::index s = 1; s < src.size(); s++)
+                for (gmx::index s = 1; s < src.ssize(); s++)
                 {
                     const t_iparams *iparams_src = (ftype == F_POSRES ? src[s].idef.iparams_posres : src[s].idef.iparams_fbposres);
 
@@ -1788,7 +1788,7 @@ static void make_exclusions_zone(gmx_domdec_t *dd, gmx_domdec_zones_t *zones,
 
         if (isExcludedAtom)
         {
-            if (n + intermolecularExclusionGroup.size() > lexcls->nalloc_a)
+            if (n + intermolecularExclusionGroup.ssize() > lexcls->nalloc_a)
             {
                 lexcls->nalloc_a =
                     over_alloc_large(n + intermolecularExclusionGroup.size());
index 3a1ea5a7dce8a452068d9f47cd02b4038e60be47..701556db2d97023086fff44ac5762e96c9680df5 100644 (file)
@@ -456,7 +456,7 @@ static void restoreAtomGroups(gmx_domdec_t *dd,
     /* Copy back the global charge group indices from state
      * and rebuild the local charge group to atom index.
      */
-    for (gmx::index i = 0; i < atomGroupsState.size(); i++)
+    for (gmx::index i = 0; i < atomGroupsState.ssize(); i++)
     {
         const int atomGroupGlobal  = atomGroupsState[i];
         const int groupSize        = gcgs_index[atomGroupGlobal + 1] - gcgs_index[atomGroupGlobal];
@@ -2632,7 +2632,7 @@ orderVector(gmx::ArrayRef<const gmx_cgsort_t>  sort,
             gmx::ArrayRef<T>                   vectorToSort,
             std::vector<T>                    *workVector)
 {
-    if (gmx::index(workVector->size()) < sort.size())
+    if (gmx::index(workVector->size()) < sort.ssize())
     {
         workVector->resize(sort.size());
     }
@@ -2844,7 +2844,7 @@ static void dd_sort_state(gmx_domdec_t *dd, rvec *cgcm, t_forcerec *fr, t_state
 
     /* Reorder the state */
     gmx::ArrayRef<const gmx_cgsort_t> cgsort = sort->sorted;
-    GMX_RELEASE_ASSERT(cgsort.size() == dd->ncg_home, "We should sort all the home atom groups");
+    GMX_RELEASE_ASSERT(cgsort.ssize() == dd->ncg_home, "We should sort all the home atom groups");
 
     if (state->flags & (1 << estX))
     {
@@ -2899,7 +2899,7 @@ static void dd_sort_state(gmx_domdec_t *dd, rvec *cgcm, t_forcerec *fr, t_state
     else
     {
         /* Copy the sorted ns cell indices back to the ns grid struct */
-        for (gmx::index i = 0; i < cgsort.size(); i++)
+        for (gmx::index i = 0; i < cgsort.ssize(); i++)
         {
             fr->ns->grid->cell_index[i] = cgsort[i].nsc;
         }
index 5a6d9bbbdf8e62351a6a075a53636bce3ff8799b..f8ade235a7b84a3dd0829b88c27478322ce34be0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -90,7 +90,7 @@ copyMovedAtomsToBufferPerAtom(gmx::ArrayRef<const int> move,
 {
     int pos_vec[DIM*2] = { 0 };
 
-    for (int g = 0; g < move.size(); g++)
+    for (int g = 0; g < move.ssize(); g++)
     {
         const auto atomGroup = atomGroups.block(g);
         /* Skip moved atoms */
@@ -117,7 +117,7 @@ copyMovedChargeGroupCogs(gmx::ArrayRef<const int> move,
 {
     int pos_vec[DIM*2] = { 0 };
 
-    for (int g = 0; g < move.size(); g++)
+    for (int g = 0; g < move.ssize(); g++)
     {
         const auto atomGroup = atomGroups.block(g);
         /* Skip moved atoms */
@@ -138,7 +138,7 @@ copyMovedUpdateGroupCogs(gmx::ArrayRef<const int> move,
 {
     int pos_vec[DIM*2] = { 0 };
 
-    for (int g = 0; g < move.size(); g++)
+    for (int g = 0; g < move.ssize(); g++)
     {
         /* Skip moved atoms */
         const int m = move[g];
@@ -162,7 +162,7 @@ static void clear_and_mark_ind(gmx::ArrayRef<const int>      move,
                                char                         *bLocalCG,
                                int                          *cell_index)
 {
-    for (int g = 0; g < move.size(); g++)
+    for (int g = 0; g < move.ssize(); g++)
     {
         if (move[g] >= 0)
         {
index 625a077afa7dee5a53405a7ddcaaef5f450cbe64..c3fe624c5ca9904fcca3964f0f9bc4ef8d4a7dd8 100644 (file)
@@ -178,7 +178,7 @@ PmeSafePointer pmeInitAtoms(const t_inputrec         *inputRec,
                             )
 {
     const index     atomCount = coordinates.size();
-    GMX_RELEASE_ASSERT(atomCount == charges.size(), "Mismatch in atom data");
+    GMX_RELEASE_ASSERT(atomCount == charges.ssize(), "Mismatch in atom data");
     PmeSafePointer  pmeSafe = pmeInitInternal(inputRec, mode, gpuInfo, pmeGpuProgram, atomCount, box);
     pme_atomcomm_t *atc     = nullptr;
 
@@ -381,7 +381,7 @@ void pmePerformGather(gmx_pme_t *pme, CodePath mode,
 {
     pme_atomcomm_t *atc                     = &(pme->atc[0]);
     const index     atomCount               = atc->n;
-    GMX_RELEASE_ASSERT(forces.size() == atomCount, "Invalid force buffer size");
+    GMX_RELEASE_ASSERT(forces.ssize() == atomCount, "Invalid force buffer size");
     const bool      forceReductionWithInput = (inputTreatment == PmeForceOutputHandling::ReduceWithInput);
     const real      scale                   = 1.0;
     const size_t    threadIndex             = 0;
@@ -447,7 +447,7 @@ void pmeSetSplineData(const gmx_pme_t *pme, CodePath mode,
     const index           atomCount   = atc->n;
     const index           pmeOrder    = pme->pme_order;
     const index           dimSize     = pmeOrder * atomCount;
-    GMX_RELEASE_ASSERT(dimSize == splineValues.size(), "Mismatch in spline data");
+    GMX_RELEASE_ASSERT(dimSize == splineValues.ssize(), "Mismatch in spline data");
     real                 *splineBuffer = pmeGetSplineDataInternal(pme, type, dimIndex);
 
     switch (mode)
@@ -472,7 +472,7 @@ void pmeSetGridLineIndices(const gmx_pme_t *pme, CodePath mode,
 {
     const pme_atomcomm_t       *atc         = &(pme->atc[0]);
     const index                 atomCount   = atc->n;
-    GMX_RELEASE_ASSERT(atomCount == gridLineIndices.size(), "Mismatch in gridline indices size");
+    GMX_RELEASE_ASSERT(atomCount == gridLineIndices.ssize(), "Mismatch in gridline indices size");
 
     IVec paddedGridSizeUnused, gridSize(0, 0, 0);
     pmeGetRealGridSizesInternal(pme, mode, gridSize, paddedGridSizeUnused);
index 0e170aea55e7c448c4c4fa43d7d8a423933f581e..0945a2ef48e0abe87cb9c699ad89a0144d316152 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -282,7 +282,7 @@ int search_einp(gmx::ArrayRef<const t_inpfile> inp, const char *name)
     {
         return -1;
     }
-    for (gmx::index i = 0; i < inp.size(); i++)
+    for (gmx::index i = 0; i < inp.ssize(); i++)
     {
         if (gmx_strcasecmp_min(name, inp[i].name_.c_str()) == 0)
         {
index ee1b2d2e7aa74c0730370b9696b53f512ab33e13..d3a7b7d12b3d8251dc9149f3f1f7a77b8f051f3c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013,2014,2015,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -1297,7 +1297,7 @@ void gmx_tng_setup_atom_subgroup(gmx_tng_trajectory_t     gmx_tng,
 
     tng_num_particles_get(tng, &nAtoms);
 
-    if (nAtoms == ind.size())
+    if (nAtoms == ind.ssize())
     {
         return;
     }
@@ -1307,7 +1307,7 @@ void gmx_tng_setup_atom_subgroup(gmx_tng_trajectory_t     gmx_tng,
     {
         tng_molecule_num_atoms_get(tng, mol, &nAtoms);
         tng_molecule_cnt_get(tng, mol, &cnt);
-        if (nAtoms == ind.size())
+        if (nAtoms == ind.ssize())
         {
             stat = TNG_SUCCESS;
         }
@@ -1323,7 +1323,7 @@ void gmx_tng_setup_atom_subgroup(gmx_tng_trajectory_t     gmx_tng,
         tng_molecule_name_set(tng, mol, name);
         tng_molecule_chain_add(tng, mol, "", &chain);
 
-        for (int i = 0; i < ind.size(); i++)
+        for (int i = 0; i < ind.ssize(); i++)
         {
             char        temp_name[256], temp_type[256];
 
index 2518095ca8e5529f74acfa0a6a162feb35161384..61803865554e8f803b38c24eb3178ca7ce1eb1c0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -775,7 +775,7 @@ int gmx_densorder(int argc, char *argv[])
         gmx::ArrayRef<const std::string> graphFiles = opt2fns("-og", NFILE, fnm);
         if (graphFiles.size() != 2)
         {
-            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", graphFiles.size());
+            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", graphFiles.ssize());
         }
         writesurftoxpms(surf1, surf2, tblock, xslices, yslices, zslices, binw, binwz, graphFiles, zslices);
     }
@@ -790,7 +790,7 @@ int gmx_densorder(int argc, char *argv[])
         gmx::ArrayRef<const std::string> rawFiles = opt2fns("-or", NFILE, fnm);
         if (rawFiles.size() != 2)
         {
-            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", rawFiles.size());
+            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", rawFiles.ssize());
         }
         writeraw(surf1, surf2, tblock, xslices, yslices, rawFiles, oenv);
     }
@@ -803,7 +803,7 @@ int gmx_densorder(int argc, char *argv[])
         if (spectra.size() != 2)
         {
             gmx_fatal(FARGS, "No or not correct number (2) of output-file-series: %td",
-                      spectra.size());
+                      spectra.ssize());
         }
         powerspectavg_intf(surf1, surf2, tblock, xslices, yslices, spectra);
     }
index fd439e1003763b6d334ae70e9ec1311d1c48883a..394c343fb9fb3b0336aca797fc9d4dc4455dbfc8 100644 (file)
@@ -123,10 +123,10 @@ static int *select_it(int nre, gmx_enxnm_t *nm, int *nset)
 
 static void sort_files(gmx::ArrayRef<std::string> files, real *settime)
 {
-    for (gmx::index i = 0; i < files.size(); i++)
+    for (gmx::index i = 0; i < files.ssize(); i++)
     {
         gmx::index minidx = i;
-        for (gmx::index j = i + 1; j < files.size(); j++)
+        for (gmx::index j = i + 1; j < files.ssize(); j++)
         {
             if (settime[j] < settime[minidx])
             {
@@ -244,7 +244,7 @@ static void edit_files(gmx::ArrayRef<std::string> files, real *readtime,
         fprintf(stderr, "          File             Current start       New start\n"
                 "---------------------------------------------------------\n");
 
-        for (gmx::index i = 0; i < files.size(); i++)
+        for (gmx::index i = 0; i < files.ssize(); i++)
         {
             fprintf(stderr, "%25s   %10.3f             ", files[i].c_str(), readtime[i]);
             ok = FALSE;
@@ -295,7 +295,7 @@ static void edit_files(gmx::ArrayRef<std::string> files, real *readtime,
     }
     else
     {
-        for (gmx::index i = 0; i < files.size(); i++)
+        for (gmx::index i = 0; i < files.ssize(); i++)
         {
             settime[i] = readtime[i];
         }
@@ -315,7 +315,7 @@ static void edit_files(gmx::ArrayRef<std::string> files, real *readtime,
     fprintf(stderr, "\nSummary of files and start times used:\n\n"
             "          File                Start time\n"
             "-----------------------------------------\n");
-    for (gmx::index i = 0; i < files.size(); i++)
+    for (gmx::index i = 0; i < files.ssize(); i++)
     {
         switch (cont_type[i])
         {
index 44e84d3480e9c3f20e01798efcc077fb20d1e1ca..2b2ce9572c52e9ad4b14a560dfb1de74ad0eacb2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -665,7 +665,7 @@ int gmx_hydorder(int argc, char *argv[])
     gmx::ArrayRef<const std::string> intfn = opt2fns("-o", NFILE, fnm);
     if (intfn.size() != 2)
     {
-        gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", intfn.size());
+        gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", intfn.ssize());
     }
     calc_tetra_order_interface(ndxfnm, tpsfnm, trxfnm, binwidth, nsttblock, &frames, &xslices, &yslices, sg1, sg2, &intfpos, oenv);
     writesurftoxpms(intfpos, frames, xslices, yslices, binwidth, intfn, nlevels);
@@ -675,7 +675,7 @@ int gmx_hydorder(int argc, char *argv[])
         gmx::ArrayRef<const std::string> spectra = opt2fns("-Spect", NFILE, fnm);
         if (spectra.size() != 2)
         {
-            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", spectra.size());
+            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", spectra.ssize());
         }
         powerspectavg(intfpos, frames, xslices, yslices, spectra);
     }
@@ -685,7 +685,7 @@ int gmx_hydorder(int argc, char *argv[])
         gmx::ArrayRef<const std::string> raw = opt2fns("-or", NFILE, fnm);
         if (raw.size() != 2)
         {
-            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", raw.size());
+            gmx_fatal(FARGS, "No or not correct number (2) of output-files: %td", raw.ssize());
         }
         writeraw(intfpos, frames, xslices, yslices, raw);
     }
index a1ece34082621009d40c838364865a44fc426472..12310fb33006843a3d7775021024fd76c21f313d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -1609,7 +1609,7 @@ int gmx_make_ndx(int argc, char *argv[])
     /* read input file(s) */
     block  = new_blocka();
     gnames = nullptr;
-    printf("Going to read %td old index file(s)\n", ndxInFiles.size());
+    printf("Going to read %td old index file(s)\n", ndxInFiles.ssize());
     if (!ndxInFiles.empty())
     {
         for (const std::string &ndxInFile : ndxInFiles)
index 10b44415ed3d41aef354ddbd3e6ada4c2a0208a9..c153c8afa38bdb9be537b160e190e848944aa72f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -140,12 +140,12 @@ nma_full_hessian(real                    *hess,
 
     if (bM)
     {
-        for (int i = 0; (i < atom_index.size()); i++)
+        for (int i = 0; (i < atom_index.ssize()); i++)
         {
             size_t ai = atom_index[i];
             for (size_t j = 0; (j < DIM); j++)
             {
-                for (int k = 0; (k < atom_index.size()); k++)
+                for (int k = 0; (k < atom_index.ssize()); k++)
                 {
                     size_t ak = atom_index[k];
                     mass_fac = gmx::invsqrt(top->atoms.atom[ai].m*top->atoms.atom[ak].m);
@@ -170,7 +170,7 @@ nma_full_hessian(real                    *hess,
     {
         for (int i = 0; i < (end-begin+1); i++)
         {
-            for (int j = 0; j < atom_index.size(); j++)
+            for (int j = 0; j < atom_index.ssize(); j++)
             {
                 size_t aj = atom_index[j];
                 mass_fac = gmx::invsqrt(top->atoms.atom[aj].m);
@@ -209,7 +209,7 @@ nma_sparse_hessian(gmx_sparsematrix_t      *sparse_hessian,
 
     if (bM)
     {
-        for (int iatom = 0; (iatom < atom_index.size()); iatom++)
+        for (int iatom = 0; (iatom < atom_index.ssize()); iatom++)
         {
             size_t ai = atom_index[iatom];
             for (size_t j = 0; (j < DIM); j++)
@@ -236,7 +236,7 @@ nma_sparse_hessian(gmx_sparsematrix_t      *sparse_hessian,
     {
         for (i = 0; i < neig; i++)
         {
-            for (int j = 0; j < atom_index.size(); j++)
+            for (int j = 0; j < atom_index.ssize(); j++)
             {
                 size_t aj = atom_index[j];
                 mass_fac = gmx::invsqrt(top->atoms.atom[aj].m);
index 5ba16ed1d8e25ac65494a7204934fef07c5e2a6e..b251dd9af954727ce8cf1dc0635fe68857f07f7e 100644 (file)
@@ -82,7 +82,7 @@ static void scan_trj_files(gmx::ArrayRef<const std::string> files,
     t_trxframe   fr;
     bool         ok;
 
-    for (gmx::index i = 0; i < files.size(); i++)
+    for (gmx::index i = 0; i < files.ssize(); i++)
     {
         ok = read_first_frame(oenv, &status, files[i].c_str(), &fr, FLAGS);
 
@@ -153,10 +153,10 @@ static void scan_trj_files(gmx::ArrayRef<const std::string> files,
 
 static void sort_files(gmx::ArrayRef<std::string> files, real *settime)
 {
-    for (gmx::index i = 0; i < files.size(); i++)
+    for (gmx::index i = 0; i < files.ssize(); i++)
     {
         gmx::index minidx = i;
-        for (gmx::index j = i + 1; j < files.size(); j++)
+        for (gmx::index j = i + 1; j < files.ssize(); j++)
         {
             if (settime[j] < settime[minidx])
             {
@@ -201,7 +201,7 @@ static void edit_files(gmx::ArrayRef<std::string> files,
                 "---------------------------------------------------------\n",
                 timeUnit.c_str(), timeUnit.c_str());
 
-        for (gmx::index i = 0; i < files.size(); i++)
+        for (gmx::index i = 0; i < files.ssize(); i++)
         {
             fprintf(stderr, "%25s   %10.3f %s          ", files[i].c_str(),
                     output_env_conv_time(oenv, readtime[i]), timeUnit.c_str());
@@ -256,7 +256,7 @@ static void edit_files(gmx::ArrayRef<std::string> files,
     }
     else
     {
-        for (gmx::index i = 0; i < files.size(); i++)
+        for (gmx::index i = 0; i < files.ssize(); i++)
         {
             settime[i] = readtime[i];
         }
@@ -273,7 +273,7 @@ static void edit_files(gmx::ArrayRef<std::string> files,
     fprintf(stderr, "\nSummary of files and start times used:\n\n"
             "          File                Start time       Time step\n"
             "---------------------------------------------------------\n");
-    for (gmx::index i = 0; i < files.size(); i++)
+    for (gmx::index i = 0; i < files.ssize(); i++)
     {
         switch (cont_type[i])
         {
@@ -321,7 +321,7 @@ static void do_demux(gmx::ArrayRef<const std::string> inFiles,
     snew(bSet, inFiles.size());
     natoms = -1;
     t      = -1;
-    for (gmx::index i = 0; i < inFiles.size(); i++)
+    for (gmx::index i = 0; i < inFiles.ssize(); i++)
     {
         read_first_frame(oenv, &(fp_in[i]), inFiles[i].c_str(), &(trx[i]),
                          TRX_NEED_X);
@@ -345,7 +345,7 @@ static void do_demux(gmx::ArrayRef<const std::string> inFiles,
     }
 
     snew(fp_out, inFiles.size());
-    for (gmx::index i = 0; i < inFiles.size(); i++)
+    for (gmx::index i = 0; i < inFiles.ssize(); i++)
     {
         fp_out[i] = open_trx(outFiles[i].c_str(), "w");
     }
@@ -364,11 +364,11 @@ static void do_demux(gmx::ArrayRef<const std::string> inFiles,
         {
             fprintf(debug, "trx[0].time = %g, time[k] = %g\n", trx[0].time, time[k]);
         }
-        for (gmx::index i = 0; i < inFiles.size(); i++)
+        for (gmx::index i = 0; i < inFiles.ssize(); i++)
         {
             bSet[i] = FALSE;
         }
-        for (gmx::index i = 0; i < inFiles.size(); i++)
+        for (gmx::index i = 0; i < inFiles.ssize(); i++)
         {
             int j = gmx::roundToInt(value[i][k]);
             range_check(j, 0, inFiles.size());
@@ -393,14 +393,14 @@ static void do_demux(gmx::ArrayRef<const std::string> inFiles,
         }
 
         bCont = (k < nval);
-        for (gmx::index i = 0; i < inFiles.size(); i++)
+        for (gmx::index i = 0; i < inFiles.ssize(); i++)
         {
             bCont = bCont && read_next_frame(oenv, fp_in[i], &trx[i]);
         }
     }
     while (bCont);
 
-    for (gmx::index i = 0; i < inFiles.size(); i++)
+    for (gmx::index i = 0; i < inFiles.ssize(); i++)
     {
         close_trx(fp_in[i]);
         close_trx(fp_out[i]);
@@ -555,7 +555,7 @@ int gmx_trjcat(int argc, char *argv[])
 
     if (bDeMux && ssize(inFiles) != nset)
     {
-        gmx_fatal(FARGS, "You have specified %td files and %d entries in the demux table", inFiles.size(), nset);
+        gmx_fatal(FARGS, "You have specified %td files and %d entries in the demux table", inFiles.ssize(), nset);
     }
 
     ftpin = fn2ftp(inFiles[0].c_str());
@@ -584,7 +584,7 @@ int gmx_trjcat(int argc, char *argv[])
     }
     else if (bDeMux && ssize(outFiles) != nset && outFiles.size() != 1)
     {
-        gmx_fatal(FARGS, "Number of output files should be 1 or %d (#input files), not %td", nset, outFiles.size());
+        gmx_fatal(FARGS, "Number of output files should be 1 or %d (#input files), not %td", nset, outFiles.ssize());
     }
     if (bDeMux)
     {
index f8aa9d5a58f16ab6983a73d05cf896abd70aaeb7..9b7c84fee6559100e9fef605f888fe982269b2d3 100644 (file)
@@ -72,7 +72,7 @@ double calcVibrationalInternalEnergy(gmx::ArrayRef<const real> eigval,
     size_t nskip = linear ? 5 : 6;
     double Evib  = 0;
     double hbar  = PLANCK1/(2*M_PI);
-    for (gmx::index i = nskip; i < eigval.size(); i++)
+    for (gmx::index i = nskip; i < eigval.ssize(); i++)
     {
         if (eigval[i] > 0)
         {
@@ -104,7 +104,7 @@ double calcVibrationalHeatCapacity(gmx::ArrayRef<const real> eigval,
     size_t nskip = linear ? 5 : 6;
     double cv    = 0;
     double hbar  = PLANCK1/(2*M_PI);
-    for (gmx::index i = nskip; i < eigval.size(); i++)
+    for (gmx::index i = nskip; i < eigval.ssize(); i++)
     {
         if (eigval[i] > 0)
         {
@@ -179,7 +179,7 @@ double calcQuasiHarmonicEntropy(gmx::ArrayRef<const real> eigval,
     size_t nskip = bLinear ? 5 : 6;
     double S     = 0;
     double hbar  = PLANCK1/(2*M_PI);
-    for (gmx::index i = nskip; (i < eigval.size()); i++)
+    for (gmx::index i = nskip; (i < eigval.ssize()); i++)
     {
         if (eigval[i] > 0)
         {
@@ -218,7 +218,7 @@ double calcSchlitterEntropy(gmx::ArrayRef<const real> eigval,
                 ssize(eigval), kteh, evcorr);
     }
     double deter = 0;
-    for (gmx::index i = nskip; i < eigval.size(); i++)
+    for (gmx::index i = nskip; i < eigval.ssize(); i++)
     {
         double dd    = 1+kteh*eigval[i]*evcorr;
         deter       += std::log(dd);
index 1960170bb067e973c9c7a32167f5b1b48191eb55..2804ab3a1ab74f4762e276a3ddbb0afd2a93daa4 100644 (file)
@@ -2646,7 +2646,7 @@ static bool do_numbering(int natoms, gmx_groups_t *groups,
     }
 
     snew(grps->nm_ind, groupsFromMdpFile.size()+1); /* +1 for possible rest group */
-    for (int i = 0; i != groupsFromMdpFile.size(); ++i)
+    for (int i = 0; i != groupsFromMdpFile.ssize(); ++i)
     {
         /* Lookup the group name in the block structure */
         gid = search_string(groupsFromMdpFile[i].c_str(), block->nr, gnames);
index 7eb4ff4498abd4c07bfdb74697de4c863919420b..d0b5b0db8c45209a52aef8cfeacb4c9f951c9c24 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -98,7 +98,7 @@ void compareViews(ArrayRef<T> input,
                   ArrayRef<T> output)
 {
     ASSERT_EQ(input.size(), output.size());
-    for (index i = 0; i != input.size(); ++i)
+    for (index i = 0; i != input.ssize(); ++i)
     {
         EXPECT_EQ(input[i], output[i]) << "for index " << i;
     }
@@ -110,7 +110,7 @@ void compareViews(ArrayRef < BasicVector < T>> input,
                   ArrayRef < BasicVector < T>> output)
 {
     ASSERT_EQ(input.size(), output.size());
-    for (index i = 0; i != input.size(); ++i)
+    for (index i = 0; i != input.ssize(); ++i)
     {
         EXPECT_EQ(input[i][XX], output[i][XX]) << "for index " << i;
         EXPECT_EQ(input[i][YY], output[i][YY]) << "for index " << i;
index fd07917451e74dfbdd4d6e24c9f3505b1e736139..3de11ebea9771daf2c956e5375bfcab1c699d78f 100644 (file)
@@ -655,14 +655,14 @@ static real energyDrift(gmx::ArrayRef<const VerletbufAtomtype> att,
 
     // Here add up the contribution of all atom pairs in the system to
     // (estimated) energy drift by looping over all atom type pairs.
-    for (int i = 0; i < att.size(); i++)
+    for (int i = 0; i < att.ssize(); i++)
     {
         // Get the thermal displacement variance for the i-atom type
         const atom_nonbonded_kinetic_prop_t *prop_i = &att[i].prop;
         real                                 s2i_2d, s2i_3d;
         get_atom_sigma2(kT_fac, prop_i, &s2i_2d, &s2i_3d);
 
-        for (int j = i; j < att.size(); j++)
+        for (int j = i; j < att.ssize(); j++)
         {
             // Get the thermal displacement variance for the j-atom type
             const atom_nonbonded_kinetic_prop_t *prop_j = &att[j].prop;
@@ -847,7 +847,7 @@ static real maxSigma(real                                   kT_fac,
 {
     GMX_ASSERT(!att.empty(), "We should have at least one type");
     real smallestMass = att[0].prop.mass;
-    for (int i = 1; i < att.size(); i++)
+    for (int i = 1; i < att.ssize(); i++)
     {
         smallestMass = std::min(smallestMass, att[i].prop.mass);
     }
@@ -1330,7 +1330,7 @@ chanceOfUpdateGroupCrossingCell(const gmx_mtop_t       &mtop,
                                 real                    kT_fac,
                                 real                    cellSize)
 {
-    GMX_RELEASE_ASSERT(static_cast<size_t>(updateGrouping.size()) == mtop.moltype.size(),
+    GMX_RELEASE_ASSERT(updateGrouping.size() == mtop.moltype.size(),
                        "The update groups should match the topology");
 
     real chance = 0;
index ecb713ce14012353677716e763a1dcdeceabb651..a07560bde73c022d597c8c6d66914d9c72642eda 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -271,7 +271,7 @@ constr_iatomptr(gmx::ArrayRef<const int> iatom_constr,
                 gmx::ArrayRef<const int> iatom_constrnc,
                 int                      con)
 {
-    if (con*3 < iatom_constr.size())
+    if (con*3 < iatom_constr.ssize())
     {
         return iatom_constr.data() + con*3;
     }
index 09f54fc4f8aa13ab59b3a3ce93537162067cd045..0ed28de87e05c0c75cd7a2f78ca5fd8c301df6a2 100644 (file)
@@ -767,7 +767,7 @@ void sum_dhdl(gmx_enerdata_t *enerd, gmx::ArrayRef<const real> lambda, t_lambda
 
         double &enerpart_lambda = enerd->enerpart_lambda[i + 1];
 
-        for (gmx::index j = 0; j < lambda.size(); j++)
+        for (gmx::index j = 0; j < lambda.ssize(); j++)
         {
             /* Note that this loop is over all dhdl components, not just the separated ones */
             const double dlam  = fepvals->all_lambda[j][i] - lambda[j];
index 34f4c663aadfb8190dfb5c261c37afa81791de1a..38e4928684f1acd3c849f1793434ddd9f653d0be 100644 (file)
@@ -1453,7 +1453,7 @@ static bondedtable_t *make_bonded_tables(FILE *fplog,
                 // being recognized and used for table 1.
                 std::string patternToFind = gmx::formatString("_%s%d.%s", tabext, i, ftp2ext(efXVG));
                 bool        madeTable     = false;
-                for (gmx::index j = 0; j < tabbfnm.size() && !madeTable; ++j)
+                for (gmx::index j = 0; j < tabbfnm.ssize() && !madeTable; ++j)
                 {
                     if (gmx::endsWith(tabbfnm[j], patternToFind))
                     {
index 21221afd2d846e8ec82f6beee9a34fb675720cbb..643d6465585177ed677b9855fb3a28ff037952f8 100644 (file)
@@ -404,7 +404,7 @@ std::vector<int> qmmmAtomIndices(const t_inputrec &ir, const gmx_mtop_t &mtop)
 void removeQmmmAtomCharges(gmx_mtop_t *mtop, gmx::ArrayRef<const int> qmmmAtoms)
 {
     int molb = 0;
-    for (int i = 0; i < qmmmAtoms.size(); i++)
+    for (int i = 0; i < qmmmAtoms.ssize(); i++)
     {
         int     indexInMolecule;
         mtopGetMolblockIndex(mtop, qmmmAtoms[i], &molb, nullptr, &indexInMolecule);
index 353a0a1726d487161fd357cbd62387ce301ea916..f78c58c00c2088e841d256242f962ccca5b5a26d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -754,7 +754,7 @@ computeMaxUpdateGroupRadius(const gmx_mtop_t                       &mtop,
         return 0;
     }
 
-    GMX_RELEASE_ASSERT(static_cast<size_t>(updateGroups.size()) == mtop.moltype.size(),
+    GMX_RELEASE_ASSERT(updateGroups.size() == mtop.moltype.size(),
                        "We need one update group entry per moleculetype");
 
     real maxRadius = 0;
index 957d373d319e76836f4c692631e586d69e172be8..f5c972a862151b6910f4661ae7e2c2b82b6f8983 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -88,13 +88,13 @@ void UpdateGroupsCog::addCogs(gmx::ArrayRef<const int>        globalAtomIndices,
     const int    localAtomBegin = cogIndices_.size();
     const size_t cogBegin       = cogs_.size();
 
-    GMX_RELEASE_ASSERT(globalAtomIndices.size() >= localAtomBegin,
+    GMX_RELEASE_ASSERT(globalAtomIndices.ssize() >= localAtomBegin,
                        "addCogs should only be called to add COGs to the list that is already present (which could be empty)");
 
     cogIndices_.reserve(globalAtomIndices.size());
 
     int moleculeBlock = 0;
-    for (int localAtom = localAtomBegin; localAtom < globalAtomIndices.size(); localAtom++)
+    for (int localAtom = localAtomBegin; localAtom < globalAtomIndices.ssize(); localAtom++)
     {
         const int   globalAtom = globalAtomIndices[localAtom];
         int         moleculeIndex;
index fe98a6ccce9bb3faf696f6d04edc655560bb428e..cbbae59a48655178e5f74da3247b8da4127a0763 100644 (file)
@@ -758,7 +758,7 @@ static void spread_vsite2(const t_iatom ia[], real a,
 void constructVsitesGlobal(const gmx_mtop_t         &mtop,
                            gmx::ArrayRef<gmx::RVec>  x)
 {
-    GMX_ASSERT(x.size() >= static_cast<gmx::index>(mtop.natoms), "x should contain the whole system");
+    GMX_ASSERT(x.ssize() >= mtop.natoms, "x should contain the whole system");
     GMX_ASSERT(!mtop.moleculeBlockIndices.empty(), "molblock indices are needed in constructVsitesGlobal");
 
     for (size_t mb = 0; mb < mtop.molblock.size(); mb++)
index b3a73ee7ad380927225ce784a2340b952f74a32a..6d0cfd9de279c64211ec115cfe48b6601d5e8ff3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -83,7 +83,7 @@ gmx_multisim_t *init_multisystem(MPI_Comm                         comm,
     MPI_Comm_size(comm, &numRanks);
     if (numRanks % multidirs.size() != 0)
     {
-        gmx_fatal(FARGS, "The number of ranks (%d) is not a multiple of the number of simulations (%td)", numRanks, multidirs.size());
+        gmx_fatal(FARGS, "The number of ranks (%d) is not a multiple of the number of simulations (%td)", numRanks, multidirs.ssize());
     }
 
     int numRanksPerSim = numRanks/multidirs.size();
@@ -92,7 +92,7 @@ gmx_multisim_t *init_multisystem(MPI_Comm                         comm,
 
     if (debug)
     {
-        fprintf(debug, "We have %td simulations, %d ranks per simulation, local simulation is %d\n", multidirs.size(), numRanksPerSim, rankWithinComm/numRanksPerSim);
+        fprintf(debug, "We have %td simulations, %d ranks per simulation, local simulation is %d\n", multidirs.ssize(), numRanksPerSim, rankWithinComm/numRanksPerSim);
     }
 
     ms       = new gmx_multisim_t;
index ef9956a9c8bbf761b9361852f18dd67fb5d53d2e..9305abd47fe181e237881d4c8981d1cf84f81334 100644 (file)
@@ -207,7 +207,7 @@ void comp_state(const t_state *st1, const t_state *st2,
 rvec *makeRvecArray(gmx::ArrayRef<const gmx::RVec> v,
                     gmx::index                     n)
 {
-    GMX_ASSERT(v.size() >= n, "We can't copy more elements than the vector size");
+    GMX_ASSERT(v.ssize() >= n, "We can't copy more elements than the vector size");
 
     rvec *dest;
 
index f6547f81ade248087bbfb66c688e7f31542669e6..ca5d7965b3b9586884f44113197c7f47631adb86 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -1430,7 +1430,7 @@ void put_atoms_in_box(int ePBC, const matrix box, gmx::ArrayRef<gmx::RVec> x)
 
     if (TRICLINIC(box))
     {
-        for (gmx::index i = 0; (i < x.size()); ++i)
+        for (gmx::index i = 0; (i < x.ssize()); ++i)
         {
             for (m = npbcdim-1; m >= 0; m--)
             {
@@ -1453,7 +1453,7 @@ void put_atoms_in_box(int ePBC, const matrix box, gmx::ArrayRef<gmx::RVec> x)
     }
     else
     {
-        for (gmx::index i = 0; (i < x.size()); ++i)
+        for (gmx::index i = 0; (i < x.ssize()); ++i)
         {
             for (d = 0; d < npbcdim; d++)
             {
@@ -1497,7 +1497,7 @@ void put_atoms_in_triclinic_unitcell(int ecenter, const matrix box,
     shift_center[1] = shm12*shift_center[2];
     shift_center[2] = 0;
 
-    for (gmx::index i = 0; (i < x.size()); ++i)
+    for (gmx::index i = 0; (i < x.ssize()); ++i)
     {
         for (m = DIM-1; m >= 0; m--)
         {
@@ -1542,7 +1542,7 @@ void put_atoms_in_compact_unitcell(int ePBC, int ecenter, const matrix box,
     }
 
     calc_box_center(ecenter, box, box_center);
-    for (gmx::index i = 0; (i < x.size()); ++i)
+    for (gmx::index i = 0; (i < x.ssize()); ++i)
     {
         pbc_dx(&pbc, x[i], box_center, dx);
         rvec_add(box_center, dx, x[i]);
index 2d09c42336ebaf2c0bb37a40eb05baa60db4d6dd..89eac4578ed5bc5e282179ad5da144ef9b29b100 100644 (file)
@@ -1079,7 +1079,7 @@ static void do_constraint(struct pull_t *pull, t_pbc *pbc,
         /* update the atom positions */
         auto localAtomIndices = pgrp->atomSet.localIndex();
         copy_dvec(dr, tmp);
-        for (gmx::index j = 0; j < localAtomIndices.size(); j++)
+        for (gmx::index j = 0; j < localAtomIndices.ssize(); j++)
         {
             ii = localAtomIndices[j];
             if (!pgrp->localWeights.empty())
index 2f129777bc849103e40ec807114f6bd7b6a87027..a2c3210fb55cd36338379dce9faa77bdaa1e82a4 100644 (file)
@@ -598,7 +598,7 @@ real add_rot_forces(gmx_enfrot *er,
         gmx_enfrotgrp *erg = &ergRef;
         Vrot += erg->V;  /* add the local parts from the nodes */
         const auto    &localRotationGroupIndex = erg->atomSet->localIndex();
-        for (gmx::index l = 0; l < localRotationGroupIndex.size(); l++)
+        for (gmx::index l = 0; l < localRotationGroupIndex.ssize(); l++)
         {
             /* Get the right index of the local force */
             int ii = localRotationGroupIndex[l];
@@ -1984,7 +1984,7 @@ static real do_flex2_lowlevel(
     const auto &localRotationGroupIndex      = erg->atomSet->localIndex();
     const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex();
 
-    for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++)
+    for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++)
     {
         /* Local index of a rotation group atom  */
         ii = localRotationGroupIndex[j];
@@ -2223,7 +2223,7 @@ static real do_flex_lowlevel(
     const auto &localRotationGroupIndex      = erg->atomSet->localIndex();
     const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex();
 
-    for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++)
+    for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++)
     {
         /* Local index of a rotation group atom  */
         int ii = localRotationGroupIndex[j];
@@ -2907,7 +2907,7 @@ static void do_radial_motion_pf(
     /* Each process calculates the forces on its local atoms */
     const auto &localRotationGroupIndex      = erg->atomSet->localIndex();
     const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex();
-    for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++)
+    for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++)
     {
         /* Local index of a rotation group atom  */
         int ii = localRotationGroupIndex[j];
@@ -3098,7 +3098,7 @@ static void do_radial_motion2(
     /* Each process calculates the forces on its local atoms */
     const auto &localRotationGroupIndex      = erg->atomSet->localIndex();
     const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex();
-    for (gmx::index j = 0; j < localRotationGroupIndex.size(); j++)
+    for (gmx::index j = 0; j < localRotationGroupIndex.ssize(); j++)
     {
         if (bPF)
         {
@@ -3758,7 +3758,7 @@ static void choose_pbc_image(rvec x[],
                              matrix box, int npbcdim)
 {
     const auto &localRotationGroupIndex = erg->atomSet->localIndex();
-    for (gmx::index i = 0; i < localRotationGroupIndex.size(); i++)
+    for (gmx::index i = 0; i < localRotationGroupIndex.ssize(); i++)
     {
         /* Index of a rotation group atom  */
         int ii = localRotationGroupIndex[i];
@@ -3835,7 +3835,7 @@ void do_rotation(const t_commrec       *cr,
             if (bNS)
             {
                 const auto &collectiveRotationGroupIndex = erg->atomSet->collectiveIndex();
-                for (gmx::index i = 0; i < collectiveRotationGroupIndex.size(); i++)
+                for (gmx::index i = 0; i < collectiveRotationGroupIndex.ssize(); i++)
                 {
                     /* Index of local atom w.r.t. the collective rotation group */
                     int ii        = collectiveRotationGroupIndex[i];
index c33a110340c1505a93860f0568b05be186b30d59..3f39df0ccefb200fc51e456e46b7406c71194aad 100644 (file)
@@ -251,7 +251,7 @@ static void make_cyl_refgrps(const t_commrec *cr,
             pdyna.dv.resize(localAtomIndices.size());
 
             /* loop over all atoms in the main ref group */
-            for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.size(); indexInSet++)
+            for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.ssize(); indexInSet++)
             {
                 int    atomIndex = localAtomIndices[indexInSet];
                 rvec   dx;
@@ -867,7 +867,7 @@ static bool pullGroupObeysPbcRestrictions(const pull_group_work_t &group,
     }
 
     auto localAtomIndices = group.atomSet.localIndex();
-    for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.size(); indexInSet++)
+    for (gmx::index indexInSet = 0; indexInSet < localAtomIndices.ssize(); indexInSet++)
     {
         rvec dx;
         pbc_dx(&pbc, x[localAtomIndices[indexInSet]], x_pbc, dx);
index 228f58f2186d40d8a3edaa138bb5fcd6df325b8d..34f17427ffa15dd11e244838c7248f55fa8bcac4 100644 (file)
@@ -291,7 +291,7 @@ SelectionCollectionDataTest::runParser(
     TestReferenceChecker compound(checker_.checkCompound("ParsedSelections", "Parsed"));
     size_t               varcount = 0;
     count_ = 0;
-    for (gmx::index i = 0; i < selections.size(); ++i)
+    for (gmx::index i = 0; i < selections.ssize(); ++i)
     {
         SCOPED_TRACE(std::string("Parsing selection \"")
                      + selections[i] + "\"");
index ef6b40403d0f50b14d910e4bf16061984aabc57c..460276e61d248fca0e3a7f70017a371d98438bf6 100644 (file)
@@ -197,7 +197,7 @@ void TopologyManager::initAtomTypes(const ArrayRef<const char *const> &types)
     index    j = 0;
     for (int i = 0; i < atoms.nr; ++i, ++j)
     {
-        if (j == types.size())
+        if (j == types.ssize())
         {
             j = 0;
         }
index 86088de42b9db32f313e34f4972d6dabdd29a25b..ea26dce45e1780e0fba2fd6e94d5a5260d3a4ac2 100644 (file)
@@ -120,7 +120,7 @@ void add_grp(t_blocka *b, char ***gnames, gmx::ArrayRef<const int> a, const std:
     (*gnames)[b->nr] = gmx_strdup(name.c_str());
 
     srenew(b->a, b->nra+a.size());
-    for (int i = 0; (i < a.size()); i++)
+    for (int i = 0; (i < a.ssize()); i++)
     {
         b->a[b->nra++] = a[i];
     }
@@ -150,11 +150,11 @@ static bool grp_cmp(t_blocka *b, gmx::ArrayRef<const int> a, int index)
         gmx_fatal(FARGS, "no such index group %d in t_blocka (nr=%d)", index, b->nr);
     }
     /* compare sizes */
-    if (a.size() != b->index[index+1] - b->index[index])
+    if (a.ssize() != b->index[index+1] - b->index[index])
     {
         return FALSE;
     }
-    for (int i = 0; i < a.size(); i++)
+    for (int i = 0; i < a.ssize(); i++)
     {
         if (a[i] != b->a[b->index[index]+i])
         {
@@ -178,7 +178,7 @@ static void p_status(gmx::ArrayRef<const std::string> restype,
                    }
                    );
 
-    for (int i = 0; (i < typenames.size()); i++)
+    for (int i = 0; (i < typenames.ssize()); i++)
     {
         if (counter[i] > 0)
         {
index ad4c3a3403c9b571e3a011c12479dc0adf89a1d4..48ab089c1351f669e3b1ae3fd38813a3308293c1 100644 (file)
@@ -1086,7 +1086,7 @@ static void addMimicExclusions(t_blocka                      *excls,
     for (int k = 0; k < inter_excl.nr; ++k)
     {
         inter_excl.index[k] = prev_index;
-        for (long i = 0; i < ids.size(); i++)
+        for (long i = 0; i < ids.ssize(); i++)
         {
             if (k != ids[i])
             {
index aacebf36edb7a7ca827bd2314698d4dcf5d12604..6e621644fc049a02f1fa4a8ff8065bb9c99599cc 100644 (file)
@@ -567,7 +567,7 @@ static void compareMoltypes(FILE *fp, gmx::ArrayRef<const gmx_moltype_t> mt1, gm
 {
     fprintf(fp, "comparing molecule types\n");
     cmp_int(fp, "moltype size", -1, mt1.size(), mt2.size());
-    for (int i = 0; i < std::min(mt1.size(), mt2.size()); i++)
+    for (int i = 0; i < std::min(mt1.ssize(), mt2.ssize()); i++)
     {
         cmp_str(fp, "Name", i, *mt1[i].name, *mt2[i].name);
         compareAtoms(fp, &mt1[i].atoms, &mt2[i].atoms, relativeTolerance, absoluteTolerance);
@@ -582,7 +582,7 @@ static void compareMoltypes(FILE *fp, gmx::ArrayRef<const gmx_moltype_t> mt1, gm
 static void compareMoletypeAB(FILE *fp, gmx::ArrayRef<const gmx_moltype_t> mt1, real relativeTolerance, real absoluteTolerance)
 {
     fprintf(fp, "comparing free energy molecule types\n");
-    for (int i = 0; i < mt1.size(); i++)
+    for (int i = 0; i < mt1.ssize(); i++)
     {
         compareAtoms(fp, &mt1[i].atoms, nullptr, relativeTolerance, absoluteTolerance);
     }
index 9291870396c5dddebcb79b93a7c40e1977d2232d..fdb754d06b60db74fc461c372d7e4f8b0bed8a04 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -118,7 +118,7 @@ class ArrayRef
         //! Type of values stored in the reference.
         typedef T         value_type;
         //! Type for representing size of the reference.
-        typedef index     size_type;
+        typedef size_t    size_type;
         //! Type for representing difference between two indices.
         typedef ptrdiff_t difference_type;
         //! Const reference to an element.
@@ -222,8 +222,14 @@ class ArrayRef
         //! Returns an iterator to the reverse end of the reference.
         reverse_iterator rend() const { return reverse_iterator(begin()); }
 
-        //! Returns the size of the reference.
+        /*! \brief Returns the size of the reference.
+         *
+         * \note Use ssize for any expression involving arithmetic operations
+             (including loop indices).
+         */
         size_type size() const { return end_ - begin_; }
+        //! Returns the signed size of the reference.
+        index ssize() const { return size(); }
         //! Identical to size().
         size_type capacity() const { return end_ - begin_; }
         //! Whether the reference refers to no memory.