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
=0):
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
=0):
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
=0):
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
=0):
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
=0):
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
=0):
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
=0):
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
=0):
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
236 if PyObject_HasAttrString
(x
, "__contains__"):
239 p
= <a_u32
*>y
.data
.as_voidptr
240 for i
in prange
(n
, nogil
=True
):
241 p
[i
] = a_u32_sqrt
(p
[i
])
249 if PyObject_HasAttrString
(x
, "__contains__"):
252 p
= <a_u64
*>y
.data
.as_voidptr
253 for i
in prange
(n
, nogil
=True
):
254 p
[i
] = a_u64_sqrt
(p
[i
])
262 if PyObject_HasAttrString
(x
, "__contains__"):
265 p
= <a_f32
*>y
.data
.as_voidptr
266 for i
in prange
(n
, nogil
=True
):
267 p
[i
] = a_f32_rsqrt
(p
[i
])
269 return a_f32_rsqrt
(x
)
275 if PyObject_HasAttrString
(x
, "__contains__"):
278 p
= <a_f64
*>y
.data
.as_voidptr
279 for i
in prange
(n
, nogil
=True
):
280 p
[i
] = a_f64_rsqrt
(p
[i
])
282 return a_f64_rsqrt
(x
)
302 def __call__
(unsigned
int e
, x
, a
):
306 cdef unsigned
int m
= e
307 cdef array a_
= array_num
(a
)
308 cdef a_float
*a_p
= <a_float
*>a_
.data
.as_voidptr
309 if PyObject_HasAttrString
(x
, "__contains__"):
312 p
= <a_float
*>y
.data
.as_voidptr
313 for i
in prange
(n
, nogil
=True
):
314 p
[i
] = a_mf
(m
, p
[i
], a_p
)
316 return a_mf
(m
, x
, a_p
)
318 def gauss
(x
, a_float sigma
, a_float c
):
322 if PyObject_HasAttrString
(x
, "__contains__"):
325 p
= <a_float
*>y
.data
.as_voidptr
326 for i
in prange
(n
, nogil
=True
):
327 p
[i
] = a_mf_gauss
(p
[i
], sigma
, c
)
329 return a_mf_gauss
(x
, sigma
, c
)
331 def gauss2
(x
, a_float sigma1
, a_float c1
, a_float sigma2
, a_float c2
):
335 if PyObject_HasAttrString
(x
, "__contains__"):
338 p
= <a_float
*>y
.data
.as_voidptr
339 for i
in prange
(n
, nogil
=True
):
340 p
[i
] = a_mf_gauss2
(p
[i
], sigma1
, c1
, sigma2
, c2
)
342 return a_mf_gauss2
(x
, sigma1
, c1
, sigma2
, c2
)
344 def gbell
(x
, a_float a
, a_float b
, a_float c
):
348 if PyObject_HasAttrString
(x
, "__contains__"):
351 p
= <a_float
*>y
.data
.as_voidptr
352 for i
in prange
(n
, nogil
=True
):
353 p
[i
] = a_mf_gbell
(p
[i
], a
, b
, c
)
355 return a_mf_gbell
(x
, a
, b
, c
)
357 def sig
(x
, a_float a
, a_float c
):
361 if PyObject_HasAttrString
(x
, "__contains__"):
364 p
= <a_float
*>y
.data
.as_voidptr
365 for i
in prange
(n
, nogil
=True
):
366 p
[i
] = a_mf_sig
(p
[i
], a
, c
)
368 return a_mf_sig
(x
, a
, c
)
370 def dsig
(x
, a_float a1
, a_float c1
, a_float a2
, a_float c2
):
374 if PyObject_HasAttrString
(x
, "__contains__"):
377 p
= <a_float
*>y
.data
.as_voidptr
378 for i
in prange
(n
, nogil
=True
):
379 p
[i
] = a_mf_dsig
(p
[i
], a1
, c1
, a2
, c2
)
381 return a_mf_dsig
(x
, a1
, c1
, a2
, c2
)
383 def psig
(x
, a_float a1
, a_float c1
, a_float a2
, a_float c2
):
387 if PyObject_HasAttrString
(x
, "__contains__"):
390 p
= <a_float
*>y
.data
.as_voidptr
391 for i
in prange
(n
, nogil
=True
):
392 p
[i
] = a_mf_psig
(p
[i
], a1
, c1
, a2
, c2
)
394 return a_mf_psig
(x
, a1
, c1
, a2
, c2
)
396 def trap
(x
, a_float a
, a_float b
, a_float c
, a_float d
):
400 if PyObject_HasAttrString
(x
, "__contains__"):
403 p
= <a_float
*>y
.data
.as_voidptr
404 for i
in prange
(n
, nogil
=True
):
405 p
[i
] = a_mf_trap
(p
[i
], a
, b
, c
, d
)
407 return a_mf_trap
(x
, a
, b
, c
, d
)
409 def tri
(x
, a_float a
, a_float b
, a_float c
):
413 if PyObject_HasAttrString
(x
, "__contains__"):
416 p
= <a_float
*>y
.data
.as_voidptr
417 for i
in prange
(n
, nogil
=True
):
418 p
[i
] = a_mf_tri
(p
[i
], a
, b
, c
)
420 return a_mf_tri
(x
, a
, b
, c
)
422 def lins
(x
, a_float a
, a_float b
):
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_lins
(p
[i
], a
, b
)
433 return a_mf_lins
(x
, a
, b
)
435 def linz
(x
, a_float a
, a_float b
):
439 if PyObject_HasAttrString
(x
, "__contains__"):
442 p
= <a_float
*>y
.data
.as_voidptr
443 for i
in prange
(n
, nogil
=True
):
444 p
[i
] = a_mf_linz
(p
[i
], a
, b
)
446 return a_mf_linz
(x
, a
, b
)
448 def s
(x
, a_float a
, a_float b
):
452 if PyObject_HasAttrString
(x
, "__contains__"):
455 p
= <a_float
*>y
.data
.as_voidptr
456 for i
in prange
(n
, nogil
=True
):
457 p
[i
] = a_mf_s
(p
[i
], a
, b
)
459 return a_mf_s
(x
, a
, b
)
461 def z
(x
, a_float a
, a_float b
):
465 if PyObject_HasAttrString
(x
, "__contains__"):
468 p
= <a_float
*>y
.data
.as_voidptr
469 for i
in prange
(n
, nogil
=True
):
470 p
[i
] = a_mf_z
(p
[i
], a
, b
)
472 return a_mf_z
(x
, a
, b
)
474 def pi
(x
, a_float a
, a_float b
, a_float c
, a_float d
):
478 if PyObject_HasAttrString
(x
, "__contains__"):
481 p
= <a_float
*>y
.data
.as_voidptr
482 for i
in prange
(n
, nogil
=True
):
483 p
[i
] = a_mf_pi
(p
[i
], a
, b
, c
, d
)
485 return a_mf_pi
(x
, a
, b
, c
, d
)
493 self.ctx
.summax
= +A_FLOAT_INF
494 self.ctx
.summin
= -A_FLOAT_INF
495 self.ctx
.outmax
= +A_FLOAT_INF
496 self.ctx
.outmin
= -A_FLOAT_INF
497 a_pid_init
(&self.ctx
)
498 def kpid
(self, a_float kp
, a_float ki
, a_float kd
):
499 a_pid_kpid
(&self.ctx
, kp
, ki
, kd
)
501 def run
(self, a_float set
, a_float fdb
):
502 return a_pid_run
(&self.ctx
, set
, fdb
)
503 def pos
(self, a_float set
, a_float fdb
):
504 return a_pid_pos
(&self.ctx
, set
, fdb
)
505 def inc
(self, a_float set
, a_float fdb
):
506 return a_pid_inc
(&self.ctx
, set
, fdb
)
508 a_pid_zero
(&self.ctx
)
513 def __set__
(self, a_float kp
):
518 def __set__
(self, a_float ki
):
523 def __set__
(self, a_float kd
):
527 return self.ctx
.summax
528 def __set__
(self, a_float summax
):
529 self.ctx
.summax
= summax
532 return self.ctx
.summin
533 def __set__
(self, a_float summin
):
534 self.ctx
.summin
= summin
540 return self.ctx
.outmax
541 def __set__
(self, a_float outmax
):
542 self.ctx
.outmax
= outmax
545 return self.ctx
.outmin
546 def __set__
(self, a_float outmin
):
547 self.ctx
.outmin
= outmin
558 from a
.pid_fuzzy cimport
*
560 cdef class pid_fuzzy
:
561 CAP
= A_PID_FUZZY_CAP
562 CAP_ALGEBRA
= A_PID_FUZZY_CAP_ALGEBRA
563 CAP_BOUNDED
= A_PID_FUZZY_CAP_BOUNDED
564 CUP
= A_PID_FUZZY_CUP
565 CUP_ALGEBRA
= A_PID_FUZZY_CUP_ALGEBRA
566 CUP_BOUNDED
= A_PID_FUZZY_CUP_BOUNDED
567 EQU
= A_PID_FUZZY_EQU
569 cdef readonly array me
570 cdef readonly array mec
571 cdef readonly array mkp
572 cdef readonly array mki
573 cdef readonly array mkd
575 self.ctx
.pid
.summax
= +A_FLOAT_INF
576 self.ctx
.pid
.summin
= -A_FLOAT_INF
577 self.ctx
.pid
.outmax
= +A_FLOAT_INF
578 self.ctx
.pid
.outmin
= -A_FLOAT_INF
579 self.ctx
.kp
= self.ctx
.pid
.kp
= 1
580 self.ctx
.op
= a_fuzzy_equ
581 a_pid_fuzzy_init
(&self.ctx
)
582 def op
(self, unsigned
int op
):
583 a_pid_fuzzy_set_op
(&self.ctx
, op
)
585 def rule
(self, me
, mec
, mkp
, mki
, mkd
):
586 self.me
= array_num
([_2
for _1
in me
for _2
in _1
])
587 self.mec
= array_num
([_2
for _1
in mec
for _2
in _1
])
588 self.mkp
= array_num
([_2
for _1
in mkp
for _2
in _1
])
589 self.mki
= array_num
([_2
for _1
in mki
for _2
in _1
])
590 self.mkd
= array_num
([_2
for _1
in mkd
for _2
in _1
])
591 a_pid_fuzzy_rule
(&self.ctx
, <unsigned
int>len(me
),
592 <a_float
*>self.me
.data
.as_voidptr
,
593 <a_float
*>self.mec
.data
.as_voidptr
,
594 <a_float
*>self.mkp
.data
.as_voidptr
,
595 <a_float
*>self.mki
.data
.as_voidptr
,
596 <a_float
*>self.mkd
.data
.as_voidptr
)
598 def set_block
(self, unsigned
int num
):
599 cdef void *ptr
= a_pid_fuzzy_block
(&self.ctx
)
600 ptr
= PyMem_Realloc
(ptr
, A_PID_FUZZY_BLOCK
(num
))
601 a_pid_fuzzy_set_block
(&self.ctx
, ptr
, num
)
603 def kpid
(self, a_float kp
, a_float ki
, a_float kd
):
604 a_pid_fuzzy_kpid
(&self.ctx
, kp
, ki
, kd
)
606 def run
(self, a_float set
, a_float fdb
):
607 return a_pid_fuzzy_run
(&self.ctx
, set
, fdb
)
608 def pos
(self, a_float set
, a_float fdb
):
609 return a_pid_fuzzy_pos
(&self.ctx
, set
, fdb
)
610 def inc
(self, a_float set
, a_float fdb
):
611 return a_pid_fuzzy_inc
(&self.ctx
, set
, fdb
)
612 def __dealloc__
(self):
613 PyMem_Free
(a_pid_fuzzy_block
(&self.ctx
))
615 a_pid_fuzzy_zero
(&self.ctx
)
620 def __set__
(self, a_float kp
):
626 def __set__
(self, a_float ki
):
632 def __set__
(self, a_float kd
):
637 return self.ctx
.pid
.summax
638 def __set__
(self, a_float summax
):
639 self.ctx
.pid
.summax
= summax
642 return self.ctx
.pid
.summin
643 def __set__
(self, a_float summin
):
644 self.ctx
.pid
.summin
= summin
647 return self.ctx
.pid
.sum
650 return self.ctx
.pid
.outmax
651 def __set__
(self, a_float outmax
):
652 self.ctx
.pid
.outmax
= outmax
655 return self.ctx
.pid
.outmin
656 def __set__
(self, a_float outmin
):
657 self.ctx
.pid
.outmin
= outmin
660 return self.ctx
.pid
.out
663 return self.ctx
.pid
.fdb
666 return self.ctx
.pid
.err
669 return self.ctx
.order
672 return self.ctx
.block
673 def __set__
(self, unsigned
int block
):
674 self.set_block
(block
)
676 from a
.pid_neuro cimport
*
678 cdef class pid_neuro
:
681 self.ctx
.pid
.summax
= +A_FLOAT_INF
682 self.ctx
.pid
.summin
= -A_FLOAT_INF
683 self.ctx
.pid
.outmax
= +A_FLOAT_INF
684 self.ctx
.pid
.outmin
= -A_FLOAT_INF
685 self.ctx
.k
= self.ctx
.pid
.kp
= 1
689 a_pid_neuro_init
(&self.ctx
)
690 def kpid
(self, a_float k
, a_float kp
, a_float ki
, a_float kd
):
691 a_pid_neuro_kpid
(&self.ctx
, k
, kp
, ki
, kd
)
693 def wpid
(self, a_float wp
, a_float wi
, a_float wd
):
694 a_pid_neuro_wpid
(&self.ctx
, wp
, wi
, wd
)
696 def run
(self, a_float set
, a_float fdb
):
697 return a_pid_neuro_run
(&self.ctx
, set
, fdb
)
698 def inc
(self, a_float set
, a_float fdb
):
699 return a_pid_neuro_inc
(&self.ctx
, set
, fdb
)
701 a_pid_neuro_zero
(&self.ctx
)
706 def __set__
(self, a_float k
):
710 return self.ctx
.pid
.kp
711 def __set__
(self, a_float kp
):
715 return self.ctx
.pid
.ki
716 def __set__
(self, a_float ki
):
720 return self.ctx
.pid
.kd
721 def __set__
(self, a_float kd
):
726 def __set__
(self, a_float wp
):
731 def __set__
(self, a_float wi
):
736 def __set__
(self, a_float wd
):
740 return self.ctx
.pid
.outmax
741 def __set__
(self, a_float outmax
):
742 self.ctx
.pid
.outmax
= outmax
745 return self.ctx
.pid
.outmin
746 def __set__
(self, a_float outmin
):
747 self.ctx
.pid
.outmin
= outmin
750 return self.ctx
.pid
.out
753 return self.ctx
.pid
.fdb
756 return self.ctx
.pid
.err
761 from a
.poly cimport
*
763 def poly_eval
(x
, *a
):
769 cdef a_size a_n
= len(a
)
771 a_p
= <a_float
*>a_
.data
.as_voidptr
772 if PyObject_HasAttrString
(x
, "__contains__"):
775 p
= <a_float
*>y
.data
.as_voidptr
776 for i
in prange
(n
, nogil
=True
):
777 p
[i
] = a_poly_eval
(a_p
, a_n
, p
[i
])
779 return a_poly_eval
(a_p
, a_n
, x
)
781 def poly_evar
(x
, *a
):
787 cdef a_size a_n
= len(a
)
789 a_p
= <a_float
*>a_
.data
.as_voidptr
790 if PyObject_HasAttrString
(x
, "__contains__"):
793 p
= <a_float
*>y
.data
.as_voidptr
794 for i
in prange
(n
, nogil
=True
):
795 p
[i
] = a_poly_evar
(a_p
, a_n
, p
[i
])
797 return a_poly_evar
(a_p
, a_n
, x
)
803 def __init__
(self, num
, den
):
804 tf
.num
.__set__
(self, num
)
805 tf
.den
.__set__
(self, den
)
806 def __call__
(self, a_float x
):
807 return a_tf_iter
(&self.ctx
, x
)
812 cdef readonly array
input
816 def __set__
(self, num
):
817 self._num
= array_num
(num
)
818 self.input = array_num
(num
)
819 a_tf_set_num
(&self.ctx
, <unsigned
int>len(num
), <a_float
*>self._num
.data
.as_voidptr
, <a_float
*>self.input.data
.as_voidptr
)
821 cdef readonly array output
825 def __set__
(self, den
):
826 self._den
= array_num
(den
)
827 self.output
= array_num
(den
)
828 a_tf_set_den
(&self.ctx
, <unsigned
int>len(den
), <a_float
*>self._den
.data
.as_voidptr
, <a_float
*>self.output
.data
.as_voidptr
)
830 from a
.trajbell cimport
*
834 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):
835 return a_trajbell_gen
(&self.ctx
, jm
, am
, vm
, p0
, p1
, v0
, v1
)
840 if PyObject_HasAttrString
(dt
, "__contains__"):
843 p
= <a_float
*>x
.data
.as_voidptr
844 for i
in prange
(n
, nogil
=True
):
845 p
[i
] = a_trajbell_pos
(&self.ctx
, p
[i
])
847 return a_trajbell_pos
(&self.ctx
, dt
)
852 if PyObject_HasAttrString
(dt
, "__contains__"):
855 p
= <a_float
*>x
.data
.as_voidptr
856 for i
in prange
(n
, nogil
=True
):
857 p
[i
] = a_trajbell_vel
(&self.ctx
, p
[i
])
859 return a_trajbell_vel
(&self.ctx
, dt
)
864 if PyObject_HasAttrString
(dt
, "__contains__"):
867 p
= <a_float
*>x
.data
.as_voidptr
868 for i
in prange
(n
, nogil
=True
):
869 p
[i
] = a_trajbell_acc
(&self.ctx
, p
[i
])
871 return a_trajbell_acc
(&self.ctx
, dt
)
876 if PyObject_HasAttrString
(dt
, "__contains__"):
879 p
= <a_float
*>x
.data
.as_voidptr
880 for i
in prange
(n
, nogil
=True
):
881 p
[i
] = a_trajbell_jer
(&self.ctx
, p
[i
])
883 return a_trajbell_jer
(&self.ctx
, dt
)
927 from a
.trajpoly3 cimport
*
929 cdef class trajpoly3
:
931 def __init__
(self, a_float ts
, a_float p0
, a_float p1
, a_float v0
=0, a_float v1
=0):
932 a_trajpoly3_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
)
933 def gen
(self, a_float ts
, a_float p0
, a_float p1
, a_float v0
=0, a_float v1
=0):
934 a_trajpoly3_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
)
940 if PyObject_HasAttrString
(dt
, "__contains__"):
943 p
= <a_float
*>x
.data
.as_voidptr
944 for i
in prange
(n
, nogil
=True
):
945 p
[i
] = a_trajpoly3_pos
(&self.ctx
, p
[i
])
947 return a_trajpoly3_pos
(&self.ctx
, dt
)
952 if PyObject_HasAttrString
(dt
, "__contains__"):
955 p
= <a_float
*>x
.data
.as_voidptr
956 for i
in prange
(n
, nogil
=True
):
957 p
[i
] = a_trajpoly3_vel
(&self.ctx
, p
[i
])
959 return a_trajpoly3_vel
(&self.ctx
, dt
)
964 if PyObject_HasAttrString
(dt
, "__contains__"):
967 p
= <a_float
*>x
.data
.as_voidptr
968 for i
in prange
(n
, nogil
=True
):
969 p
[i
] = a_trajpoly3_acc
(&self.ctx
, p
[i
])
971 return a_trajpoly3_acc
(&self.ctx
, dt
)
982 from a
.trajpoly5 cimport
*
984 cdef class trajpoly5
:
986 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):
987 a_trajpoly5_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
)
988 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):
989 a_trajpoly5_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
)
995 if PyObject_HasAttrString
(dt
, "__contains__"):
998 p
= <a_float
*>x
.data
.as_voidptr
999 for i
in prange
(n
, nogil
=True
):
1000 p
[i
] = a_trajpoly5_pos
(&self.ctx
, p
[i
])
1002 return a_trajpoly5_pos
(&self.ctx
, dt
)
1006 cdef Py_ssize_t i
, n
1007 if PyObject_HasAttrString
(dt
, "__contains__"):
1010 p
= <a_float
*>x
.data
.as_voidptr
1011 for i
in prange
(n
, nogil
=True
):
1012 p
[i
] = a_trajpoly5_vel
(&self.ctx
, p
[i
])
1014 return a_trajpoly5_vel
(&self.ctx
, dt
)
1018 cdef Py_ssize_t i
, n
1019 if PyObject_HasAttrString
(dt
, "__contains__"):
1022 p
= <a_float
*>x
.data
.as_voidptr
1023 for i
in prange
(n
, nogil
=True
):
1024 p
[i
] = a_trajpoly5_acc
(&self.ctx
, p
[i
])
1026 return a_trajpoly5_acc
(&self.ctx
, dt
)
1037 from a
.trajpoly7 cimport
*
1039 cdef class trajpoly7
:
1040 cdef a_trajpoly7 ctx
1041 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):
1042 a_trajpoly7_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
, j0
, j1
)
1043 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):
1044 a_trajpoly7_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
, j0
, j1
)
1049 cdef Py_ssize_t i
, n
1050 if PyObject_HasAttrString
(dt
, "__contains__"):
1053 p
= <a_float
*>x
.data
.as_voidptr
1054 for i
in prange
(n
, nogil
=True
):
1055 p
[i
] = a_trajpoly7_pos
(&self.ctx
, p
[i
])
1057 return a_trajpoly7_pos
(&self.ctx
, dt
)
1061 cdef Py_ssize_t i
, n
1062 if PyObject_HasAttrString
(dt
, "__contains__"):
1065 p
= <a_float
*>x
.data
.as_voidptr
1066 for i
in prange
(n
, nogil
=True
):
1067 p
[i
] = a_trajpoly7_vel
(&self.ctx
, p
[i
])
1069 return a_trajpoly7_vel
(&self.ctx
, dt
)
1073 cdef Py_ssize_t i
, n
1074 if PyObject_HasAttrString
(dt
, "__contains__"):
1077 p
= <a_float
*>x
.data
.as_voidptr
1078 for i
in prange
(n
, nogil
=True
):
1079 p
[i
] = a_trajpoly7_acc
(&self.ctx
, p
[i
])
1081 return a_trajpoly7_acc
(&self.ctx
, dt
)
1085 cdef Py_ssize_t i
, n
1086 if PyObject_HasAttrString
(dt
, "__contains__"):
1089 p
= <a_float
*>x
.data
.as_voidptr
1090 for i
in prange
(n
, nogil
=True
):
1091 p
[i
] = a_trajpoly7_jer
(&self.ctx
, p
[i
])
1093 return a_trajpoly7_jer
(&self.ctx
, dt
)
1107 from a
.trajtrap cimport
*
1109 cdef class trajtrap
:
1111 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):
1112 return a_trajtrap_gen
(&self.ctx
, vm
, ac
, de
, p0
, p1
, v0
, v1
)
1116 cdef Py_ssize_t i
, n
1117 if PyObject_HasAttrString
(dt
, "__contains__"):
1120 p
= <a_float
*>x
.data
.as_voidptr
1121 for i
in prange
(n
, nogil
=True
):
1122 p
[i
] = a_trajtrap_pos
(&self.ctx
, p
[i
])
1124 return a_trajtrap_pos
(&self.ctx
, dt
)
1128 cdef Py_ssize_t i
, n
1129 if PyObject_HasAttrString
(dt
, "__contains__"):
1132 p
= <a_float
*>x
.data
.as_voidptr
1133 for i
in prange
(n
, nogil
=True
):
1134 p
[i
] = a_trajtrap_vel
(&self.ctx
, p
[i
])
1136 return a_trajtrap_vel
(&self.ctx
, dt
)
1140 cdef Py_ssize_t i
, n
1141 if PyObject_HasAttrString
(dt
, "__contains__"):
1144 p
= <a_float
*>x
.data
.as_voidptr
1145 for i
in prange
(n
, nogil
=True
):
1146 p
[i
] = a_trajtrap_acc
(&self.ctx
, p
[i
])
1148 return a_trajtrap_acc
(&self.ctx
, dt
)
1186 from a
.version cimport
*
1190 def __init__
(self, unsigned
int major
= 0, unsigned
int minor
= 0, unsigned
int third
= 0, unsigned
int extra
= 0):
1191 self.ctx
.major
= major
1192 self.ctx
.minor
= minor
1193 self.ctx
.third
= third
1194 self.ctx
.extra
= extra
1195 self.ctx
.alpha
[0] = 46
1198 a_version_tostr
(&self.ctx
, str, sizeof(str))
1201 def check
(unsigned
int major
= 0, unsigned
int minor
= 0, unsigned
int patch
= 0):
1202 return a_version_check
(major
, minor
, patch
)
1203 def cmp(self, version that
):
1204 return a_version_cmp
(&self.ctx
, &that
.ctx
)
1205 def __lt__
(self, version that
):
1206 return a_version_lt
(&self.ctx
, &that
.ctx
)
1207 def __gt__
(self, version that
):
1208 return a_version_gt
(&self.ctx
, &that
.ctx
)
1209 def __le__
(self, version that
):
1210 return a_version_le
(&self.ctx
, &that
.ctx
)
1211 def __ge__
(self, version that
):
1212 return a_version_ge
(&self.ctx
, &that
.ctx
)
1213 def __eq__
(self, version that
):
1214 return a_version_eq
(&self.ctx
, &that
.ctx
)
1215 def __ne__
(self, version that
):
1216 return a_version_ne
(&self.ctx
, &that
.ctx
)
1217 def parse
(self, bytes ver
):
1218 a_version_parse
(&self.ctx
, ver
)
1221 return object.__hash__
(self)
1224 return self.ctx
.major
1225 def __set__
(self, unsigned
int major
):
1226 self.ctx
.major
= major
1229 return self.ctx
.minor
1230 def __set__
(self, unsigned
int minor
):
1231 self.ctx
.minor
= minor
1234 return self.ctx
.third
1235 def __set__
(self, unsigned
int third
):
1236 self.ctx
.third
= third
1239 return self.ctx
.extra
1240 def __set__
(self, unsigned
int extra
):
1241 self.ctx
.extra
= extra
1245 a_version_alpha
(&self.ctx
, alpha
)
1247 def __set__
(self, bytes alpha
):
1248 a_version_set_alpha
(&self.ctx
, alpha
)
1249 MAJOR
= A_VERSION_MAJOR
1250 MINOR
= A_VERSION_MINOR
1251 PATCH
= A_VERSION_PATCH
1252 TWEAK
= A_VERSION_TWEAK
1254 if PY_MAJOR_VERSION
>= 3:
1255 VERSION
= A_VERSION
.decode
()