File: memorytest.py

package info (click to toggle)
python-numarray 1.1.1-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,428 kB
  • ctags: 8,469
  • sloc: ansic: 92,018; python: 20,861; makefile: 263; sh: 13
file content (44 lines) | stat: -rw-r--r-- 898 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
This module provides a selftest for the numarray.memory c-extension.

>>> m = new_memory(10)
>>> len(m)
10
>>> for i in range(len(m)):
...     m[i] = i
>>> str(m)
'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t'
>>> [ x for x in m ]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> [ x for x in m.copy()]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

A slice of a memory object returns an alias to the sliced region, not a copy.

>>> str(m[5:8])
'\\x05\\x06\\x07'

>>> m[5:8].tolist()
[5, 6, 7]
>>> m[5:8] = [20, 30, 40]
>>> m.tolist()
[0, 1, 2, 3, 4, 20, 30, 40, 8, 9]
>>> n = new_memory(10)
>>> o = new_memory(3)
>>> n.clear()
>>> for i in range(len(o)):
...     o[i] = 10
>>> n[2:5] = o
>>> n.tolist()
[0, 0, 10, 10, 10, 0, 0, 0, 0, 0]
"""

from numarray.memory import *

def test():
    import doctest, numarray.memorytest as memorytest
    return doctest.testmod(memorytest)

if __name__ == "__main__":
    test()