Skip to content

Commit

Permalink
complete reformat using miss_hit
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Jun 7, 2022
1 parent 08bd437 commit 617618d
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 92 deletions.
23 changes: 11 additions & 12 deletions example/demo_zmat_basic.m
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
% addpath('../')

% compression
[dzip,info]=zmat(uint8(eye(5,5)))
[dzip, info] = zmat(uint8(eye(5, 5)));

% decompression
orig=reshape(zmat(dzip,0),info.size)
orig = reshape(zmat(dzip, 0), info.size);

% base64 encoding and decoding
base64=zmat('zmat toolbox',1,'base64');
char(base64)
base64 = zmat('zmat toolbox', 1, 'base64');
char(base64);

orig=zmat(base64,0,'base64');
char(orig)
orig = zmat(base64, 0, 'base64');
char(orig);

% encode ND numeric array
orig=single(rand(5));
[Aencoded,info]=zmat(orig,1,'lzma')
orig = single(rand(5));
[Aencoded, info] = zmat(orig, 1, 'lzma');

% decode compressed ND array and restore size/type
Adecoded=zmat(Aencoded,info)

all(all(Adecoded==orig))
class(Adecoded)
Adecoded = zmat(Aencoded, info);

all(all(Adecoded == orig));
class(Adecoded);
4 changes: 4 additions & 0 deletions miss_hit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project_root

suppress_rule: "redundant_brackets"
indent_function_file_body: false
80 changes: 40 additions & 40 deletions src/compilezmat.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compilation script for zmat in MATLAB and GNU Octave
%
%
% author: Qianqian Fang <q.fang at neu.edu>
%
%
% Dependency (Windows only):
% 1.If you have MATLAB R2017b or later, you may skip this step.
% To compile mcxlabcl in MATLAB R2017a or earlier on Windows, you must
% pre-install the MATLAB support for MinGW-w64 compiler
% To compile mcxlabcl in MATLAB R2017a or earlier on Windows, you must
% pre-install the MATLAB support for MinGW-w64 compiler
% https://www.mathworks.com/matlabcentral/fileexchange/52848-matlab-support-for-mingw-w64-c-c-compiler
%
% Note: it appears that installing the above Add On is no longer working
Expand All @@ -21,57 +21,57 @@
% Then, start MATLAB, and in the command window, run
%
% setenv('MW_MINGW64_LOC','C:\msys64\usr');
% 2.After installation of MATLAB MinGW support, you must type
% "mex -setup C" in MATLAB and select "MinGW64 Compiler (C)".
% 2.After installation of MATLAB MinGW support, you must type
% "mex -setup C" in MATLAB and select "MinGW64 Compiler (C)".
% 3.Once you select the MingW C compiler, you should run "mex -setup C++"
% again in MATLAB and select "MinGW64 Compiler (C++)" to compile C++.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

filelist={'lz4/lz4.c','lz4/lz4hc.c','easylzma/compress.c','easylzma/decompress.c', ...
'easylzma/lzma_header.c', 'easylzma/lzip_header.c', 'easylzma/common_internal.c', ...
'easylzma/pavlov/LzmaEnc.c', 'easylzma/pavlov/LzmaDec.c', 'easylzma/pavlov/LzmaLib.c' ...
'easylzma/pavlov/LzFind.c', 'easylzma/pavlov/Bra.c', 'easylzma/pavlov/BraIA64.c' ...
'easylzma/pavlov/Alloc.c', 'easylzma/pavlov/7zCrc.c','zmatlib.c'};
filelist = {'lz4/lz4.c', 'lz4/lz4hc.c', 'easylzma/compress.c', 'easylzma/decompress.c', ...
'easylzma/lzma_header.c', 'easylzma/lzip_header.c', 'easylzma/common_internal.c', ...
'easylzma/pavlov/LzmaEnc.c', 'easylzma/pavlov/LzmaDec.c', 'easylzma/pavlov/LzmaLib.c' ...
'easylzma/pavlov/LzFind.c', 'easylzma/pavlov/Bra.c', 'easylzma/pavlov/BraIA64.c' ...
'easylzma/pavlov/Alloc.c', 'easylzma/pavlov/7zCrc.c', 'zmatlib.c'};

