edbennett / performant-numpy

A lesson on ways to write Numpy code that is performant
Other
1 stars 2 forks source link

Generalised ufunc exercise needs to create Tn array #1

Closed colinsauze closed 5 years ago

colinsauze commented 5 years ago

The supplied non vectorised example expects a return from ftcs but doesn't return anything. But this will get removed when vectorising it.

The Tn parameter needs some pre-initalisation before being passed in.

for t in range(nt): Tn = ftcs(Ti, alpha, dt, dx) Ti = Tn.copy()

can become:

for t in range(nt): Tn = numpy.empty_like(Ti) ftcs(Ti, alpha, dt, dx,Tn) Ti = Tn.copy()

I'll submit a pull request with modified code.

edbennett commented 5 years ago

The instruction "so that run_ftcs works properly" was intended to imply that this wasn't meant to work as-is, and would only work when correctly vectorised, but maybe it's better to start off with a working example…