ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
verbose.m
Go to the documentation of this file.
1%> \brief
2%> Return a MATLAB double, cell, or table matrix whose rows or
3%> columns are unrolled according to a prespecified ``weight``.
4%>
5%> \param[in] cmat : The input compact MATLAB double, cell, or table
6%> matrix that is to be unrolled along an axis.
7%> \param[in] dim : The input scalar MATLAB integer
8%> that can be either ``1`` or ``2``
9%> representing the axis along with the
10%> array must be unrolled.<br>
11%> An input value of ``1`` implies unrolling
12%> along the rows of the input ``cmat``,
13%> that is, unrolling the ``cmat`` columns.
14%> \param[in] weight : The input MATLAB matrix of integer values
15%> of size ``size(cmat, dim)`` containing the set
16%> of weights to used for unrolling the input ``cmat``.
17%> \param[in] checked : The input scalar Python Boolean value.<br>
18%> If ``true``, the condition ``~all(rem(weight, 1) == 0) || any(weight < 0)`` will be asserted.<br>
19%> This can be useful for debugging, but can slow down the runtime performance.<br>
20%> (**optional**, default = ``false``)
21%>
22%> \return
23%> ``vmat`` : The output MATLAB matrix of the same type and kind
24%> as the input ``cmat``, containing the ``cmat`` that
25%> is unrolled along the specified axis ``dim`` using
26%> the input weights.<br>
27%>
28%> \interface{verbose}
29%> \code{.m}
30%>
31%> vmat = pm.array.verbose(cmat, dim, weight)
32%> vmat = pm.array.verbose(cmat, dim, weight, checked)
33%>
34%> \endcode
35%>
36%> \warning
37%> Negative weights lead to a runtime error.<br>
38%> Any entry corresponding to a zero weight is ignored in the output ``vmat``.<br>
39%>
40%> \example{verbose}
41%> \include{lineno} example/array/verbose/main.m
42%> \output{verbose}
43%> \include{lineno} example/array/verbose/main.out.m
44%>
45%> \final{verbose}
46%>
47%> \author
48%> \JoshuaOsborne, May 21 2024, 4:24 PM, University of Texas at Arlington<br>
49%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
50%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
51function vmat = verbose(cmat, dim, weight, checked)
52 if nargin < 4
53 checked = false;
54 end
55 if nargin < 3
56 help("pm.array.verbose");
57 error ( newline ...
58 + "At least three input arguments are required" + newline ...
59 + "as described in the documentation above." + newline ...
60 + newline ...
61 );
62 end
63 if checked
64 if ~all(rem(weight, 1) == 0) || any(weight < 0)
65 help("pm.array.verbose");
66 disp("weight");
67 disp( weight );
68 error ( newline ...
69 + "The input ``weight`` argument displayed above" + newline ...
70 + "must be all non-negative whole-numbers." + newline ...
71 + newline ...
72 );
73 end
74 if ~any(dim == [1, 2])
75 help("pm.array.verbose");
76 disp("dim");
77 disp( dim );
78 error ( newline ...
79 + "The input ``dim`` argument displayed above" + newline ...
80 + "must be either 1 or 2." + newline ...
81 + newline ...
82 );
83 end
84 if length(weight) ~= size(cmat, dim)
85 help("pm.array.verbose");
86 error ( newline ...
87 + "The condition ``length(weight) == size(cmat, dim)``" + newline ...
88 + "must hold for the corresponding input arguments." + newline ...
89 + newline ...
90 + pm.io.tab() + "length(weight) = " + string(length(weight)) + newline ...
91 + pm.io.tab() + "size(cmat,dim) = " + string(size(cmat,dim)) + newline ...
92 + newline ...
93 );
94 end
95 end
96 cumsumwei = cumsum(weight);
97 sumwei = cumsumwei(end);
98 nrow = size(cmat, 1);
99 ncol = size(cmat, 2);
100 if dim == 1
101 if isa(cmat, "cell")
102 vmat = cell(sumwei, ncol);
103 elseif isa(cmat, "double")
104 vmat = zeros(sumwei, ncol);
105 else
106 vmat = cmat;
107 end
108 istart = 1;
109 for ientry = 1 : nrow
110 iend = cumsumwei(ientry);
111 for iwei = istart : iend
112 vmat(iwei, :) = cmat(ientry, :);
113 end
114 istart = iend + 1;
115 end
116 else
117 if isa(cmat, "cell")
118 vmat = cell(nrow, sumwei);
119 elseif isa(cmat, "double")
120 vmat = zeros(nrow, sumwei);
121 else
122 vmat = cmat;
123 end
124 istart = 1;
125 for ientry = 1 : ncol
126 iend = cumsumwei(ientry);
127 for iwei = istart : iend
128 vmat(:, iwei) = cmat(:, ientry);
129 end
130 istart = iend + 1;
131 end
132 end
133end
function tab()
Return a scalar MATLAB string containing 4 blank characters equivalent to a tab character.
function verbose(in cmat, in dim, in weight, in checked)
Return a MATLAB double, cell, or table matrix whose rows or columns are unrolled according to a presp...