mexfile='zmat.cpp';
suffix='.o';
if(ispc)
suffix='.obj';
mexfile = 'zmat.cpp';
suffix = '.o';
if (ispc)
suffix = '.obj';
end
if(~exist('OCTAVE_VERSION','builtin'))
delete(['*',suffix]);
if(ispc)
CCFLAG='CFLAGS=''-O3 -g -I../include -Ieasylzma -Ieasylzma/pavlov -Ilz4'' -c';
LINKFLAG='CXXLIBS=''$CLIBS -lz'' -output ../zipmat -outdir ../';
if (~exist('OCTAVE_VERSION', 'builtin'))
delete(['*', suffix]);
if (ispc)
CCFLAG = 'CFLAGS=''-O3 -g -I../include -Ieasylzma -Ieasylzma/pavlov -Ilz4'' -c';
LINKFLAG = 'CXXLIBS=''$CLIBS -lz'' -output ../zipmat -outdir ../';
else
CCFLAG='CFLAGS=''-O3 -g -I../include -Ieasylzma -Ieasylzma/pavlov -Ilz4 -fPIC'' -c';
LINKFLAG='CXXLIBS=''\$CLIBS -lz'' -output ../zipmat -outdir ../';
CCFLAG = 'CFLAGS=''-O3 -g -I../include -Ieasylzma -Ieasylzma/pavlov -Ilz4 -fPIC'' -c';
LINKFLAG = 'CXXLIBS=''\$CLIBS -lz'' -output ../zipmat -outdir ../';
end
for i=1:length(filelist)
fprintf(1,'mex %s %s\n', CCFLAG, filelist{i});
for i = 1:length(filelist)
fprintf(1, 'mex %s %s\n', CCFLAG, filelist{i});
eval(sprintf('mex %s %s', CCFLAG, filelist{i}));
end
filelist=dir(['*' suffix]);
filelist={filelist.name};
cmd=sprintf('mex %s -I../include -Ieasylzma %s %s',mexfile, LINKFLAG, sprintf('%s ' ,filelist{:}));
fprintf(1,'%s\n',cmd);
eval(cmd)
filelist = dir(['*' suffix]);
filelist = {filelist.name};
cmd = sprintf('mex %s -I../include -Ieasylzma %s %s', mexfile, LINKFLAG, sprintf('%s ', filelist{:}));
fprintf(1, '%s\n', cmd);
eval(cmd);
else
delete('*.o');
CCFLAG='-O3 -g -c -I../include -Ieasylzma -Ieasylzma/pavlov -Ilz4';
LINKFLAG='-o ../zipmat -lz';
for i=1:length(filelist)
fprintf(stdout,'mex %s %s\n', CCFLAG, filelist{i});
CCFLAG = '-O3 -g -c -I../include -Ieasylzma -Ieasylzma/pavlov -Ilz4';
LINKFLAG = '-o ../zipmat -lz';
for i = 1:length(filelist)
fprintf(stdout, 'mex %s %s\n', CCFLAG, filelist{i});
fflush(stdout);
eval(sprintf('mex %s %s', CCFLAG, filelist{i}));
end
if(ispc)
filelist=dir(['*.o']);
filelist={filelist.name};
if (ispc)
filelist = dir(['*.o']);
filelist = {filelist.name};
end
cmd=sprintf('mex %s -I../include -Ieasylzma %s %s',mexfile, LINKFLAG, regexprep(sprintf('%s ' ,filelist{:}),'\.c[p]*','\.o'));
fprintf(stdout,'%s\n',cmd);fflush(stdout);
eval(cmd)
cmd = sprintf('mex %s -I../include -Ieasylzma %s %s', mexfile, LINKFLAG, regexprep(sprintf('%s ', filelist{:}), '\.c[p]*', '\.o'));
fprintf(stdout, '%s\n', cmd);
fflush(stdout);
eval(cmd);
end

