// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1448, %rsp           # imm = 0x1448
leaq 0xc0(%rsp), %rdi
callq 0x4bf4
leaq 0x48(%rsp), %rdi
movsd 0x49c4(%rip), %xmm0     # 0x9008
movsd 0x49c4(%rip), %xmm1     # 0x9010
callq 0x4cb0
movl $0x2c, %edi
callq 0x21b0
xorpd %xmm0, %xmm0
movupd %xmm0, 0x1c(%rax)
movupd %xmm0, 0x10(%rax)
movq %rax, 0x18(%rsp)
movupd %xmm0, (%rax)
movl $0xa, %ebp
leaq 0x48(%rsp), %r14
leaq 0xc(%rsp), %r15
leaq 0x10(%rsp), %r12
leaq 0xc0(%rsp), %r13
movl $0x1, 0xc(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x4e70
decl %ebp
jne 0x468e
xorl %ebx, %ebx
leaq 0xc0(%rsp), %r15
leaq 0x48(%rsp), %r12
leaq 0xc(%rsp), %r13
leaq 0x10(%rsp), %rbp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movsd %xmm0, 0x30(%rsp)
movq %r15, %rdi
callq 0x770d
movq %rbx, 0x38(%rsp)
addsd 0x4980(%rip), %xmm0     # 0x9078
mulsd 0x4960(%rip), %xmm0     # 0x9060
movsd %xmm0, 0x40(%rsp)
movq %r15, %rdi
callq 0x770d
cvttsd2si 0x40(%rsp), %r14
movsd 0x48eb(%rip), %xmm1     # 0x9008
movl %r14d, %ebx
ucomisd %xmm0, %xmm1
jbe 0x478a
testl %r14d, %r14d
je 0x4774
movl $0x1, 0xc(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x10(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x4e70
decl %ebx
jne 0x472b
movl $0x1, 0x10(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x4d1a
decl %r14d
jne 0x4757
movsd 0x30(%rsp), %xmm0
addsd 0x488e(%rip), %xmm0     # 0x9010
movsd %xmm0, 0x30(%rsp)
jmp 0x47d8
testl %r14d, %r14d
je 0x47d8
movl $0x1, 0x10(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x4d1a
decl %ebx
jne 0x478f
movl $0x1, 0xc(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x10(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x4e70
decl %r14d
jne 0x47ab
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rsi
xorl %edi, %edi
cmpq $0x1, %rsi
setne %dil
movq (%rax,%rdi,8), %rax
testq %rax, %rax
movq 0x38(%rsp), %rbx
je 0x482b
movq (%rax), %r8
cmpl $0x1, 0x8(%r8)
je 0x4825
movq (%r8), %r8
testq %r8, %r8
je 0x482b
movslq 0x8(%r8), %rcx
xorl %r9d, %r9d
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
cmpq %rdi, %rdx
jne 0x482e
cmpl $0x1, %ecx
jne 0x4804
movl 0x14(%r8), %r9d
jmp 0x482e
xorl %r9d, %r9d
movslq %r9d, %rax
movq 0x18(%rsp), %rcx
incl (%rcx,%rax,4)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movapd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
incl %ebx
cmpl $0x30d40, %ebx          # imm = 0x30D40
jne 0x46e3
cmpl $0xa, 0x4c(%rsp)
jne 0x4b3f
movq 0x8780(%rip), %r15      # 0xcff0
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0x8b7c
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x8755(%rip), %rdi      # 0xcff0
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x88(%rsp), %rsi
leaq 0x90(%rsp), %rdx
leaq 0x48(%rsp), %rdi
callq 0x5d34
movq 0x8727(%rip), %rdi      # 0xcff0
callq 0x2230
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x86f1(%rip), %rdi      # 0xcff0
leaq 0x4be7(%rip), %rsi      # 0x94ed
movl $0x7, %edx
callq 0x21c0
movsd 0x30(%rsp), %xmm0
divsd 0x4722(%rip), %xmm0     # 0x9040
movq 0x86cb(%rip), %rdi      # 0xcff0
callq 0x2230
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x8695(%rip), %rdi      # 0xcff0
leaq 0x4b93(%rip), %rsi      # 0x94f5
movl $0x12, %edx
callq 0x21c0
movapd 0x20(%rsp), %xmm0
divsd 0x46c6(%rip), %xmm0     # 0x9040
movq 0x866f(%rip), %rdi      # 0xcff0
movapd %xmm0, 0x20(%rsp)
callq 0x2230
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x8633(%rip), %rdi      # 0xcff0
leaq 0x4b44(%rip), %rsi      # 0x9508
movl $0xa, %edx
callq 0x21c0
movapd 0x20(%rsp), %xmm0
addsd 0x468c(%rip), %xmm0     # 0x9068
andpd 0x46bc(%rip), %xmm0     # 0x90a0
movq 0x8605(%rip), %rdi      # 0xcff0
movapd %xmm0, 0x20(%rsp)
callq 0x2230
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movl $0x1, %r15d
movq 0x85c3(%rip), %r12      # 0xcff0
leaq 0x10(%rsp), %r13
movq %r12, %rdi
movq %r15, %rsi
callq 0x20f0
movb $0x20, 0x10(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x21c0
movq 0x18(%rsp), %rcx
movl (%rcx,%r15,4), %esi
movq %rax, %rdi
callq 0x2260
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
incq %r15
cmpq $0xb, %r15
jne 0x4a32
movapd 0x20(%rsp), %xmm0
ucomisd 0x45cc(%rip), %xmm0     # 0x9070
jbe 0x4b01
movq 0x8543(%rip), %rdi      # 0xcff0
leaq 0x4a5f(%rip), %rsi      # 0x9513
movl $0x17, %edx
callq 0x21c0
movq 0x852b(%rip), %rdi      # 0xcff0
movapd 0x20(%rsp), %xmm0
callq 0x2230
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2100
jmp 0x4b17
callq 0x2547
callq 0x2be5
callq 0x323d
xorl %ebp, %ebp
callq 0x3f66
movq 0x18(%rsp), %rdi
callq 0x2180
leaq 0x50(%rsp), %rdi
callq 0x5c7a
movl %ebp, %eax
addq $0x1448, %rsp           # imm = 0x1448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4980(%rip), %rdi      # 0x94c6
leaq 0x48ea(%rip), %rsi      # 0x9437
leaq 0x498e(%rip), %rcx      # 0x94e2
movl $0x13b, %edx            # imm = 0x13B
callq 0x20e0
movq %rax, %r14
jmp 0x4b82
jmp 0x4b75
jmp 0x4b75
jmp 0x4b75
jmp 0x4b75
jmp 0x4b75
jmp 0x4b75
jmp 0x4b75
jmp 0x4b75
jmp 0x4b75
movq %rax, %r14
movq 0x18(%rsp), %rdi
callq 0x2180
leaq 0x50(%rsp), %rdi
callq 0x5c7a
movq %r14, %rdi
callq 0x2270