Skip to content

Commit

Permalink
support Toeplitz matrices, use case-insensitive comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Jun 5, 2020
1 parent 3119ce4 commit 9434103
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 12 additions & 10 deletions jdatadecode.m
Original file line number Diff line number Diff line change
Expand Up @@ -236,47 +236,49 @@
shapeid={shapeid};
end
arraydata=double(arraydata).';
if(strcmp(shapeid{1},'diag'))
if(strcmpi(shapeid{1},'diag'))
ndata=spdiags(arraydata(:),0,arraysize(1),arraysize(2));
elseif(strcmp(shapeid{1},'upper') || strcmp(shapeid{1},'uppersymm'))
elseif(strcmpi(shapeid{1},'upper') || strcmpi(shapeid{1},'uppersymm'))
ndata=zeros(arraysize);
ndata(triu(true(size(ndata)))')=arraydata(:);
if(strcmp(shapeid{1},'uppersymm'))
if(strcmpi(shapeid{1},'uppersymm'))
ndata(triu(true(size(ndata))))=arraydata(:);
end
ndata=ndata.';
elseif(strcmp(shapeid{1},'lower') || strcmp(shapeid{1},'lowersymm'))
elseif(strcmpi(shapeid{1},'lower') || strcmpi(shapeid{1},'lowersymm'))
ndata=zeros(arraysize);
ndata(tril(true(size(ndata)))')=arraydata(:);
if(strcmp(shapeid{1},'lowersymm'))
if(strcmpi(shapeid{1},'lowersymm'))
ndata(tril(true(size(ndata))))=arraydata(:);
end
ndata=ndata.';
elseif(strcmp(shapeid{1},'upperband') || strcmp(shapeid{1},'uppersymmband'))
elseif(strcmpi(shapeid{1},'upperband') || strcmpi(shapeid{1},'uppersymmband'))
if(length(shapeid)>1 && isvector(arraydata))
datasize=double([shapeid{2}+1, prod(datasize)/(shapeid{2}+1)]);
end
ndata=spdiags(reshape(arraydata,min(arraysize),datasize(1)),-datasize(1)+1:0,arraysize(2),arraysize(1)).';
if(strcmp(shapeid{1},'uppersymmband'))
if(strcmpi(shapeid{1},'uppersymmband'))
diagonal=diag(ndata);
ndata=ndata+ndata.';
ndata(1:arraysize(1)+1:end)=diagonal;
end
elseif(strcmp(shapeid{1},'lowerband') || strcmp(shapeid{1},'lowersymmband'))
elseif(strcmpi(shapeid{1},'lowerband') || strcmpi(shapeid{1},'lowersymmband'))
if(length(shapeid)>1 && isvector(arraydata))
datasize=double([shapeid{2}+1, prod(datasize)/(shapeid{2}+1)]);
end
ndata=spdiags(reshape(arraydata,min(arraysize),datasize(1)),0:datasize(1)-1,arraysize(2),arraysize(1)).';
if(strcmp(shapeid{1},'lowersymmband'))
if(strcmpi(shapeid{1},'lowersymmband'))
diagonal=diag(ndata);
ndata=ndata+ndata.';
ndata(1:arraysize(1)+1:end)=diagonal;
end
elseif(strcmp(shapeid{1},'band'))
elseif(strcmpi(shapeid{1},'band'))
if(length(shapeid)>1 && isvector(arraydata))
datasize=double([shapeid{2}+shapeid{3}+1, prod(datasize)/(shapeid{2}+shapeid{3}+1)]);
end
ndata=spdiags(reshape(arraydata,min(arraysize),datasize(1)),double(shapeid{2}):-1:-double(shapeid{3}),arraysize(1),arraysize(2));
elseif(strcmpi(shapeid{1},'toeplitz'))
ndata=toeplitz(arraydata(:,1),arraydata(:,2)).';
end
if(opt.fullarrayshape && issparse(ndata))
ndata=cast(full(ndata),data(j).(N_('_ArrayType_')));
Expand Down
6 changes: 6 additions & 0 deletions jdataencode.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@
elseif(uband<size(item,2)-1 || lband<size(item,1)-1) % band
newitem.(N('_ArrayShape_'))={'band',uband,lband};
newitem.(N('_ArrayData_'))=spdiags(item.',-uband:lband).';
elseif(all(toeplitz(item(:,1),item(1,:))==item)) % Toeplitz matrix
newitem.(N('_ArrayShape_'))='toeplitz';
newitem.(N('_ArrayZipSize_'))=[2,max(size(item))];
newitem.(N('_ArrayData_'))=zeros(2,max(size(item)));
newitem.(N('_ArrayData_'))(1,1:size(item,2))=item(1,:);
newitem.(N('_ArrayData_'))(2,1:size(item,1))=item(:,1).';
else % full matrix
newitem=item;
end
Expand Down

0 comments on commit 9434103

Please sign in to comment.