acer

32622 Reputation

29 Badges

20 years, 43 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

In my opinion the applyrule command is very weakly coded. I am not aware of any involved maple procedure or package that relies on it in a major way while not inheriting applyrule's many flaws.

I would reach for other tools first, like structured types and access or replacement tools that used types (subsindets, evalindets, indets, etc).

@tomleslie 

My edits were not intended as a criticism, and I hope weren't taken that way. Apologies it it was. I understand quite well that you were going for exposition and a prototype.

Having said that, the changes were quite short though the speedup is considerable. And its executable statements are just as understandable IMO (barring removal of comments). Things like making the mask creation done with evalhf, having the mask be float[8] datatype, some memory savings by inplace operations, and using `zip` rather than .~ for applying the mask.

It's almost fast enough for the process to be done with Explore, with parameters for the `width` and `centrefreq`. Fast experimentation of the filter application is one reason why I think fast can be useful.

(I am reminded again of a wish for fast, effective, and flexible peak detection in Maple.)

@tomleslie Nice job.

Attached is a revision that runs a bit faster.

restart;

img := ImageTools:-Read("https://i.imgur.com/7tXecNX.png"):

img2:=img[22..621,1..600]:

func:=proc(IMG, width, centrefreq)
  local F,H,W,filter,imgfft,filtfft,filtimg;
  uses ImageTools, ArrayTools, DiscreteTransforms;

  (W,H):=Width(IMG),Height(IMG);
  F:=subs([c=centrefreq,w=width],
          proc(i,j)
            evalhf( 1 - ( exp( - ( sqrt( (i-W/2)^2 + (j-W/2)^2 ) - c )^2/w )) );
          end proc):

  filter:= Array( 1..H, 1..W, F, 'datatype'='float[8]');

  imgfft:= CircularShift( FourierTransform(IMG), H/2, W/2 );

  filtfft:= CircularShift( zip(`*`,filter,imgfft), H/2, W/2 );

  InverseFourierTransform( filtfft,'inplace');

  map[evalhf,'inplace'](Re,filtfft);
  filtimg:= FitIntensity(Array(filtfft,'datatype'='float[8]'),
                         'inplace'=true ):

  end proc:

res := CodeTools:-Usage( func(img2, 150, sqrt(15000.0)) ):

memory used=203.24MiB, alloc change=90.72MiB, cpu time=543.00ms, real time=546.00ms, gc time=44.00ms

#ImageTools:-Embed([img2, res]);

#Q:=Matrix(3,3,(i,j)->sqrt( 2500.0 * (3*(i-1)+j) ));

#ImageTools:-Embed(convert(map(u->ImageTools:-Scale(func(img2, 200, u),0.5),Q),listlist));

 


Download ImProc_faster.mw

@ThU There is also keyboard shortcut for indexed underscripts, Ctl-Shift-_ (control-shift-underscore) for 2D Input mode.

There are also items on the Layout Palette for both indexed and literal name subscripts. (Those palette items have tooltips that show which is which).

Using either keyboard shortcut or palette entry you can obtain nice typeset subscripted input for indexed subscripts, without having to see the 1D style square-bracketed name in the input, and without having to change any preferences.

@vv Yes, that's why I called it "hmm". As in "things that make you go `hmm`". 

@Ian Jones Using Maple 2017.3 and the change-of-variables gets the following (even without conversion to MeijerG).

I find it interesting what happens to the imaginary component, without the change of variables.

restart;

ig:=cos(alpha*s)*(1/8*I)*(-HankelH1(0, beta*s)-(2*I)*BesselK(0, beta*s)/Pi)/beta^2:

ans:=value(IntegrationTools:-Change(Int(ig,s=0..infinity),s=sqrt(t),[t])):

lprint(ans);
   1/8*(I*beta^2*((-alpha^2+beta^2)/beta^2)^(1/2)*((alpha^2+beta^2)/beta^2)^(1/2)+alpha^2-beta^2)/beta^3/(alpha^2-beta^2)/((alpha^2+beta^2)/beta^2)^(1/2)

evalf(eval(ans,[alpha=1,beta=3/2]));
                     0.03081667756 - 0.04969039945 I

hmm:=value(Int(ig,s=0..infinity)):

lprint(hmm);                                                                       
   1/8/beta^3/((alpha^2+beta^2)/beta^2)^(1/2)

evalf(eval(hmm,[alpha=1,beta=3/2]));                                               
                              0.03081667755

evalf(Int(eval(ig,[alpha=1,beta=3/2]),s=0..infinity));
                       0.03081667757 - 0.04969039950 I

int( 1/8*(cos(alpha*s)*(-BesselJ(0,beta*s))/beta^2), s=0..infinity );
                                    0

evalf(Int( eval( 1/8*(cos(alpha*s)*(-BesselJ(0,beta*s))/beta^2),
                 [alpha=1,beta=3/2] ), s=0..infinity ));
                              -0.04969039950
Using 64bit Linux, those last few exact examples above (from `hmm` onward) produce the same non-zero part of the result in Maple 11.02, but not in Maple 12.00.

[edited] It looks like some problem with a mix of floats and symbolics.

I originally guessed a floatPi issue, too hastily and wrongly, away from actual Maple.

It would be interesting to dig down into why `evalf/int` is using such different series, according to the presence of the float.

 

@Daniel Skoog Thanks Daniel.

I've just deleted a Comment of my own above, where I went created and injected such annotations manually into the PLOT structure. Of course your method of doing this is much better.

I coded my version because... I did not see any mention or examples of annotations on the Maple 2017.3 help page for the plots:-pointplot command. Could that be remedied, with both description and example?

