// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x1b8, %rsp            # imm = 0x1B8
leaq 0x160(%rsp), %rdi
leaq 0x9a8a(%rip), %rsi      # 0xb230
movl $0x50, %edx
callq 0x1150
leaq 0x130(%rsp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x1040
movsd 0x99ec(%rip), %xmm0     # 0xb1b8
movsd %xmm0, 0x130(%rsp)
movsd 0x99d3(%rip), %xmm0     # 0xb1b0
movsd %xmm0, 0x138(%rsp)
movsd 0x99ba(%rip), %xmm0     # 0xb1a8
movsd %xmm0, 0x140(%rsp)
movsd 0x99a1(%rip), %xmm0     # 0xb1a0
movsd %xmm0, 0x148(%rsp)
movsd 0x9988(%rip), %xmm0     # 0xb198
movsd %xmm0, 0x150(%rsp)
movq 0x9a00(%rip), %rax      # 0xb220
movq %rax, 0x120(%rsp)
movq 0x99f9(%rip), %rax      # 0xb228
movq %rax, 0x128(%rsp)
leaq 0x160(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x130(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl $0x2, 0xa8(%rsp)
movl $0x5, 0xac(%rsp)
movl $0x15, 0xb0(%rsp)
movl $0x0, 0xb8(%rsp)
leaq 0xd0(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0x99f6(%rip), %rax      # 0xb290
movq %rax, 0x70(%rsp)
movq 0x99f2(%rip), %rax      # 0xb298
movq %rax, 0x78(%rsp)
movq 0x99ee(%rip), %rax      # 0xb2a0
movq %rax, 0x80(%rsp)
movq 0x99e7(%rip), %rax      # 0xb2a8
movq %rax, 0x88(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x50(%rsp)
movq $0x0, 0x58(%rsp)
movl $0x2, 0x60(%rsp)
movl $0x2, 0x64(%rsp)
movl $0x15, 0x68(%rsp)
movq 0x9985(%rip), %rax      # 0xb280
movq %rax, 0x30(%rsp)
movq 0x9981(%rip), %rax      # 0xb288
movq %rax, 0x38(%rsp)
leaq 0x120(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x50(%rsp), %rdi
callq 0x5390
leaq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl 0x60(%rsp), %edx
xorl %eax, %eax
movl %eax, %ecx
movl $0x2c, %r8d
movl $0x1, %r9d
callq 0x8ec0
leaq 0x120(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x5660
movsd %xmm0, 0x28(%rsp)
movsd 0x28(%rsp), %xmm2
xorps %xmm1, %xmm1
xorl %eax, %eax
movl %eax, %edi
movl $0x30, %esi
movaps %xmm1, %xmm0
callq 0x92c0
movq %rsp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
leaq 0x120(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0x98(%rsp), %rsi
callq 0x56a0
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
movl $0x2, %edx
xorl %eax, %eax
movl %eax, %ecx
movl $0x36, %r8d
movl $0x1, %r9d
callq 0x8ec0
addq $0x1b8, %rsp            # imm = 0x1B8
retq
nop