// File: /workspace/github_c_makefile_star2_O2/aligusnet[P]morpheus/tests/least_squares_test.c
// Function: test_least_squares
void test_least_squares() {
  double X[] = {
    1, 3,
    1, 5,
    1, 10,
    1, 0,
    1, 4
  };
  double y[] = {9, 13, 23, 3, 11};

  double theta[] = {3, 2};

  double tmp_buffer[2*5];

  morpheus_params_t params;
  params.data.x = X;
  params.data.y = y;
  params.data.num_features = 2;
  params.data.num_examples = 5;
  params.data.layout = morpheus_row_major;
  params.reg.type = morpheus_reg_none;
  params.memory_buffer = tmp_buffer;

  // prediction
  double X_to_predict[] = {
    1, 7,
    1, 9
  };

  morpheus_data_t data_to_predict;
  data_to_predict.x = X_to_predict;
  data_to_predict.y = 0;
  data_to_predict.num_features = 2;
  data_to_predict.num_examples = 2;
  data_to_predict.layout = morpheus_row_major;

  double prediction[2];
  double prediction_expected[] = {17, 21};
  morpheus_ls_hypothesis(&data_to_predict, theta, prediction);
  TEST_ASSERT_EQUAL_DOUBLE_ARRAY(prediction_expected, prediction, data_to_predict.num_features);

  // cost function
  double v = morpheus_ls_cost(theta, &params);
  TEST_ASSERT_EQUAL_DOUBLE(0, v);

  // gradient
  double grad[2];
  double grad_expected[] = {0, 0};
  morpheus_ls_gradient(theta, &params, grad);
  TEST_ASSERT_EQUAL_DOUBLE_ARRAY(grad_expected, grad, 2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
leaq 0x5b9c(%rip), %rsi      # 0x71a0
pushq $0xa
popq %rcx
leaq 0x140(%rsp), %rax
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
movaps 0x5ad4(%rip), %xmm0     # 0x70f0
leaq 0x90(%rsp), %rcx
movaps %xmm0, (%rcx)
movaps 0x5ad2(%rip), %xmm0     # 0x7100
movaps %xmm0, 0x10(%rcx)
movabsq $0x4026000000000000, %rdx # imm = 0x4026000000000000
movq %rdx, 0x20(%rcx)
movaps 0x5ae9(%rip), %xmm0     # 0x7130
leaq 0xb8(%rsp), %rbx
movq %rax, (%rbx)
movq %rcx, 0x8(%rbx)
movabsq $0x500000002, %rax      # imm = 0x500000002
movq %rax, 0x10(%rbx)
pushq $0x15
popq %rax
movl %eax, 0x18(%rbx)
andl $0x0, 0x20(%rbx)
leaq 0x40(%rsp), %r14
movaps %xmm0, (%r14)
leaq 0xf0(%rsp), %rcx
movq %rcx, 0x30(%rbx)
movaps 0x5b76(%rip), %xmm0     # 0x7200
leaq 0x50(%rsp), %rcx
movaps %xmm0, 0x10(%rcx)
leaq 0x70(%rsp), %r15
movq %rcx, (%r15)
andq $0x0, 0x8(%r15)
movaps 0x5b49(%rip), %xmm0     # 0x71f0
movaps %xmm0, (%rcx)
movabsq $0x200000002, %rcx      # imm = 0x200000002
movq %rcx, 0x10(%r15)
movl %eax, 0x18(%r15)
movaps 0x5acd(%rip), %xmm0     # 0x7190
leaq 0x20(%rsp), %r12
movaps %xmm0, (%r12)
leaq 0x30(%rsp), %r13
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3c20
movl 0x10(%r15), %edx
pushq $0x2c
popq %r8
pushq $0x1
popq %rbp
movq %r12, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
movl %ebp, %r9d
callq 0x5b0f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3dc3
movaps %xmm0, %xmm2
pushq $0x30
popq %rsi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorl %edi, %edi
callq 0x5cd4
xorps %xmm0, %xmm0
movq %rsp, %r15
movaps %xmm0, (%r15)
leaq 0x10(%rsp), %r12
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3dd3
pushq $0x2
popq %rdx
pushq $0x36
popq %r8
movq %r15, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
movl %ebp, %r9d
callq 0x5b0f
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop