Skip to content

Commit 233b97e

Browse files
committed
Reformat help text for consistency
1 parent aa2e568 commit 233b97e

File tree

17 files changed

+66
-55
lines changed

17 files changed

+66
-55
lines changed

array2spArray.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
function spA = array2spArray(A)
22
%ARRAY2SPARRAY Convert a full array into a sparse array structure.
3-
% A sparse array structure has the following fields:
3+
%
4+
% spA = array2spArray(A) A sparse array structure has the following fields:
45
%
56
% 'Size', which is a row vector of the sizes of each dimension of the full
6-
% array -- for example, a column vector with N entries has a size of N; a
7-
% row vector with N entries has a size of (1,N); a matrix with N entries has
8-
% a size (J,K), where JK = N; a three-way array with N entries has a size
7+
% array -- for example, a column vector with N entries has a size of N; a row
8+
% vector with N entries has a size of (1,N); a matrix with N entries has a
9+
% size (J,K), where JK = N; a three-way array with N entries has a size
910
% (J,K,L), where JKL = N;
1011
%
1112
% 'Ind', which is a column vector of linear indices of nonzero values in the
1213
% full array that they represent;
1314
%
1415
% 'Val', which is a column vector of the values at those indices.
1516
%
16-
% Version 1.0 by Andrew J. Milne, The MARCS Institute, Western Sydney
17-
% University, 2018-01-09
17+
% All singleton dimensions are removed.
18+
%
19+
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
1820
%
1921
% See also SPARRAY2ARRAY.
2022

spArray2Array.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
function A = spArray2Array(spA)
22
%SPARRAY2ARRAY Convert a sparse array structure into a full array.
33
%
4-
% Version 1.0 by Andrew J. Milne, The MARCS Institute, Western Sydney
5-
% University, 2018-01-09
4+
% A = spArray2Array(spA)
5+
%
6+
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
67
%
78
% See also ARRAY2SPARRAY.
89

spConv.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function spC = spConv(spA,spB,shape)
22
%SPCONV N-dimensional convolution of two N-dimensional sparse array structures.
3+
%
34
% spC = spConv(spA,spB,shape): N-dimensional convolution of two N-dimensional
45
% full arrays, each represented as a sparse array structure or a full array.
56
% The output is a sparse array structure.
@@ -45,18 +46,18 @@
4546
indASzC = spSub2spInd(sizC,subsA);
4647
indBSzC = spSub2spInd(sizC,subsB);
4748

48-
% Do the convolution
49+
%% Do the convolution
4950
indC = indASzC + indBSzC' - 1; % Outer sum of indices, minus 1
5051
indC = indC(:);
5152
valC = spA.Val.*spB.Val'; % Outer product of values
5253
valC = valC(:);
5354
sparseC = sparse(indC,1,valC); % Accumulate (sum) over repeated indices
5455

55-
% Make sparse array structure for full convolution
56+
%% Make sparse array structure for full convolution
5657
[indC,~,valC] = find(sparseC);
57-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5859
spC = struct('Size',sizC,'Ind',indC,'Val',valC);
59-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6061

6162
if isequal(shape,'same') % Remove entries outside size A
6263
% Convert linear indices of spC to subs
@@ -69,9 +70,9 @@
6970
% convert subsCTrunc to linear index for array of size spA.Size
7071
indC = spSub2spInd(spA.Size,subsCTrunc);
7172
% Make into a sparse array structure
72-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7374
spC = struct('Size',spA.Size,'Ind',indC,'Val',valC);
74-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7576
elseif isequal(shape,'circ') % Wrap entries around size A
7677
% Convert linear indices of spC to subs
7778
subsC = spInd2spSub(spC);
@@ -83,9 +84,9 @@
8384
sparseC = sparse(indC,1,valC);
8485
% Make into a sparse array structure
8586
[indC,~,valC] = find(sparseC);
86-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8788
spC = struct('Size',spA.Size,'Ind',indC,'Val',valC);
88-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8990
end
9091

9192
end

spCosSim.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
function s = spCosSim(spA,spB)
22
%SPCOSSIM Cosine similarity of two sparse array structures
3+
%
34
% s = spCosSim(spA,spB): Cosine similarity of two vectorized full arrays,
45
% each represented as a sparse array structure or as a full array. They must
56
% have the same numbers of entries (including zeros). The output is a scalar.
67
%
7-
% Version 1.0 by Andrew J. Milne, The MARCS Institute, Western Sydney
8-
% University, 2018-01-09
8+
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
99
%
1010
% See also SPPDIST.
1111

1212
persistent innerAA innerBB spALast spBLast
1313

1414
if nargin ~= 2
15-
error('There must be exactly two arguments (arrays or sparse array structures).')
15+
error(['There must be exactly two arguments (arrays or sparse array ', ...
16+
'structures).'])
1617
end
1718

1819
% Convert full array arguments to sparse array structures

spFlip.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function spC = spFlip(spA,dim)
22
%SPFLIP Flip order of entries in dimensions specified in 'dim'.
3+
%
34
% spC = spFlip(spA,dim): Flip the order of entries of the full array,
45
% represented as a sparse array structure or full array, in the dimensions
56
% specified in the row vector or scalar 'dim'. The output is a sparse array
67
% structure.
78
%
8-
% Version 1.0 by Andrew J. Milne, The MARCS Institute, Western Sydney
9-
% University, 2018-01-16
9+
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
1010
%
1111
% See also FLIP.
1212

