You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: test_chop.m
    path of file: ./repos/chop
    
    the code of the file until where you have to start completion: function test_chop
%TEST_CHOP Test the chop function.
%   The tests are for single precision and fp16.

clear chop fp options options2 assert_eq

rng(1)

n = 0;
uh = 2^(-11);  % Unit roundoff for fp16.
pi_h = 6432*uh; % fp16(pi)

% Check handling of defaults and persistent variable.
fp.format = 'bfloat16'; [c,options] = chop(pi,fp);
assert_eq(fp.format,options.format)
assert_eq(options.subnormal,0)

fp.format = []; [c,options] = chop(pi,fp);
assert_eq(options.format,'h')  % Check default;

fp.subnormal = 0; [c,options] = chop(pi,fp);
assert_eq(options.subnormal,0)

fp.subnormal = []; [c,options] = chop(pi,fp);
assert_eq(options.subnormal,1)  % Check default;

fp.round = []; [c,options] = chop(pi,fp);
assert_eq(options.round,1)  % Check default.

fp.flip = []; [c,options] = chop(pi,fp);
assert_eq(options.flip,0)  % Check no default.

fp.explim = []; [c,options] = chop(pi,fp);
assert_eq(options.explim,1)  % Check default.

fp.explim = 0; [c,options] = chop(pi,fp);
assert_eq(options.explim,0)  % Check no default.

clear chop fp options

    
function test_chop
%TEST_CHOP Test the chop function.
%   The tests are for single precision and fp16.

clear chop fp options options2 assert_eq

rng(1)

n = 0;
uh = 2^(-11);  % Unit roundoff for fp16.
pi_h = 6432*uh; % fp16(pi)

% Check handling of defaults and persistent variable.
fp.format = 'bfloat16'; [c,options] = chop(pi,fp);
assert_eq(fp.format,options.format)
assert_eq(options.subnormal,0)

fp.format = []; [c,options] = chop(pi,fp);
assert_eq(options.format,'h')  % Check default;

fp.subnormal = 0; [c,options] = chop(pi,fp);
assert_eq(options.subnormal,0)

fp.subnormal = []; [c,options] = chop(pi,fp);
assert_eq(options.subnormal,1)  % Check default;

fp.round = []; [c,options] = chop(pi,fp);
assert_eq(options.round,1)  % Check default.

fp.flip = []; [c,options] = chop(pi,fp);
assert_eq(options.flip,0)  % Check no default.

fp.explim = []; [c,options] = chop(pi,fp);
assert_eq(options.explim,1)  % Check default.

fp.explim = 0; [c,options] = chop(pi,fp);
assert_eq(options.explim,0)  % Check no default.

clear chop fp options
fp.flip = 1; [~,options] = chop([],fp);
assert_eq(options.format,'h')
assert_eq(options.round,1)
assert_eq(options.subnormal,1)

clear chop fp options
% check all default options
fp.format = []; fp.subnormal = [];
fp.round = []; fp.flip = [];
fp.p = [];
[c,options] = chop(pi,fp);
assert_eq(options.format,'h')
assert_eq(options.subnormal,1)
assert_eq(options.round,1)
assert_eq(options.flip,0)
assert_eq(options.p,0.5)
% % Takes different path from previous test since fpopts exists.
% fp.subnormal = 0;
% fp.format = []; [c,options] = chop(pi,fp);
% assert_eq(options.format,'h')

% Check flip output.
clear chop fp
fp.flip = 1; fp.format = 'd';
c = ones(8,1);
d = chop(c,fp); assert_eq(norm(d-c,1)>0,true);
d = chop(c',fp); assert_eq(norm(d-c',1)>0,true);
fp.p = 0; % No bits flipped.
d = chop(c,fp); assert_eq(d,d);
fp.p = 1; % All bits flipped.
d = chop(c,fp); assert_eq(all(d ~= c),true);

clear chop
[~,fp] = chop;
assert_eq(fp.subnormal,1)
assert_eq(fp.format,'h')
[c,options] = chop(pi);
assert_eq(options.format,'h')
assert_eq(options.subnormal,1)
assert_eq(options.round,1)
assert_eq(options.flip,0)
assert_eq(options.p,0.5)

fp.format = 'd'; [c,options] = chop(pi,fp);
assert_eq(options.format,'d')
assert_eq(options.subnormal,1)
assert_eq(options.params, [53 1023])
[~,fp] = chop;
assert_eq(fp.format,'d')
assert_eq(fp.subnormal,1)
assert_eq(fp.params, [53 1023])

clear fp
fp.format = 'bfloat16'; [c,options] = chop(pi,fp);
assert_eq(options.format,'bfloat16')
assert_eq(options.subnormal,0)
assert_eq(options.params, [8 127])
[~,fp] = chop;
assert_eq(fp.format,'bfloat16')
assert_eq(fp.subnormal,0)
assert_eq(fp.params, [8 127])

clear chop
[~,fp] = chop;
fp.format = 'b'; [c,options] = chop(pi,fp);
assert_eq(options.subnormal,1) % No subnormals only if that field was empty.

% Check these usages do not give an error.
c = chop([]);
chop([]);
chop([],fp);
chop(1,fp);
c = chop(1,fp);

% Test matrix.
options.format = 'b';
A = magic(4);
C = chop(A,options);
assert_eq(A,C);
B = A + randn(size(A))*1e-12;
C = chop(B,options);
assert_eq(A,C);
A2 = hilb(6); C = chop(A2);

options.format = 'c';
options.params = [8 127];  % bfloat16
C1 = chop(A,options);
assert_eq(A,C1);
C2 = chop(B,options);
assert_eq(A,C2);
assert_eq(C,chop(A2));

clear options
options.format = 'c';
options.params = [11 15];  % h
options2.format = 'h';
A = hilb(6);
[X1,opt] = chop(A,options);
[X2,opt2] = chop(A,options2);
assert_eq(X1,X2)
% assert_eq(chop(A,options),chop(A,options2));

% Row vector
clear options
options.format = 'h';
A = -10:10;
C = chop(A,options);
assert_eq(A,C);
B = A + randn(size(A))*1e-12;
C = chop(B,options);
assert_eq(A,C);

% Column vector
options.format = 's';
A = (-10:10)';
C = chop(A,options);
assert_eq(A,C);
B = A + A.*rand(size(A))*1e-14;  % Keep 0 as 0.
C = chop(B,options);
assert_eq(A,C);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Main loop: test single, half and quarter formats.
for i = 1:4
clear chop fp options

if i == 1
   % Single precision tests.
   [u,xmins,xmin,xmax,p,emins,emin,emax] = float_params('single');
   options.format = 's';
elseif i == 2
   % Half precision tests.
   [u,xmins,xmin,xmax,p,emins,emin,emax] = float_params('half');
   options.format = 'h';
elseif i == 3
   % Half precision tests.
   [u,xmins,xmin,xmax,p,emins,emin,emax] = float_params('fp8-e4m3');
   options.format = 'fp8-e4m3';
elseif i == 4
   % Half precision tests.
   [u,xmins,xmin,xmax,p,emins,emin,emax] = float_params('fp8-e5m2');
   options.format = 'fp8-e5m2';
end