コード例 #1
0
ファイル: pvq.c プロジェクト: KyleSiefring/daala
/** Computes Householder reflection that aligns the reference r to the
 *  dimension in r with the greatest absolute value. The reflection
 *  vector is returned in r.
 *
 * @param [in,out]  r      reference vector to be reflected, reflection
 *                         also returned in r
 * @param [in]      n      number of dimensions in r
 * @param [in]      gr     gain of reference vector
 * @param [out]     sign   sign of reflection
 * @return                 dimension number to which reflection aligns
 **/
int od_compute_householder(double *r, int n, double gr, int *sign) {
  int m;
  int i;
  int s;
  double maxr;
  /* Pick component with largest magnitude. Not strictly
   * necessary, but it helps numerical stability */
  m = 0;
  maxr = 0;
  for (i = 0; i < n; i++) {
    if (fabs(r[i]) > maxr) {
      maxr = fabs(r[i]);
      m = i;
    }
  }
  OD_LOG((OD_LOG_PVQ, OD_LOG_DEBUG, "max r: %f %f %d", maxr, r[m], m));
  s = r[m] > 0 ? 1 : -1;
  /* This turns r into a Householder reflection vector that would reflect
   * the original r[] to e_m */
  r[m] += gr*s;
  *sign = s;
  return m;
}
コード例 #2
0
ファイル: logging_test.c プロジェクト: ekr/daala
int main(int argc, char **argv) {
  int i;
  ogg_int16_t int16_buffer[BUFFER_WIDTH * BUFFER_HEIGHT];
  float float_buffer[BUFFER_WIDTH * BUFFER_HEIGHT];
  ogg_uint32_t uint32_buffer[BUFFER_WIDTH * BUFFER_HEIGHT];
  (void)argc;
  (void)argv;

  /* Test the basic functionality. */
  setenv("OD_LOG_MODULES", "generic:3", 1);
  od_log_init(od_logging_test_emit);

  /* This should log. */
  reset_result();
  OD_LOG((OD_LOG_GENERIC, OD_LOG_ERR, "Blah blah %s:%d", "XXX", 9));
  expected_result("Blah blah XXX:9");

  /* This should not log (level too low) */
  reset_result();
  OD_LOG((OD_LOG_GENERIC, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9));
  expected_nothing();

  /* This should not log (facility not set) */
  reset_result();
  OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_ERR, "Blah blah %s:%d", "XXX", 9));
  expected_nothing();

  /* Test multiple modules */
  setenv("OD_LOG_MODULES", "generic:3,entropy-coder:5", 1);
  od_log_init(od_logging_test_emit);
  reset_result();
  OD_LOG((OD_LOG_GENERIC, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9));
  expected_nothing();

  reset_result();
  OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9));
  expected_something();

  /* Test multiple modules in the other order*/
  setenv("OD_LOG_MODULES", "entropy-coder:5,generic:3", 1);
  od_log_init(od_logging_test_emit);
  reset_result();
  OD_LOG((OD_LOG_GENERIC, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9));
  expected_nothing();

  reset_result();
  OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9));
  expected_something();

  /* Test bogus module string */
  setenv("OD_LOG_MODULES", "generic:XXX,blahblah:9,entropy-coder:5", 1);
  od_log_init(od_logging_test_emit);
  reset_result();
  OD_LOG((OD_LOG_GENERIC, OD_LOG_ERR, "Blah blah %s:%d", "XXX", 9));
  expected_nothing();

  reset_result();
  OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "Blah blah %s:%d", "XXX", 9));
  expected_something();

  /* Test a ridiculous fmt string */
  memset(bogus_fmt_string, 'X', sizeof(bogus_fmt_string));
  bogus_fmt_string[sizeof(bogus_fmt_string) - 2] = 'Y';
  bogus_fmt_string[sizeof(bogus_fmt_string) - 1] = '\0';
  OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, bogus_fmt_string, "XXX", 9));


  /* Test matrices */
  for (i=0; i<(BUFFER_WIDTH * BUFFER_HEIGHT); ++i) {
    int16_buffer[i] = 1000 + i;
  }
  reset_result();
  od_log_matrix_int16(OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "PREFIX:",
                    int16_buffer, BUFFER_WIDTH, BUFFER_HEIGHT);
  expected_result(expected_matrix_int16);

  for (i=0; i<(BUFFER_WIDTH * BUFFER_HEIGHT); ++i) {
    float_buffer[i] = 1 + (float)i / 1000;
  }
  reset_result();
  od_log_matrix_float(OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "PREFIX:",
                    float_buffer, BUFFER_WIDTH, BUFFER_HEIGHT);
  expected_result(expected_matrix_float);

  for (i=0; i<(BUFFER_WIDTH * BUFFER_HEIGHT); ++i) {
    uint32_buffer[i] = 1000000 + i;
  }
  reset_result();
  od_log_matrix_uint32(OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG, "PREFIX:",
                       uint32_buffer, BUFFER_WIDTH, BUFFER_HEIGHT);
  expected_result(expected_matrix_uint32);

  if (failed)
    exit(1);

  exit(0);
}