@@ -32,12 +32,12 @@
3232
% vector of 1s for flips and 0s for no flips
3333
logDim(dim) = 1;
3434
% vector of 1s for flips and -1s for no flips
35-
mult = logDim;
36-
mult(logDim==0) = -1;
35+
signChange = logDim;
36+
signChange(logDim==0) = -1;
3737
% convert to subs
3838
subA = spInd2spSub(spA);
3939
% do the flips
40-
flipSubA = (logDim.*spA.Size - subA + logDim).*mult;
40+
flipSubA = (logDim.*spA.Size - subA + logDim).*signChange;
4141
% convert to linearindex
4242
indA = spSub2spInd(spA.Size,flipSubA);
4343
end

spInd2spSub.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
function subsA = spInd2spSub(spA)
22
%SPIND2SPSUB Convert a sparse array's linear index into a matrix of subscripts.
33
%
4-
% Version 1.0 by Andrew J. Milne, The MARCS Institute, Western Sydney
5-
% University, 2018-01-09
4+
% subsA = spInd2spSub(spA)
5+
%
6+
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
67
%
78
% See also SPSUB2SPIND, IND2SUB.
89

spInner.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
function c = spInner(varargin)
22
%SPINNER Inner (scalar) product of two sparse array structures.
3+
%
34
% c = spInner(varargin): Inner (scalar) product of two full arrays, each
45
% represented as a sparse array structure or a full array. There are
56
% alternative definitions of 'inner product' for tensors/arrays. Here, it is
67
% their scalar product -- the sum of entries resulting from their entrywise
78
% (Hadamard) product. The sparse arrays can entered as a comma separated list
89
% or as a members of a cell.
910
%
10-
% Version 1.0 by Andrew J. Milne, The MARCS Institute, Western Sydney
11-
% University, 2018-01-09
11+
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
1212

1313
% Check whether varargin is a comma separated list or a cell array
1414
if ~iscell(varargin{1})
@@ -19,7 +19,8 @@
1919
nSpA = size(spA,2); % count the number of arrays
2020

2121
if nSpA ~= 2
22-
error('There must be two arguments (sparse array structures or full arrays).')
22+
error(['There must be exactly two arguments (arrays or sparse array ', ...
23+
'structures).'])
2324
end
2425

2526
% Convert full array arguments to sparse array structures

spOuter.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function spC = spOuter(varargin)
2-
%SPOUTER THE Outer (tensor) product of sparse array structures.
2+
%SPOUTER Outer (tensor) product of sparse array structures.
3+
%
34
% spC = spOuter(varargin): The outer (tensor) product of full arrays, each
45
% represented as a sparse array structure or a full array (or scalar). The
56
% sparse array structures can be entered as a comma separated list or as a
@@ -9,8 +10,7 @@
910
% (N,P), the resulting tensor has size (M,N,P), not size (1,M,N,P). The
1011
% output is a sparse array structure.
1112
%
12-
% Version 1.0 by Andrew J. Milne, The MARCS Institute, Western Sydney
13-
% University, 2018-01-09
13+
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
1414

1515
% Check whether varargin is a comma separated list or a cell array
1616
if ~iscell(varargin{1})

spPDist.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
function d = spPDist(spA,spB,p)
22
%PDIST p-norm distance between two sparse array structures.
3+
%
34
% d = spPDist(spA,spB,p): The p-norm distance between two vectorized full
45
% arrays, each represented as a sparse array structure or as a full array.
56
% They must have the same numbers of entries (including zeros). When there
67
% are only two arguments, p = 2 is the default, which gives the Euclidean
78
% distance between the two vectors; when p = 1, this function gives the
89
% taxicab distance; when p = inf, it gives the maximum difference.
910
%
10-
% Version 1.0 by Andrew J. Milne, The MARCS Institute, Western Sydney
11-
% University, 2018-01-09
11+
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
1212
%
1313
% See also SPCOSSIM.
1414

1515
if nargin < 3
1616
p = 2;
1717
end
1818
if nargin < 2
19-
error('There must be exactly two arguments (arrays or sparse array structures).')
19+
error(['There must be exactly two arguments (arrays or sparse array ', ...
20+
'structures).'])
2021
end
2122

2223
% Convert full array arguments to sparse array structures

spPerm.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function spC = spPerm(spA,order)
22
%SPPERM Permute dimensions of sparse array structure.
3+
%
34
% spC = spPerm(spA,order): Permute the dimensions of the full array
45
% represented as a sparse array structure or a full array. The second
56
% argument is the vector of permutations. The output is a sparse array
67
% structure.
78
%
8-
% Version 1.0 by Andrew J. Milne, The MARCS Institute, Western Sydney
9-
% University, 2018-01-09
9+
% By Andrew J. Milne, The MARCS Institute, Western Sydney University
1010
%
1111
% See also SPIND2SPSUB, SPSUB2SPIND, PERMUTE.
1212

0 commit comments

Comments
 (0)