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: M1_multiply_doc.m
    path of file: ./repos/mtt/libs/tensor_toolbox_2.5/doc
    
    the code of the file until where you have to start completion: %% Multiplying tensors

%% Tensor times vector (ttv for tensor)
% Compute a tensor times a vector (or vectors) in one (or more) modes.
rand('state',0);
X = tenrand([5,3,4,2]); %<-- Create a dense tensor.
A = rand(5,1); B = rand(3,1); C = rand(4,1); D = rand(2,1); %<-- Some vectors.
%%
Y = ttv(X, A, 1) %<-- X times A in mode 1.
%%
Y = ttv(X, {A,B,C,D}, 1) %<-- Same as above.
%%
Y = ttv(X, {A,B,C,D}, [1 2 3 4]) %<-- All-mode multiply produces a scalar.
%%
Y = ttv(X, {D,C,B,A}, [4 3 2 1]) %<-- Same as above.
%%
Y = ttv(X, {A,B,C,D}) %<-- Same as above.
%%
Y = ttv(X, {C,D}, [3 4]) %<-- X times C in mode-3 & D in mode-4.
%%
Y = ttv(X, {A,B,C,D}, [3 4]) %<-- Same as above.
%%
Y = ttv(X, {A,B,D
    
function |innerprod| efficiently computes the inner product
% between two tensors X and Y.  The code does this efficiently
% depending on what types of tensors X and Y.
X = tensor(rand(2,2,2))
Y = ktensor({rand(2,2),rand(2,2),rand(2,2)})
%%
z = innerprod(X,Y)
%% Contraction on tensors (contract for tensor)
% The function |contract| sums the entries of X along dimensions I and
% J.  Contraction is a generalization of matrix trace. In other words,
% the trace is performed along the two-dimensional slices defined by
% dimensions I and J. It is possible to implement tensor
% multiplication as an outer product followed by a contraction.
X = sptenrand([4 3 2],5); 
Y = sptenrand([3 2 4],5);
%%
Z1 = ttt(X,Y,1,3); %<-- Normal tensor multiplication
%%
Z2 = contract(ttt(X,Y),1,6); %<-- Outer product + contract
%%
norm(Z1-Z2) %<-- Should be zero
%%
% Using |contract| on either sparse or dense tensors gives the same
% result
X = sptenrand([4 2 3 4],20); 
Z1 = contract(X,1,4)        % sparse version of contract
%%
Z2 = contract(full(X),1,4)  % dense version of contract
%%
norm(full(Z1) - Z2) %<-- Should be zero
%%
% The result may be dense or sparse, depend