%% $RCSfile: sdspperm2.tlc,v $ %% $Revision: 1.4 $ %% $Date: 2000/02/08 23:20:59 $ %% %% Copyright (c) 1995-2000 The MathWorks, Inc. %% %% Abstract: Permute a vector or a matrix by rows or columns %implements sdspperm2 "C" %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Permute Matrix (%) - % */ %% %assign permute_rows = 1 %assign permute_cols = 2 %% %assign INPORT_A = 0 %assign INPORT_P = 1 %assign OUTPORT = 0 %% %assign a_width = LibBlockInputSignalWidth(INPORT_A) %assign p_width = LibBlockInputSignalWidth(INPORT_P) %assign out_width = LibBlockOutputSignalWidth(OUTPORT) %assign cplx = LibBlockInputSignalIsComplex(INPORT_A) != 0 %assign dtype = cplx ? "creal_T" : "real_T" %assign numDims = LibBlockInputSignalNumDimensions(INPORT_A) %assign dims = LibBlockInputSignalDimensions(INPORT_A) %assign rows = dims[0] %assign cols = (numDims == 2) ? dims[1] : 1 %% %% %% Block could be multirate if and only if it has more than %% one input port (eg, a reset input). If it is multirate, %% generate "sample hit" conditional so code executes at the %% block's base rate, and not the overall model base rate. %% %assign differentPortRates = !LibIsSFcnSingleRate(block) %% %if differentPortRates if (%) { % %endif %% %% %% If the signal input is unoriented, ignore the block's mode %% parameter and just perform the operation on indices of the vector. %assign modeParamFromBlockMask = SFcnParamSettings.MODE %assign mode = (numDims == 2) ? modeParamFromBlockMask : permute_rows %% %if (mode==permute_cols && cols==1) || (mode==permute_rows && rows==1) %% %% Degenerate case where permute just copies input to output. %% Index values in P are all clipped to equal 1. %% %if out_width == 1 /* Scalar output equals scalar input. */ % = %; %else %% Switch inner and out loops based on mode %assign outer_loop = (mode==permute_cols) ? p_width : a_width %assign inner_loop = (mode==permute_cols) ? a_width : p_width %% The *u is a special case for scalar input A %if mode==permute_cols %assign u = (inner_loop > 1) ? "u[i]" : "u[0]" %else %assign u = (outer_loop > 1) ? "u[p]" : "u[0]" %endif { % *u = (%*)%; % *y = %; %if outer_loop > 1 int_T p; for(p=0; p < %; p++) { %endif %if inner_loop > 1 int_T i; for(i=0; i < %; i++) { %endif *y++ = %; %if inner_loop > 1 } %endif %if outer_loop > 1 } %endif } %endif %else %% %% Inputs and mode allow permute to occur. %% %if mode == permute_cols %%%%%%%%%%%%%%%%%%%%% /* Permute columns */ %%%%%%%%%%%%%%%%%%%%% { % *y = %; %% %if p_width > 1 int_T i; for (i=0; i<%; i++) { /* Convert to zero based indexing. */ int_T i_idx = (int_T)(%-1); %else %% %% Permute input is a scalar %% int_T i_idx = (int_T)(%-1); %endif %% /* Clip bad index */ if (i_idx < 0) { i_idx = 0; } else if (i_idx > %) { i_idx = %; } %% %if rows > 1 { int_T A_idx = i_idx*%; int_T j; for(j=0; j < %; j++) { *y++ = %; } } %else %% %% Permuting columns of row vector %% %if p_width > 1 *y++ = %; %else *y = %; %endif %endif %% %if p_width > 1 } %% end for %endif } %elseif mode == permute_rows %%%%%%%%%%%%%%%%%% /* Permute rows */ %%%%%%%%%%%%%%%%%% { % *y = %; %% %if p_width > 1 int_T i; for (i=0; i<%; i++) { /* Convert to zero based indexing. */ int_T i_idx = (int_T)(%-1); %else %% %% Permute input is a scalar %% int_T i_idx = (int_T)(%-1); %endif %% /* Clip bad index */ if (i_idx < 0) { i_idx = 0; } else if (i_idx > %) { i_idx = %; } %% %if cols > 1 { int_T A_idx = i_idx; int_T jNp = 0; int_T j; for(j=0; j < %; j++) { /* # rows in output = length of perm vector */ y[jNp] = %; A_idx += %; jNp += %; } y++; /* Next row */ } %else %% %% Permuting rows of column vector %% %if p_width > 1 *y++ = %; %else *y = %; %endif %endif %% %if p_width > 1 } %% end for %endif } %endif %% Modes %endif %% Degenerate case %if differentPortRates } %endif %endfunction %% [EOF] sdspperm2.tlc