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