double RestraintCache::get_score(kernel::Restraint *r, const Subset &s, const Assignment &a) const { IMP_OBJECT_LOG; set_was_used(true); Slice slice = get_slice(r, s); Assignment ra = slice.get_sliced(a); return get_score(r, ra); }
/* * Implement mapping assignment sub-script for the type. */ static int sipArray_ass_subscript(PyObject *self, PyObject *key, PyObject *value) { sipArrayObject *array = (sipArrayObject *)self; SIP_SSIZE_T start, len; void *value_data; if (check_writable(array) < 0) return -1; if (PyIndex_Check(key)) { start = PyNumber_AsSsize_t(key, PyExc_IndexError); if (start == -1 && PyErr_Occurred()) return -1; if (start < 0) start += array->len; if (check_index(array, start) < 0) return -1; if ((value_data = get_value(array, value)) == NULL) return -1; len = 1; } else if (PySlice_Check(key)) { Py_ssize_t stop, step; if (sipConvertFromSliceObject(key, array->len, &start, &stop, &step, &len) < 0) return -1; if (step != 1) { PyErr_SetNone(PyExc_NotImplementedError); return -1; } if ((value_data = get_slice(array, value, len)) == NULL) return -1; } else { bad_key(key); return -1; } memmove(element(array, start), value_data, len * array->stride); return 0; }
static double iteration(int m0, int m1, int m2, int n0, int n1, int n2, double Alpha[], double Beta[], MAPTYPE *vol, double B0[], double B1[], double B2[], double f[], double mx, int nh, double h[], int *psh) { int j2, j1, j0, i2, i1, i0; double *dat, *wt0, *wt1, *Alpha1, *Beta1; double t2[MAXB*MAXB], t1[MAXB], ll; dat = (double *)mxCalloc(n1*n0, sizeof(double)); wt0 = (double *)mxCalloc(n1*n0, sizeof(double)); wt1 = (double *)mxCalloc(n1*n0, sizeof(double)); Alpha1 = (double *)mxCalloc(m1*m0*m1*m0, sizeof(double)); Beta1 = (double *)mxCalloc(m1*m0, sizeof(double)); hist(m0,m1,m2, n0,n1,n2, vol, B0,B1,B2,f, nh,(nh-1.0)/mx,h, dat, psh); ll = 0.0; for(j2=0;j2<n2; j2++) { get_slice(vol,j2,dat); for(i0=0; i0<m0*m1; i0++) { t2[i0] = 0.0; for(i2=0;i2<m2; i2++) t2[i0] += B2[j2+n2*i2]*f[i0+m0*m1*i2]; } for(j1=0; j1<n1; j1++) { for(i0=0; i0<m0; i0++) { t1[i0] = 0.0; for(i1=0;i1<m1; i1++) t1[i0] += B1[j1+n1*i1]*t2[i0+m0*i1]; } for(j0=0; j0<n0; j0++) { double sc = 0.0; for(i0=0; i0<m0; i0++) sc += B0[j0+n0*i0]*t1[i0]; weights(dat[j0+n0*j1], exp(sc), nh, (nh-1.0)/mx,h, &wt0[j0+n0*j1], &wt1[j0+n0*j1], &ll); } } kronutil(n0,n1,n2, m0,m1,m2, j2, wt0,wt1, B0,B1,B2, Alpha1,Beta1, Alpha,Beta); } mxFree((void *)dat); mxFree((void *)wt0); mxFree((void *)wt1); mxFree((void *)Alpha1); mxFree((void *)Beta1); return(ll); }
/* Create a histogram from data modulated by a linear combination of seperable * basis functions * m0 - number of bases in x dimension * m1 - number of bases in y dimension * m2 - number of bases in z dimension * n0 - x dimension of volume * n1 - y dimension of volume * n2 - z dimension of volume * vol - mapped volume * B0 - seperable bases - x * B1 - seperable bases - y * B2 - seperable bases - z * f - basis function coefficients * nh - number of histogram bins * s - scale from image intensity to histogram bin number (1/binwidth) * h - histogram * dat - buffer for storing a plane of data * * required: m0, m1, m2, n0, n1, n2, vol, B0, B1, B2, f, nh, s * modified: h, dat */ static void hist(int m0, int m1, int m2, int n0, int n1, int n2, MAPTYPE *vol, double *B0, double *B1, double *B2, double *f, int nh, double s, double *h, double *dat, int *psh) { int i0, i1, i2; int j0, j1, j2; double t2[MAXB*MAXB], t1[MAXB]; for(j2=0;j2<n2; j2++) { get_slice(vol,j2,dat); for(i0=0; i0<m0*m1; i0++) { t2[i0] = 0.0; for(i2=0;i2<m2; i2++) t2[i0] += B2[j2+n2*i2]*f[i0+m0*m1*i2]; } for(j1=0; j1<n1; j1++) { double *pdat = dat+j1*n0; for(i0=0; i0<m0; i0++) { t1[i0] = 0.0; for(i1=0;i1<m1; i1++) t1[i0] += B1[j1+n1*i1]*t2[i0+m0*i1]; } for(j0=0; j0<n0; j0++) { double y, y0 = pdat[j0]*s; #ifdef IGNORE_ZEROS if (y0>0.0) #else if (y0>=0.0) #endif { int iy; double dy, sc = 0.0; for(i0=0;i0<m0; i0++) sc += B0[j0+n0*i0]*t1[i0]; y = y0*exp(sc); if (y>=0 && y<(nh-1)) { iy = floor(y); dy = y-iy; h[iy] += 1-dy; h[iy+1] += dy; } } } } } normhist(nh,h,1/s,psh); }
/** * Receive messages from the iridium gss send by different iridium terminal * @param server_fd server socket descriptor * @param forward_ip the destination ip address * @return -1 on failure, 0 on client disconnect, n(>0) bytes read */ int receive_iridium_msgs(int client_fd) { int payload_len = 0; int finish = 0; slice *slice = malloc(SLICE_LEN); payload_len = get_slice(client_fd, slice); finish = resemble_iridium_msgs(slice, payload_len); if (finish) forward_iridium_msg(slice->header.sn); free(slice); return 0; }
void FindBar::replace_text(Gtk::TextIter& start, Gtk::TextIter& end, Glib::ustring& replacement) { auto buf = window_.current_buffer()->buffer(); if(buf->get_slice(start, end) == replacement) { return; } //Store the offset to the start of the selection set to be replaced auto offset = start.get_offset(); //Erase the selection buf->erase(start, end); //Build a new iterator from the stored offset, and insert the text there auto new_start = buf->get_iter_at_offset(offset); buf->insert(new_start, replacement); }
void Client:: issue_get_for_key(const std::string& column_family, const std::string& key, const SlicePredicate& predicate, std::vector<ColumnOrSuperColumn>& columns, ConsistencyLevel::type consistency_level) { ColumnParent cparent; cparent.column_family = column_family; get_slice(columns, key, cparent, predicate, consistency_level); if (columns.size() == 0) { RowNotFoundException row_not_found_ex(column_family, key); throw row_not_found_ex; } }
/* * Implement sequence assignment slice sub-script for the type. */ static int sipArray_ass_slice(PyObject *self, int left, int right, PyObject *value) { sipArrayObject *array = (sipArrayObject *)self; void *value_data; if (check_writable(array) < 0) return -1; fix_bounds(array->len, &left, &right); if ((value_data = get_slice(array, value, right - left)) == NULL) return -1; memmove(element(array, left), value_data, (right - left) * array->stride); return 0; }
/******************************************************************************** * Unused code */ double constr(int m0, int m1, int m2, int n0, int n1, int n2, double Beta[], MAPTYPE *vol, double B0[], double B1[], double B2[]) { int j2, i2, i01; double *dat, *Beta1, sm; dat = (double *)mxCalloc(n1*n0, sizeof(double)); Beta1 = (double *)mxCalloc(m1*m0, sizeof(double)); sm = 0.0; for(j2=0;j2<n2; j2++) { get_slice(vol,j2,dat); kronutil1(n0,n1,m0,m1, dat, B0, B1, Beta1); for(i2=0; i2<m2; i2++) for(i01=0; i01<m0*m1; i01++) Beta[i01 + i2*m0*m1] += Beta1[i01]*B2[j2 + i2*n2]; for(i01=0; i01<n0*n1; i01++) sm += dat[i01]; } mxFree((void *)Beta1); mxFree((void *)dat); return(sm); }
void SpOpenRec(void) { char fname[MAX_SLICE_LENGTH+1]; int namelen; int fileorg; int filemode; int filetype; int format; long mrs; long fileid; FILE *fd; struct FILE_INFO *info; #ifdef VMS struct RAB *rab; RecInfo *rinfo; unsigned int rfm,rat; #endif /* VMS */ dbgmsg("SP.OPENREC"); InBuf = &Tbuf[3]; OutBuf = &Tbuf[2]; OutCount = 0; namelen = get_slice((unsigned char *) fname); fname[namelen] = '\0'; fileorg = (int) get_8(); filemode = (int) get_8(); filetype = (int) get_8(); format = (int) get_8(); mrs = get_32(); dbgmsg("file=\"%s\" %d:%d:%d:%d %ld", fname, fileorg, filemode, filetype, format, mrs); /* Validate request */ if ((strlen(fname) == 0) || (fileorg < 3) || (fileorg > 4) || (filetype < 0) || (filetype > 2) || (filemode < 1) || (filemode > 6) || (format < 0) || (format > 1)) { SpFail(ER_ERROR); return; } if (filetype == TYPE_DONTCARE) filetype = TYPE_RECORD; #ifdef VMS if (fileorg == ORG_VARIABLE) rfm = FAB$C_VAR; rfm = (fileorg == ORG_VARIABLE)?FAB$C_VAR:FAB$C_FIX; rat = (filetype == TYPE_RECORD)?FAB$M_FTN:0; /* FTN:FAB$M_CR */ /* We ignore format under VMS */ /* decide whether to open or create file */ if ((filemode == 1) || (filemode == 4)) rab = vmsopen(fname, rfm, rat); else rab = vmscreate(fname, rfm, rat, rfm); if (rab == (struct RAB *) NULL) { SpFail(ER_NOFILE); return; } rinfo = newinfo(); if (rinfo == (RecInfo *) NULL) { vmsclose(rab); SpFail(ER_ERROR); } else { rinfo->baserec = 0; rinfo->prev = (FilePos *) NULL; rinfo->next = (FilePos *) NULL; } fd = stdout; /* Must be something ! */ #else fd = fopen(fname, OpenModes[fileorg-1][filemode-1]); if (fd == NULL) { SpFail(ER_NOFILE); return; } #endif /* VMS */ /* File opened OK */ fileid = RememberFile(fd, fileorg); if (fileid == NO_SLOT) { SpFail(ER_NORESOURCE); return; } /* Things are looking good Houston....beep */ info = &FileInfo[fileid]; info->buff = (unsigned char *) malloc((int) mrs+3); /* Room for CR, NL, EOS */ if (info->buff == (unsigned char *) NULL) { ForgetFile(fileid); SpFail(ER_NORESOURCE); return; } info->mrs = mrs; info->recordsize = -1; info->format = format; info->type = filetype; info->recno = 0; info->lastop = FIOP_NONE; info->pasteof = false; #ifdef VMS info->rab = rab; info->poslist = rinfo; #else if (fileorg == ORG_VARIABLE) { info->putfn = (format == FMT_FORMATTED)?form_seq_write_rec:unform_seq_write_rec; info->getfn = (format == FMT_FORMATTED)?form_seq_read_rec:unform_seq_read_rec; /* Need to allocate a read-ahead buffer for formatted files */ if (format == FMT_FORMATTED) { info->llbuff = (unsigned char *) malloc(LL_BUF_SIZE); info->llind = LL_BUF_SIZE; if (info->llbuff == (unsigned char *) NULL) { free(info->buff); ForgetFile(fileid); SpFail(ER_NORESOURCE); return; } } else { info->llbuff = NULL; info->llind = 0; } } else { info->putfn = direct_write_rec; info->getfn = direct_read_rec; info->llbuff = NULL; info->llind = 0; } #endif /* VMS */ put_8(ER_SUCCESS); put_32(mrs); put_32(fileid); put_32(filetype); put_count(OutCount); }
void SpPutRec(void) { long fileid; FILE *fd; long recordsize; int chunksize; long offset; bool dowrite=false; struct FILE_INFO *info; int res; dbgmsg("SP.PUTREC"); InBuf = &Tbuf[3]; OutBuf = &Tbuf[2]; OutCount = 0; fileid = get_32(); recordsize = get_32(); chunksize = get_16(); offset = get_32(); if (get_8()) dowrite = true; dbgmsg("fileid=%ld, recordsize=%ld, chunksize=%d, offset=%ld, write=%d", fileid, recordsize, chunksize, offset, dowrite); if ((fileid < 0) || (fileid > MAX_FILES)) { put_8(ER_BADID); put_count(OutCount); return; } info = &FileInfo[fileid]; if (info->fd == NULL) { put_8(ER_BADID); put_count(OutCount); return; } if (info->lastop == FIOP_READ) { put_8(ER_NOPOSN); put_count(OutCount); return; } if (info->recordsize == -1) info->recordsize = recordsize; dbgmsg("recordsize=%ld, info->recordsize=%ld", recordsize, info->recordsize); dbgmsg("info->mrs=%ld", info->mrs); if ((recordsize > info->recordsize) || (recordsize > info->mrs) || (offset+(long)chunksize > info->mrs)) { dbgmsg("ER_ERROR: recordsize screwup"); put_8(ER_ERROR); put_count(OutCount); return; } get_slice(&(info->buff[offset])); info->dirty = true; if (dowrite == true) { info->recno++; #ifdef VMS res = vmsput(info->rab, info->buff, (int) recordsize); vmssavepos(info); #else res = info->putfn(info->fd, info->buff, recordsize); #endif /* VMS */ info->dirty = false; info->recordsize = -1; } else res = ER_SUCCESS; info->lastop = FIOP_WRITE; info->pasteof = false; put_8(res); put_count(OutCount); }