Matrix Matrix::getCol(int index) const { Matrix Col (getm(),1); int i=0; for(i=0; i<getm();i++){ Col[i][0]=(*this)[i][index]; } return Col; }
// Matrix Transpose Matrix Matrix::transp() const { Matrix transpAns(getn(),getm()); int i=0,j=0; for (i=0; i<getm(); i++) { for (j=0; j<getn();j++) { transpAns[j][i]=(*this)[i][j]; } } return transpAns; }
void Matrix::setCol(int index, Matrix in) { int i=0; for(i=0; i<getm();i++){ (*this)[i][index]=in[i][0]; } }
void main() { clrscr(); int m,n,p,q,a[20][20],b[20][20],c[20][20]; cout<<"Enter no:of rows & columns of first matrix:"; cin>>m>>n; cout<<"Enter no:of rows & columns of second matrix:"; cin>>p>>q; if(m!=p||n!=q) cout<<"Matrix addition and substraction not possible.\n"; else { cout<<"Enter elements of First matrix:\n"; getm(m,n,a); cout<<"Enter elements of Second matrix:\n"; getm(p,q,b); clrscr(); cout<<"First matrix:\n"; prim(m,n,a); cout<<"Second matrix:\n"; prim(p,q,b); cout<<"Matrix Sum:\n"; addm(m,n,a,b); cout<<"Matrix Difference:\n"; subm(m,n,a,b); } if(m!=q) cout<<"Matrix multiplication not possible."; else { if(m!=p||n!=q) { cout<<"Enter elements of First matrix:\n"; getm(m,n,a); cout<<"Enter elements of Second matrix:\n"; getm(p,q,b); clrscr(); cout<<"First matrix:\n"; prim(m,n,a); cout<<"Second matrix:\n"; prim(p,q,b); } cout<<"Matrix Product:\n"; mulm(m,n,q,a,b,c); } getch(); }
void printSinglecopyDocument::sPopulate() { ParameterList getp = getParamsDocList(); MetaSQLQuery getm(_docinfoQueryString); XSqlQuery getq = getm.toQuery(getp); if (getq.first()) emit populated(&getq); }
void loadstate(Mach *m, void *buf) { size_t i; u8 *p; p = buf; p += get4(p, &m->ac); p += get4(p, &m->io); p += get4(p, &m->pc); p += get4(p, &m->ov); for (i = 0; i < nelem(m->mem); i++) p += get4(p, &m->mem[i]); p += getm(m->flag, p, sizeof(m->flag)); p += getm(m->sense, p, sizeof(m->sense)); p += get1(p, &m->halt); for (i = 0; i < nelem(m->sym); i++) p += get4(p, &m->sym[i]); }
void aplus_main(long argc, char** argv) { #if !defined(_INTERPRETER_ONLY) extern void AplusLoop(); #endif I i; /* the number of arguments parsed */ #if !defined(_INTERPRETER_ONLY) dapinit(); #endif initReleaseData(_releaseCode); initVersion(); initDefaultATREE(argv[0]); initCallouts(); i = parseargs(argc, argv); if( !_quiet ) printId(); atmpinit(); envinit(); if(0!=_megsforheap)setk1(_megsforheap); /* must be before mem init! */ ai(_workarea); /* initialize */ if(_enable_coredump) { setSigv(1); setSigb(1); coreLimSet(aplusInfinity); } versSet(_version); releaseCodeSet(_releaseCode); phaseOfReleaseSet(_phaseOfRelease); majorReleaseSet(_majorRelease); minorReleaseSet(_minorRelease); startupSyslog(_version); xi(argv[0]); /* installation */ argvInstall(argc, argv, i); /* set up _argv */ uextInstall(); /* user lib install */ #if !defined(_INTERPRETER_ONLY) AplusLoop(argc, argv, i); #else if (i < argc && argv[i] && *argv[i]) loadafile(argv[i],0); if (Tf) pr(); while(1) getm(); #endif /********************************************************************** These functions are moved to AplusLoop if (i < argc && argv[i] && *argv[i]) loadafile(argv[i],0); / * load script * / if (Tf) pr(); / * initial prompt * / **********************************************************************/ }
std::vector<float> Matrix::asVector() { int rows, cols; rows = getm(); cols = getn(); int length = rows * cols; std::vector<float> result(length); int row = 0, col = 0; for(int i = 0; i < length; i++) { row = i / cols; col = i % cols; result[i] = (*this)[row][col]; } return result; }
void printMulticopyDocument::populate() { ParameterList getp = getParamsDocList(); MetaSQLQuery getm(_docinfoQueryString); XSqlQuery getq = getm.toQuery(getp); if (getq.first()) { if (getq.value("posted").toBool()) { _data->_post->setChecked(false); _data->_post->hide(); } else _data->_post->setVisible(! _data->_postPrivilege.isEmpty()); emit populated(&getq); } }
bool Matrix::operator ==(const Matrix& b) const { float local_m = getm(); float local_n = getn(); // first compare dimensions if(local_m != b.getm()) return false; if(local_n != b.getn()) return false; // now compare each value. for(unsigned int i=0;i<local_m;++i) { for(unsigned int j=0;j<local_n;j++) { if( (*this)[i][j] != b[i][j]) { return false; } } } return true; }
char * formataddr (char *orig, char *str) { register int len; register int isgroup; register char *dst; register char *cp; register char *sp; register struct mailname *mp = NULL; /* if we don't have a buffer yet, get one */ if (bufsiz == 0) { buf = mh_xmalloc (BUFINCR); last_dst = buf; /* XXX */ bufsiz = BUFINCR - 6; /* leave some slop */ bufend = buf + bufsiz; } /* * If "orig" points to our buffer we can just pick up where we * left off. Otherwise we have to copy orig into our buffer. */ if (orig == buf) dst = last_dst; else if (!orig || !*orig) { dst = buf; *dst = '\0'; } else { dst = last_dst; /* XXX */ CHECKMEM (orig); CPY (orig); } /* concatenate all the new addresses onto 'buf' */ for (isgroup = 0; (cp = getname (str)); ) { if ((mp = getm (cp, NULL, 0, fmt_norm, NULL)) == NULL) continue; if (isgroup && (mp->m_gname || !mp->m_ingrp)) { *dst++ = ';'; isgroup = 0; } /* if we get here we're going to add an address */ if (dst != buf) { *dst++ = ','; *dst++ = ' '; } if (mp->m_gname) { CHECKMEM (mp->m_gname); CPY (mp->m_gname); isgroup++; } sp = adrformat (mp); CHECKMEM (sp); CPY (sp); mnfree (mp); } if (isgroup) *dst++ = ';'; *dst = '\0'; last_dst = dst; return (buf); }
double addmigration (int ci, int li, int oldmigcount, double oldtlength, int *newmigcount, double *newtlength) { int newsis, edge; double weight; double mproposenum, mproposedenom, temp; struct edge *gtree = C[ci]->G[li].gtree; double mtime; int mcount; int holdfpop; assert (C[ci]->G[li].mignum >= 0 && C[ci]->G[li].tlength > 0); IMA_reset_edgemiginfo (&newedgemig); IMA_reset_edgemiginfo (&newsismig); newedgemig.edgeid = edge = oldedgemig.edgeid; newedgemig.li = li; if (edge < L[li].numgenes) newedgemig.upt = 0; else newedgemig.upt = gtree[gtree[edge].up[0]].time; newedgemig.fpop = gtree[gtree[edge].down].pop; newedgemig.pop = newedgemig.temppop = gtree[edge].pop; newedgemig.dnt = gtree[edge].time; newedgemig.mig[0].mt = -1; fillmiginfoperiods (ci, &newedgemig); if (gtree[edge].down == C[ci]->G[li].root) /* simulate migration on the sister branch as well */ { //IMA_reset_edgemiginfo (&newsismig); newedgemig.fpop = -1; //pop unknown, as edge must be determined by migration if (gtree[gtree[edge].down].up[0] == edge) newsis = gtree[gtree[edge].down].up[1]; else newsis = gtree[gtree[edge].down].up[0]; if (newsis < L[li].numgenes) newsismig.upt = 0; else newsismig.upt = gtree[gtree[newsis].up[0]].time; newsismig.edgeid = newsis; newsismig.li = li; newsismig.fpop = -1; //pop unknown, as edge must be determined by migration newsismig.pop = newsismig.temppop = gtree[newsis].pop; newsismig.dnt = gtree[newsis].time; newsismig.mig[0].mt = -1; fillmiginfoperiods (ci, &newsismig); } else { newedgemig.fpop = gtree[gtree[edge].down].pop; newsismig.edgeid = -1; newsismig.mtall = 0; newsismig.b = newsismig.e = -1;// no second edge to deal with } holdfpop = newedgemig.fpop; assert((newsismig.mtall > 0 && newsismig.edgeid >= 0) || newsismig.mtall == 0); getm (ci, &newedgemig, &newsismig, &oldedgemig, &oldsismig); if (newedgemig.fpop == -1) { assert(newsismig.edgeid != -1); assert(newedgemig.e == lastperiodnumber); newedgemig.fpop = newsismig.fpop = C[ci]->G[li].root; } if (gtree[newedgemig.edgeid].down == C[ci]->G[li].root) gtree[C[ci]->G[li].root].pop = newedgemig.fpop; /*checkpp = 1; //debug 8_30_10 */ temp = getmprob (ci, &newedgemig, &newsismig, &oldedgemig, &oldsismig); /*checkpp = 0; //debug 8_30_10 */ mproposedenom = temp; assert (temp > -1e200 && temp < 1e200); /* calculate probability of reverse update */ mtime = oldtlength - oldedgemig.mtall - oldsismig.mtall + newedgemig.mtall; mcount = oldmigcount - oldedgemig.mpall - oldsismig.mpall + newedgemig.mpall; if (newsismig.edgeid >= 0) { mtime += newsismig.mtall; mcount += newsismig.mpall; } temp = getmprob (ci, &oldedgemig, &oldsismig, &newedgemig, &newsismig); mproposenum = temp; assert (temp > -1e200 && temp < 1e200); weight = mproposenum - mproposedenom; *newmigcount = mcount; *newtlength = mtime; return weight; } /* addmigration */
const straintensor& SANISAND_alpha_Eij::Hij(const PlasticFlow& plastic_flow, const stresstensor& Stre, const straintensor& Stra, const MaterialParameter& material_parameter) { // const double rt23 = sqrt(2.0/3.0); // stresstensor a_a_in; // double a_in = 0.0; double e0 = gete0(material_parameter); double e_r = gete_r(material_parameter); double lambda = getlambda(material_parameter); double xi = getxi(material_parameter); double Pat = getPat(material_parameter); double alpha_cc = getalpha_cc(material_parameter); double c = getc(material_parameter); double nb = getnb(material_parameter); double h0 = geth0(material_parameter); double ch = getch(material_parameter); double G0 = getG0(material_parameter); double m = getm(material_parameter); stresstensor alpha = getalpha(material_parameter); stresstensor n; stresstensor s_bar; double norm_s = 0.0; double r_ef = 0.0; double cos3theta = 0.0; double g = 0.0; double ec = e_r; double e = e0; double psi = 0.0; double alpha_b_c = 0.0; stresstensor alpha_b_tensor; stresstensor b_ref; stresstensor temp_tensor; double lower = 0.0; double h = G0*h0; double p = Stre.p_hydrostatic(); stresstensor s = Stre.deviator(); s_bar = s - (alpha *p); norm_s = sqrt( (s_bar("ij")*s_bar("ij")).trace() ); if (p > 0.0 && norm_s > 0.0) { n = s_bar * (1.0/norm_s); r_ef = rt32 * norm_s / p; cos3theta = -3.0 * sqrt(6.0) * n.Jinvariant3(); } if (p <= 0.0) cos3theta = 1.0; if (cos3theta > 1.0) cos3theta = 1.0; if (cos3theta < -1.0) cos3theta = -1.0; g = getg(c, cos3theta); if ( p >= 0.0 ) ec = getec(e_r, lambda, xi, Pat, p); e = e0 + (1.0 + e0) * Stra.Iinvariant1(); psi = e - ec; alpha_b_c = alpha_cc * exp(-nb*psi); alpha_b_tensor = n * (rt23 * g * alpha_b_c); b_ref = n * rt23 * alpha_b_c * (1.0+c); // b_ref = n * rt23 * alpha_cc * (1.0+c); // Method 1 temp_tensor = b_ref - (alpha_b_tensor - alpha); //// Method 2, better to use this when "p" is small //temp_tensor = b_ref - (alpha_b_tensor - s*(1.0/p)); lower = rt32*(temp_tensor("ij")*n("ij")).trace(); if ( lower>0 ) h = G0 * h0 * (1-ch*e) * sqrt(Pat/p) / (lower*lower); // h = G0 * h0 * (1-ch*e) * sqrt(Pat/p); // h = h0; // Method 1 temp_tensor = alpha_b_tensor - alpha; // Method 2 //temp_tensor = alpha_b_tensor+n*m - s*(1.0/p); TensorEvolution::TensorEvolutionHij = temp_tensor * (h*r_ef); return TensorEvolution::TensorEvolutionHij; }
static int field_encode_address(const char *name, char **value, int encoding, const char *charset) { int prefixlen = strlen(name) + 2, column = prefixlen, groupflag; int asciichars, specialchars, eightbitchars, reformat = 0, errflag = 0; size_t len; char *mp, *cp = NULL, *output = NULL; char *tmpbuf = NULL; size_t tmpbufsize = 0; struct mailname *mn; char errbuf[BUFSIZ]; /* * Because these are addresses, we need to handle them individually. * * Break them down and process them one by one. This means we have to * rewrite the whole header, but that's unavoidable. */ /* * The output headers always have to start with a space first; this * is just the way the API works right now. */ output = add(" ", output); for (groupflag = 0; (mp = getname(*value)); ) { if ((mn = getm(mp, NULL, 0, errbuf, sizeof(errbuf))) == NULL) { advise(NULL, "%s: %s", errbuf, mp); errflag++; continue; } reformat = 0; /* * We only care if the phrase (m_pers) or any trailing comment * (m_note) have 8-bit characters. If doing q-p, we also need * to encode anything marked as qspecial(). Unquote it first * so the specialchars count is right. */ if (! mn->m_pers) goto check_note; if ((len = strlen(mn->m_pers)) + 1 > tmpbufsize) { tmpbuf = mh_xrealloc(tmpbuf, tmpbufsize = len + 1); } unquote_string(mn->m_pers, tmpbuf); if (scanstring(tmpbuf, &asciichars, &eightbitchars, &specialchars)) { /* * If we have 8-bit characters, encode it. */ if (encoding == CE_UNKNOWN) encoding = pref_encoding(asciichars, specialchars, eightbitchars); /* * This is okay, because the output of unquote_string will be either * equal or shorter than the original. */ strcpy(mn->m_pers, tmpbuf); switch (encoding) { case CE_BASE64: if (field_encode_base64(NULL, &mn->m_pers, charset)) { errflag++; goto out; } break; case CE_QUOTED: if (field_encode_quoted(NULL, &mn->m_pers, charset, asciichars, eightbitchars + specialchars, 1)) { errflag++; goto out; } break; default: advise(NULL, "Internal error: unknown RFC-2047 encoding type"); errflag++; goto out; } reformat++; } check_note: /* * The "note" field is generally a comment at the end of the address, * at least as how it's implemented here. Notes are always surrounded * by parenthesis (since they're comments). Strip them out and * then put them back when we format the final field, but they do * not get encoded. */ if (! mn->m_note) goto do_reformat; if ((len = strlen(mn->m_note)) + 1 > tmpbufsize) { tmpbuf = mh_xrealloc(tmpbuf, tmpbufsize = len + 1); } if (mn->m_note[0] != '(' || mn->m_note[len - 1] != ')') { advise(NULL, "Internal error: Invalid note field \"%s\"", mn->m_note); errflag++; goto out; } strncpy(tmpbuf, mn->m_note + 1, len - 1); tmpbuf[len - 2] = '\0'; if (scanstring(tmpbuf, &asciichars, &eightbitchars, &specialchars)) { /* * If we have 8-bit characters, encode it. */ if (encoding == CE_UNKNOWN) encoding = pref_encoding(asciichars, specialchars, eightbitchars); switch (encoding) { case CE_BASE64: if (field_encode_base64(NULL, &tmpbuf, charset)) { errflag++; goto out; } break; case CE_QUOTED: if (field_encode_quoted(NULL, &tmpbuf, charset, asciichars, eightbitchars + specialchars, 1)) { errflag++; goto out; } break; default: advise(NULL, "Internal error: unknown RFC-2047 encoding type"); errflag++; goto out; } reformat++; /* * Make sure the size of tmpbuf is correct (it always gets * reallocated in the above functions). */ tmpbufsize = strlen(tmpbuf) + 1; /* * Put the note field back surrounded by parenthesis. */ mn->m_note = mh_xrealloc(mn->m_note, tmpbufsize + 2); snprintf(mn->m_note, tmpbufsize + 2, "(%s)", tmpbuf); } do_reformat: /* * So, some explanation is in order. * * We know we need to rewrite at least one address in the header, * otherwise we wouldn't be here. If we had to reformat this * particular address, then run it through adrformat(). Otherwise * we can use m_text directly. */ /* * If we were in a group but are no longer, make sure we add a * semicolon (which needs to be FIRST, as it needs to be at the end * of the last address). */ if (groupflag && ! mn->m_ingrp) { output = add(";", output); column += 1; } groupflag = mn->m_ingrp; if (mn->m_gname) { cp = add(mn->m_gname, NULL); } if (reformat) { cp = add(adrformat(mn), cp); } else { cp = add(mn->m_text, cp); } len = strlen(cp); /* * If we're not at the beginning of the line, add a command and * either a space or a newline. */ if (column != prefixlen) { if (len + column + 2 > OUTPUTLINELEN) { if ((size_t) (prefixlen + 3) < tmpbufsize) tmpbuf = mh_xrealloc(tmpbuf, tmpbufsize = prefixlen + 3); snprintf(tmpbuf, tmpbufsize, ",\n%*s", column = prefixlen, ""); output = add(tmpbuf, output); } else { output = add(", ", output); column += 2; } } /* * Finally add the address */ output = add(cp, output); column += len; free(cp); cp = NULL; } /* * Just in case we're at the end of a list */ if (groupflag) { output = add(";", output); } output = add("\n", output); free(*value); *value = output; output = NULL; out: if (tmpbuf) free(tmpbuf); if (output) free(output); return errflag > 0; }