Matlab equivalent syntax in Python

Akand Islam sohel807 at gmail.com
Fri Nov 26 16:15:50 EST 2010


On Nov 26, 12:37 am, Tim Roberts <t... at probo.com> wrote:
> Akand Islam <sohel... at gmail.com> wrote:
>
> >Can anyone please suggest me what will be the good way to use matlab
> >equivalent of "profile clear, profile on, profile off, profile resume
> >and profile viewer" in Python?
>
> Python has a number of ways of measuring elapsed time, including the
> "timeit" module and the "trace" module.  There's nothing that will display
> the results in a pretty graph, so the answer depends on what you are after.
> --
> Tim Roberts, t... at probo.com
> Providenza & Boekelheide, Inc.

Dear Tim Roberts,
Thanks for your posting. Like, here is the following Matlab codes
which I am trying to transform into Python. Here you
will find "profile clear, profile on, profile off, profile resume,
profile viewer, and drawnow" syntaxes. So, what will be these
equivalents
in Python?

Regards,
Akand

===============================================================================================================
function x = amg_solve(GUI_HANDLES);

amg_globals;
str=get(GUI_HANDLES.panelText,'String');

%Check the source of the problem specification
if PROB_SRC==USER_SPEC_FD %if the user finite difference matrix is to
be used
    str=strcat(str,sprintf('\n    Initializing Problem to User
Specifications              '));
    str=strcat(str,sprintf('\n    USER: Please enter your input file
name at the console...'));
    set(GUI_HANDLES.panelText,'String',str);
    drawnow;
    amg_usersetFD; %set up globals as the user has specified them
elseif PROB_SRC==USER_SPEC_FEM %if the user finite element matrix is
to be used
    str=strcat(str,sprintf('\n    Initializing Problem to User
Specifications              '));
    str=strcat(str,sprintf('\n    USER: Please enter your input file
name at the console...'));
    set(GUI_HANDLES.panelText,'String',str);
    drawnow;
    amg_usersetFEM; %set up globals as the user has specified them
elseif PROB_SRC==EXAMPLE1 %if example 1 is called for
    str=strcat(str,sprintf('\n    Initializing Problem to Poisson
Example             '));
    set(GUI_HANDLES.panelText,'String',str);
    drawnow;
    amg_example1; %set up globals for example 1
end

profile clear;

if SETUP_OPT==AT_ONCE %if user wishes to find all coarse grids up
front
    % see "restrict.m" for what happens otherwise
    str=strcat(str,sprintf('\n    Calling Setup Algorithm to Determine
Coarse Grids   '));
    set(GUI_HANDLES.panelText,'String',str);
    drawnow;
    if SHOW_PROFILE==YES
        profile on;
    end
    amg_setup(1); %call setup algorithm
    if SHOW_PROFILE==YES
        profile off;
    end
end

INIT_RESID = norm(RHS - (A(1).matrix * X_Guess)); %get initial
residual
str=strcat(str,sprintf('\n    2-Norm of Initial Residual is
%d                     ', INIT_RESID));
set(GUI_HANDLES.panelText,'String',str);
drawnow;

x = X_Guess;
cycleCount = 1; %count the number of AMG cycles executed
while (cycleCount<=CYCLES)
    str=strcat(str,sprintf('\n    Starting AMG Cycle Number
%i...                     ', cycleCount));
    set(GUI_HANDLES.panelText,'String',str);
    drawnow;
    if SHOW_PROFILE==YES
        profile resume;
    end
    x = amg_cycle(cycleCount,1,RHS,x); %execute as many AMG cycles if
necessary
    if SHOW_PROFILE==YES
        profile off;
    end
    str=strcat(str,sprintf('\n    2-Norm of Residual after AMG Cycle
Number %i is %d  ', cycleCount, norm(RH2(cycleCount,1))));
    set(GUI_HANDLES.panelText,'String',str);
    drawnow;
    cycleCount=cycleCount+1; %incriment cycle count
end

FINAL_RESID = norm(RHS - (A(1).matrix * x)); %get initial residual

str=strcat(str,sprintf('\nFinished...
'));
set(GUI_HANDLES.panelText,'String',str);
drawnow;

if SHOW_PROFILE==YES
    profile viewer;
end
==================================================================================================================================



More information about the Python-list mailing list