BasicVectorOperations/basicVectorOperations.m

45 lines
1.5 KiB
Mathematica
Raw Normal View History

2024-12-05 12:48:11 +01:00
% -----------------
% Copyright © 2019 ACK Cyfronet AGH, Poland.
%
% This work was partially funded by EPOS Project funded in frame of PL-POIR4.2
% -----------------
function [out_vector]=basicVectorOperations(in_vector, numerator, denominator, k, operation_type)
%% BASICVECTOROPERATION Tool for performing simple operations on a given number vector
%
% Input Arguments:
%
% in_vector - input vector
%
% numerator, denominator, k - scalar number - operands of the operation to be performed on the vector
%
% operation_type - name of operation to be performed on vector
%
% Output Arguments:
%
% out_vector - output vector that is the result of the operation
%
2024-12-09 14:11:17 +01:00
error(['Test from experimental-testing-live-code-edits 1']);
2024-12-05 12:48:11 +01:00
switch operation_type
case {'^', 'POWER'}
if(isempty(denominator))
denominator = 1;
end
out_vector = in_vector .^ (numerator/denominator);
case {'FILL_FROM_INDEX'}
if(k>length(in_vector))
error(['Index out of bound. Vector length is: %d, but index is %d'], length(in_vector), k);
else
out_vector = [in_vector(1:k) zeros(1,length(in_vector)-k)];
end
case {'FILL_TO_INDEX'}
if(k>length(in_vector))
error(['Index out of bound. Vector length is: %d, but index is %d'], length(in_vector), k);
else
out_vector = [zeros(1,k) in_vector(k+1:length(in_vector))];
end
otherwise
error(['unsupported operation: "' operation_type '"']);
end
end