fix warning: python/src/a.pyx:604:29: Unused entry 'genexpr'
[liba.git] / python / src / a.pyx
blob101d27b3b579c88faf9ad884ec3dde857bc515df
1 #cython: autotestdict=False
2 #cython: auto_pickle=False
3 #cython: boundscheck=False
4 #cython: wraparound=False
5 from a cimport *
6 from cpython cimport *
7 from cpython.array cimport array
8 from cython.parallel import prange
10 cdef inline array_i8(object o):
11 return array('b', o)
13 cdef inline array_u8(object o):
14 return array('B', o)
16 cdef inline array_i16(object o):
17 return array('h', o)
19 cdef inline array_u16(object o):
20 return array('H', o)
22 cdef inline array_i32(object o):
23 if INT32_MAX == INT_MAX:
24 return array('i', o)
25 return array('l', o)
27 cdef inline array_u32(object o):
28 if UINT32_MAX == UINT_MAX:
29 return array('I', o)
30 return array('L', o)
32 cdef inline array_i64(object o):
33 if INT64_MAX == LONG_MAX:
34 return array('l', o)
35 return array('q', o)
37 cdef inline array_u64(object o):
38 if UINT64_MAX == ULONG_MAX:
39 return array('L', o)
40 return array('Q', o)
42 cdef inline array_f32(object o):
43 return array('f', o)
45 cdef inline array_f64(object o):
46 return array('d', o)
48 cdef inline array_num(object o):
49 if A_FLOAT_TYPE == A_FLOAT_SINGLE:
50 return array('f', o)
51 return array('d', o)
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)
59 from a.crc cimport *
61 cdef class crc8:
62 cdef readonly array table
63 def __cinit__(self):
64 self.table = array_u8((0,) * 0x100)
65 def gen(self, a_u8 poly, bint reversed = False):
66 if reversed:
67 a_crc8l_init(<a_u8 *>self.table.data.as_voidptr, poly)
68 else:
69 a_crc8m_init(<a_u8 *>self.table.data.as_voidptr, poly)
70 return self
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)
81 p[n] = value
82 return block
84 cdef class crc16:
85 cdef readonly array table
86 def __cinit__(self):
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):
90 if reversed:
91 a_crc16l_init(<a_u16 *>self.table.data.as_voidptr, poly)
92 self.eval = a_crc16l
93 else:
94 a_crc16m_init(<a_u16 *>self.table.data.as_voidptr, poly)
95 self.eval = a_crc16m
96 return self
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)
109 else:
110 a_u16_setl(p + n, value)
111 return block
113 cdef class crc32:
114 cdef readonly array table
115 def __cinit__(self):
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):
119 if reversed:
120 a_crc32l_init(<a_u32 *>self.table.data.as_voidptr, poly)
121 self.eval = a_crc32l
122 else:
123 a_crc32m_init(<a_u32 *>self.table.data.as_voidptr, poly)
124 self.eval = a_crc32m
125 return self
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)
138 else:
139 a_u32_setl(p + n, value)
140 return block
142 cdef class crc64:
143 cdef readonly array table
144 def __cinit__(self):
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):
148 if reversed:
149 a_crc64l_init(<a_u64 *>self.table.data.as_voidptr, poly)
150 self.eval = a_crc64l
151 else:
152 a_crc64m_init(<a_u64 *>self.table.data.as_voidptr, poly)
153 self.eval = a_crc64m
154 return self
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)
167 else:
168 a_u64_setl(p + n, value)
169 return block
171 from a.hpf cimport *
173 cdef class hpf:
174 cdef a_hpf ctx
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))
179 return self
180 def __call__(self, a_float x):
181 return a_hpf_iter(&self.ctx, x)
182 def zero(self):
183 a_hpf_zero(&self.ctx)
184 return self
185 property alpha:
186 def __get__(self):
187 return self.ctx.alpha
188 def __set__(self, a_float alpha):
189 self.ctx.alpha = alpha
190 property output:
191 def __get__(self):
192 return self.ctx.output
193 property input:
194 def __get__(self):
195 return self.ctx.input
197 from a.lpf cimport *
199 cdef class lpf:
200 cdef a_lpf ctx
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))
205 return self
206 def __call__(self, a_float x):
207 return a_lpf_iter(&self.ctx, x)
208 def zero(self):
209 a_lpf_zero(&self.ctx)
210 return self
211 property alpha:
212 def __get__(self):
213 return self.ctx.alpha
214 def __set__(self, a_float alpha):
215 self.ctx.alpha = alpha
216 property output:
217 def __get__(self):
218 return self.ctx.output
220 from a.math cimport *
222 def isqrt(x: int):
223 if x <= 1:
224 return x
225 x0 = 1 << ((x.bit_length() + 1) >> 1)
226 x1 = (x0 + x // x0) >> 1
227 while x0 > x1:
228 x0 = x1
229 x1 = (x0 + x // x0) >> 1
230 return x0
232 def sqrt_u32(x):
233 cdef array y
234 cdef a_u32 *p
235 cdef Py_ssize_t i
236 cdef Py_ssize_t n
237 if PyObject_HasAttrString(x, "__contains__"):
238 n = len(x)
239 y = array_u32(x)
240 p = <a_u32 *>y.data.as_voidptr
241 for i in prange(n, nogil=True):
242 p[i] = a_u32_sqrt(p[i])
243 return array_u16(y)
244 return a_u32_sqrt(x)
246 def sqrt_u64(x):
247 cdef array y
248 cdef a_u64 *p
249 cdef Py_ssize_t i
250 cdef Py_ssize_t n
251 if PyObject_HasAttrString(x, "__contains__"):
252 n = len(x)
253 y = array_u64(x)
254 p = <a_u64 *>y.data.as_voidptr
255 for i in prange(n, nogil=True):
256 p[i] = a_u64_sqrt(p[i])
257 return array_u32(y)
258 return a_u64_sqrt(x)
260 def rsqrt_f32(x):
261 cdef array y
262 cdef a_f32 *p
263 cdef Py_ssize_t i
264 cdef Py_ssize_t n
265 if PyObject_HasAttrString(x, "__contains__"):
266 n = len(x)
267 y = array_f32(x)
268 p = <a_f32 *>y.data.as_voidptr
269 for i in prange(n, nogil=True):
270 p[i] = a_f32_rsqrt(p[i])
271 return y
272 return a_f32_rsqrt(x)
274 def rsqrt_f64(x):
275 cdef array y
276 cdef a_f64 *p
277 cdef Py_ssize_t i
278 cdef Py_ssize_t n
279 if PyObject_HasAttrString(x, "__contains__"):
280 n = len(x)
281 y = array_f64(x)
282 p = <a_f64 *>y.data.as_voidptr
283 for i in prange(n, nogil=True):
284 p[i] = a_f64_rsqrt(p[i])
285 return y
286 return a_f64_rsqrt(x)
288 from a.mf cimport *
290 cdef class mf:
291 NUL = A_MF_NUL
292 GAUSS = A_MF_GAUSS
293 GAUSS2 = A_MF_GAUSS2
294 GBELL = A_MF_GBELL
295 SIG = A_MF_SIG
296 DSIG = A_MF_DSIG
297 PSIG = A_MF_PSIG
298 TRAP = A_MF_TRAP
299 TRI = A_MF_TRI
300 LINS = A_MF_LINS
301 LINZ = A_MF_LINZ
302 S = A_MF_S
303 Z = A_MF_Z
304 PI = A_MF_PI
305 @staticmethod
306 def __call__(unsigned int e, x, a):
307 cdef array y
308 cdef a_float *p
309 cdef Py_ssize_t i
310 cdef Py_ssize_t n
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__"):
315 n = len(x)
316 y = array_num(x)
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)
320 return y
321 return a_mf(m, x, a_p)
322 @staticmethod
323 def gauss(x, a_float sigma, a_float c):
324 cdef array y
325 cdef a_float *p
326 cdef Py_ssize_t i
327 cdef Py_ssize_t n
328 if PyObject_HasAttrString(x, "__contains__"):
329 n = len(x)
330 y = array_num(x)
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)
334 return y
335 return a_mf_gauss(x, sigma, c)
336 @staticmethod
337 def gauss2(x, a_float sigma1, a_float c1, a_float sigma2, a_float c2):
338 cdef array y
339 cdef a_float *p
340 cdef Py_ssize_t i
341 cdef Py_ssize_t n
342 if PyObject_HasAttrString(x, "__contains__"):
343 n = len(x)
344 y = array_num(x)
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)
348 return y
349 return a_mf_gauss2(x, sigma1, c1, sigma2, c2)
350 @staticmethod
351 def gbell(x, a_float a, a_float b, a_float c):
352 cdef array y
353 cdef a_float *p
354 cdef Py_ssize_t i
355 cdef Py_ssize_t n
356 if PyObject_HasAttrString(x, "__contains__"):
357 n = len(x)
358 y = array_num(x)
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)
362 return y
363 return a_mf_gbell(x, a, b, c)
364 @staticmethod
365 def sig(x, a_float a, a_float c):
366 cdef array y
367 cdef a_float *p
368 cdef Py_ssize_t i
369 cdef Py_ssize_t n
370 if PyObject_HasAttrString(x, "__contains__"):
371 n = len(x)
372 y = array_num(x)
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)
376 return y
377 return a_mf_sig(x, a, c)
378 @staticmethod
379 def dsig(x, a_float a1, a_float c1, a_float a2, a_float c2):
380 cdef array y
381 cdef a_float *p
382 cdef Py_ssize_t i
383 cdef Py_ssize_t n
384 if PyObject_HasAttrString(x, "__contains__"):
385 n = len(x)
386 y = array_num(x)
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)
390 return y
391 return a_mf_dsig(x, a1, c1, a2, c2)
392 @staticmethod
393 def psig(x, a_float a1, a_float c1, a_float a2, a_float c2):
394 cdef array y
395 cdef a_float *p
396 cdef Py_ssize_t i
397 cdef Py_ssize_t n
398 if PyObject_HasAttrString(x, "__contains__"):
399 n = len(x)
400 y = array_num(x)
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)
404 return y
405 return a_mf_psig(x, a1, c1, a2, c2)
406 @staticmethod
407 def trap(x, a_float a, a_float b, a_float c, a_float d):
408 cdef array y
409 cdef a_float *p
410 cdef Py_ssize_t i
411 cdef Py_ssize_t n
412 if PyObject_HasAttrString(x, "__contains__"):
413 n = len(x)
414 y = array_num(x)
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)
418 return y
419 return a_mf_trap(x, a, b, c, d)
420 @staticmethod
421 def tri(x, a_float a, a_float b, a_float c):
422 cdef array y
423 cdef a_float *p
424 cdef Py_ssize_t i
425 cdef Py_ssize_t n
426 if PyObject_HasAttrString(x, "__contains__"):
427 n = len(x)
428 y = array_num(x)
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)
432 return y
433 return a_mf_tri(x, a, b, c)
434 @staticmethod
435 def lins(x, a_float a, a_float b):
436 cdef array y
437 cdef a_float *p
438 cdef Py_ssize_t i
439 cdef Py_ssize_t n
440 if PyObject_HasAttrString(x, "__contains__"):
441 n = len(x)
442 y = array_num(x)
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)
446 return y
447 return a_mf_lins(x, a, b)
448 @staticmethod
449 def linz(x, a_float a, a_float b):
450 cdef array y
451 cdef a_float *p
452 cdef Py_ssize_t i
453 cdef Py_ssize_t n
454 if PyObject_HasAttrString(x, "__contains__"):
455 n = len(x)
456 y = array_num(x)
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)
460 return y
461 return a_mf_linz(x, a, b)
462 @staticmethod
463 def s(x, a_float a, a_float b):
464 cdef array y
465 cdef a_float *p
466 cdef Py_ssize_t i
467 cdef Py_ssize_t n
468 if PyObject_HasAttrString(x, "__contains__"):
469 n = len(x)
470 y = array_num(x)
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)
474 return y
475 return a_mf_s(x, a, b)
476 @staticmethod
477 def z(x, a_float a, a_float b):
478 cdef array y
479 cdef a_float *p
480 cdef Py_ssize_t i
481 cdef Py_ssize_t n
482 if PyObject_HasAttrString(x, "__contains__"):
483 n = len(x)
484 y = array_num(x)
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)
488 return y
489 return a_mf_z(x, a, b)
490 @staticmethod
491 def pi(x, a_float a, a_float b, a_float c, a_float d):
492 cdef array y
493 cdef a_float *p
494 cdef Py_ssize_t i
495 cdef Py_ssize_t n
496 if PyObject_HasAttrString(x, "__contains__"):
497 n = len(x)
498 y = array_num(x)
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)
502 return y
503 return a_mf_pi(x, a, b, c, d)
505 from a.pid cimport *
507 cdef class pid:
508 cdef a_pid ctx
509 def __init__(self):
510 self.ctx.kp = 1
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)
518 return self
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)
525 def zero(self):
526 a_pid_zero(&self.ctx)
527 return self
528 property kp:
529 def __get__(self):
530 return self.ctx.kp
531 def __set__(self, a_float kp):
532 self.ctx.kp = kp
533 property ki:
534 def __get__(self):
535 return self.ctx.ki
536 def __set__(self, a_float ki):
537 self.ctx.ki = ki
538 property kd:
539 def __get__(self):
540 return self.ctx.kd
541 def __set__(self, a_float kd):
542 self.ctx.kd = kd
543 property summax:
544 def __get__(self):
545 return self.ctx.summax
546 def __set__(self, a_float summax):
547 self.ctx.summax = summax
548 property summin:
549 def __get__(self):
550 return self.ctx.summin
551 def __set__(self, a_float summin):
552 self.ctx.summin = summin
553 property sum:
554 def __get__(self):
555 return self.ctx.sum
556 property outmax:
557 def __get__(self):
558 return self.ctx.outmax
559 def __set__(self, a_float outmax):
560 self.ctx.outmax = outmax
561 property outmin:
562 def __get__(self):
563 return self.ctx.outmin
564 def __set__(self, a_float outmin):
565 self.ctx.outmin = outmin
566 property out:
567 def __get__(self):
568 return self.ctx.out
569 property fdb:
570 def __get__(self):
571 return self.ctx.fdb
572 property err:
573 def __get__(self):
574 return self.ctx.err
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
586 cdef a_pid_fuzzy ctx
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
592 def __init__(self):
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)
602 return self
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)
615 return self
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)
620 return self
621 def kpid(self, a_float kp, a_float ki, a_float kd):
622 a_pid_fuzzy_kpid(&self.ctx, kp, ki, kd)
623 return self
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))
632 def zero(self):
633 a_pid_fuzzy_zero(&self.ctx)
634 return self
635 property kp:
636 def __get__(self):
637 return self.ctx.kp
638 def __set__(self, a_float kp):
639 self.ctx.pid.kp = kp
640 self.ctx.kp = kp
641 property ki:
642 def __get__(self):
643 return self.ctx.ki
644 def __set__(self, a_float ki):
645 self.ctx.pid.ki = ki
646 self.ctx.ki = ki
647 property kd:
648 def __get__(self):
649 return self.ctx.kd
650 def __set__(self, a_float kd):
651 self.ctx.pid.kd = kd
652 self.ctx.kd = kd
653 property summax:
654 def __get__(self):
655 return self.ctx.pid.summax
656 def __set__(self, a_float summax):
657 self.ctx.pid.summax = summax
658 property summin:
659 def __get__(self):
660 return self.ctx.pid.summin
661 def __set__(self, a_float summin):
662 self.ctx.pid.summin = summin
663 property sum:
664 def __get__(self):
665 return self.ctx.pid.sum
666 property outmax:
667 def __get__(self):
668 return self.ctx.pid.outmax
669 def __set__(self, a_float outmax):
670 self.ctx.pid.outmax = outmax
671 property outmin:
672 def __get__(self):
673 return self.ctx.pid.outmin
674 def __set__(self, a_float outmin):
675 self.ctx.pid.outmin = outmin
676 property out:
677 def __get__(self):
678 return self.ctx.pid.out
679 property fdb:
680 def __get__(self):
681 return self.ctx.pid.fdb
682 property err:
683 def __get__(self):
684 return self.ctx.pid.err
685 property order:
686 def __get__(self):
687 return self.ctx.order
688 property block:
689 def __get__(self):
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:
697 cdef a_pid_neuro ctx
698 def __init__(self):
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
704 self.ctx.wp = 0.1
705 self.ctx.wi = 0.1
706 self.ctx.wd = 0.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)
710 return self
711 def wpid(self, a_float wp, a_float wi, a_float wd):
712 a_pid_neuro_wpid(&self.ctx, wp, wi, wd)
713 return self
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)
718 def zero(self):
719 a_pid_neuro_zero(&self.ctx)
720 return self
721 property k:
722 def __get__(self):
723 return self.ctx.k
724 def __set__(self, a_float k):
725 self.ctx.k = k
726 property kp:
727 def __get__(self):
728 return self.ctx.pid.kp
729 def __set__(self, a_float kp):
730 self.ctx.pid.kp = kp
731 property ki:
732 def __get__(self):
733 return self.ctx.pid.ki
734 def __set__(self, a_float ki):
735 self.ctx.pid.ki = ki
736 property kd:
737 def __get__(self):
738 return self.ctx.pid.kd
739 def __set__(self, a_float kd):
740 self.ctx.pid.kd = kd
741 property wp:
742 def __get__(self):
743 return self.ctx.wp
744 def __set__(self, a_float wp):
745 self.ctx.wp = wp
746 property wi:
747 def __get__(self):
748 return self.ctx.wi
749 def __set__(self, a_float wi):
750 self.ctx.wi = wi
751 property wd:
752 def __get__(self):
753 return self.ctx.wd
754 def __set__(self, a_float wd):
755 self.ctx.wd = wd
756 property outmax:
757 def __get__(self):
758 return self.ctx.pid.outmax
759 def __set__(self, a_float outmax):
760 self.ctx.pid.outmax = outmax
761 property outmin:
762 def __get__(self):
763 return self.ctx.pid.outmin
764 def __set__(self, a_float outmin):
765 self.ctx.pid.outmin = outmin
766 property out:
767 def __get__(self):
768 return self.ctx.pid.out
769 property fdb:
770 def __get__(self):
771 return self.ctx.pid.fdb
772 property err:
773 def __get__(self):
774 return self.ctx.pid.err
775 property ec:
776 def __get__(self):
777 return self.ctx.ec
779 from a.poly cimport *
781 def poly_eval(x, *a):
782 cdef array y
783 cdef array a_
784 cdef a_float *p
785 cdef a_float *a_p
786 cdef Py_ssize_t i
787 cdef Py_ssize_t n
788 cdef a_size a_n = len(a)
789 a_ = array_num(a)
790 a_p = <a_float *>a_.data.as_voidptr
791 if PyObject_HasAttrString(x, "__contains__"):
792 n = len(x)
793 y = array_num(x)
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])
797 return y
798 return a_poly_eval(a_p, a_n, x)
800 def poly_evar(x, *a):
801 cdef array y
802 cdef array a_
803 cdef a_float *p
804 cdef a_float *a_p
805 cdef Py_ssize_t i
806 cdef Py_ssize_t n
807 cdef a_size a_n = len(a)
808 a_ = array_num(a)
809 a_p = <a_float *>a_.data.as_voidptr
810 if PyObject_HasAttrString(x, "__contains__"):
811 n = len(x)
812 y = array_num(x)
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])
816 return y
817 return a_poly_evar(a_p, a_n, x)
819 from a.tf cimport *
821 cdef class tf:
822 cdef a_tf ctx
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)
828 def zero(self):
829 a_tf_zero(&self.ctx)
830 return self
831 cdef array _num
832 cdef readonly array input
833 property num:
834 def __get__(self):
835 return self._num
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)
840 cdef array _den
841 cdef readonly array output
842 property den:
843 def __get__(self):
844 return self._den
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 *
852 cdef class trajbell:
853 cdef a_trajbell ctx
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)
856 def pos(self, dt):
857 cdef array x
858 cdef a_float *p
859 cdef Py_ssize_t i
860 cdef Py_ssize_t n
861 if PyObject_HasAttrString(dt, "__contains__"):
862 n = len(dt)
863 x = array_num(dt)
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])
867 return x
868 return a_trajbell_pos(&self.ctx, dt)
869 def vel(self, dt):
870 cdef array x
871 cdef a_float *p
872 cdef Py_ssize_t i
873 cdef Py_ssize_t n
874 if PyObject_HasAttrString(dt, "__contains__"):
875 n = len(dt)
876 x = array_num(dt)
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])
880 return x
881 return a_trajbell_vel(&self.ctx, dt)
882 def acc(self, dt):
883 cdef array x
884 cdef a_float *p
885 cdef Py_ssize_t i
886 cdef Py_ssize_t n
887 if PyObject_HasAttrString(dt, "__contains__"):
888 n = len(dt)
889 x = array_num(dt)
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])
893 return x
894 return a_trajbell_acc(&self.ctx, dt)
895 def jer(self, dt):
896 cdef array x
897 cdef a_float *p
898 cdef Py_ssize_t i
899 cdef Py_ssize_t n
900 if PyObject_HasAttrString(dt, "__contains__"):
901 n = len(dt)
902 x = array_num(dt)
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])
906 return x
907 return a_trajbell_jer(&self.ctx, dt)
908 property t:
909 def __get__(self):
910 return self.ctx.t
911 property tv:
912 def __get__(self):
913 return self.ctx.tv
914 property ta:
915 def __get__(self):
916 return self.ctx.ta
917 property td:
918 def __get__(self):
919 return self.ctx.td
920 property taj:
921 def __get__(self):
922 return self.ctx.taj
923 property tdj:
924 def __get__(self):
925 return self.ctx.tdj
926 property p0:
927 def __get__(self):
928 return self.ctx.p0
929 property p1:
930 def __get__(self):
931 return self.ctx.p1
932 property v0:
933 def __get__(self):
934 return self.ctx.v0
935 property v1:
936 def __get__(self):
937 return self.ctx.v1
938 property vm:
939 def __get__(self):
940 return self.ctx.vm
941 property jm:
942 def __get__(self):
943 return self.ctx.jm
944 property am:
945 def __get__(self):
946 return self.ctx.am
947 property dm:
948 def __get__(self):
949 return self.ctx.dm
951 from a.trajpoly3 cimport *
953 cdef class trajpoly3:
954 cdef a_trajpoly3 ctx
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)
959 return self
960 def pos(self, dt):
961 cdef array x
962 cdef a_float *p
963 cdef Py_ssize_t i
964 cdef Py_ssize_t n
965 if PyObject_HasAttrString(dt, "__contains__"):
966 n = len(dt)
967 x = array_num(dt)
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])
971 return x
972 return a_trajpoly3_pos(&self.ctx, dt)
973 def vel(self, dt):
974 cdef array x
975 cdef a_float *p
976 cdef Py_ssize_t i
977 cdef Py_ssize_t n
978 if PyObject_HasAttrString(dt, "__contains__"):
979 n = len(dt)
980 x = array_num(dt)
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])
984 return x
985 return a_trajpoly3_vel(&self.ctx, dt)
986 def acc(self, dt):
987 cdef array x
988 cdef a_float *p
989 cdef Py_ssize_t i
990 cdef Py_ssize_t n
991 if PyObject_HasAttrString(dt, "__contains__"):
992 n = len(dt)
993 x = array_num(dt)
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])
997 return x
998 return a_trajpoly3_acc(&self.ctx, dt)
999 property p:
1000 def __get__(self):
1001 return self.ctx.p
1002 property v:
1003 def __get__(self):
1004 return self.ctx.v
1005 property a:
1006 def __get__(self):
1007 return self.ctx.a
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)
1017 return self
1018 def pos(self, dt):
1019 cdef array x
1020 cdef a_float *p
1021 cdef Py_ssize_t i
1022 cdef Py_ssize_t n
1023 if PyObject_HasAttrString(dt, "__contains__"):
1024 n = len(dt)
1025 x = array_num(dt)
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])
1029 return x
1030 return a_trajpoly5_pos(&self.ctx, dt)
1031 def vel(self, dt):
1032 cdef array x
1033 cdef a_float *p
1034 cdef Py_ssize_t i
1035 cdef Py_ssize_t n
1036 if PyObject_HasAttrString(dt, "__contains__"):
1037 n = len(dt)
1038 x = array_num(dt)
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])
1042 return x
1043 return a_trajpoly5_vel(&self.ctx, dt)
1044 def acc(self, dt):
1045 cdef array x
1046 cdef a_float *p
1047 cdef Py_ssize_t i
1048 cdef Py_ssize_t n
1049 if PyObject_HasAttrString(dt, "__contains__"):
1050 n = len(dt)
1051 x = array_num(dt)
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])
1055 return x
1056 return a_trajpoly5_acc(&self.ctx, dt)
1057 property p:
1058 def __get__(self):
1059 return self.ctx.p
1060 property v:
1061 def __get__(self):
1062 return self.ctx.v
1063 property a:
1064 def __get__(self):
1065 return self.ctx.a
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)
1075 return self
1076 def pos(self, dt):
1077 cdef array x
1078 cdef a_float *p
1079 cdef Py_ssize_t i
1080 cdef Py_ssize_t n
1081 if PyObject_HasAttrString(dt, "__contains__"):
1082 n = len(dt)
1083 x = array_num(dt)
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])
1087 return x
1088 return a_trajpoly7_pos(&self.ctx, dt)
1089 def vel(self, dt):
1090 cdef array x
1091 cdef a_float *p
1092 cdef Py_ssize_t i
1093 cdef Py_ssize_t n
1094 if PyObject_HasAttrString(dt, "__contains__"):
1095 n = len(dt)
1096 x = array_num(dt)
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])
1100 return x
1101 return a_trajpoly7_vel(&self.ctx, dt)
1102 def acc(self, dt):
1103 cdef array x
1104 cdef a_float *p
1105 cdef Py_ssize_t i
1106 cdef Py_ssize_t n
1107 if PyObject_HasAttrString(dt, "__contains__"):
1108 n = len(dt)
1109 x = array_num(dt)
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])
1113 return x
1114 return a_trajpoly7_acc(&self.ctx, dt)
1115 def jer(self, dt):
1116 cdef array x
1117 cdef a_float *p
1118 cdef Py_ssize_t i
1119 cdef Py_ssize_t n
1120 if PyObject_HasAttrString(dt, "__contains__"):
1121 n = len(dt)
1122 x = array_num(dt)
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])
1126 return x
1127 return a_trajpoly7_jer(&self.ctx, dt)
1128 property p:
1129 def __get__(self):
1130 return self.ctx.p
1131 property v:
1132 def __get__(self):
1133 return self.ctx.v
1134 property a:
1135 def __get__(self):
1136 return self.ctx.a
1137 property j:
1138 def __get__(self):
1139 return self.ctx.j
1141 from a.trajtrap cimport *
1143 cdef class trajtrap:
1144 cdef a_trajtrap ctx
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)
1147 def pos(self, dt):
1148 cdef array x
1149 cdef a_float *p
1150 cdef Py_ssize_t i
1151 cdef Py_ssize_t n
1152 if PyObject_HasAttrString(dt, "__contains__"):
1153 n = len(dt)
1154 x = array_num(dt)
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])
1158 return x
1159 return a_trajtrap_pos(&self.ctx, dt)
1160 def vel(self, dt):
1161 cdef array x
1162 cdef a_float *p
1163 cdef Py_ssize_t i
1164 cdef Py_ssize_t n
1165 if PyObject_HasAttrString(dt, "__contains__"):
1166 n = len(dt)
1167 x = array_num(dt)
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])
1171 return x
1172 return a_trajtrap_vel(&self.ctx, dt)
1173 def acc(self, dt):
1174 cdef array x
1175 cdef a_float *p
1176 cdef Py_ssize_t i
1177 cdef Py_ssize_t n
1178 if PyObject_HasAttrString(dt, "__contains__"):
1179 n = len(dt)
1180 x = array_num(dt)
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])
1184 return x
1185 return a_trajtrap_acc(&self.ctx, dt)
1186 property t:
1187 def __get__(self):
1188 return self.ctx.t
1189 property p0:
1190 def __get__(self):
1191 return self.ctx.p0
1192 property p1:
1193 def __get__(self):
1194 return self.ctx.p1
1195 property v0:
1196 def __get__(self):
1197 return self.ctx.v0
1198 property v1:
1199 def __get__(self):
1200 return self.ctx.v1
1201 property vc:
1202 def __get__(self):
1203 return self.ctx.vc
1204 property ta:
1205 def __get__(self):
1206 return self.ctx.ta
1207 property td:
1208 def __get__(self):
1209 return self.ctx.td
1210 property pa:
1211 def __get__(self):
1212 return self.ctx.pa
1213 property pd:
1214 def __get__(self):
1215 return self.ctx.pd
1216 property ac:
1217 def __get__(self):
1218 return self.ctx.ac
1219 property de:
1220 def __get__(self):
1221 return self.ctx.de
1223 from a.version cimport *
1225 cdef class version:
1226 cdef a_version ctx
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
1233 def __repr__(self):
1234 cdef char str[48]
1235 a_version_tostr(&self.ctx, str, sizeof(str))
1236 return str.decode()
1237 @staticmethod
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)
1256 return self
1257 def __hash__(self):
1258 return object.__hash__(self)
1259 property major:
1260 def __get__(self):
1261 return self.ctx.major
1262 def __set__(self, unsigned int major):
1263 self.ctx.major = major
1264 property minor:
1265 def __get__(self):
1266 return self.ctx.minor
1267 def __set__(self, unsigned int minor):
1268 self.ctx.minor = minor
1269 property third:
1270 def __get__(self):
1271 return self.ctx.third
1272 def __set__(self, unsigned int third):
1273 self.ctx.third = third
1274 property extra:
1275 def __get__(self):
1276 return self.ctx.extra
1277 def __set__(self, unsigned int extra):
1278 self.ctx.extra = extra
1279 property alpha:
1280 def __get__(self):
1281 cdef char alpha[5]
1282 a_version_alpha(&self.ctx, alpha)
1283 return 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()
1293 else:
1294 VERSION = A_VERSION