80 changes: 40 additions & 40 deletions zmat.m
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
function varargout=zmat(varargin)
function varargout = zmat(varargin)
%
% output=zmat(input)
% or
% [output, info]=zmat(input, iscompress, method)
% output=zmat(input, info)
%
% A portable data compression/decompression toolbox for MATLAB/GNU Octave
%
%
% author: Qianqian Fang <q.fang at neu.edu>
% initial version created on 04/30/2019
%
% input:
% input: a char, non-complex numeric or logical vector or array
% iscompress: (optional) if iscompress is 1, zmat compresses/encodes the input,
% iscompress: (optional) if iscompress is 1, zmat compresses/encodes the input,
% if 0, it decompresses/decodes the input. Default value is 1.
%
% if iscompress is set to a negative integer, (-iscompress) specifies
% the compression level. For zlib/gzip, default level is 6 (1-9); for
% the compression level. For zlib/gzip, default level is 6 (1-9); for
% lzma/lzip, default level is 5 (1-9); for lz4hc, default level is 8 (1-16).
% the default compression level is used if iscompress is set to 1.
%
% zmat removes the trailing newline when iscompress=2 and method='base64'
% all newlines are removed when iscompress=3 and method='base64'
%
% if one defines iscompress as the info struct (2nd output of zmat), zmat
% if one defines iscompress as the info struct (2nd output of zmat), zmat
% will perform a decoding/decompression operation and recover the original
% input using the info stored in the info structure.
% method: (optional) compression method, currently, zmat supports the below methods
Expand All @@ -36,17 +36,17 @@
% 'base64': encode or decode use base64 format
%
% output:
% output: a uint8 row vector, storing the compressed or decompressed data;
% output: a uint8 row vector, storing the compressed or decompressed data;
% empty when an error is encountered
% info: (optional) a struct storing additional info regarding the input data, may have
% 'type': the class of the input array
% 'size': the dimensions of the input array
% 'byte': the number of bytes per element in the input array
% 'method': a copy of the 3rd input indicating the encoding method
% 'status': the zlib/lzma/lz4 compression/decompression function return value,
% including potential error codes; see documentation of the respective
% 'status': the zlib/lzma/lz4 compression/decompression function return value,
% including potential error codes; see documentation of the respective
% libraries for details
% 'level': a copy of the iscompress flag; if non-zero, specifying compression
% 'level': a copy of the iscompress flag; if non-zero, specifying compression
% level, see above
%
% example:
Expand All @@ -60,58 +60,58 @@
% -- this function is part of the ZMAT toolbox (http://github.com/fangq/zmat)
%

if(exist('zipmat')~=3 && exist('zipmat')~=2)
if (exist('zipmat') ~= 3 && exist('zipmat') ~= 2)
error('zipmat mex file is not found. you must download the mex file or recompile');
end

if(nargin==0)
fprintf(1,'Usage:\n\t[output,info]=zmat(input,iscompress,method);\nPlease run "help zmat" for more details.\n');
return;
if (nargin == 0)
fprintf(1, 'Usage:\n\t[output,info]=zmat(input,iscompress,method);\nPlease run "help zmat" for more details.\n');
return
end

input=varargin{1};
iscompress=1;
zipmethod='zlib';
input = varargin{1};
iscompress = 1;
zipmethod = 'zlib';

if(~(ischar(input) || islogical(input) || (isnumeric(input) && isreal(input))))
if (~(ischar(input) || islogical(input) || (isnumeric(input) && isreal(input))))
error('input must be a char, non-complex numeric or logical vector or N-D array');
end

if(ischar(input))
input=uint8(input);
if (ischar(input))
input = uint8(input);
end

if(nargin>1)
iscompress=varargin{2};
if(isstruct(varargin{2}))
inputinfo=varargin{2};
iscompress=0;
zipmethod=inputinfo.method;
if (nargin > 1)
iscompress = varargin{2};
if (isstruct(varargin{2}))
inputinfo = varargin{2};
iscompress = 0;
zipmethod = inputinfo.method;
end
end

if(nargin>2)
zipmethod=varargin{3};
if (nargin > 2)
zipmethod = varargin{3};
end

iscompress=round(iscompress);
iscompress = round(iscompress);

if((strcmp(zipmethod,'zlib') || strcmp(zipmethod,'gzip')) && iscompress<=-10)
iscompress=-9;
if ((strcmp(zipmethod, 'zlib') || strcmp(zipmethod, 'gzip')) && iscompress <= -10)
iscompress = -9;
end

[varargout{1:max(1,nargout)}]=zipmat(input,iscompress,zipmethod);
[varargout{1:max(1, nargout)}] = zipmat(input, iscompress, zipmethod);

if(strcmp(zipmethod,'base64') && iscompress>1)
varargout{1}=char(varargout{1});
if(iscompress==2)
varargout{1}=regexprep(varargout{1},'\n$','');
elseif(iscompress>2)
varargout{1}=regexprep(varargout{1},'\n','');
if (strcmp(zipmethod, 'base64') && iscompress > 1)
varargout{1} = char(varargout{1});
if (iscompress == 2)
varargout{1} = regexprep(varargout{1}, '\n$', '');
elseif (iscompress > 2)
varargout{1} = regexprep(varargout{1}, '\n', '');
end
end

if(exist('inputinfo','var') && isfield(inputinfo,'type'))
varargout{1}=typecast(varargout{1},inputinfo.type);
varargout{1}=reshape(varargout{1},inputinfo.size);
if (exist('inputinfo', 'var') && isfield(inputinfo, 'type'))
varargout{1} = typecast(varargout{1}, inputinfo.type);
varargout{1} = reshape(varargout{1}, inputinfo.size);
end

0 comments on commit 617618d

Please sign in to comment.