// File: /workspace/github_cpp_makefile_star2_O2/redpony[P]cpyp/crp_test.cc
// Function: main
int main() {
  cpyp::MT19937 eng;
  double tot = 0;
  double xt = 0;
  cpyp::crp<int> crp(0.5, 1.0);
  unsigned cust = 10;
  vector<int> hist(cust + 1, 0);
  for (unsigned i = 0; i < cust; ++i) { crp.increment(1, 1.0, eng); }
  const int samples = 200000;
  const bool simulate = true;
  for (int k = 0; k < samples; ++k) {
  if (!simulate) {
    crp.clear();
    for (unsigned i = 0; i < cust; ++i) { crp.increment(1, 1.0, eng); }
  } else {
    unsigned da = cpyp::sample_uniform01<double>(eng) * cust;
    bool a = cpyp::sample_uniform01<double>(eng) < 0.5;
    if (a) {
      for (unsigned i = 0; i < da; ++i) { crp.increment(1, 1.0, eng); }
      for (unsigned i = 0; i < da; ++i) { crp.decrement(1, eng); }
      xt += 1.0;
    } else {
      for (unsigned i = 0; i < da; ++i) { crp.decrement(1, eng); }
      for (unsigned i = 0; i < da; ++i) { crp.increment(1, 1.0, eng); }
    }
  }
  int c = crp.num_tables(1);
  ++hist[c];
  tot += c;
  }
  assert(cust == crp.num_customers());
  cerr << crp << endl;
  cerr << crp.log_likelihood() << endl;
  cerr << "P(a) = " << (xt / samples) << endl;
  cerr << "mean num tables = " << (tot / samples) << endl;
  double error = fabs((tot / samples) - 5.4);
  cerr << "  error = " << error << endl;
  for (unsigned i = 1; i <= cust; ++i)
  cerr << i << ' ' << (hist[i]) << endl;
  if (error > 0.1) {
    cerr << "*** error is too big = " << error << endl;
    return 1;
  }
  test_mh1();
  test_mh1a();
  test_mh2();
  test_mfcrp();
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1458, %rsp           # imm = 0x1458
leaq 0xd0(%rsp), %rdi
callq 0x3f30
leaq 0x58(%rsp), %rdi
movsd 0x54d6(%rip), %xmm0     # 0x9008
movsd 0x54d6(%rip), %xmm1     # 0x9010
callq 0x3f80
leaq 0x8(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x40(%rsp), %rdi
pushq $0xb
popq %rsi
leaq 0x4(%rsp), %rcx
callq 0x3fe8
pushq $0xa
popq %rbp
leaq 0x58(%rsp), %rbx
leaq 0x4(%rsp), %r14
leaq 0x8(%rsp), %r15
leaq 0xd0(%rsp), %r12
subl $0x1, %ebp
jb 0x3ba2
movl $0x1, 0x4(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x41d2
jmp 0x3b73
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %r13d, %r13d
leaq 0xd0(%rsp), %rbx
leaq 0x58(%rsp), %r14
leaq 0x8(%rsp), %r15
leaq 0x4(%rsp), %r12
movapd %xmm0, 0x10(%rsp)
cmpl $0x30d40, %r13d         # imm = 0x30D40
je 0x3d05
movq %rbx, %rdi
callq 0x427a
movq %r13, 0x30(%rsp)
mulsd 0x5472(%rip), %xmm0     # 0x9060
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
callq 0x427a
cvttsd2si 0x38(%rsp), %rbp
movsd 0x53fd(%rip), %xmm1     # 0x9008
ucomisd %xmm0, %xmm1
movl %ebp, %r13d
jbe 0x3c47
movl %ebp, %r13d
subl $0x1, %r13d
jb 0x3c7f
movl $0x1, 0x4(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x41d2
jmp 0x3c17
subl $0x1, %r13d
jb 0x3cc2
movl $0x1, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x4086
jmp 0x3c47
movl $0x1, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x4086
subl $0x1, %ebp
jae 0x3c67
movsd 0x28(%rsp), %xmm0
addsd 0x537e(%rip), %xmm0     # 0x9010
movsd %xmm0, 0x28(%rsp)
jmp 0x3cc7
movl $0x1, 0x4(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x41d2
subl $0x1, %ebp
jae 0x3c9a
movl $0x1, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x3f18
movq 0x30(%rsp), %r13
cltq
movq 0x40(%rsp), %rcx
incl (%rcx,%rax,4)
cvtsi2sd %eax, %xmm0
movapd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
incl %r13d
jmp 0x3bcc
cmpl $0xa, 0x5c(%rsp)
jne 0x3eb3
movq 0xa2d9(%rip), %rsi      # 0xdff0
leaq 0x58(%rsp), %rdi
callq 0x8372
movq 0xa2c8(%rip), %rdi      # 0xdff0
callq 0x2080
leaq 0x58(%rsp), %rdi
callq 0x3f0a
movq 0xa2b2(%rip), %rdi      # 0xdff0
callq 0x2200
movq %rax, %rdi
callq 0x2080
movq 0xa29e(%rip), %rdi      # 0xdff0
leaq 0x5765(%rip), %rsi      # 0x94be
callq 0x2170
movsd 0x28(%rsp), %xmm0
divsd 0x52d4(%rip), %xmm0     # 0x9040
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x2080
movq 0xa26d(%rip), %rdi      # 0xdff0
leaq 0x573c(%rip), %rsi      # 0x94c6
callq 0x2170
movapd 0x10(%rsp), %xmm0
divsd 0x52a3(%rip), %xmm0     # 0x9040
movq %rax, %rdi
movapd %xmm0, 0x10(%rsp)
callq 0x2200
movq %rax, %rdi
callq 0x2080
movq 0xa236(%rip), %rdi      # 0xdff0
leaq 0x5718(%rip), %rsi      # 0x94d9
callq 0x2170
movapd 0x10(%rsp), %xmm0
addsd 0x5294(%rip), %xmm0     # 0x9068
andpd 0x52c4(%rip), %xmm0     # 0x90a0
movq %rax, %rdi
movapd %xmm0, 0x10(%rsp)
callq 0x2200
movq %rax, %rdi
callq 0x2080
pushq $0x1
popq %rbx
movq 0xa1f4(%rip), %r14      # 0xdff0
pushq $0x20
popq %rbp
cmpq $0xb, %rbx
je 0x3e37
movq %r14, %rdi
movq %rbx, %rsi
callq 0x20e0
movq %rax, %rdi
movl %ebp, %esi
callq 0x21a0
movq 0x40(%rsp), %rcx
movl (%rcx,%rbx,4), %esi
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x2080
incq %rbx
jmp 0x3dff
movapd 0x10(%rsp), %xmm0
ucomisd 0x522b(%rip), %xmm0     # 0x9070
jbe 0x3e75
movq 0xa1a2(%rip), %rdi      # 0xdff0
leaq 0x568f(%rip), %rsi      # 0x94e4
callq 0x2170
movq %rax, %rdi
movapd 0x10(%rsp), %xmm0
callq 0x2200
movq %rax, %rdi
callq 0x2080
pushq $0x1
popq %rbx
jmp 0x3e8b
callq 0x2430
callq 0x287f
callq 0x2cbb
xorl %ebx, %ebx
callq 0x359c
leaq 0x40(%rsp), %rdi
callq 0x5be4
leaq 0x60(%rsp), %rdi
callq 0x5008
movl %ebx, %eax
addq $0x1458, %rsp           # imm = 0x1458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x55dd(%rip), %rdi      # 0x9497
leaq 0x5547(%rip), %rsi      # 0x9408
leaq 0x55eb(%rip), %rcx      # 0x94b3
movl $0x13b, %edx            # imm = 0x13B
callq 0x20d0
movq %rax, %rbx
jmp 0x3ef8
jmp 0x3eeb
jmp 0x3eeb
jmp 0x3eeb
jmp 0x3eeb
jmp 0x3eeb
jmp 0x3eeb
jmp 0x3eeb
jmp 0x3eeb
jmp 0x3eeb
jmp 0x3eeb
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x5be4
leaq 0x60(%rsp), %rdi
callq 0x5008
movq %rbx, %rdi
callq 0x2240