Beispiel #1
0
/*
  Differentiation of Qtimesx in reverse (adjoint) mode:
   gradient     of useful results: *out *Qdiag *x *ltri
   with respect to varying inputs: *out *Qdiag *x *ltri
   Plus diff mem management of: out:in Qdiag:in x:in ltri:in
*/
void Qtimesx_b(int d, double *Qdiag, double *Qdiagb, double *ltri, double *
  ltrib, double *x, double *xb, double *out, double *outb) {
  // strictly lower triangular part
  int id, i, j, Lparamsidx;
  int adFrom;
  Lparamsidx = 0;
  for (i = 0; i < d; ++i) {
    adFrom = i + 1;
    for (j = adFrom; j < d; ++j) {
      pushinteger4(Lparamsidx);
      Lparamsidx = Lparamsidx + 1;
    }
    pushinteger4(adFrom);
  }
  for (i = d - 1; i > -1; --i) {
    popinteger4(&adFrom);
    for (j = d - 1; j > adFrom - 1; --j) {
      popinteger4(&Lparamsidx);
      ltrib[Lparamsidx] = ltrib[Lparamsidx] + x[i] * outb[j];
      xb[i] = xb[i] + ltri[Lparamsidx] * outb[j];
    }
  }
  for (id = d - 1; id > -1; --id) {
    Qdiagb[id] = Qdiagb[id] + x[id] * outb[id];
    xb[id] = xb[id] + Qdiag[id] * outb[id];
    outb[id] = 0.0;
  }
}
Beispiel #2
0
void pushbit(int bit) {
  if (adbitilbuf != -1) {
    adbitilbuf = -1 ;
    adbitinlbuf = 0 ;
  }
  adbitbuf<<=1 ;
  if (bit) adbitbuf++ ;
  if (adbitibuf>=32) {
    pushinteger4(adbitbuf) ;
    adbitbuf = 0 ;
    adbitibuf = 1 ;
  } else
    adbitibuf++ ;
}
Beispiel #3
0
int main(int argc, char *argv[]) {
  double x, Y[10], px, PY[10] ;
  int a, B[20], pa, PB[20] ;
  int pc1, pc2, pc3, pc4 ;
  int i ;

  x = -1.0 ;
  for (i=0 ; i<10 ; ++i)
    Y[i] = i*1.1 ;
  a = -1 ;
  for (i=0 ; i<20 ; ++i)
    B[i] = i ;

  pushreal8(x) ;
  pushreal8array(Y,10) ;
  pushcontrol1b(1) ;
  pushcontrol3b(4) ;
  pushcontrol1b(0) ;
  pushcontrol5b(14) ;

  showallstacks() ;

  pushinteger4(a) ;
  pushinteger4array(B,20) ;

  showallstacks() ;

  popinteger4array(PB,20) ;

  showallstacks() ;

  lookinteger4(&pa) ;
  printf("l -1:%i\n",pa) ;
  lookcontrol5b(&pc1) ;
  printf("l 14?:%i\n",pc1) ;
  lookcontrol1b(&pc1) ;
  printf("l  0?:%i\n",pc1) ;
  pushcontrol5b( 7) ;
  pushcontrol5b(29) ;
  pushcontrol5b(23) ;
  pushcontrol5b(24) ;
  pushcontrol5b(25) ;
  pushcontrol5b(26) ;
  pushcontrol5b(27) ;

  showallstacks() ;

  pushcontrol5b(28) ;
  pushcontrol5b(21) ;
  pushcontrol5b(22) ;
  pushcontrol5b(23) ;
  pushcontrol5b(24) ;
  pushcontrol5b(25) ;
  pushcontrol5b(26) ;
  pushcontrol5b(27) ;
  pushcontrol5b(28) ;
  pushcontrol5b(29) ;

  printallbuffers() ;

  popcontrol5b(&pc3) ;
  printf("29?:%i\n",pc3) ;
  popcontrol5b(&pc3) ;
  printf("28?:%i\n",pc3) ;
  popcontrol5b(&pc3) ;
  printf("27?:%i\n",pc3) ;
  popcontrol5b(&pc3) ;
  printf("26?:%i\n",pc3) ;
  popcontrol5b(&pc3) ;
  printf("25?:%i\n",pc3) ;
  popcontrol5b(&pc3) ;
  printf("24?:%i\n",pc3) ;
  popcontrol5b(&pc3) ;
  printf("23?:%i\n",pc3) ;
  popcontrol5b(&pc3) ;
  printf("22?:%i\n",pc3) ;
  popcontrol5b(&pc3) ;
  printf("21?:%i\n",pc3) ;

  showallstacks() ;

  lookcontrol5b(&pc1) ;
  printf("L 28?:%i\n",pc1) ;
  popcontrol5b(&pc1) ;
  printf("28?:%i\n",pc1) ;

  showallstacks() ;

  popcontrol5b(&pc1) ;
  printf("27?:%i\n",pc1) ;
  popcontrol5b(&pc1) ;
  printf("26?:%i\n",pc1) ;
  popcontrol5b(&pc1) ;
  printf("25?:%i\n",pc1) ;
  popcontrol5b(&pc1) ;
  printf("24?:%i\n",pc1) ;
  popcontrol5b(&pc1) ;
  printf("23?:%i\n",pc1) ;
  popcontrol5b(&pc1) ;
  printf("29?:%i\n",pc1) ;
  popcontrol5b(&pc1) ;
  printf(" 7?:%i\n",pc1) ;
  popinteger4(&pa) ;
  printf("-1:%i\n",pa) ;

  showallstacks() ;

  lookcontrol5b(&pc1) ;
  printf("L 14?:%i\n",pc1) ;
  lookcontrol1b(&pc1) ;
  printf("L  0?:%i\n",pc1) ;
  lookcontrol3b(&pc1) ;
  printf("L  4?:%i\n",pc1) ;

  showallstacks() ;

  popcontrol5b(&pc1) ;
  printf("14?:%i\n",pc1) ;
  popcontrol1b(&pc1) ;
  printf(" 0?:%i\n",pc1) ;
  popcontrol3b(&pc1) ;
  printf(" 4?:%i\n",pc1) ;
  popcontrol1b(&pc1) ;
  printf(" 1?:%i\n",pc1) ;
  popreal8array(PY,10) ;
  //printf("y:%f\n",PY) ;
  popreal8(&px) ;
  printf("-1.0:%f\n",px) ;

  showallstacks() ;
}