Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

""" 

GSL arrays 

""" 

  

from cysignals.memory cimport sig_malloc, sig_free 

  

cdef class GSLDoubleArray: 

""" 

EXAMPLES:: 

  

sage: a = WaveletTransform(128,'daubechies',4) 

sage: for i in range(1, 11): 

....: a[i] = 1 

sage: a[:6:2] 

[0.0, 1.0, 1.0] 

""" 

def __init__(self, size_t n, size_t stride = 1, data = None): 

""" 

EXAMPLES:: 

  

sage: from sage.libs.gsl.array import GSLDoubleArray 

sage: a = GSLDoubleArray(10) 

""" 

cdef int i 

  

self.n = n 

self.stride = stride 

self.data = <double *> sig_malloc(sizeof(double)*n) 

if data is not None: 

for i from 0 <= i < n: 

self.data[i] = data[i] 

else: 

for i from 0 <= i < n: 

self.data[i] = 0 

  

def __dealloc__(self): 

""" 

EXAMPLES:: 

  

sage: from sage.libs.gsl.array import GSLDoubleArray 

sage: a = GSLDoubleArray(10) 

sage: del a 

""" 

sig_free(self.data) 

  

def __len__(self): 

""" 

EXAMPLES:: 

  

sage: from sage.libs.gsl.array import GSLDoubleArray 

sage: a = GSLDoubleArray(10) 

sage: len(a) 

10 

""" 

return self.n 

  

def __repr__(self): 

""" 

EXAMPLES:: 

  

sage: from sage.libs.gsl.array import GSLDoubleArray 

sage: a = GSLDoubleArray(10) 

sage: a 

[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 

""" 

return str(list(self)) 

  

def __setitem__(self, size_t i, x): 

""" 

EXAMPLES:: 

  

sage: from sage.libs.gsl.array import GSLDoubleArray 

sage: a = GSLDoubleArray(10) 

sage: a[5] = 3 

sage: a 

[0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0] 

""" 

# just set real for now 

if i < 0 or i >= self.n: 

raise IndexError 

self.data[i] = x 

  

def __getitem__(self, i): 

""" 

EXAMPLES:: 

  

sage: from sage.libs.gsl.array import GSLDoubleArray 

sage: a = GSLDoubleArray(10) 

sage: for i in range(10): 

....: a[i] = i 

sage: a[3:7] 

[3.0, 4.0, 5.0, 6.0] 

""" 

if isinstance(i, slice): 

start, stop, step = i.indices(len(self)) 

# TODO -- make this actually fast. 

return list(self)[start:stop:step] 

else: 

if i < 0 or i >= self.n: 

raise IndexError 

return self.data[i]