:

## Overcoming the slowness of the map and zip functions

Maple
It is quite frustrating how slow map or zip acts over rtables (examples below). I find it quite useful to write a separate procedure and use the new compiler abilities in Maple 10.
```> X := Statistics:-Sample(Uniform(0,1), 10^5):
> XCopy := Vector(X):
> Y := Statistics:-Sample(Uniform(0,1), 10^5):
> ts:=time(): B:=zip((x,y)->evalhf(x/y), X, Y); time()-ts; # X/Y

[ 1 .. 100000 Vector[row] ]
[ Data Type: anything     ]
B := [ Storage: rectangular    ]
[ Order: Fortran_order    ]

11.627

> p := proc(XX_::rtable(datatype=float[8]), YY_::rtable(datatype=float[8]), ans::rtable(datatype=float[8]), N::integer)

>   local i::integer;

>   for i to N do

>     ans[i] := XX_[i]/YY_[i];

>   end do;

>   return;

> end proc:

> cp := Compiler:-Compile(p):

> A := Vector(1..10^5,datatype=float[8]);

[ 1 .. 100000 Vector[column] ]
[ Data Type: float[8]        ]
A := [ Storage: rectangular       ]
[ Order: Fortran_order       ]

> ts:=time(): cp(X,Y,A,10^5); time()-ts; # use cp to calculate A=X/Y

0.030

> ArrayTools:-IsZero(A-B);

true

> ts := time(): map[inplace](x->evalhf(log(x)), XCopy); time()-ts; # even computing the log(XCopy) in place is horribly slow

[ 1 .. 100000 Vector[row] ]
[ Data Type: float[8]     ]
[ Storage: rectangular    ]
[ Order: Fortran_order    ]

10.174

> q := proc(X_::rtable(datatype=float[8]), N::integer)

>   local i::integer;

>   for i to N do

>     X_[i] := log(X_[i]);

>   end do;

>   return;

> end proc:

> cq := Compiler:-Compile(q):

> ts:=time(): cq(X,10^5); time()-ts;

0.120

> ArrayTools:-IsZero(X-XCopy);

true
```

﻿