Skip to content

Commit a8a4a15

Browse files
committed
Added links to chapters
1 parent d1484ac commit a8a4a15

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

06-custom-vectorization.rst

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,43 @@ Custom vectorization
1010
Introduction
1111
------------
1212

13-
.. One of the strength of Numpy is that it allows you to write your own array class. The mechanism is a bit tedious but it is worth the effort.
13+
One of the strength of Numpy is that it allows you to `subclass the ndarray
14+
<https://docs.scipy.org/doc/numpy/user/basics.subclassing.html>`_ object. The
15+
process is a bit tedious but it is worth the effort because it allows you to
16+
create new objects that suit perfectly your problem. We'll examine in the
17+
following section two real-word cases (typed list and memory aware) that are
18+
extensively used in the `glumpy <http://glumpy.github.io>`_ project while the
19+
last one (double precision array) is a more academic case.
1420

1521

1622
Typed list
1723
----------
1824

25+
Typed list (also known as ragged array) is a list of items that all have the
26+
same data type (in the sense of numpy). They offer both the list and ndarray
27+
API (with some restriction of course). Since respective API may be not
28+
compatible in some cases, we have to make some choices:
29+
30+
.. code:: python
31+
32+
>>> l = TypedList(int)
33+
>>> l.append([1,2])
34+
>>> l.append([3])
35+
>>> print(l)
36+
[1, 2], [3]
37+
>>> print(l+1)
38+
[2, 3], [4]
39+
40+
For the `+` operator, we'll choose to use Numpy API where the value is added to
41+
each individual item instead of expanding the list by appending a new item
42+
(`1`).
43+
44+
1945
..
2046
We would like to define a typed list object such that if offers both the Python
2147
list API and the Numpy array API (with some restriction of course). We would
2248
like for example to be able to write:
2349
24-
.. code:: python
25-
26-
>>> l = TypedList(int)
27-
>>> l.append(1)
2850

2951
We first need to subclass the ndarray object and define a new init method.
3052

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ This work is licensed under a
44
[Creative Commons Attribution 4.0 International License]
55
(http://creativecommons.org/licenses/by/4.0/).
66

7-
**Work in progress. No due date yet.**
7+
* [Preface](preface.rst)
8+
* [Introduction](introduction.rst)
9+
* [Anatomy of an array](anatomy.rst)
10+
* [Code vectorization](code-vectorization.rst)
11+
* [Problem vectorization](problem-vectorization.rst)
12+
* [Custom vectorization](custom-vectorization.rst)
13+
* [Beyond Numpy](beyond-numpy.rst)
14+
* [Conclusion](conclusion.rst)
15+
* [Quick references](quick-reference.rst)
16+
* [Bibliography](bibliography.rst)

0 commit comments

Comments
 (0)