1 #cython: autotestdict=False
2 #cython: auto_pickle=False
3 #cython: boundscheck=False
4 #cython: wraparound=False
7 from cpython
.array cimport array
8 from cython
.parallel
import prange
10 cdef inline array_i8
(object o
):
13 cdef inline array_u8
(object o
):
16 cdef inline array_i16
(object o
):
19 cdef inline array_u16
(object o
):
22 cdef inline array_i32
(object o
):
23 if INT32_MAX
== INT_MAX
:
27 cdef inline array_u32
(object o
):
28 if UINT32_MAX
== UINT_MAX
:
32 cdef inline array_i64
(object o
):
33 if INT64_MAX
== LONG_MAX
:
37 cdef inline array_u64
(object o
):
38 if UINT64_MAX
== ULONG_MAX
:
42 cdef inline array_f32
(object o
):
45 cdef inline array_f64
(object o
):
48 cdef inline array_num
(object o
):
49 if A_FLOAT_TYPE
== A_FLOAT_SINGLE
:
53 def hash_bkdr
(bytes
str, a_u32 val
= 0) -> a_u32
:
54 return a_hash_bkdr
(str, val
)
56 def hash_sdbm
(bytes
str, a_u32 val
= 0) -> a_u32
:
57 return a_hash_sdbm
(str, val
)
62 cdef readonly array table
64 self.table
= array_u8
((0,) * 0x100)
65 def gen
(self, a_u8 poly
, bint reversed
= False
):
67 a_crc8l_init
(<a_u8
*>self.table
.data
.as_voidptr
, poly
)
69 a_crc8m_init
(<a_u8
*>self.table
.data
.as_voidptr
, poly
)
71 def __init__
(self, a_u8 poly
, bint reversed
= False
):
72 self.gen
(poly
, reversed
)
73 def __call__
(self, bytes block
, a_u8 value
= 0):
74 cdef const unsigned
char *p
= <const unsigned
char *>block
75 return a_crc8
(<a_u8
*>self.table
.data
.as_voidptr
, p
, len(block
), value
)
76 def pack
(self, bytes block
, a_u8 value
= 0):
77 cdef size_t n
= len(block
)
78 block
= block
+ bytes
(1)
79 cdef unsigned
char *p
= <unsigned
char *>block
80 value
= a_crc8
(<a_u8
*>self.table
.data
.as_voidptr
, p
, n
, value
)
85 cdef readonly array table
87 self.table
= array_u16
((0,) * 0x100)
88 cdef a_u16
(*eval)(const a_u16
*, const
void *, a_size
, a_u16
)
89 def gen
(self, a_u16 poly
, bint reversed
= False
):
91 a_crc16l_init
(<a_u16
*>self.table
.data
.as_voidptr
, poly
)
94 a_crc16m_init
(<a_u16
*>self.table
.data
.as_voidptr
, poly
)
97 def __init__
(self, a_u16 poly
, bint reversed
= False
):
98 self.gen
(poly
, reversed
)
99 def __call__
(self, bytes block
, a_u16 value
= 0):
100 cdef const unsigned
char *p
= <const unsigned
char *>block
101 return self.eval(<a_u16
*>self.table
.data
.as_voidptr
, p
, len(block
), value
)
102 def pack
(self, bytes block
, a_u16 value
= 0):
103 cdef size_t n
= len(block
)
104 block
= block
+ bytes
(2)
105 cdef unsigned
char *p
= <unsigned
char *>block
106 value
= self.eval(<a_u16
*>self.table
.data
.as_voidptr
, p
, n
, value
)
107 if self.eval == a_crc16m
:
108 a_u16_setb
(p
+ n
, value
)
110 a_u16_setl
(p
+ n
, value
)
114 cdef readonly array table
116 self.table
= array_u32
((0,) * 0x100)
117 cdef a_u32
(*eval)(const a_u32
*, const
void *, a_size
, a_u32
)
118 def gen
(self, a_u32 poly
, bint reversed
= False
):
120 a_crc32l_init
(<a_u32
*>self.table
.data
.as_voidptr
, poly
)
123 a_crc32m_init
(<a_u32
*>self.table
.data
.as_voidptr
, poly
)
126 def __init__
(self, a_u32 poly
, bint reversed
= False
):
127 self.gen
(poly
, reversed
)
128 def __call__
(self, bytes block
, a_u32 value
= 0):
129 cdef const unsigned
char *p
= <const unsigned
char *>block
130 return self.eval(<a_u32
*>self.table
.data
.as_voidptr
, p
, len(block
), value
)
131 def pack
(self, bytes block
, a_u32 value
= 0):
132 cdef size_t n
= len(block
)
133 block
= block
+ bytes
(4)
134 cdef unsigned
char *p
= <unsigned
char *>block
135 value
= self.eval(<a_u32
*>self.table
.data
.as_voidptr
, p
, n
, value
)
136 if self.eval == a_crc32m
:
137 a_u32_setb
(p
+ n
, value
)
139 a_u32_setl
(p
+ n
, value
)
143 cdef readonly array table
145 self.table
= array_u64
((0,) * 0x100)
146 cdef a_u64
(*eval)(const a_u64
*, const
void *, a_size
, a_u64
)
147 def gen
(self, a_u64 poly
, bint reversed
= False
):
149 a_crc64l_init
(<a_u64
*>self.table
.data
.as_voidptr
, poly
)
152 a_crc64m_init
(<a_u64
*>self.table
.data
.as_voidptr
, poly
)
155 def __init__
(self, a_u64 poly
, bint reversed
= False
):
156 self.gen
(poly
, reversed
)
157 def __call__
(self, bytes block
, a_u64 value
= 0):
158 cdef const unsigned
char *p
= <const unsigned
char *>block
159 return self.eval(<a_u64
*>self.table
.data
.as_voidptr
, p
, len(block
), value
)
160 def pack
(self, bytes block
, a_u64 value
= 0):
161 cdef size_t n
= len(block
)
162 block
= block
+ bytes
(8)
163 cdef unsigned
char *p
= <unsigned
char *>block
164 value
= self.eval(<a_u64
*>self.table
.data
.as_voidptr
, p
, n
, value
)
165 if self.eval == a_crc64m
:
166 a_u64_setb
(p
+ n
, value
)
168 a_u64_setl
(p
+ n
, value
)
175 def __init__
(self, a_float fc
, a_float ts
):
176 a_hpf_init
(&self.ctx
, a_hpf_gen
(fc
, ts
))
177 def gen
(self, a_float fc
, a_float ts
):
178 a_hpf_init
(&self.ctx
, a_hpf_gen
(fc
, ts
))
180 def __call__
(self, a_float x
):
181 return a_hpf_iter
(&self.ctx
, x
)
183 a_hpf_zero
(&self.ctx
)
187 return self.ctx
.alpha
188 def __set__
(self, a_float alpha
):
189 self.ctx
.alpha
= alpha
192 return self.ctx
.output
195 return self.ctx
.input
201 def __init__
(self, a_float fc
, a_float ts
):
202 a_lpf_init
(&self.ctx
, a_lpf_gen
(fc
, ts
))
203 def gen
(self, a_float fc
, a_float ts
):
204 a_lpf_init
(&self.ctx
, a_lpf_gen
(fc
, ts
))
206 def __call__
(self, a_float x
):
207 return a_lpf_iter
(&self.ctx
, x
)
209 a_lpf_zero
(&self.ctx
)
213 return self.ctx
.alpha
214 def __set__
(self, a_float alpha
):
215 self.ctx
.alpha
= alpha
218 return self.ctx
.output
220 from a
.math cimport
*
225 x0
= 1 << ((x
.bit_length
() + 1) >> 1)
226 x1
= (x0
+ x
// x0
) >> 1
229 x1
= (x0
+ x
// x0
) >> 1
237 if PyObject_HasAttrString
(x
, "__contains__"):
240 p
= <a_u32
*>y
.data
.as_voidptr
241 for i
in prange
(n
, nogil
=True
):
242 p
[i
] = a_u32_sqrt
(p
[i
])
251 if PyObject_HasAttrString
(x
, "__contains__"):
254 p
= <a_u64
*>y
.data
.as_voidptr
255 for i
in prange
(n
, nogil
=True
):
256 p
[i
] = a_u64_sqrt
(p
[i
])
265 if PyObject_HasAttrString
(x
, "__contains__"):
268 p
= <a_f32
*>y
.data
.as_voidptr
269 for i
in prange
(n
, nogil
=True
):
270 p
[i
] = a_f32_rsqrt
(p
[i
])
272 return a_f32_rsqrt
(x
)
279 if PyObject_HasAttrString
(x
, "__contains__"):
282 p
= <a_f64
*>y
.data
.as_voidptr
283 for i
in prange
(n
, nogil
=True
):
284 p
[i
] = a_f64_rsqrt
(p
[i
])
286 return a_f64_rsqrt
(x
)
306 def __call__
(unsigned
int e
, x
, a
):
311 cdef unsigned
int m
= e
312 cdef array a_
= array_num
(a
)
313 cdef a_float
*a_p
= <a_float
*>a_
.data
.as_voidptr
314 if PyObject_HasAttrString
(x
, "__contains__"):
317 p
= <a_float
*>y
.data
.as_voidptr
318 for i
in prange
(n
, nogil
=True
):
319 p
[i
] = a_mf
(m
, p
[i
], a_p
)
321 return a_mf
(m
, x
, a_p
)
323 def gauss
(x
, a_float sigma
, a_float c
):
328 if PyObject_HasAttrString
(x
, "__contains__"):
331 p
= <a_float
*>y
.data
.as_voidptr
332 for i
in prange
(n
, nogil
=True
):
333 p
[i
] = a_mf_gauss
(p
[i
], sigma
, c
)
335 return a_mf_gauss
(x
, sigma
, c
)
337 def gauss2
(x
, a_float sigma1
, a_float c1
, a_float sigma2
, a_float c2
):
342 if PyObject_HasAttrString
(x
, "__contains__"):
345 p
= <a_float
*>y
.data
.as_voidptr
346 for i
in prange
(n
, nogil
=True
):
347 p
[i
] = a_mf_gauss2
(p
[i
], sigma1
, c1
, sigma2
, c2
)
349 return a_mf_gauss2
(x
, sigma1
, c1
, sigma2
, c2
)
351 def gbell
(x
, a_float a
, a_float b
, a_float c
):
356 if PyObject_HasAttrString
(x
, "__contains__"):
359 p
= <a_float
*>y
.data
.as_voidptr
360 for i
in prange
(n
, nogil
=True
):
361 p
[i
] = a_mf_gbell
(p
[i
], a
, b
, c
)
363 return a_mf_gbell
(x
, a
, b
, c
)
365 def sig
(x
, a_float a
, a_float c
):
370 if PyObject_HasAttrString
(x
, "__contains__"):
373 p
= <a_float
*>y
.data
.as_voidptr
374 for i
in prange
(n
, nogil
=True
):
375 p
[i
] = a_mf_sig
(p
[i
], a
, c
)
377 return a_mf_sig
(x
, a
, c
)
379 def dsig
(x
, a_float a1
, a_float c1
, a_float a2
, a_float c2
):
384 if PyObject_HasAttrString
(x
, "__contains__"):
387 p
= <a_float
*>y
.data
.as_voidptr
388 for i
in prange
(n
, nogil
=True
):
389 p
[i
] = a_mf_dsig
(p
[i
], a1
, c1
, a2
, c2
)
391 return a_mf_dsig
(x
, a1
, c1
, a2
, c2
)
393 def psig
(x
, a_float a1
, a_float c1
, a_float a2
, a_float c2
):
398 if PyObject_HasAttrString
(x
, "__contains__"):
401 p
= <a_float
*>y
.data
.as_voidptr
402 for i
in prange
(n
, nogil
=True
):
403 p
[i
] = a_mf_psig
(p
[i
], a1
, c1
, a2
, c2
)
405 return a_mf_psig
(x
, a1
, c1
, a2
, c2
)
407 def trap
(x
, a_float a
, a_float b
, a_float c
, a_float d
):
412 if PyObject_HasAttrString
(x
, "__contains__"):
415 p
= <a_float
*>y
.data
.as_voidptr
416 for i
in prange
(n
, nogil
=True
):
417 p
[i
] = a_mf_trap
(p
[i
], a
, b
, c
, d
)
419 return a_mf_trap
(x
, a
, b
, c
, d
)
421 def tri
(x
, a_float a
, a_float b
, a_float c
):
426 if PyObject_HasAttrString
(x
, "__contains__"):
429 p
= <a_float
*>y
.data
.as_voidptr
430 for i
in prange
(n
, nogil
=True
):
431 p
[i
] = a_mf_tri
(p
[i
], a
, b
, c
)
433 return a_mf_tri
(x
, a
, b
, c
)
435 def lins
(x
, a_float a
, a_float b
):
440 if PyObject_HasAttrString
(x
, "__contains__"):
443 p
= <a_float
*>y
.data
.as_voidptr
444 for i
in prange
(n
, nogil
=True
):
445 p
[i
] = a_mf_lins
(p
[i
], a
, b
)
447 return a_mf_lins
(x
, a
, b
)
449 def linz
(x
, a_float a
, a_float b
):
454 if PyObject_HasAttrString
(x
, "__contains__"):
457 p
= <a_float
*>y
.data
.as_voidptr
458 for i
in prange
(n
, nogil
=True
):
459 p
[i
] = a_mf_linz
(p
[i
], a
, b
)
461 return a_mf_linz
(x
, a
, b
)
463 def s
(x
, a_float a
, a_float b
):
468 if PyObject_HasAttrString
(x
, "__contains__"):
471 p
= <a_float
*>y
.data
.as_voidptr
472 for i
in prange
(n
, nogil
=True
):
473 p
[i
] = a_mf_s
(p
[i
], a
, b
)
475 return a_mf_s
(x
, a
, b
)
477 def z
(x
, a_float a
, a_float b
):
482 if PyObject_HasAttrString
(x
, "__contains__"):
485 p
= <a_float
*>y
.data
.as_voidptr
486 for i
in prange
(n
, nogil
=True
):
487 p
[i
] = a_mf_z
(p
[i
], a
, b
)
489 return a_mf_z
(x
, a
, b
)
491 def pi
(x
, a_float a
, a_float b
, a_float c
, a_float d
):
496 if PyObject_HasAttrString
(x
, "__contains__"):
499 p
= <a_float
*>y
.data
.as_voidptr
500 for i
in prange
(n
, nogil
=True
):
501 p
[i
] = a_mf_pi
(p
[i
], a
, b
, c
, d
)
503 return a_mf_pi
(x
, a
, b
, c
, d
)
511 self.ctx
.summax
= +A_FLOAT_INF
512 self.ctx
.summin
= -A_FLOAT_INF
513 self.ctx
.outmax
= +A_FLOAT_INF
514 self.ctx
.outmin
= -A_FLOAT_INF
515 a_pid_init
(&self.ctx
)
516 def kpid
(self, a_float kp
, a_float ki
, a_float kd
):
517 a_pid_kpid
(&self.ctx
, kp
, ki
, kd
)
519 def run
(self, a_float set
, a_float fdb
):
520 return a_pid_run
(&self.ctx
, set
, fdb
)
521 def pos
(self, a_float set
, a_float fdb
):
522 return a_pid_pos
(&self.ctx
, set
, fdb
)
523 def inc
(self, a_float set
, a_float fdb
):
524 return a_pid_inc
(&self.ctx
, set
, fdb
)
526 a_pid_zero
(&self.ctx
)
531 def __set__
(self, a_float kp
):
536 def __set__
(self, a_float ki
):
541 def __set__
(self, a_float kd
):
545 return self.ctx
.summax
546 def __set__
(self, a_float summax
):
547 self.ctx
.summax
= summax
550 return self.ctx
.summin
551 def __set__
(self, a_float summin
):
552 self.ctx
.summin
= summin
558 return self.ctx
.outmax
559 def __set__
(self, a_float outmax
):
560 self.ctx
.outmax
= outmax
563 return self.ctx
.outmin
564 def __set__
(self, a_float outmin
):
565 self.ctx
.outmin
= outmin
576 from a
.pid_fuzzy cimport
*
578 cdef class pid_fuzzy
:
579 CAP
= A_PID_FUZZY_CAP
580 CAP_ALGEBRA
= A_PID_FUZZY_CAP_ALGEBRA
581 CAP_BOUNDED
= A_PID_FUZZY_CAP_BOUNDED
582 CUP
= A_PID_FUZZY_CUP
583 CUP_ALGEBRA
= A_PID_FUZZY_CUP_ALGEBRA
584 CUP_BOUNDED
= A_PID_FUZZY_CUP_BOUNDED
585 EQU
= A_PID_FUZZY_EQU
587 cdef readonly array me
588 cdef readonly array mec
589 cdef readonly array mkp
590 cdef readonly array mki
591 cdef readonly array mkd
593 self.ctx
.pid
.summax
= +A_FLOAT_INF
594 self.ctx
.pid
.summin
= -A_FLOAT_INF
595 self.ctx
.pid
.outmax
= +A_FLOAT_INF
596 self.ctx
.pid
.outmin
= -A_FLOAT_INF
597 self.ctx
.kp
= self.ctx
.pid
.kp
= 1
598 self.ctx
.op
= a_fuzzy_equ
599 a_pid_fuzzy_init
(&self.ctx
)
600 def op
(self, unsigned
int op
):
601 a_pid_fuzzy_set_op
(&self.ctx
, op
)
603 def rule
(self, me
, mec
, mkp
, mki
, mkd
):
604 self.me
= array_num
([_2
for _1
in me
for _2
in _1
])
605 self.mec
= array_num
([_2
for _1
in mec
for _2
in _1
])
606 self.mkp
= array_num
([_2
for _1
in mkp
for _2
in _1
])
607 self.mki
= array_num
([_2
for _1
in mki
for _2
in _1
])
608 self.mkd
= array_num
([_2
for _1
in mkd
for _2
in _1
])
609 a_pid_fuzzy_rule
(&self.ctx
, <unsigned
int>len(me
),
610 <a_float
*>self.me
.data
.as_voidptr
,
611 <a_float
*>self.mec
.data
.as_voidptr
,
612 <a_float
*>self.mkp
.data
.as_voidptr
,
613 <a_float
*>self.mki
.data
.as_voidptr
,
614 <a_float
*>self.mkd
.data
.as_voidptr
)
616 def set_block
(self, unsigned
int num
):
617 cdef void *ptr
= a_pid_fuzzy_block
(&self.ctx
)
618 ptr
= PyMem_Realloc
(ptr
, A_PID_FUZZY_BLOCK
(num
))
619 a_pid_fuzzy_set_block
(&self.ctx
, ptr
, num
)
621 def kpid
(self, a_float kp
, a_float ki
, a_float kd
):
622 a_pid_fuzzy_kpid
(&self.ctx
, kp
, ki
, kd
)
624 def run
(self, a_float set
, a_float fdb
):
625 return a_pid_fuzzy_run
(&self.ctx
, set
, fdb
)
626 def pos
(self, a_float set
, a_float fdb
):
627 return a_pid_fuzzy_pos
(&self.ctx
, set
, fdb
)
628 def inc
(self, a_float set
, a_float fdb
):
629 return a_pid_fuzzy_inc
(&self.ctx
, set
, fdb
)
630 def __dealloc__
(self):
631 PyMem_Free
(a_pid_fuzzy_block
(&self.ctx
))
633 a_pid_fuzzy_zero
(&self.ctx
)
638 def __set__
(self, a_float kp
):
644 def __set__
(self, a_float ki
):
650 def __set__
(self, a_float kd
):
655 return self.ctx
.pid
.summax
656 def __set__
(self, a_float summax
):
657 self.ctx
.pid
.summax
= summax
660 return self.ctx
.pid
.summin
661 def __set__
(self, a_float summin
):
662 self.ctx
.pid
.summin
= summin
665 return self.ctx
.pid
.sum
668 return self.ctx
.pid
.outmax
669 def __set__
(self, a_float outmax
):
670 self.ctx
.pid
.outmax
= outmax
673 return self.ctx
.pid
.outmin
674 def __set__
(self, a_float outmin
):
675 self.ctx
.pid
.outmin
= outmin
678 return self.ctx
.pid
.out
681 return self.ctx
.pid
.fdb
684 return self.ctx
.pid
.err
687 return self.ctx
.order
690 return self.ctx
.block
691 def __set__
(self, unsigned
int block
):
692 self.set_block
(block
)
694 from a
.pid_neuro cimport
*
696 cdef class pid_neuro
:
699 self.ctx
.pid
.summax
= +A_FLOAT_INF
700 self.ctx
.pid
.summin
= -A_FLOAT_INF
701 self.ctx
.pid
.outmax
= +A_FLOAT_INF
702 self.ctx
.pid
.outmin
= -A_FLOAT_INF
703 self.ctx
.k
= self.ctx
.pid
.kp
= 1
707 a_pid_neuro_init
(&self.ctx
)
708 def kpid
(self, a_float k
, a_float kp
, a_float ki
, a_float kd
):
709 a_pid_neuro_kpid
(&self.ctx
, k
, kp
, ki
, kd
)
711 def wpid
(self, a_float wp
, a_float wi
, a_float wd
):
712 a_pid_neuro_wpid
(&self.ctx
, wp
, wi
, wd
)
714 def run
(self, a_float set
, a_float fdb
):
715 return a_pid_neuro_run
(&self.ctx
, set
, fdb
)
716 def inc
(self, a_float set
, a_float fdb
):
717 return a_pid_neuro_inc
(&self.ctx
, set
, fdb
)
719 a_pid_neuro_zero
(&self.ctx
)
724 def __set__
(self, a_float k
):
728 return self.ctx
.pid
.kp
729 def __set__
(self, a_float kp
):
733 return self.ctx
.pid
.ki
734 def __set__
(self, a_float ki
):
738 return self.ctx
.pid
.kd
739 def __set__
(self, a_float kd
):
744 def __set__
(self, a_float wp
):
749 def __set__
(self, a_float wi
):
754 def __set__
(self, a_float wd
):
758 return self.ctx
.pid
.outmax
759 def __set__
(self, a_float outmax
):
760 self.ctx
.pid
.outmax
= outmax
763 return self.ctx
.pid
.outmin
764 def __set__
(self, a_float outmin
):
765 self.ctx
.pid
.outmin
= outmin
768 return self.ctx
.pid
.out
771 return self.ctx
.pid
.fdb
774 return self.ctx
.pid
.err
779 from a
.poly cimport
*
781 def poly_eval
(x
, *a
):
788 cdef a_size a_n
= len(a
)
790 a_p
= <a_float
*>a_
.data
.as_voidptr
791 if PyObject_HasAttrString
(x
, "__contains__"):
794 p
= <a_float
*>y
.data
.as_voidptr
795 for i
in prange
(n
, nogil
=True
):
796 p
[i
] = a_poly_eval
(a_p
, a_n
, p
[i
])
798 return a_poly_eval
(a_p
, a_n
, x
)
800 def poly_evar
(x
, *a
):
807 cdef a_size a_n
= len(a
)
809 a_p
= <a_float
*>a_
.data
.as_voidptr
810 if PyObject_HasAttrString
(x
, "__contains__"):
813 p
= <a_float
*>y
.data
.as_voidptr
814 for i
in prange
(n
, nogil
=True
):
815 p
[i
] = a_poly_evar
(a_p
, a_n
, p
[i
])
817 return a_poly_evar
(a_p
, a_n
, x
)
823 def __init__
(self, num
, den
):
824 tf
.num
.__set__
(self, num
)
825 tf
.den
.__set__
(self, den
)
826 def __call__
(self, a_float x
):
827 return a_tf_iter
(&self.ctx
, x
)
832 cdef readonly array
input
836 def __set__
(self, num
):
837 self._num
= array_num
(num
)
838 self.input = array_num
(num
)
839 a_tf_set_num
(&self.ctx
, <unsigned
int>len(num
), <a_float
*>self._num
.data
.as_voidptr
, <a_float
*>self.input.data
.as_voidptr
)
841 cdef readonly array output
845 def __set__
(self, den
):
846 self._den
= array_num
(den
)
847 self.output
= array_num
(den
)
848 a_tf_set_den
(&self.ctx
, <unsigned
int>len(den
), <a_float
*>self._den
.data
.as_voidptr
, <a_float
*>self.output
.data
.as_voidptr
)
850 from a
.trajbell cimport
*
854 def gen
(self, a_float jm
, a_float am
, a_float vm
, a_float p0
, a_float p1
, a_float v0
= 0, a_float v1
= 0):
855 return a_trajbell_gen
(&self.ctx
, jm
, am
, vm
, p0
, p1
, v0
, v1
)
861 if PyObject_HasAttrString
(dt
, "__contains__"):
864 p
= <a_float
*>x
.data
.as_voidptr
865 for i
in prange
(n
, nogil
=True
):
866 p
[i
] = a_trajbell_pos
(&self.ctx
, p
[i
])
868 return a_trajbell_pos
(&self.ctx
, dt
)
874 if PyObject_HasAttrString
(dt
, "__contains__"):
877 p
= <a_float
*>x
.data
.as_voidptr
878 for i
in prange
(n
, nogil
=True
):
879 p
[i
] = a_trajbell_vel
(&self.ctx
, p
[i
])
881 return a_trajbell_vel
(&self.ctx
, dt
)
887 if PyObject_HasAttrString
(dt
, "__contains__"):
890 p
= <a_float
*>x
.data
.as_voidptr
891 for i
in prange
(n
, nogil
=True
):
892 p
[i
] = a_trajbell_acc
(&self.ctx
, p
[i
])
894 return a_trajbell_acc
(&self.ctx
, dt
)
900 if PyObject_HasAttrString
(dt
, "__contains__"):
903 p
= <a_float
*>x
.data
.as_voidptr
904 for i
in prange
(n
, nogil
=True
):
905 p
[i
] = a_trajbell_jer
(&self.ctx
, p
[i
])
907 return a_trajbell_jer
(&self.ctx
, dt
)
951 from a
.trajpoly3 cimport
*
953 cdef class trajpoly3
:
955 def __init__
(self, a_float ts
, a_float p0
, a_float p1
, a_float v0
= 0, a_float v1
= 0):
956 a_trajpoly3_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
)
957 def gen
(self, a_float ts
, a_float p0
, a_float p1
, a_float v0
= 0, a_float v1
= 0):
958 a_trajpoly3_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
)
965 if PyObject_HasAttrString
(dt
, "__contains__"):
968 p
= <a_float
*>x
.data
.as_voidptr
969 for i
in prange
(n
, nogil
=True
):
970 p
[i
] = a_trajpoly3_pos
(&self.ctx
, p
[i
])
972 return a_trajpoly3_pos
(&self.ctx
, dt
)
978 if PyObject_HasAttrString
(dt
, "__contains__"):
981 p
= <a_float
*>x
.data
.as_voidptr
982 for i
in prange
(n
, nogil
=True
):
983 p
[i
] = a_trajpoly3_vel
(&self.ctx
, p
[i
])
985 return a_trajpoly3_vel
(&self.ctx
, dt
)
991 if PyObject_HasAttrString
(dt
, "__contains__"):
994 p
= <a_float
*>x
.data
.as_voidptr
995 for i
in prange
(n
, nogil
=True
):
996 p
[i
] = a_trajpoly3_acc
(&self.ctx
, p
[i
])
998 return a_trajpoly3_acc
(&self.ctx
, dt
)
1009 from a
.trajpoly5 cimport
*
1011 cdef class trajpoly5
:
1012 cdef a_trajpoly5 ctx
1013 def __init__
(self, a_float ts
, a_float p0
, a_float p1
, a_float v0
= 0, a_float v1
= 0, a_float a0
= 0, a_float a1
= 0):
1014 a_trajpoly5_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
)
1015 def gen
(self, a_float ts
, a_float p0
, a_float p1
, a_float v0
= 0, a_float v1
= 0, a_float a0
= 0, a_float a1
= 0):
1016 a_trajpoly5_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
)
1023 if PyObject_HasAttrString
(dt
, "__contains__"):
1026 p
= <a_float
*>x
.data
.as_voidptr
1027 for i
in prange
(n
, nogil
=True
):
1028 p
[i
] = a_trajpoly5_pos
(&self.ctx
, p
[i
])
1030 return a_trajpoly5_pos
(&self.ctx
, dt
)
1036 if PyObject_HasAttrString
(dt
, "__contains__"):
1039 p
= <a_float
*>x
.data
.as_voidptr
1040 for i
in prange
(n
, nogil
=True
):
1041 p
[i
] = a_trajpoly5_vel
(&self.ctx
, p
[i
])
1043 return a_trajpoly5_vel
(&self.ctx
, dt
)
1049 if PyObject_HasAttrString
(dt
, "__contains__"):
1052 p
= <a_float
*>x
.data
.as_voidptr
1053 for i
in prange
(n
, nogil
=True
):
1054 p
[i
] = a_trajpoly5_acc
(&self.ctx
, p
[i
])
1056 return a_trajpoly5_acc
(&self.ctx
, dt
)
1067 from a
.trajpoly7 cimport
*
1069 cdef class trajpoly7
:
1070 cdef a_trajpoly7 ctx
1071 def __init__
(self, a_float ts
, a_float p0
, a_float p1
, a_float v0
= 0, a_float v1
= 0, a_float a0
= 0, a_float a1
= 0, a_float j0
= 0, a_float j1
= 0):
1072 a_trajpoly7_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
, j0
, j1
)
1073 def gen
(self, a_float ts
, a_float p0
, a_float p1
, a_float v0
= 0, a_float v1
= 0, a_float a0
= 0, a_float a1
= 0, a_float j0
= 0, a_float j1
= 0):
1074 a_trajpoly7_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
, j0
, j1
)
1081 if PyObject_HasAttrString
(dt
, "__contains__"):
1084 p
= <a_float
*>x
.data
.as_voidptr
1085 for i
in prange
(n
, nogil
=True
):
1086 p
[i
] = a_trajpoly7_pos
(&self.ctx
, p
[i
])
1088 return a_trajpoly7_pos
(&self.ctx
, dt
)
1094 if PyObject_HasAttrString
(dt
, "__contains__"):
1097 p
= <a_float
*>x
.data
.as_voidptr
1098 for i
in prange
(n
, nogil
=True
):
1099 p
[i
] = a_trajpoly7_vel
(&self.ctx
, p
[i
])
1101 return a_trajpoly7_vel
(&self.ctx
, dt
)
1107 if PyObject_HasAttrString
(dt
, "__contains__"):
1110 p
= <a_float
*>x
.data
.as_voidptr
1111 for i
in prange
(n
, nogil
=True
):
1112 p
[i
] = a_trajpoly7_acc
(&self.ctx
, p
[i
])
1114 return a_trajpoly7_acc
(&self.ctx
, dt
)
1120 if PyObject_HasAttrString
(dt
, "__contains__"):
1123 p
= <a_float
*>x
.data
.as_voidptr
1124 for i
in prange
(n
, nogil
=True
):
1125 p
[i
] = a_trajpoly7_jer
(&self.ctx
, p
[i
])
1127 return a_trajpoly7_jer
(&self.ctx
, dt
)
1141 from a
.trajtrap cimport
*
1143 cdef class trajtrap
:
1145 def gen
(self, a_float vm
, a_float ac
, a_float de
, a_float p0
, a_float p1
, a_float v0
= 0, a_float v1
= 0):
1146 return a_trajtrap_gen
(&self.ctx
, vm
, ac
, de
, p0
, p1
, v0
, v1
)
1152 if PyObject_HasAttrString
(dt
, "__contains__"):
1155 p
= <a_float
*>x
.data
.as_voidptr
1156 for i
in prange
(n
, nogil
=True
):
1157 p
[i
] = a_trajtrap_pos
(&self.ctx
, p
[i
])
1159 return a_trajtrap_pos
(&self.ctx
, dt
)
1165 if PyObject_HasAttrString
(dt
, "__contains__"):
1168 p
= <a_float
*>x
.data
.as_voidptr
1169 for i
in prange
(n
, nogil
=True
):
1170 p
[i
] = a_trajtrap_vel
(&self.ctx
, p
[i
])
1172 return a_trajtrap_vel
(&self.ctx
, dt
)
1178 if PyObject_HasAttrString
(dt
, "__contains__"):
1181 p
= <a_float
*>x
.data
.as_voidptr
1182 for i
in prange
(n
, nogil
=True
):
1183 p
[i
] = a_trajtrap_acc
(&self.ctx
, p
[i
])
1185 return a_trajtrap_acc
(&self.ctx
, dt
)
1223 from a
.version cimport
*
1227 def __init__
(self, unsigned
int major
= 0, unsigned
int minor
= 0, unsigned
int third
= 0, unsigned
int extra
= 0):
1228 self.ctx
.major
= major
1229 self.ctx
.minor
= minor
1230 self.ctx
.third
= third
1231 self.ctx
.extra
= extra
1232 self.ctx
.alpha
[0] = 46
1235 a_version_tostr
(&self.ctx
, str, sizeof(str))
1238 def check
(unsigned
int major
= 0, unsigned
int minor
= 0, unsigned
int patch
= 0):
1239 return a_version_check
(major
, minor
, patch
)
1240 def cmp(self, version that
):
1241 return a_version_cmp
(&self.ctx
, &that
.ctx
)
1242 def __lt__
(self, version that
):
1243 return a_version_lt
(&self.ctx
, &that
.ctx
)
1244 def __gt__
(self, version that
):
1245 return a_version_gt
(&self.ctx
, &that
.ctx
)
1246 def __le__
(self, version that
):
1247 return a_version_le
(&self.ctx
, &that
.ctx
)
1248 def __ge__
(self, version that
):
1249 return a_version_ge
(&self.ctx
, &that
.ctx
)
1250 def __eq__
(self, version that
):
1251 return a_version_eq
(&self.ctx
, &that
.ctx
)
1252 def __ne__
(self, version that
):
1253 return a_version_ne
(&self.ctx
, &that
.ctx
)
1254 def parse
(self, bytes ver
):
1255 a_version_parse
(&self.ctx
, ver
)
1258 return object.__hash__
(self)
1261 return self.ctx
.major
1262 def __set__
(self, unsigned
int major
):
1263 self.ctx
.major
= major
1266 return self.ctx
.minor
1267 def __set__
(self, unsigned
int minor
):
1268 self.ctx
.minor
= minor
1271 return self.ctx
.third
1272 def __set__
(self, unsigned
int third
):
1273 self.ctx
.third
= third
1276 return self.ctx
.extra
1277 def __set__
(self, unsigned
int extra
):
1278 self.ctx
.extra
= extra
1282 a_version_alpha
(&self.ctx
, alpha
)
1284 def __set__
(self, bytes alpha
):
1285 a_version_set_alpha
(&self.ctx
, alpha
)
1286 MAJOR
= A_VERSION_MAJOR
1287 MINOR
= A_VERSION_MINOR
1288 PATCH
= A_VERSION_PATCH
1289 TWEAK
= A_VERSION_TWEAK
1291 if PY_MAJOR_VERSION
>= 3:
1292 VERSION
= A_VERSION
.decode
()