function [type,m,r] = match_type(varargin)
% MATCH_TYPE - propagate type, dilation factor, multiplicity
%
% [type,m,r] = match_type(P1,P2,P3,...)
%
% This is used only in multiwavelet calculations.
%
% If one or more of the input arguments have matching type, m, r,
% and the rest have no type, return the matching values.
% If there is a mismatch, or none of the arguments has a type,
% return type='', m=0, r=0
%
% This is used to assign the correct type to the result of a
% calculation, such as a matrix product.
% For example, a symbol matrix times a non-typed matrix returns
% type 'symbol'. A symbol matrix times a polyphase matrix
% returns type ''.
%
% This routine is not meant to be called by the user. It is called
% from inside the basic arithmetic routines.
% Copyright (c) 2004 by Fritz Keinert (keinert@iastate.edu),
% Dept. of Mathematics, Iowa State University, Ames, IA 50011.
% This software may be freely used and distributed for non-commercial
% purposes, provided this copyright statement is preserved, and
% appropriate credit for its use is given.
%
% Last update: Feb 20, 2004
type = '';
m = 0;
r = 0;
for i=1:nargin
% we can ignore any standard matrices mixed in with the arguments
if isa(varargin{i},'mpoly')
% check type
if ~strcmp(varargin{i}.type,'')
if strcmp(type,'')
% first nonempty type found
type = varargin{i}.type;
elseif ~strcmp(type, varargin{i}.type)
% mismatch
type = '';
m = 0;
r = 0;
return
end
end
% check dilation factor
if (varargin{i}.m ~= 0)
if (m == 0)
% first nonempty dilation factor found
m = varargin{i}.m;
elseif (m ~= varargin{i}.m)
% mismatch
type = '';
m = 0;
r = 0;
return
end
end
% check multiplicity
if (varargin{i}.r ~= 0)
if (r == 0)
% first nonempty dilation factor found
r = varargin{i}.r;
elseif (r ~= varargin{i}.r)
% mismatch
type = '';
m = 0;
r = 0;
return
end
end
end
end