MaplePrimes Commons General Technical Discussions

The primary forum for technical discussions.

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.

Click Maple Math, enter x^2/(1+x).   The Preview disappears as soon as I press "/", and the result is not pretty-printed.

x^2/(1+x)

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...

Quite often, when plotting an expression in involving trigonometric functions applied to (a rational polynomial of) the main variable, it is desirable to have the major ticks along the x-axis be labeled by multiples of Pi. In particular, it can be much more appealing to have those tickmarks be labeled with short rationals multiplied by the 2D Math symbol π.

In examining ODE models containing parameters I don't like to assign values to these, but use the form

param:={a=2, b=7};
and then
eval(expression, param);

This works well. There are situations, however, where this method can be cumbersome.
This would be the case in a situation like this:

plot(a*sin(x),x=0..b);

You could do

plot(op(eval([a*sin(x),x=0..b],param)));

But maybe an operator having a syntax similar to 'assuming' could be useful.

If I assign a list to a variable named depth it causes invalid object errors in for loops for Maple12

depth:=[1,2,3,4,5,6,7,8]:

for i from 1 to 4 do
  i;
end do;

Error, invalid object: mspace(height = "0.0ex",width = "0.0em",[1, 2, 3, 4, 5, 6, 7, 8] = "0.0ex",linebreak = "newline") and  1 additional error.

 

 

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.

Most of the comparisons (that I've seen so far) amongst Maple, Matlab, and Mathematica are either incomplete, inaccurate, or biased.

This collection of three articles [1 (1), 2 (2),

Dear Maple users

I use Maple in my physics class in high school. In connection to that I have stumbled on a couple of oddities with the new version 14:

It looks like a bug, that Maple...

I'm not sure why this is, but almost any topic I look up there is a link to someone who has done something similar to it in Matlab or Mathematica but not Maple.  And almost always if something is found in Maple, it can be found in both Matlab and Mathematica. 

Let's take for example googling rock paper and scissors.  Someone's done a simulation in Matlab and there's a notebook in mathematica, however I find nothing in Maple.  Also, however,...

On Tuesday August 10, 2010, the first meeting of an ad hoc group focused on exploring the use of MapleSim in the engineering curriculum met at McMaster University, Hamilton, Ontario, Canada.  Faculty from McMaster University, Kettering University, Lawrence Technical University, University of Waterloo, Ryerson University, University of Ontario Inst. of Technology, and the State University of New York (Buffalo and Binghamton).

The full-day workshop provided an ideal...

 

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)

This is the third post in a four-part series; the earlier posts are Generating...

First 18 19 20 21 22 23 24 Last Page 20 of 80