Debugging numpy (any C code of Python) using gdb

I created a tiny python script that executes some python code, that executes some C code:

# contents of dbg_broadcast.py
import numpy
print list(numpy.broadcast([[1,2]],[[3],[4]]))

> gdb python
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
.................. bla bla bla ..................................................

# Adding breakpoint to function "arraymultiter_new" (example):
(gdb) break arraymultiter_new

# There is name completition by Tab.
# Run script
(gdb) run dbg_broadcast.py 
Starting program: /home/asdasd/work/bin/python dbg_broadcast.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, arraymultiter_new (__NPY_UNUSED_TAGGEDsubtype=0x7ffff6abbf80 <PyArrayMultiIter_Type>, 
    args=0x7ffff32dd050, kwds=0x0) at numpy/core/src/multiarray/iterators.c:1578
1578 {
(gdb) 


And here we are.





Scipy in pypy

Looks like it is too early for using scipy in Pypy. There is a plenty of dependencies on C-code there.
I was able to install scipy 0.17 in pypy. I disabled all failed dependencies. Unfortunately it is completely useless. Almost everything doesn't work.

https://github.com/serge-m/scipy/blob/v0.17.0_for_pypy_bin/bin/scipy_0.17.0_for_pypy_draft.tar.gz



Building Pypy

Pypy builds faster if using -O2 option.



To build faster (according to pypy documentation) use prebuilt pypy from http://buildbot.pypy.org/nightly/trunk/

Using virtualenv to create virtual environment for it.

Build script (to be placed in pypy source directory):

#!/bin/bash
cd pypy/goal || exit 1
source <path to existing pypy environment>/bin/activate || exit 2
pypy ../../rpython/bin/rpython --batch -O2 targetpypystandalone



TIL about PyPy

Building from source root using command
pypy_src$ rpython/bin/rpython -Ojit pypy/goal/targetpypystandalone.py
produces structure with obsolete pypy-c and libpypy-c.so in
/tmp/usession-release-4.0.1-XXXX/build/pypy-nightly/bin/

Probably pypy compiler places there files integrated in the src distribution. To get fresh versions I had to use pypy-c and libpypy-c.so from sources root.

UPDATE:
Probably I was completely wrong.
pypy/tool/release/package.py has an option for (not) stripping resulting binary file: "--nostrip". By default it is enabled. Looks like it removed something unused from binaries. This operation updates timestamp of the pypy-c and libpypy-c.so. So probably that was the cause of my misunderstanding.


Script for packaging and creating virtual environment:

#!/bin/bash

rm -rf ./my_builds/ || exit 2
mkdir ./my_builds/ || exit 3

DST_NAME=$1
if [ -z "$DST_NAME" ]; then
    echo "DST_NAME is  empty"
    exit 3
fi

# runs packaging
./pypy/tool/release/package.py --builddir /home/pypy/builds/ --nostrip --archive-name $DST_NAME || exit 4

# creates a new virtual environment
virtualenv -p /home/pypy/builds/$DST_NAME/bin/pypy /home/pypy/env/$DST_NAME

# installing nose for numpy testing (optional)
source /home/pypy/env/$DST_NAME/bin/activate
pip install nose




avconv

convert video to jpeg with good quality
avconv -i input_video.mp4 -qmax 1 -qmin 1 images_%05d.jpg

crop video
avconv -i input.avi -vf crop=<width>:<height>:<x>:<y> output_%05d.png


create gif using http://gifmaker.me/

М

Пусть человечество лучше погибнет в результате восстания машин, чем в глобальной войне. Тогда мы умрём дураками, но хотя бы людьми.

Operations with lists in Java

Initializa list:

List<String> names = Arrays.asList("Bob", "John", "Alice");