ps. Plot annotations do not work in my Maple 2017.2 or Maple 2017.3 for 64bit ubuntu 14.04. Java complains about "TRANSLUCENT translucency" in the console. Is it confirmed to work OK with ubuntu 16.04 ?

@Samir Khan It's very likely that his point 1) is problematic because he just typed `feet` and `inch` as regular names rather than as units. Otherwise his claim that calling simplify(w) "produces 10*feet+6*inch" would not have attained. In this case your suggestion to load Units:-Simple would not help.

Why are you posting yet another duplicate of the very recent question (by member NorwegianStudent) about doing just this??

You already asked yet another duplicate, about how to do just the first part of NorwegianStudent's question. (Then you pasted _Maxim_'s answer to that into the earlier thread, claiming you got "some" help which is a very inadequate attribution IMO.)

 

 

@mapleatha Uploading a worksheet/document containing your problematic example is often very useful. Why not do It?! Big Green Arrow in the Mapleprimes editor.

@mapleatha As has been explained to you by some other people, a formulation like A=B=C in the way that you mean it mathematically is not a valid Maple construct.

The mechanisms I've shown you last above are merely pretty-printing mechanisms. The do not produce expressions that you can use for computation because their return values cannot be Maple constructs that match your hoped-for mathematical interpretation (at least, not without further coding to effect such interpreting).

 

@mapleatha Here is another approach to dealing with your earlier Question about printing A=B=C.

When you first started asking I wasn't sure whether you wanted only an effect on pretty-printing of 2D output, or also a similar look to 2D input. Now it seems more clear that you may be satisfied by just an effect on output, which makes it easier to implement.

Note the there are two procedures defined in the Startup Code Region of this attachment. Without those defined you won't get the effect.

 

The procedures EQ and `print/Determinant` are defined in the Startup Code Region of this worksheet.

If you want these effects in another Worksheet or Document then you willl have to copy those definitions into their respective Startup Code Regions (or use and initialization file, or store the procs in a new .mla archive in libname).

 

M:=<-3,-4;-3,-2>;

M := Matrix(2, 2, {(1, 1) = -3, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2})

'LinearAlgebra:-Determinant(M)' = LinearAlgebra:-Determinant(M);

LinearAlgebra[Determinant](Matrix(2, 2, {(1, 1) = -3, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2})) = -6

EQ(A, B, C);

A = B and B = C

EQ(A, B, M, C, M, C, B, A);

A = B and B = (Matrix(2, 2, {(1, 1) = -3, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2})) and (Matrix(2, 2, {(1, 1) = -3, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2})) = C and C = (Matrix(2, 2, {(1, 1) = -3, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2})) and (Matrix(2, 2, {(1, 1) = -3, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2})) = C and C = B and B = A

EQ('LinearAlgebra:-Determinant(M)', LinearAlgebra:-Determinant(M) );

LinearAlgebra[Determinant](Matrix(2, 2, {(1, 1) = -3, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2})) = -6

EQ(''LinearAlgebra:-Determinant''(M),
   'LinearAlgebra:-Determinant(M)',
   LinearAlgebra:-Determinant(M) );

('LinearAlgebra:-Determinant')(Matrix(2, 2, {(1, 1) = -3, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2})) = LinearAlgebra[Determinant](Matrix(2, 2, {(1, 1) = -3, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2})) and LinearAlgebra[Determinant](Matrix(2, 2, {(1, 1) = -3, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2})) = -6

T:=M-lambda*LinearAlgebra:-IdentityMatrix(2):

EQ( 'LinearAlgebra:-Determinant(T)',
    sort(LinearAlgebra:-Determinant(T)),
    0 );

LinearAlgebra[Determinant](Matrix(2, 2, {(1, 1) = -3-lambda, (1, 2) = -4, (2, 1) = -3, (2, 2) = -2-lambda})) = lambda^2+5*lambda-6 and lambda^2+5*lambda-6 = 0

 


Download typesetdeteq.mw

@mapleatha 

First level right-click popup menu's item is "2-D Math". (This seems to be what you've missed.)

That item leads to a secondary submenu popup with an item "Convert To".

That item leads to a tertiary submenu popup with an item "Atomic Identifier.

 

@AmusingYeti I believe that the ability to return memory to the OS upon garbage collection came with Maple 17, building upon the major overhaul of the memory management system seen in Maple 16.

The help page for topic updates,Maple16,memorymanagement which gives some details of the initial changes. The help pages for topic updates,Maple17,MemoryRegions describes the subsequent changes to allow allocation and management of separate memory heaps (including the ability to return larger cleared blocks to the OS).

Here is an example, run in Maple 2017.3 using 64bit Linux and the Standard GUI. (Note that the command kernelopts(heaps) was new to Maple 17.)

restart;

kernelopts(heaps);

_rtable[18446884572585271294]

kernelopts(bytesalloc);

8781824

M:=Matrix(4000,datatype=float[8]):

kernelopts(heaps);

_rtable[18446884572585273214]

kernelopts(bytesalloc);

170340352

M:='M': # unassign
a: b: c: # clear %,%%,%%%

gc(); # no reference to the Matrix should persist

kernelopts(heaps);

_rtable[18446884572585271414]

kernelopts(bytesalloc);

42336256

 


Download heaps.mw

The other notable aspects of the memory management overhaul include the ability to do garbage collection of disparate chunks in parallel, and the improvement to garbage collection during external calls (think of LinearAlgebra with sfloats in external compiled functions).

First 273 274 275 276 277 278 279 Last Page 275 of 596