There are a few problems with this line as it stands.  First, I believe that PEP8 says (and it is a good idea besides) to put modules imports on separate lines.  This is because if there is a problem importing something the traceback will tell you exactly what module is causing problems.  If you get an ImportError right now it is ambiguous as to which of the four modules is failing.  To prevent this, this line should be transformed to the following:

```python
import collections
import math
import linecache
import copy
```

Next up, you shouldn't be using the math module at all.  You should be using numpy instead.  In normal Python, numpy functions are 10-1000x faster than what is in math.  In Cython, which we are in here, they reach C-speeds (1000x+).  You need to add the following lines instead of ```import math``` and then replace all math.* funcs with the numpy equivalent.

```python
cimport numpy as np
import numpy as np
```

Your use of linecache is definitely interesting!  Not wrong or bad, I have just never seen it used for this ;).

The copy module is imported but never used.  The import should be removed.