1 #cython: autotestdict=False
2 #cython: auto_pickle=False
3 #cython: boundscheck=False
4 #cython: wraparound=False
5 #cython: initializedcheck=False
6 #cython: language_level=3str
7 #cython: c_string_type=bytes
8 #cython: c_string_encoding=utf-8
9 from cython
.parallel
import prange
10 from cython
.view cimport array
11 from cpython cimport
*
14 cdef array u32_new
(Py_ssize_t n
):
16 if UINT32_MAX
> UINT_MAX
:
18 return array
(shape
=(n
,), itemsize
=4, format
=u32
, mode
='c')
20 cdef a_u32
*u32_set
(array o
, object x
, Py_ssize_t n
):
21 cdef a_u32
*r
= <a_u32
*>o
.data
27 cpdef array new_u32
(object x
):
30 if PyObject_HasAttrString
(x
, "__len__"):
37 cdef array u64_new
(Py_ssize_t n
):
39 if UINT64_MAX
> ULONG_MAX
:
41 return array
(shape
=(n
,), itemsize
=8, format
=u64
, mode
='c')
43 cdef a_u64
*u64_set
(array o
, object x
, Py_ssize_t n
):
44 cdef a_u64
*r
= <a_u64
*>o
.data
50 cpdef array new_u64
(object x
):
53 if PyObject_HasAttrString
(x
, "__len__"):
60 cdef array f32_new
(Py_ssize_t n
):
61 return array
(shape
=(n
,), itemsize
=4, format
='f', mode
='c')
63 cdef a_f32
*f32_set
(array o
, object x
, Py_ssize_t n
):
64 cdef a_f32
*r
= <a_f32
*>o
.data
70 cpdef array new_f32
(object x
):
73 if PyObject_HasAttrString
(x
, "__len__"):
80 cdef array f64_new
(Py_ssize_t n
):
81 return array
(shape
=(n
,), itemsize
=8, format
='d', mode
='c')
83 cdef a_f64
*f64_set
(array o
, object x
, Py_ssize_t n
):
84 cdef a_f64
*r
= <a_f64
*>o
.data
90 cpdef array new_f64
(object x
):
93 if PyObject_HasAttrString
(x
, "__len__"):
100 cdef a_float
*num_set
(array o
, object x
, Py_ssize_t n
):
101 cdef a_float
*r
= <a_float
*>o
.data
107 cdef array
(*num_new
)(Py_ssize_t n
)
110 if A_FLOAT_TYPE
== A_FLOAT_SINGLE
:
114 cdef array num2_new
(object x2
):
115 cdef Py_ssize_t n
= 0
121 cdef a_float
*num2_set
(array o
, object x2
):
122 cdef a_float
*r
= <a_float
*>o
.data
123 cdef Py_ssize_t n
= 0
132 def hash_bkdr
(const
char *str, a_u32 val
=0) -> a_u32
:
133 return a_hash_bkdr
(str, val
)
135 def hash_sdbm
(const
char *str, a_u32 val
=0) -> a_u32
:
136 return a_hash_sdbm
(str, val
)
141 cdef a_u8
[0x100] table
144 return <a_u8
[::1]>self.table
145 def gen
(self, a_u8 poly
, bint reversed
=0):
147 a_crc8l_init
(self.table
, poly
)
149 a_crc8m_init
(self.table
, poly
)
151 def __init__
(self, a_u8 poly
, bint reversed
=0):
152 self.gen
(poly
, reversed
)
153 def __call__
(self, bytes block
, a_u8 value
=0):
154 return a_crc8
(self.table
, <char *>block
, len(block
), value
)
155 def pack
(self, bytes block
, a_u8 value
=0):
156 cdef size_t n
= len(block
)
157 block
= block
+ bytes
(1)
158 cdef char *p
= <char *>block
159 value
= a_crc8
(self.table
, p
, n
, value
)
164 cdef a_u16
[0x100] table
167 return <a_u16
[::1]>self.table
168 cdef a_u16
(*eval)(const a_u16
*, const
void *, a_size
, a_u16
)
169 def gen
(self, a_u16 poly
, bint reversed
=0):
171 a_crc16l_init
(self.table
, poly
)
174 a_crc16m_init
(self.table
, poly
)
177 def __init__
(self, a_u16 poly
, bint reversed
=0):
178 self.gen
(poly
, reversed
)
179 def __call__
(self, bytes block
, a_u16 value
=0):
180 return self.eval(self.table
, <char *>block
, len(block
), value
)
181 def pack
(self, bytes block
, a_u16 value
=0):
182 cdef size_t n
= len(block
)
183 block
= block
+ bytes
(2)
184 cdef char *p
= <char *>block
185 value
= self.eval(self.table
, p
, n
, value
)
186 if self.eval == a_crc16m
:
187 a_u16_setb
(p
+ n
, value
)
189 a_u16_setl
(p
+ n
, value
)
193 cdef a_u32
[0x100] table
196 return <a_u32
[::1]>self.table
197 cdef a_u32
(*eval)(const a_u32
*, const
void *, a_size
, a_u32
)
198 def gen
(self, a_u32 poly
, bint reversed
=0):
200 a_crc32l_init
(self.table
, poly
)
203 a_crc32m_init
(self.table
, poly
)
206 def __init__
(self, a_u32 poly
, bint reversed
=0):
207 self.gen
(poly
, reversed
)
208 def __call__
(self, bytes block
, a_u32 value
=0):
209 return self.eval(self.table
, <char *>block
, len(block
), value
)
210 def pack
(self, bytes block
, a_u32 value
=0):
211 cdef size_t n
= len(block
)
212 block
= block
+ bytes
(4)
213 cdef char *p
= <char *>block
214 value
= self.eval(self.table
, p
, n
, value
)
215 if self.eval == a_crc32m
:
216 a_u32_setb
(p
+ n
, value
)
218 a_u32_setl
(p
+ n
, value
)
222 cdef a_u64
[0x100] table
225 return <a_u64
[::1]>self.table
226 cdef a_u64
(*eval)(const a_u64
*, const
void *, a_size
, a_u64
)
227 def gen
(self, a_u64 poly
, bint reversed
=0):
229 a_crc64l_init
(self.table
, poly
)
232 a_crc64m_init
(self.table
, poly
)
235 def __init__
(self, a_u64 poly
, bint reversed
=0):
236 self.gen
(poly
, reversed
)
237 def __call__
(self, bytes block
, a_u64 value
=0):
238 return self.eval(self.table
, <char *>block
, len(block
), value
)
239 def pack
(self, bytes block
, a_u64 value
=0):
240 cdef size_t n
= len(block
)
241 block
= block
+ bytes
(8)
242 cdef char *p
= <char *>block
243 value
= self.eval(self.table
, p
, n
, value
)
244 if self.eval == a_crc64m
:
245 a_u64_setb
(p
+ n
, value
)
247 a_u64_setl
(p
+ n
, value
)
254 def __init__
(self, a_float fc
, a_float ts
):
255 a_hpf_init
(&self.ctx
, a_hpf_gen
(fc
, ts
))
256 def gen
(self, a_float fc
, a_float ts
):
257 a_hpf_init
(&self.ctx
, a_hpf_gen
(fc
, ts
))
259 def __call__
(self, a_float x
):
260 return a_hpf_iter
(&self.ctx
, x
)
262 a_hpf_zero
(&self.ctx
)
266 return self.ctx
.alpha
267 def __set__
(self, a_float alpha
):
268 self.ctx
.alpha
= alpha
271 return self.ctx
.output
274 return self.ctx
.input
280 def __init__
(self, a_float fc
, a_float ts
):
281 a_lpf_init
(&self.ctx
, a_lpf_gen
(fc
, ts
))
282 def gen
(self, a_float fc
, a_float ts
):
283 a_lpf_init
(&self.ctx
, a_lpf_gen
(fc
, ts
))
285 def __call__
(self, a_float x
):
286 return a_lpf_iter
(&self.ctx
, x
)
288 a_lpf_zero
(&self.ctx
)
292 return self.ctx
.alpha
293 def __set__
(self, a_float alpha
):
294 self.ctx
.alpha
= alpha
297 return self.ctx
.output
299 from a
.math cimport
*
305 x0
= 1 << ((x
.bit_length
() + 1) >> 1)
306 x1
= (x0
+ x
// x0
) >> 1
309 x1
= (x0
+ x
// x0
) >> 1
312 def sqrt_u32
(object x
):
316 cdef const a_u32
[::1] p
317 if PyObject_HasAttrString
(x
, "__len__"):
319 r
= u32_new
(p
.shape
[0])
321 for i
in prange
(p
.shape
[0], nogil
=True
):
322 q
[i
] = a_u32_sqrt
(p
[i
])
326 def sqrt_u64
(object x
):
330 cdef const a_u64
[::1] p
331 if PyObject_HasAttrString
(x
, "__len__"):
333 r
= u64_new
(p
.shape
[0])
335 for i
in prange
(p
.shape
[0], nogil
=True
):
336 q
[i
] = a_u64_sqrt
(p
[i
])
340 def rsqrt_f32
(object x
):
344 cdef const a_f32
[::1] p
345 if PyObject_HasAttrString
(x
, "__len__"):
347 r
= f32_new
(p
.shape
[0])
349 for i
in prange
(p
.shape
[0], nogil
=True
):
350 q
[i
] = a_f32_rsqrt
(p
[i
])
352 return a_f32_rsqrt
(x
)
354 def rsqrt_f64
(object x
):
358 cdef const a_f64
[::1] p
359 if PyObject_HasAttrString
(x
, "__len__"):
361 r
= f64_new
(p
.shape
[0])
363 for i
in prange
(p
.shape
[0], nogil
=True
):
364 q
[i
] = a_f64_rsqrt
(p
[i
])
366 return a_f64_rsqrt
(x
)
386 def __call__
(unsigned
int e
, object x
, const a_float
[::1] a
):
390 cdef const a_float
[::1] p
391 if PyObject_HasAttrString
(x
, "__len__"):
393 r
= num_new
(p
.shape
[0])
394 q
= <a_float
*>r
.data
395 for i
in prange
(p
.shape
[0], nogil
=True
):
396 q
[i
] = a_mf
(e
, p
[i
], &a
[0])
398 return a_mf
(e
, x
, &a
[0])
400 def gauss
(object x
, a_float sigma
, a_float c
):
404 cdef const a_float
[::1] p
405 if PyObject_HasAttrString
(x
, "__len__"):
407 r
= num_new
(p
.shape
[0])
408 q
= <a_float
*>r
.data
409 for i
in prange
(p
.shape
[0], nogil
=True
):
410 q
[i
] = a_mf_gauss
(p
[i
], sigma
, c
)
412 return a_mf_gauss
(x
, sigma
, c
)
414 def gauss2
(object x
, a_float sigma1
, a_float c1
, a_float sigma2
, a_float c2
):
418 cdef const a_float
[::1] p
419 if PyObject_HasAttrString
(x
, "__len__"):
421 r
= num_new
(p
.shape
[0])
422 q
= <a_float
*>r
.data
423 for i
in prange
(p
.shape
[0], nogil
=True
):
424 q
[i
] = a_mf_gauss2
(p
[i
], sigma1
, c1
, sigma2
, c2
)
426 return a_mf_gauss2
(x
, sigma1
, c1
, sigma2
, c2
)
428 def gbell
(object x
, a_float a
, a_float b
, a_float c
):
432 cdef const a_float
[::1] p
433 if PyObject_HasAttrString
(x
, "__len__"):
435 r
= num_new
(p
.shape
[0])
436 q
= <a_float
*>r
.data
437 for i
in prange
(p
.shape
[0], nogil
=True
):
438 q
[i
] = a_mf_gbell
(p
[i
], a
, b
, c
)
440 return a_mf_gbell
(x
, a
, b
, c
)
442 def sig
(object x
, a_float a
, a_float c
):
446 cdef const a_float
[::1] p
447 if PyObject_HasAttrString
(x
, "__len__"):
449 r
= num_new
(p
.shape
[0])
450 q
= <a_float
*>r
.data
451 for i
in prange
(p
.shape
[0], nogil
=True
):
452 q
[i
] = a_mf_sig
(p
[i
], a
, c
)
454 return a_mf_sig
(x
, a
, c
)
456 def dsig
(object x
, a_float a1
, a_float c1
, a_float a2
, a_float c2
):
460 cdef const a_float
[::1] p
461 if PyObject_HasAttrString
(x
, "__len__"):
463 r
= num_new
(p
.shape
[0])
464 q
= <a_float
*>r
.data
465 for i
in prange
(p
.shape
[0], nogil
=True
):
466 q
[i
] = a_mf_dsig
(p
[i
], a1
, c1
, a2
, c2
)
468 return a_mf_dsig
(x
, a1
, c1
, a2
, c2
)
470 def psig
(object x
, a_float a1
, a_float c1
, a_float a2
, a_float c2
):
474 cdef const a_float
[::1] p
475 if PyObject_HasAttrString
(x
, "__len__"):
477 r
= num_new
(p
.shape
[0])
478 q
= <a_float
*>r
.data
479 for i
in prange
(p
.shape
[0], nogil
=True
):
480 q
[i
] = a_mf_psig
(p
[i
], a1
, c1
, a2
, c2
)
482 return a_mf_psig
(x
, a1
, c1
, a2
, c2
)
484 def trap
(object x
, a_float a
, a_float b
, a_float c
, a_float d
):
488 cdef const a_float
[::1] p
489 if PyObject_HasAttrString
(x
, "__len__"):
491 r
= num_new
(p
.shape
[0])
492 q
= <a_float
*>r
.data
493 for i
in prange
(p
.shape
[0], nogil
=True
):
494 q
[i
] = a_mf_trap
(p
[i
], a
, b
, c
, d
)
496 return a_mf_trap
(x
, a
, b
, c
, d
)
498 def tri
(object x
, a_float a
, a_float b
, a_float c
):
502 cdef const a_float
[::1] p
503 if PyObject_HasAttrString
(x
, "__len__"):
505 r
= num_new
(p
.shape
[0])
506 q
= <a_float
*>r
.data
507 for i
in prange
(p
.shape
[0], nogil
=True
):
508 q
[i
] = a_mf_tri
(p
[i
], a
, b
, c
)
510 return a_mf_tri
(x
, a
, b
, c
)
512 def lins
(object x
, a_float a
, a_float b
):
516 cdef const a_float
[::1] p
517 if PyObject_HasAttrString
(x
, "__len__"):
519 r
= num_new
(p
.shape
[0])
520 q
= <a_float
*>r
.data
521 for i
in prange
(p
.shape
[0], nogil
=True
):
522 q
[i
] = a_mf_lins
(p
[i
], a
, b
)
524 return a_mf_lins
(x
, a
, b
)
526 def linz
(object x
, a_float a
, a_float b
):
530 cdef const a_float
[::1] p
531 if PyObject_HasAttrString
(x
, "__len__"):
533 r
= num_new
(p
.shape
[0])
534 q
= <a_float
*>r
.data
535 for i
in prange
(p
.shape
[0], nogil
=True
):
536 q
[i
] = a_mf_linz
(p
[i
], a
, b
)
538 return a_mf_linz
(x
, a
, b
)
540 def s
(object x
, a_float a
, a_float b
):
544 cdef const a_float
[::1] p
545 if PyObject_HasAttrString
(x
, "__len__"):
547 r
= num_new
(p
.shape
[0])
548 q
= <a_float
*>r
.data
549 for i
in prange
(p
.shape
[0], nogil
=True
):
550 q
[i
] = a_mf_s
(p
[i
], a
, b
)
552 return a_mf_s
(x
, a
, b
)
554 def z
(object x
, a_float a
, a_float b
):
558 cdef const a_float
[::1] p
559 if PyObject_HasAttrString
(x
, "__len__"):
561 r
= num_new
(p
.shape
[0])
562 q
= <a_float
*>r
.data
563 for i
in prange
(p
.shape
[0], nogil
=True
):
564 q
[i
] = a_mf_z
(p
[i
], a
, b
)
566 return a_mf_z
(x
, a
, b
)
568 def pi
(object x
, a_float a
, a_float b
, a_float c
, a_float d
):
572 cdef const a_float
[::1] p
573 if PyObject_HasAttrString
(x
, "__len__"):
575 r
= num_new
(p
.shape
[0])
576 q
= <a_float
*>r
.data
577 for i
in prange
(p
.shape
[0], nogil
=True
):
578 q
[i
] = a_mf_pi
(p
[i
], a
, b
, c
, d
)
580 return a_mf_pi
(x
, a
, b
, c
, d
)
588 self.ctx
.summax
= +A_FLOAT_INF
589 self.ctx
.summin
= -A_FLOAT_INF
590 self.ctx
.outmax
= +A_FLOAT_INF
591 self.ctx
.outmin
= -A_FLOAT_INF
592 a_pid_init
(&self.ctx
)
593 def kpid
(self, a_float kp
, a_float ki
, a_float kd
):
594 a_pid_kpid
(&self.ctx
, kp
, ki
, kd
)
596 def run
(self, a_float set
, a_float fdb
):
597 return a_pid_run
(&self.ctx
, set
, fdb
)
598 def pos
(self, a_float set
, a_float fdb
):
599 return a_pid_pos
(&self.ctx
, set
, fdb
)
600 def inc
(self, a_float set
, a_float fdb
):
601 return a_pid_inc
(&self.ctx
, set
, fdb
)
603 a_pid_zero
(&self.ctx
)
608 def __set__
(self, a_float kp
):
613 def __set__
(self, a_float ki
):
618 def __set__
(self, a_float kd
):
622 return self.ctx
.summax
623 def __set__
(self, a_float summax
):
624 self.ctx
.summax
= summax
627 return self.ctx
.summin
628 def __set__
(self, a_float summin
):
629 self.ctx
.summin
= summin
635 return self.ctx
.outmax
636 def __set__
(self, a_float outmax
):
637 self.ctx
.outmax
= outmax
640 return self.ctx
.outmin
641 def __set__
(self, a_float outmin
):
642 self.ctx
.outmin
= outmin
653 from a
.pid_fuzzy cimport
*
655 cdef class pid_fuzzy
:
656 CAP
= A_PID_FUZZY_CAP
657 CAP_ALGEBRA
= A_PID_FUZZY_CAP_ALGEBRA
658 CAP_BOUNDED
= A_PID_FUZZY_CAP_BOUNDED
659 CUP
= A_PID_FUZZY_CUP
660 CUP_ALGEBRA
= A_PID_FUZZY_CUP_ALGEBRA
661 CUP_BOUNDED
= A_PID_FUZZY_CUP_BOUNDED
662 EQU
= A_PID_FUZZY_EQU
664 cdef readonly array me
665 cdef readonly array mec
666 cdef readonly array mkp
667 cdef readonly array mki
668 cdef readonly array mkd
670 self.ctx
.pid
.summax
= +A_FLOAT_INF
671 self.ctx
.pid
.summin
= -A_FLOAT_INF
672 self.ctx
.pid
.outmax
= +A_FLOAT_INF
673 self.ctx
.pid
.outmin
= -A_FLOAT_INF
674 self.ctx
.kp
= self.ctx
.pid
.kp
= 1
675 self.ctx
.op
= a_fuzzy_equ
676 a_pid_fuzzy_init
(&self.ctx
)
677 def op
(self, unsigned
int op
):
678 a_pid_fuzzy_set_op
(&self.ctx
, op
)
680 def rule
(self, me
, mec
, mkp
, mki
, mkd
):
681 self.me
= num2_new
(me
)
682 self.mec
= num2_new
(mec
)
683 self.mkp
= num2_new
(mkp
)
684 self.mki
= num2_new
(mki
)
685 self.mkd
= num2_new
(mkd
)
686 a_pid_fuzzy_rule
(&self.ctx
, len(me
),
687 num2_set
(self.me
, me
),
688 num2_set
(self.mec
, mec
),
689 num2_set
(self.mkp
, mkp
),
690 num2_set
(self.mki
, mki
),
691 num2_set
(self.mkd
, mkd
))
693 def set_block
(self, unsigned
int num
):
694 cdef void *ptr
= a_pid_fuzzy_block
(&self.ctx
)
695 ptr
= PyMem_Realloc
(ptr
, A_PID_FUZZY_BLOCK
(num
))
696 a_pid_fuzzy_set_block
(&self.ctx
, ptr
, num
)
698 def kpid
(self, a_float kp
, a_float ki
, a_float kd
):
699 a_pid_fuzzy_kpid
(&self.ctx
, kp
, ki
, kd
)
701 def run
(self, a_float set
, a_float fdb
):
702 return a_pid_fuzzy_run
(&self.ctx
, set
, fdb
)
703 def pos
(self, a_float set
, a_float fdb
):
704 return a_pid_fuzzy_pos
(&self.ctx
, set
, fdb
)
705 def inc
(self, a_float set
, a_float fdb
):
706 return a_pid_fuzzy_inc
(&self.ctx
, set
, fdb
)
707 def __dealloc__
(self):
708 PyMem_Free
(a_pid_fuzzy_block
(&self.ctx
))
710 a_pid_fuzzy_zero
(&self.ctx
)
715 def __set__
(self, a_float kp
):
721 def __set__
(self, a_float ki
):
727 def __set__
(self, a_float kd
):
732 return self.ctx
.pid
.summax
733 def __set__
(self, a_float summax
):
734 self.ctx
.pid
.summax
= summax
737 return self.ctx
.pid
.summin
738 def __set__
(self, a_float summin
):
739 self.ctx
.pid
.summin
= summin
742 return self.ctx
.pid
.sum
745 return self.ctx
.pid
.outmax
746 def __set__
(self, a_float outmax
):
747 self.ctx
.pid
.outmax
= outmax
750 return self.ctx
.pid
.outmin
751 def __set__
(self, a_float outmin
):
752 self.ctx
.pid
.outmin
= outmin
755 return self.ctx
.pid
.out
758 return self.ctx
.pid
.fdb
761 return self.ctx
.pid
.err
764 return self.ctx
.order
767 return self.ctx
.block
768 def __set__
(self, unsigned
int block
):
769 self.set_block
(block
)
771 from a
.pid_neuro cimport
*
773 cdef class pid_neuro
:
776 self.ctx
.pid
.summax
= +A_FLOAT_INF
777 self.ctx
.pid
.summin
= -A_FLOAT_INF
778 self.ctx
.pid
.outmax
= +A_FLOAT_INF
779 self.ctx
.pid
.outmin
= -A_FLOAT_INF
780 self.ctx
.k
= self.ctx
.pid
.kp
= 1
784 a_pid_neuro_init
(&self.ctx
)
785 def kpid
(self, a_float k
, a_float kp
, a_float ki
, a_float kd
):
786 a_pid_neuro_kpid
(&self.ctx
, k
, kp
, ki
, kd
)
788 def wpid
(self, a_float wp
, a_float wi
, a_float wd
):
789 a_pid_neuro_wpid
(&self.ctx
, wp
, wi
, wd
)
791 def run
(self, a_float set
, a_float fdb
):
792 return a_pid_neuro_run
(&self.ctx
, set
, fdb
)
793 def inc
(self, a_float set
, a_float fdb
):
794 return a_pid_neuro_inc
(&self.ctx
, set
, fdb
)
796 a_pid_neuro_zero
(&self.ctx
)
801 def __set__
(self, a_float k
):
805 return self.ctx
.pid
.kp
806 def __set__
(self, a_float kp
):
810 return self.ctx
.pid
.ki
811 def __set__
(self, a_float ki
):
815 return self.ctx
.pid
.kd
816 def __set__
(self, a_float kd
):
821 def __set__
(self, a_float wp
):
826 def __set__
(self, a_float wi
):
831 def __set__
(self, a_float wd
):
835 return self.ctx
.pid
.outmax
836 def __set__
(self, a_float outmax
):
837 self.ctx
.pid
.outmax
= outmax
840 return self.ctx
.pid
.outmin
841 def __set__
(self, a_float outmin
):
842 self.ctx
.pid
.outmin
= outmin
845 return self.ctx
.pid
.out
848 return self.ctx
.pid
.fdb
851 return self.ctx
.pid
.err
856 from a
.poly cimport
*
858 def poly_eval
(object x
, const a_float
[::1] a
):
862 cdef const a_float
[::1] p
863 if PyObject_HasAttrString
(x
, "__len__"):
865 r
= num_new
(p
.shape
[0])
866 q
= <a_float
*>r
.data
867 for i
in prange
(p
.shape
[0], nogil
=True
):
868 q
[i
] = a_poly_eval
(&a
[0], a
.shape
[0], p
[i
])
870 return a_poly_eval
(&a
[0], a
.shape
[0], x
)
872 def poly_evar
(object x
, const a_float
[::1] a
):
876 cdef const a_float
[::1] p
877 if PyObject_HasAttrString
(x
, "__len__"):
879 r
= num_new
(p
.shape
[0])
880 q
= <a_float
*>r
.data
881 for i
in prange
(p
.shape
[0], nogil
=True
):
882 q
[i
] = a_poly_evar
(&a
[0], a
.shape
[0], p
[i
])
884 return a_poly_evar
(&a
[0], a
.shape
[0], x
)
890 def __init__
(self, object num
, object den
):
891 tf
.num
.__set__
(self, num
)
892 tf
.den
.__set__
(self, den
)
893 def __call__
(self, a_float x
):
894 return a_tf_iter
(&self.ctx
, x
)
898 cdef readonly array _num
899 cdef readonly array
input
903 def __set__
(self, object num
):
904 cdef unsigned
int n
= len(num
)
905 self._num
= num_new
(n
)
906 self.input = num_new
(n
)
907 a_tf_set_num
(&self.ctx
, n
, num_set
(self._num
, num
, n
), <a_float
*>self.input.data
)
908 cdef readonly array _den
909 cdef readonly array output
913 def __set__
(self, object den
):
914 cdef unsigned
int n
= len(den
)
915 self._den
= num_new
(n
)
916 self.output
= num_new
(n
)
917 a_tf_set_den
(&self.ctx
, n
, num_set
(self._den
, den
, n
), <a_float
*>self.output
.data
)
919 from a
.trajbell cimport
*
923 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):
924 return a_trajbell_gen
(&self.ctx
, jm
, am
, vm
, p0
, p1
, v0
, v1
)
925 def pos
(self, object x
):
929 cdef const a_float
[::1] p
930 if PyObject_HasAttrString
(x
, "__len__"):
932 r
= num_new
(p
.shape
[0])
933 q
= <a_float
*>r
.data
934 for i
in prange
(p
.shape
[0], nogil
=True
):
935 q
[i
] = a_trajbell_pos
(&self.ctx
, p
[i
])
937 return a_trajbell_pos
(&self.ctx
, x
)
938 def vel
(self, object x
):
942 cdef const a_float
[::1] p
943 if PyObject_HasAttrString
(x
, "__len__"):
945 r
= num_new
(p
.shape
[0])
946 q
= <a_float
*>r
.data
947 for i
in prange
(p
.shape
[0], nogil
=True
):
948 q
[i
] = a_trajbell_vel
(&self.ctx
, p
[i
])
950 return a_trajbell_vel
(&self.ctx
, x
)
951 def acc
(self, object x
):
955 cdef const a_float
[::1] p
956 if PyObject_HasAttrString
(x
, "__len__"):
958 r
= num_new
(p
.shape
[0])
959 q
= <a_float
*>r
.data
960 for i
in prange
(p
.shape
[0], nogil
=True
):
961 q
[i
] = a_trajbell_acc
(&self.ctx
, p
[i
])
963 return a_trajbell_acc
(&self.ctx
, x
)
964 def jer
(self, object x
):
968 cdef const a_float
[::1] p
969 if PyObject_HasAttrString
(x
, "__len__"):
971 r
= num_new
(p
.shape
[0])
972 q
= <a_float
*>r
.data
973 for i
in prange
(p
.shape
[0], nogil
=True
):
974 q
[i
] = a_trajbell_jer
(&self.ctx
, p
[i
])
976 return a_trajbell_jer
(&self.ctx
, x
)
1020 from a
.trajpoly3 cimport
*
1022 cdef class trajpoly3
:
1023 cdef a_trajpoly3 ctx
1024 def __init__
(self, a_float ts
, a_float p0
, a_float p1
, a_float v0
=0, a_float v1
=0):
1025 a_trajpoly3_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
)
1026 def gen
(self, a_float ts
, a_float p0
, a_float p1
, a_float v0
=0, a_float v1
=0):
1027 a_trajpoly3_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
)
1029 def pos
(self, object x
):
1033 cdef const a_float
[::1] p
1034 if PyObject_HasAttrString
(x
, "__len__"):
1036 r
= num_new
(p
.shape
[0])
1037 q
= <a_float
*>r
.data
1038 for i
in prange
(p
.shape
[0], nogil
=True
):
1039 q
[i
] = a_trajpoly3_pos
(&self.ctx
, p
[i
])
1041 return a_trajpoly3_pos
(&self.ctx
, x
)
1042 def vel
(self, object x
):
1046 cdef const a_float
[::1] p
1047 if PyObject_HasAttrString
(x
, "__len__"):
1049 r
= num_new
(p
.shape
[0])
1050 q
= <a_float
*>r
.data
1051 for i
in prange
(p
.shape
[0], nogil
=True
):
1052 q
[i
] = a_trajpoly3_vel
(&self.ctx
, p
[i
])
1054 return a_trajpoly3_vel
(&self.ctx
, x
)
1055 def acc
(self, object x
):
1059 cdef const a_float
[::1] p
1060 if PyObject_HasAttrString
(x
, "__len__"):
1062 r
= num_new
(p
.shape
[0])
1063 q
= <a_float
*>r
.data
1064 for i
in prange
(p
.shape
[0], nogil
=True
):
1065 q
[i
] = a_trajpoly3_acc
(&self.ctx
, p
[i
])
1067 return a_trajpoly3_acc
(&self.ctx
, x
)
1078 from a
.trajpoly5 cimport
*
1080 cdef class trajpoly5
:
1081 cdef a_trajpoly5 ctx
1082 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):
1083 a_trajpoly5_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
)
1084 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):
1085 a_trajpoly5_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
)
1087 def pos
(self, object x
):
1091 cdef const a_float
[::1] p
1092 if PyObject_HasAttrString
(x
, "__len__"):
1094 r
= num_new
(p
.shape
[0])
1095 q
= <a_float
*>r
.data
1096 for i
in prange
(p
.shape
[0], nogil
=True
):
1097 q
[i
] = a_trajpoly5_pos
(&self.ctx
, p
[i
])
1099 return a_trajpoly5_pos
(&self.ctx
, x
)
1100 def vel
(self, object x
):
1104 cdef const a_float
[::1] p
1105 if PyObject_HasAttrString
(x
, "__len__"):
1107 r
= num_new
(p
.shape
[0])
1108 q
= <a_float
*>r
.data
1109 for i
in prange
(p
.shape
[0], nogil
=True
):
1110 q
[i
] = a_trajpoly5_vel
(&self.ctx
, p
[i
])
1112 return a_trajpoly5_vel
(&self.ctx
, x
)
1113 def acc
(self, object x
):
1117 cdef const a_float
[::1] p
1118 if PyObject_HasAttrString
(x
, "__len__"):
1120 r
= num_new
(p
.shape
[0])
1121 q
= <a_float
*>r
.data
1122 for i
in prange
(p
.shape
[0], nogil
=True
):
1123 q
[i
] = a_trajpoly5_acc
(&self.ctx
, p
[i
])
1125 return a_trajpoly5_acc
(&self.ctx
, x
)
1136 from a
.trajpoly7 cimport
*
1138 cdef class trajpoly7
:
1139 cdef a_trajpoly7 ctx
1140 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):
1141 a_trajpoly7_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
, j0
, j1
)
1142 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):
1143 a_trajpoly7_gen
(&self.ctx
, ts
, p0
, p1
, v0
, v1
, a0
, a1
, j0
, j1
)
1145 def pos
(self, object x
):
1149 cdef const a_float
[::1] p
1150 if PyObject_HasAttrString
(x
, "__len__"):
1152 r
= num_new
(p
.shape
[0])
1153 q
= <a_float
*>r
.data
1154 for i
in prange
(p
.shape
[0], nogil
=True
):
1155 q
[i
] = a_trajpoly7_pos
(&self.ctx
, p
[i
])
1157 return a_trajpoly7_pos
(&self.ctx
, x
)
1158 def vel
(self, object x
):
1162 cdef const a_float
[::1] p
1163 if PyObject_HasAttrString
(x
, "__len__"):
1165 r
= num_new
(p
.shape
[0])
1166 q
= <a_float
*>r
.data
1167 for i
in prange
(p
.shape
[0], nogil
=True
):
1168 q
[i
] = a_trajpoly7_vel
(&self.ctx
, p
[i
])
1170 return a_trajpoly7_vel
(&self.ctx
, x
)
1171 def acc
(self, object x
):
1175 cdef const a_float
[::1] p
1176 if PyObject_HasAttrString
(x
, "__len__"):
1178 r
= num_new
(p
.shape
[0])
1179 q
= <a_float
*>r
.data
1180 for i
in prange
(p
.shape
[0], nogil
=True
):
1181 q
[i
] = a_trajpoly7_acc
(&self.ctx
, p
[i
])
1183 return a_trajpoly7_acc
(&self.ctx
, x
)
1184 def jer
(self, object x
):
1188 cdef const a_float
[::1] p
1189 if PyObject_HasAttrString
(x
, "__len__"):
1191 r
= num_new
(p
.shape
[0])
1192 q
= <a_float
*>r
.data
1193 for i
in prange
(p
.shape
[0], nogil
=True
):
1194 q
[i
] = a_trajpoly7_jer
(&self.ctx
, p
[i
])
1196 return a_trajpoly7_jer
(&self.ctx
, x
)
1210 from a
.trajtrap cimport
*
1212 cdef class trajtrap
:
1214 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):
1215 return a_trajtrap_gen
(&self.ctx
, vm
, ac
, de
, p0
, p1
, v0
, v1
)
1216 def pos
(self, object x
):
1220 cdef const a_float
[::1] p
1221 if PyObject_HasAttrString
(x
, "__len__"):
1223 r
= num_new
(p
.shape
[0])
1224 q
= <a_float
*>r
.data
1225 for i
in prange
(p
.shape
[0], nogil
=True
):
1226 q
[i
] = a_trajtrap_pos
(&self.ctx
, p
[i
])
1228 return a_trajtrap_pos
(&self.ctx
, x
)
1229 def vel
(self, object x
):
1233 cdef const a_float
[::1] p
1234 if PyObject_HasAttrString
(x
, "__len__"):
1236 r
= num_new
(p
.shape
[0])
1237 q
= <a_float
*>r
.data
1238 for i
in prange
(p
.shape
[0], nogil
=True
):
1239 q
[i
] = a_trajtrap_vel
(&self.ctx
, p
[i
])
1241 return a_trajtrap_vel
(&self.ctx
, x
)
1242 def acc
(self, object x
):
1246 cdef const a_float
[::1] p
1247 if PyObject_HasAttrString
(x
, "__len__"):
1249 r
= num_new
(p
.shape
[0])
1250 q
= <a_float
*>r
.data
1251 for i
in prange
(p
.shape
[0], nogil
=True
):
1252 q
[i
] = a_trajtrap_acc
(&self.ctx
, p
[i
])
1254 return a_trajtrap_acc
(&self.ctx
, x
)
1292 from a
.version cimport
*
1296 def __init__
(self, unsigned
int major
=0, unsigned
int minor
=0, unsigned
int third
=0, unsigned
int extra
=0):
1297 self.ctx
.major
= major
1298 self.ctx
.minor
= minor
1299 self.ctx
.third
= third
1300 self.ctx
.extra
= extra
1301 self.ctx
.alpha
[0] = 46
1304 a_version_tostr
(&self.ctx
, str, sizeof(str))
1307 def check
(unsigned
int major
=0, unsigned
int minor
=0, unsigned
int patch
=0):
1308 return a_version_check
(major
, minor
, patch
)
1309 def cmp(self, version that
):
1310 return a_version_cmp
(&self.ctx
, &that
.ctx
)
1311 def __lt__
(self, version that
):
1312 return a_version_lt
(&self.ctx
, &that
.ctx
)
1313 def __gt__
(self, version that
):
1314 return a_version_gt
(&self.ctx
, &that
.ctx
)
1315 def __le__
(self, version that
):
1316 return a_version_le
(&self.ctx
, &that
.ctx
)
1317 def __ge__
(self, version that
):
1318 return a_version_ge
(&self.ctx
, &that
.ctx
)
1319 def __eq__
(self, version that
):
1320 return a_version_eq
(&self.ctx
, &that
.ctx
)
1321 def __ne__
(self, version that
):
1322 return a_version_ne
(&self.ctx
, &that
.ctx
)
1323 def parse
(self, const
char *ver
):
1324 a_version_parse
(&self.ctx
, ver
)
1327 return object.__hash__
(self)
1330 return self.ctx
.major
1331 def __set__
(self, unsigned
int major
):
1332 self.ctx
.major
= major
1335 return self.ctx
.minor
1336 def __set__
(self, unsigned
int minor
):
1337 self.ctx
.minor
= minor
1340 return self.ctx
.third
1341 def __set__
(self, unsigned
int third
):
1342 self.ctx
.third
= third
1345 return self.ctx
.extra
1346 def __set__
(self, unsigned
int extra
):
1347 self.ctx
.extra
= extra
1351 a_version_alpha
(&self.ctx
, alpha
)
1353 def __set__
(self, const
char *alpha
):
1354 a_version_set_alpha
(&self.ctx
, alpha
)
1355 MAJOR
= A_VERSION_MAJOR
1356 MINOR
= A_VERSION_MINOR
1357 PATCH
= A_VERSION_PATCH
1358 TWEAK
= A_VERSION_TWEAK
1360 if PY_MAJOR_VERSION
>= 3:
1361 VERSION
= A_VERSION
.decode
()