static PyObject * int_abs(PyIntObject *v) { if (v->ob_ival >= 0) return int_pos(v); else return int_neg(v); }
float dtw_windowed(void * seq1v, void * seq2v, int seq1_len, int seq2_len, int window) { // THIS WILL SEGFAULT IF seq1 AND seq2 ARE NOT (n,m)x4 float* seq1 = (float*) seq1v; float* seq2 = (float*) seq2v; float* distance_mat = make_mat(seq1_len, seq2_len, INFINITY); //printf("n: %d, m: %d\n", seq1_len, seq2_len); distance_mat[int_pos(0,0, seq1_len)] = 0; window = MAX(window, abs(seq1_len - seq2_len)); //printf("Window: %d\n", window); int i, j; for (i = 1; i < seq1_len; i++) { //for (j = MAX(1, i-window); j < MIN(seq2_len,i+window); j++) { for (j = 1; j < seq2_len; j++) { // Wish there was a better way to do this... float eucl_dist = euclidean(seq1[int_pos(i,0,4)], seq1[int_pos(i,1,4)], seq2[int_pos(j,0,4)], seq2[int_pos(j,1,4)]); float cosi_dist = cosine(seq1[int_pos(i,2,4)], seq1[int_pos(i,3,4)], seq2[int_pos(j,2,4)], seq2[int_pos(j,3,4)]); distance_mat[int_pos(i,j,seq2_len)] = (eucl_dist + cosi_dist) + MIN(distance_mat[int_pos(i-1,j-1,seq2_len)], MIN(distance_mat[int_pos(i-1,j,seq2_len)], distance_mat[int_pos(i,j-1,seq2_len)])); } } // find minimal value along the last column as our distance float retval = distance_mat[int_pos(seq1_len-1, seq2_len-1, seq2_len)]; free(distance_mat); return retval; }
float* make_mat(const int n, const int m, const float fill) { float* mat = (float *)calloc(n * m, sizeof(float)); int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { mat[int_pos(i, j, m)] = fill; } } return mat; }
void HookSvc::ProcessDVDMark(int idx, const Point& pos) { DRect user_lct(GetDVDLabelLocation(idx, pos)); DPoint real_pos(PhisPos()); cont->device_to_user(real_pos.x, real_pos.y); if( user_lct.Contains(real_pos) ) { DPoint int_pos(real_pos - user_lct.A()); if( IsAtPicture(GetDVDMark(false), Point((int)int_pos.x, (int)int_pos.y)) ) { pAction->AtDVDMark(idx); } } }
static PyObject * int_lshift(PyIntObject *v, PyIntObject *w) { register long a, b; CONVERT_TO_LONG(v, a); CONVERT_TO_LONG(w, b); if (b < 0) { PyErr_SetString(PyExc_ValueError, "negative shift count"); return NULL; } if (a == 0 || b == 0) return int_pos(v); if (b >= LONG_BIT) { return PyInt_FromLong(0L); } a = (long)((unsigned long)a << b); return PyInt_FromLong(a); }
static PyObject * int_rshift(PyIntObject *v, PyIntObject *w) { register long a, b; CONVERT_TO_LONG(v, a); CONVERT_TO_LONG(w, b); if (b < 0) { PyErr_SetString(PyExc_ValueError, "negative shift count"); return NULL; } if (a == 0 || b == 0) return int_pos(v); if (b >= LONG_BIT) { if (a < 0) a = -1; else a = 0; } else { a = Py_ARITHMETIC_RIGHT_SHIFT(long, a, b); } return PyInt_FromLong(a); }