%% $RCSfile: sdspperm.tlc,v $ %% $Revision: 1.9 $ %% $Date: 2000/06/15 20:37:47 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Permute a vector or a matrix by rows or columns %implements sdspperm "C" %% Function: BlockInstanceSetup =============================================== %% %function BlockInstanceSetup(block, system) void %% % % % %% %endfunction %% 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 mode = LibBlockParameterValue(Mode,0) %assign cols = CAST("Number",LibBlockParameterValue(Cols,0)) %assign a_width = CAST("Number",LibDataInputPortWidth(INPORT_A)) %assign rows = CAST("Number",a_width/cols) %assign p_width = CAST("Number",LibDataInputPortWidth(INPORT_P)) %assign out_width = CAST("Number",LibDataOutputPortWidth(OUTPORT)) %assign cplx = LibBlockInputSignalIsComplex(INPORT_A) != 0 %assign dtype = cplx ? "creal_T" : "real_T" %% %if !IsInputPortContiguous(block,INPORT_A) || !IsInputPortContiguous(block,INPORT_P) % %endif %% %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 %endfunction %% [EOF] sdspperm.tlc