Product Tips & Techniques

Tips and Tricks on how to get the most about Maple and MapleSim

@John Fredsted

This thread is 3 years old, I don't wish to upset anyone by "reviving" it, forgive me.

I came to this thread as I was searching for information on how to write efficient procedures.

I learned a great deal by looking at how others write a proc.

Now the LinearAlgebra package implements a KroneckerProduct so the need for user-written procedures to...

A new release of MapleSim is now available.

MapleSim 4.5 Highlights

  • Enhanced Modelica support, including the ability to access new collections of components using the Modelica import feature

  • Increased speed and modeling capabilities for continuous systems with discrete events. The enhanced engine handles a far greater class of these systems than earlier versions, and shows significant...

Maple 14.01 is now available. It provides updates in many areas, including:

  • Mathematics: Updates to the VectorCalculus, DifferentialAlgebra, MathematicalFunctions, and Student packages, the convert command, and tools for solving differential equations
  • Interface: Enhancements to context menus, tables, embedded components, document blocks, and the start-up code region
  • Plotting:

A couple of days ago I found out that gzread from the zlib library can be used for fast reading of binary files in Maple from the disk to memory - about 100 times faster than readbytes - something like in the following simplified example, 

A:=Array(1..2^26,99,datatype=integer[1]):

time(writebytes("A",A));close("A");

                                9.360

B:=Array(1..2^26,1,datatype=integer[1]):
time(readbytes("A",B));close("A");

                                8.065
B[1],B[-1];

                                99, 99

myreadbytes:=proc(f)
local gzopen, gzread, gzclose, n, p, A;
gzopen:=define_external('gzopen',
    'path'::string,
    'mode'::string,
    'RETURN'::integer[4],
    'LIB'="zlibwapi.dll");
gzread:=define_external('gzread',
    'file'::integer[4],
    'buf'::REF(ARRAY(datatype=integer[1])),    
    'len'::integer[4],
    'RETURN'::integer[4],
    'LIB'="zlibwapi.dll");
gzclose:=define_external('gzclose',
    'file'::integer[4],
    'RETURN'::integer[4],
    'LIB'="zlibwapi.dll");
n:=FileTools:-Size(f);
A:=Array(1..n,datatype=integer[1]);
try p:=gzopen(f,"rb");
if gzread(p,A,n)=n
then return A end if
finally gzclose(p)
end try
end proc:
time(assign(C=myreadbytes("A")));

                                0.062

C[1],C[-1];

                                99, 99

'time(myreadbytes("A"))'$5;


                  0.078, 0.062, 0.046, 0.046, 0.046

E:=Array(1..2^26,2,datatype=integer[1]):
time(ArrayTools:-Copy(A,E));

                                0.093

That needs some tweaking, because that works only on uncompressed files. If a file ("A" in this example) was gzipped, then the gzread would ungzip n (uncompressed) bytes in it in this example, instead of copying it into the memory - but it is not a big deal, in general.

Does anybody know about a similar replacement for writebytes? gzwrite doesn't work for copying (it compresses the array.)

I used the zlibwapi.dll library from http://www.winimage.com/zLibDll/index.html, it is a version of zlib 1.2.5 (written by Jean-Loup Gailly and Mark Adler) built by Gilles Vollant. The code is for a 32-bit system (Windows). That should work in 32-bit Linux after replacing that dll with standard libz.so.1, as well as on 64-bit systems after replacing integer[4] with integer[8] in most places.

Student's t distribution is named after William Sealy Gosset's pseudonym, Student. He published using this pseudonym because his employer, the Guinness brewery in Ireland, did not allow its employees to publish scientific papers after an incident where trade secrets were disclosed. In this blog...

This post is a further development of my earlier question in reply to John's post. I have implemented a basic version of the CANDECOMP/PARAFAC algorithm referred to on Wikipedia and described 

There are a few ways to view the source of a Maple procedure, such as by using the commands  showstat and print. And these work as usual for the exports of a module. But for procedures which are declared as local to a module these methods do not work right away since by default modules' contents are opaque.

One way around this is to change a setting, by issuing kernelopts(opaquemodules=false) prior to attempting...

I selected the whole document and expanded the document blocks. There near the top of the document were nine copies of "plots[interactive]()" all in a row. Deleting them fixed the problem. Seldom is a fix so easy. Many thanks.

If you want to know what ::uneval does (it's an advanced option for procedure parameters), you can look at the uneval section of ?parameter_modifiers.  It is useful when you want to write a function which works on raw user input rather than on evaluated input.  This is quite tricky, and fraught with danger, and should only be used as a last resort;  but sometimes it really is rather handy.

I've been making some use of the Maple Cloud for a while now, and thought that I'd share some comments.

So far, it's been quite useful to me, and I like it. This surprised me a bit. I expected not to find it useful, and to dismiss it with an old-timer's "Bah, humbug... as useless as Maple+twitter!" But, to the contrary, I've found a use for it; a need that isn't otherwise...

A new edition of The Mathematics Survival Kit – Maple Edition is now available.  It contains 25 new topics, which were created in response to requests from readers of the first edition of the book. New materials range from basic operations such as factoring and fractions, to graph sketching, vectors, and integration.

The Math Survival Kit gives students the opportunity to review exactly the concept or technique they are stuck on, learn what they need to know,...

Let's compare the performance of two methods of computing the inverse of a large datatype=float[8] Matrix.


The two methods are that of calling `MatrixInverse`,...

If you want better performance then don't use 2D Math mode to enter procedures which call  `.` (dot).

The following timings are not the result of the order in which the cases are performed. The timings stay roughly the same if the blocks delimited by restarts are executed out of order.

Important new updates are now available for Maple T.A. 6.  These updates improve performance and stability in areas related to the gradebook, assignment editor, question repository, course module import, and Blackboard and MapleNet integration.

In addition to these improvements, Maplesoft has also released language packs for French and Traditional Chinese. These language packs are a result of the new translatable interface in Maple T.A. 6. If your institution requires...

 

This is the fourth and final part of a blog post, the first three parts of which can be found here: Generating Samples from Custom Probability Distributions (I)

First 31 32 33 34 35 36 37 Last Page 33 of 64