Increment a manopt counter in a store or storedb. function store = incrementcounter(store, countername) function store = incrementcounter(store, countername, increment) function incrementcounter(storedb, countername) function incrementcounter(storedb, countername, increment) Increment a counter by 1 (default) or by 'increment'. The counter itself is stored in a store structure (inside store.shared) or in a storedb object (inside storedb.shared); shared is a structure and countername is a string that will be used as field name to store the counter value. Since storedb objects are passed by reference, there is no need to collect the output of the function. For store structures on the other hand, it is necessary to collect the output and either store it, or return it further. This manopt tool is meant to be used in conjunction with statscounter. See also: statscounter statsfunhelper
0001 function store = incrementcounter(store, countername, increment) 0002 % Increment a manopt counter in a store or storedb. 0003 % 0004 % function store = incrementcounter(store, countername) 0005 % function store = incrementcounter(store, countername, increment) 0006 % 0007 % function incrementcounter(storedb, countername) 0008 % function incrementcounter(storedb, countername, increment) 0009 % 0010 % Increment a counter by 1 (default) or by 'increment'. The counter itself 0011 % is stored in a store structure (inside store.shared) or in a storedb 0012 % object (inside storedb.shared); shared is a structure and countername is 0013 % a string that will be used as field name to store the counter value. 0014 % 0015 % Since storedb objects are passed by reference, there is no need to 0016 % collect the output of the function. For store structures on the other 0017 % hand, it is necessary to collect the output and either store it, or 0018 % return it further. 0019 % 0020 % This manopt tool is meant to be used in conjunction with statscounter. 0021 % 0022 % See also: statscounter statsfunhelper 0023 0024 % This file is part of Manopt: www.manopt.org. 0025 % Original author: Nicolas Boumal, July 27, 2018. 0026 % Contributors: 0027 % Change log: 0028 0029 assert(isa(store, 'StoreDB') || ... 0030 isstruct(store) && isfield(store, 'shared'), ... 0031 ['First input must be a store structure or a StoreDB object. ' ... 0032 'The store structure must have the shared memory.']); 0033 0034 % If the counter does not exist yet, initialize it to 0. 0035 if ~isfield(store.shared, countername) 0036 store.shared.(countername) = 0; 0037 end 0038 0039 % By default, increment counter by 1. 0040 if ~exist('increment', 'var') || isempty(increment) 0041 increment = 1; 0042 end 0043 0044 % The counter is stored in the shared memory of the store or storedb, 0045 % that is, it is not attached to a particular point on the manifold. 0046 store.shared.(countername) = store.shared.(countername) + increment; 0047 0048 end