0001 function G = slpwgraph(Xs, Xt, n, nt, evalfunctor, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 if nargin < 5
0050 raise_lackinput('slpwgraph', 5);
0051 end
0052
0053 if isempty(Xt)
0054 Xt = Xs;
0055 nt = n;
0056 end
0057
0058 tarsiz = [n, nt];
0059
0060 opts.sparse = true;
0061 opts.valtype = 'numeric';
0062 opts.maxblk = 1e7;
0063 opts = slparseprops(opts, varargin{:});
0064
0065 if ~ismember(opts.valtype, {'logical', 'numeric'})
0066 error('sltoolbox:invalidarg', ...
0067 'Invalid value type for graph: %s', opts.valtype);
0068 end
0069
0070
0071
0072
0073
0074
0075 ps = slequalpar2D(tarsiz, opts.maxblk);
0076 nm = length(ps(1).sinds);
0077 nn = length(ps(2).sinds);
0078
0079
0080
0081 if opts.sparse
0082 nblks = nm * nn;
0083 CI = cell(nblks, 1);
0084 CJ = cell(nblks, 1);
0085 CV = cell(nblks, 1);
0086
0087 k = 0;
0088 for i = 1 : nm
0089 for j = 1 : nn
0090
0091
0092 k = k + 1;
0093 inds1 = ps(1).sinds(i):ps(1).einds(i);
0094 inds2 = ps(2).sinds(j):ps(2).einds(j);
0095
0096
0097 curV = slevalfunctor(evalfunctor, Xs, Xt, inds1, inds2);
0098
0099
0100 [curI, curJ, curV] = find(curV);
0101 curI = curI + (inds1(1) - 1);
0102 curJ = curJ + (inds2(1) - 1);
0103
0104
0105 CI{k} = curI;
0106 CJ{k} = curJ;
0107 CV{k} = curV;
0108
0109 end
0110 end
0111
0112 CI = vertcat(CI{:});
0113 CJ = vertcat(CJ{:});
0114 CV = vertcat(CV{:});
0115
0116 edges = [CI, CJ];
0117 clear CI CJ;
0118
0119 islogic = strcmp(opts.valtype, 'logic');
0120
0121 G = slmakeadjmat(n, nt, edges, CV, islogic, true);
0122
0123 else
0124
0125 switch opts.valtype
0126 case 'logical'
0127 G = false(n, nt);
0128 case 'numeric'
0129 G = zeros(n, nt);
0130 end
0131
0132 for i = 1 : nm
0133 for j = 1 : nn
0134
0135
0136 inds1 = ps(1).sinds(i):ps(1).einds(i);
0137 inds2 = ps(2).sinds(j):ps(2).einds(j);
0138
0139
0140 curV = slevalfunctor(evalfunctor, Xs, Xt, inds1, inds2);
0141
0142
0143 G(inds1, inds2) = curV;
0144
0145 end
0146 end
0147
0148 end
0149
0150
0151
0152
0153
0154
0155
0156
0157