HTSeq 2.1.2__cp310-cp310-macosx_10_15_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
HTSeq/StepVector.py ADDED
@@ -0,0 +1,629 @@
1
+ # This file was automatically generated by SWIG (https://www.swig.org).
2
+ # Version 4.2.0
3
+ #
4
+ # Do not make changes to this file unless you know what you are doing - modify
5
+ # the SWIG interface file instead.
6
+
7
+ from sys import version_info as _swig_python_version_info
8
+ # Import the low-level C/C++ module
9
+ if __package__ or "." in __name__:
10
+ from . import _StepVector
11
+ else:
12
+ import _StepVector
13
+
14
+ try:
15
+ import builtins as __builtin__
16
+ except ImportError:
17
+ import __builtin__
18
+
19
+ def _swig_repr(self):
20
+ try:
21
+ strthis = "proxy of " + self.this.__repr__()
22
+ except __builtin__.Exception:
23
+ strthis = ""
24
+ return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
25
+
26
+
27
+ def _swig_setattr_nondynamic_instance_variable(set):
28
+ def set_instance_attr(self, name, value):
29
+ if name == "this":
30
+ set(self, name, value)
31
+ elif name == "thisown":
32
+ self.this.own(value)
33
+ elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
34
+ set(self, name, value)
35
+ else:
36
+ raise AttributeError("You cannot add instance attributes to %s" % self)
37
+ return set_instance_attr
38
+
39
+
40
+ def _swig_setattr_nondynamic_class_variable(set):
41
+ def set_class_attr(cls, name, value):
42
+ if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
43
+ set(cls, name, value)
44
+ else:
45
+ raise AttributeError("You cannot add class attributes to %s" % cls)
46
+ return set_class_attr
47
+
48
+
49
+ def _swig_add_metaclass(metaclass):
50
+ """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
51
+ def wrapper(cls):
52
+ return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
53
+ return wrapper
54
+
55
+
56
+ class _SwigNonDynamicMeta(type):
57
+ """Meta class to enforce nondynamic attributes (no new attributes) for a class"""
58
+ __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)
59
+
60
+
61
+ class _Pair_long_float(object):
62
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
63
+ __repr__ = _swig_repr
64
+ first = property(_StepVector._Pair_long_float_first_get, _StepVector._Pair_long_float_first_set)
65
+ second = property(_StepVector._Pair_long_float_second_get, _StepVector._Pair_long_float_second_set)
66
+
67
+ def __init__(self, first_, second_):
68
+ _StepVector._Pair_long_float_swiginit(self, _StepVector.new__Pair_long_float(first_, second_))
69
+ __swig_destroy__ = _StepVector.delete__Pair_long_float
70
+
71
+ # Register _Pair_long_float in _StepVector:
72
+ _StepVector._Pair_long_float_swigregister(_Pair_long_float)
73
+ class _StepVector_Iterator_float(object):
74
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
75
+ __repr__ = _swig_repr
76
+
77
+ def __init__(self, first, last_):
78
+ _StepVector._StepVector_Iterator_float_swiginit(self, _StepVector.new__StepVector_Iterator_float(first, last_))
79
+
80
+ def __next__(self):
81
+ return _StepVector._StepVector_Iterator_float___next__(self)
82
+
83
+ def __iter__(self):
84
+ return _StepVector._StepVector_Iterator_float___iter__(self)
85
+ __swig_destroy__ = _StepVector.delete__StepVector_Iterator_float
86
+
87
+ # Register _StepVector_Iterator_float in _StepVector:
88
+ _StepVector._StepVector_Iterator_float_swigregister(_StepVector_Iterator_float)
89
+ class _StepVector_float(object):
90
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
91
+ __repr__ = _swig_repr
92
+
93
+ def __init__(self):
94
+ _StepVector._StepVector_float_swiginit(self, _StepVector.new__StepVector_float())
95
+
96
+ def set_value(self, _from, to, value):
97
+ return _StepVector._StepVector_float_set_value(self, _from, to, value)
98
+
99
+ def remove_step(self, i):
100
+ return _StepVector._StepVector_float_remove_step(self, i)
101
+
102
+ def add_value(self, _from, to, value):
103
+ return _StepVector._StepVector_float_add_value(self, _from, to, value)
104
+
105
+ def get_all_values_pystyle(self):
106
+ return _StepVector._StepVector_float_get_all_values_pystyle(self)
107
+
108
+ def get_values_pystyle(self, _from):
109
+ return _StepVector._StepVector_float_get_values_pystyle(self, _from)
110
+
111
+ def num_values(self):
112
+ return _StepVector._StepVector_float_num_values(self)
113
+ __swig_destroy__ = _StepVector.delete__StepVector_float
114
+
115
+ # Register _StepVector_float in _StepVector:
116
+ _StepVector._StepVector_float_swigregister(_StepVector_float)
117
+ cvar = _StepVector.cvar
118
+ _StepVector_float.min_index = _StepVector.cvar._StepVector_float_min_index
119
+ _StepVector_float.max_index = _StepVector.cvar._StepVector_float_max_index
120
+
121
+ class _Pair_long_int(object):
122
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
123
+ __repr__ = _swig_repr
124
+ first = property(_StepVector._Pair_long_int_first_get, _StepVector._Pair_long_int_first_set)
125
+ second = property(_StepVector._Pair_long_int_second_get, _StepVector._Pair_long_int_second_set)
126
+
127
+ def __init__(self, first_, second_):
128
+ _StepVector._Pair_long_int_swiginit(self, _StepVector.new__Pair_long_int(first_, second_))
129
+ __swig_destroy__ = _StepVector.delete__Pair_long_int
130
+
131
+ # Register _Pair_long_int in _StepVector:
132
+ _StepVector._Pair_long_int_swigregister(_Pair_long_int)
133
+ class _StepVector_Iterator_int(object):
134
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
135
+ __repr__ = _swig_repr
136
+
137
+ def __init__(self, first, last_):
138
+ _StepVector._StepVector_Iterator_int_swiginit(self, _StepVector.new__StepVector_Iterator_int(first, last_))
139
+
140
+ def __next__(self):
141
+ return _StepVector._StepVector_Iterator_int___next__(self)
142
+
143
+ def __iter__(self):
144
+ return _StepVector._StepVector_Iterator_int___iter__(self)
145
+ __swig_destroy__ = _StepVector.delete__StepVector_Iterator_int
146
+
147
+ # Register _StepVector_Iterator_int in _StepVector:
148
+ _StepVector._StepVector_Iterator_int_swigregister(_StepVector_Iterator_int)
149
+ class _StepVector_int(object):
150
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
151
+ __repr__ = _swig_repr
152
+
153
+ def __init__(self):
154
+ _StepVector._StepVector_int_swiginit(self, _StepVector.new__StepVector_int())
155
+
156
+ def set_value(self, _from, to, value):
157
+ return _StepVector._StepVector_int_set_value(self, _from, to, value)
158
+
159
+ def remove_step(self, i):
160
+ return _StepVector._StepVector_int_remove_step(self, i)
161
+
162
+ def add_value(self, _from, to, value):
163
+ return _StepVector._StepVector_int_add_value(self, _from, to, value)
164
+
165
+ def get_all_values_pystyle(self):
166
+ return _StepVector._StepVector_int_get_all_values_pystyle(self)
167
+
168
+ def get_values_pystyle(self, _from):
169
+ return _StepVector._StepVector_int_get_values_pystyle(self, _from)
170
+
171
+ def num_values(self):
172
+ return _StepVector._StepVector_int_num_values(self)
173
+ __swig_destroy__ = _StepVector.delete__StepVector_int
174
+
175
+ # Register _StepVector_int in _StepVector:
176
+ _StepVector._StepVector_int_swigregister(_StepVector_int)
177
+ _StepVector_int.min_index = _StepVector.cvar._StepVector_int_min_index
178
+ _StepVector_int.max_index = _StepVector.cvar._StepVector_int_max_index
179
+
180
+ class _Pair_long_long(object):
181
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
182
+ __repr__ = _swig_repr
183
+ first = property(_StepVector._Pair_long_long_first_get, _StepVector._Pair_long_long_first_set)
184
+ second = property(_StepVector._Pair_long_long_second_get, _StepVector._Pair_long_long_second_set)
185
+
186
+ def __init__(self, first_, second_):
187
+ _StepVector._Pair_long_long_swiginit(self, _StepVector.new__Pair_long_long(first_, second_))
188
+ __swig_destroy__ = _StepVector.delete__Pair_long_long
189
+
190
+ # Register _Pair_long_long in _StepVector:
191
+ _StepVector._Pair_long_long_swigregister(_Pair_long_long)
192
+ class _StepVector_Iterator_long(object):
193
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
194
+ __repr__ = _swig_repr
195
+
196
+ def __init__(self, first, last_):
197
+ _StepVector._StepVector_Iterator_long_swiginit(self, _StepVector.new__StepVector_Iterator_long(first, last_))
198
+
199
+ def __next__(self):
200
+ return _StepVector._StepVector_Iterator_long___next__(self)
201
+
202
+ def __iter__(self):
203
+ return _StepVector._StepVector_Iterator_long___iter__(self)
204
+ __swig_destroy__ = _StepVector.delete__StepVector_Iterator_long
205
+
206
+ # Register _StepVector_Iterator_long in _StepVector:
207
+ _StepVector._StepVector_Iterator_long_swigregister(_StepVector_Iterator_long)
208
+ class _StepVector_long(object):
209
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
210
+ __repr__ = _swig_repr
211
+
212
+ def __init__(self):
213
+ _StepVector._StepVector_long_swiginit(self, _StepVector.new__StepVector_long())
214
+
215
+ def set_value(self, _from, to, value):
216
+ return _StepVector._StepVector_long_set_value(self, _from, to, value)
217
+
218
+ def remove_step(self, i):
219
+ return _StepVector._StepVector_long_remove_step(self, i)
220
+
221
+ def add_value(self, _from, to, value):
222
+ return _StepVector._StepVector_long_add_value(self, _from, to, value)
223
+
224
+ def get_all_values_pystyle(self):
225
+ return _StepVector._StepVector_long_get_all_values_pystyle(self)
226
+
227
+ def get_values_pystyle(self, _from):
228
+ return _StepVector._StepVector_long_get_values_pystyle(self, _from)
229
+
230
+ def num_values(self):
231
+ return _StepVector._StepVector_long_num_values(self)
232
+ __swig_destroy__ = _StepVector.delete__StepVector_long
233
+
234
+ # Register _StepVector_long in _StepVector:
235
+ _StepVector._StepVector_long_swigregister(_StepVector_long)
236
+ _StepVector_long.min_index = _StepVector.cvar._StepVector_long_min_index
237
+ _StepVector_long.max_index = _StepVector.cvar._StepVector_long_max_index
238
+
239
+ class _Pair_long_bool(object):
240
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
241
+ __repr__ = _swig_repr
242
+ first = property(_StepVector._Pair_long_bool_first_get, _StepVector._Pair_long_bool_first_set)
243
+ second = property(_StepVector._Pair_long_bool_second_get, _StepVector._Pair_long_bool_second_set)
244
+
245
+ def __init__(self, first_, second_):
246
+ _StepVector._Pair_long_bool_swiginit(self, _StepVector.new__Pair_long_bool(first_, second_))
247
+ __swig_destroy__ = _StepVector.delete__Pair_long_bool
248
+
249
+ # Register _Pair_long_bool in _StepVector:
250
+ _StepVector._Pair_long_bool_swigregister(_Pair_long_bool)
251
+ class _StepVector_Iterator_bool(object):
252
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
253
+ __repr__ = _swig_repr
254
+
255
+ def __init__(self, first, last_):
256
+ _StepVector._StepVector_Iterator_bool_swiginit(self, _StepVector.new__StepVector_Iterator_bool(first, last_))
257
+
258
+ def __next__(self):
259
+ return _StepVector._StepVector_Iterator_bool___next__(self)
260
+
261
+ def __iter__(self):
262
+ return _StepVector._StepVector_Iterator_bool___iter__(self)
263
+ __swig_destroy__ = _StepVector.delete__StepVector_Iterator_bool
264
+
265
+ # Register _StepVector_Iterator_bool in _StepVector:
266
+ _StepVector._StepVector_Iterator_bool_swigregister(_StepVector_Iterator_bool)
267
+ class _StepVector_bool(object):
268
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
269
+ __repr__ = _swig_repr
270
+
271
+ def __init__(self):
272
+ _StepVector._StepVector_bool_swiginit(self, _StepVector.new__StepVector_bool())
273
+
274
+ def set_value(self, _from, to, value):
275
+ return _StepVector._StepVector_bool_set_value(self, _from, to, value)
276
+
277
+ def remove_step(self, i):
278
+ return _StepVector._StepVector_bool_remove_step(self, i)
279
+
280
+ def add_value(self, _from, to, value):
281
+ return _StepVector._StepVector_bool_add_value(self, _from, to, value)
282
+
283
+ def get_all_values_pystyle(self):
284
+ return _StepVector._StepVector_bool_get_all_values_pystyle(self)
285
+
286
+ def get_values_pystyle(self, _from):
287
+ return _StepVector._StepVector_bool_get_values_pystyle(self, _from)
288
+
289
+ def num_values(self):
290
+ return _StepVector._StepVector_bool_num_values(self)
291
+ __swig_destroy__ = _StepVector.delete__StepVector_bool
292
+
293
+ # Register _StepVector_bool in _StepVector:
294
+ _StepVector._StepVector_bool_swigregister(_StepVector_bool)
295
+ _StepVector_bool.min_index = _StepVector.cvar._StepVector_bool_min_index
296
+ _StepVector_bool.max_index = _StepVector.cvar._StepVector_bool_max_index
297
+
298
+ class _Pair_long_obj(object):
299
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
300
+ __repr__ = _swig_repr
301
+ first = property(_StepVector._Pair_long_obj_first_get, _StepVector._Pair_long_obj_first_set)
302
+ second = property(_StepVector._Pair_long_obj_second_get, _StepVector._Pair_long_obj_second_set)
303
+
304
+ def __init__(self, first_, second_):
305
+ _StepVector._Pair_long_obj_swiginit(self, _StepVector.new__Pair_long_obj(first_, second_))
306
+ __swig_destroy__ = _StepVector.delete__Pair_long_obj
307
+
308
+ # Register _Pair_long_obj in _StepVector:
309
+ _StepVector._Pair_long_obj_swigregister(_Pair_long_obj)
310
+ class _StepVector_Iterator_obj(object):
311
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
312
+ __repr__ = _swig_repr
313
+
314
+ def __init__(self, first, last_):
315
+ _StepVector._StepVector_Iterator_obj_swiginit(self, _StepVector.new__StepVector_Iterator_obj(first, last_))
316
+
317
+ def __next__(self):
318
+ return _StepVector._StepVector_Iterator_obj___next__(self)
319
+
320
+ def __iter__(self):
321
+ return _StepVector._StepVector_Iterator_obj___iter__(self)
322
+ __swig_destroy__ = _StepVector.delete__StepVector_Iterator_obj
323
+
324
+ # Register _StepVector_Iterator_obj in _StepVector:
325
+ _StepVector._StepVector_Iterator_obj_swigregister(_StepVector_Iterator_obj)
326
+ class _StepVector_obj(object):
327
+ thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
328
+ __repr__ = _swig_repr
329
+
330
+ def __init__(self):
331
+ _StepVector._StepVector_obj_swiginit(self, _StepVector.new__StepVector_obj())
332
+
333
+ def set_value(self, _from, to, value):
334
+ return _StepVector._StepVector_obj_set_value(self, _from, to, value)
335
+
336
+ def remove_step(self, i):
337
+ return _StepVector._StepVector_obj_remove_step(self, i)
338
+
339
+ def add_value(self, _from, to, value):
340
+ return _StepVector._StepVector_obj_add_value(self, _from, to, value)
341
+
342
+ def get_all_values_pystyle(self):
343
+ return _StepVector._StepVector_obj_get_all_values_pystyle(self)
344
+
345
+ def get_values_pystyle(self, _from):
346
+ return _StepVector._StepVector_obj_get_values_pystyle(self, _from)
347
+
348
+ def num_values(self):
349
+ return _StepVector._StepVector_obj_num_values(self)
350
+ __swig_destroy__ = _StepVector.delete__StepVector_obj
351
+
352
+ # Register _StepVector_obj in _StepVector:
353
+ _StepVector._StepVector_obj_swigregister(_StepVector_obj)
354
+ _StepVector_obj.min_index = _StepVector.cvar._StepVector_obj_min_index
355
+ _StepVector_obj.max_index = _StepVector.cvar._StepVector_obj_max_index
356
+
357
+
358
+
359
+ import sys
360
+
361
+ class StepVector(object):
362
+ """A step vector is a vector with integer indices that is able to store
363
+ data efficiently if it is piece-wise constant, i.e., if the values change
364
+ in "steps". So, if a number of adjacent vectort elements have the same
365
+ value, this values will be stored only once.
366
+
367
+ The data can be either one of a number of elementary types, or any object.
368
+
369
+ Usage example:
370
+
371
+ >>> sv = StepVector.StepVector(20)
372
+ >>> sv[5:17] = 13
373
+ >>> sv[12]
374
+ 13.0
375
+ >>> list(sv)
376
+ [0.0, 0.0, 0.0, 0.0, 0.0, 13.0, 13.0, 13.0, 13.0, 13.0, 13.0, 13.0, 13.0, 13.0, 13.0, 13.0, 13.0, 0.0, 0.0, 0.0]
377
+ >>> list(sv.get_steps())
378
+ [(0, 5, 0.0), (5, 17, 13.0), (17, 20, 0.0)]
379
+
380
+ """
381
+
382
+ @classmethod
383
+ def create(cls, length=sys.maxsize, typecode='d', start_index=0):
384
+ """Construct a StepVector of the given length, with indices starting
385
+ at the given start_index and counting up to (but not including)
386
+ start_index + length.
387
+
388
+ The typecode may be:
389
+ 'd' for float values (C type 'double'),
390
+ 'i' for int values,
391
+ 'l' for long int values,
392
+ 'b' for Boolean values,
393
+ 'O' for arbitrary Python objects as value.
394
+
395
+ The vector is initialized with the value zero (or, for typecode 'O',
396
+ with None).
397
+ """
398
+ if typecode == 'd':
399
+ swigclass = _StepVector_float
400
+ elif typecode == 'i':
401
+ swigclass = _StepVector_int
402
+ elif typecode == 'l':
403
+ swigclass = _StepVector_long
404
+ elif typecode == 'b':
405
+ swigclass = _StepVector_bool
406
+ elif typecode == 'O':
407
+ swigclass = _StepVector_obj
408
+ else:
409
+ raise ValueError("unsupported typecode")
410
+ obj = cls()
411
+ obj._typecode = typecode
412
+ obj._swigobj = swigclass()
413
+ obj.start = start_index
414
+ obj.stop = start_index + length
415
+ return obj
416
+
417
+ def __setitem__(self, index, value):
418
+ """To set element i of StepVector sv to the value v, write
419
+ sv[i] = v
420
+ If you want to set a whole step, say, all values from i to j (not
421
+ including j), write
422
+ sv[i:j] = v
423
+ Note that the StepVector class will only notice that all the values
424
+ from i to j are equal if you assign them in this fashion. Assigning each
425
+ item individually in a loop from i to j will result in the value v being
426
+ stored many times.
427
+ """
428
+ if isinstance(value, StepVector):
429
+ if self._swigobj is value._swigobj and \
430
+ value.start == index.start and value.stop == index.stop:
431
+ return
432
+ else:
433
+ raise NotImplemented("Stepvector-to-Stepvector assignment still missing")
434
+ if isinstance(index, slice):
435
+ if index.step is not None and index.step != 1:
436
+ raise ValueError("Striding slices (i.e., step != 1) are not supported")
437
+ if index.start is None:
438
+ start = self.start
439
+ else:
440
+ if index.start < self.start:
441
+ raise IndexError("start too small")
442
+ start = index.start
443
+ if index.stop is None:
444
+ stop = self.stop
445
+ else:
446
+ if index.stop > self.stop:
447
+ raise IndexError("stop too large")
448
+ stop = index.stop
449
+
450
+ # Note the "-1": The C++ object uses closed intervals, but we follow
451
+ # Python convention here and use half-open ones.
452
+ self._swigobj.set_value(start, stop-1, value)
453
+
454
+ else:
455
+ self._swigobj.set_value(index, index, value)
456
+
457
+ def get_steps(self, values_only=False, merge_steps=True):
458
+ """Iterate over the steps of the vector.
459
+
460
+ Args:
461
+ values_only (bool): Return only the values of the StepVector, without
462
+ the index boundaries.
463
+
464
+ merge_steps (bool): Perform on-the-fly merging of consecutive steps if
465
+ their value is the same. Setting this option ensures that consecutive
466
+ steps have distinct values.
467
+
468
+ Returns: an iterator of triplets, with each triplet containing the start
469
+ index, end index, and value of that step. If values_only is True, the
470
+ function returns an iterator of the values only.
471
+ """
472
+ startvals = self._swigobj.get_values_pystyle(self.start)
473
+ prevstart = self.start
474
+ prevval = next(startvals).second
475
+ for pair in startvals:
476
+ stepstart, value = pair.first, pair.second
477
+ if merge_steps and value == prevval:
478
+ continue
479
+ if (self.stop is not None) and (stepstart >= self.stop):
480
+ if not values_only:
481
+ yield prevstart, self.stop, prevval
482
+ else:
483
+ yield prevval
484
+ return
485
+ if not values_only:
486
+ yield prevstart, stepstart, prevval
487
+ else:
488
+ yield prevval
489
+ prevstart, prevval = stepstart, value
490
+ else:
491
+ if not values_only:
492
+ yield prevstart, min(self.stop, self._swigobj.max_index + 1), prevval
493
+ else:
494
+ yield prevval
495
+
496
+ def __getitem__(self, index):
497
+ """Given a StepVector sv, writing sv[i] returns sv's element i (where i
498
+ is an integer).
499
+
500
+ If you use a slice, i.e. 'sv[i:j]', you get a view on the StepVector,
501
+ i.e., the same data, but changed boundaries.
502
+
503
+ Striding slices, i.e. 'sv[i:j:2]' are not supported.
504
+ """
505
+ if isinstance(index, slice):
506
+ if index.step is not None and index.step != 1:
507
+ raise ValueError("Striding slices (i.e., step != 1) are not supported")
508
+ if index.start is None:
509
+ start = self.start
510
+ else:
511
+ if index.start < self.start:
512
+ raise IndexError("start too small")
513
+ start = index.start
514
+ if index.stop is None:
515
+ stop = self.stop
516
+ else:
517
+ if index.stop > self.stop:
518
+ raise IndexError("stop too large")
519
+ stop = index.stop
520
+ res = self.__class__()
521
+ res._typecode = self.typecode
522
+ res._swigobj = self._swigobj
523
+ res.start = start
524
+ res.stop = stop
525
+ return res
526
+ else:
527
+ return next(self._swigobj.get_values_pystyle(index)).second
528
+
529
+ def remove_step(self, start):
530
+ """Remve a step with this starting coordinate, in place.
531
+
532
+ Args:
533
+ start: Starting coordinate of the step.
534
+ """
535
+ self._swigobj.remove_step(start)
536
+
537
+ def __iter__(self):
538
+ """When asked to provide an iterator, a StepVector will yield all its
539
+ values, repeating each value according to the length of the step.
540
+ Hence, calling, e.g., 'list(sv)' will transform the StepVector 'sv'
541
+ into an ordinary list.
542
+ """
543
+ for start, stop, value in self.get_steps():
544
+ for i in range(start, stop):
545
+ yield value
546
+
547
+ def __repr__(self):
548
+ if self.start == -sys.maxsize - 1:
549
+ start_s = "-inf"
550
+ else:
551
+ start_s = str(self.start)
552
+ if self.stop == sys.maxsize:
553
+ stop_s = "inf"
554
+ else:
555
+ stop_s = str(self.stop)
556
+ return "<%s object, type '%s', index range %s:%s, %d step(s)>" % (
557
+ self.__class__.__name__, self.typecode(), start_s,
558
+ stop_s, self.num_steps())
559
+
560
+ def typecode(self):
561
+ "Returns the typecode."
562
+ return self._typecode
563
+
564
+ def __len__(self):
565
+ """The length of a StepVector is defined by its index range, not by
566
+ the number of steps.
567
+ """
568
+ return self.stop - self.start
569
+
570
+ def num_steps(self):
571
+ """Returns the number of steps, i.e., the number of triples that get_steps
572
+ returns.
573
+ """
574
+ return self._swigobj.num_values()
575
+
576
+ def __eq__(self, other):
577
+ """StepVectors can be compared for equality. This is conceptually done
578
+ element for element, but, for performance, taking steps in one go.
579
+ """
580
+ if self.start_index() != other.start_index() or len(self) != len(other) or \
581
+ self.typecode() != other.typecode():
582
+ print("Mark A")
583
+ return False
584
+ selfsteps = self.get_steps()
585
+ othrsteps = other.get_steps()
586
+ selfstart, selfstop, selfval = next(selfsteps)
587
+ othrstart, othrstop, othrval = next(othrsteps)
588
+ while selfstop < self.start_index() + len(self) and \
589
+ othrstop < other.start_index() + len(other):
590
+ assert selfstart < othrstop and othrstart < selfstop
591
+ if not(selfval == othrval):
592
+ return False
593
+ if selfstop < othrstop:
594
+ selfstart, selfstop, selfval = next(selfsteps)
595
+ elif othrstop < selfstop:
596
+ othrstart, othrstop, othrval = next(othrsteps)
597
+ else:
598
+ selfstart, selfstop, selfval = next(selfsteps)
599
+ othrstart, othrstop, othrval = next(othrsteps)
600
+ return True
601
+
602
+ def __neq__(self, other):
603
+ return not (self == other)
604
+
605
+ def __reduce__(self):
606
+ if self.__class__ is not StepVector:
607
+ raise NotImplemented(
608
+ "Attempting to pickle a subclass of StepVector without redefined __reduce__.")
609
+ return (
610
+ _StepVector_unpickle,
611
+ (self.stop - self.start, self._typecode, self.start),
612
+ None,
613
+ None,
614
+ ((slice(start, stop), val) for start, stop, val in self.get_steps()))
615
+
616
+ def __iadd__(self, value):
617
+ self._swigobj.add_value(self.start, self.stop-1, value)
618
+ return self
619
+
620
+ def apply(self, func, start=None, stop=None):
621
+ # TODO: check!
622
+ for stepstart, stepstop, value in self.get_steps(start, stop):
623
+ self[stepstart:stepstop] = func(value)
624
+
625
+ def _StepVector_unpickle(length, typecode, start):
626
+ return StepVector.create(length, typecode, start)
627
+
628
+
629
+