// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x190, %rsp            # imm = 0x190
leaq 0x59b9(%rip), %rsi      # 0x71b0
leaq 0x140(%rsp), %rax
movl $0xa, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
movaps 0x58df(%rip), %xmm0     # 0x70f0
leaq 0x90(%rsp), %rcx
movaps %xmm0, (%rcx)
movaps 0x58dd(%rip), %xmm0     # 0x7100
movaps %xmm0, 0x10(%rcx)
movabsq $0x4026000000000000, %rdx # imm = 0x4026000000000000
movq %rdx, 0x20(%rcx)
movaps 0x58f4(%rip), %xmm0     # 0x7130
leaq 0x40(%rsp), %rbx
movaps %xmm0, (%rbx)
leaq 0xb8(%rsp), %r14
movq %rax, (%r14)
movq %rcx, 0x8(%r14)
movabsq $0x500000002, %rax      # imm = 0x500000002
movq %rax, 0x10(%r14)
movl $0x15, %eax
movl %eax, 0x18(%r14)
movl $0x0, 0x20(%r14)
leaq 0xf0(%rsp), %rcx
movq %rcx, 0x30(%r14)
movaps 0x598b(%rip), %xmm0     # 0x7210
leaq 0x50(%rsp), %rcx
movaps %xmm0, 0x10(%rcx)
movaps 0x596b(%rip), %xmm0     # 0x7200
movaps %xmm0, (%rcx)
leaq 0x70(%rsp), %r15
movq %rcx, (%r15)
movq $0x0, 0x8(%r15)
movabsq $0x200000002, %rcx      # imm = 0x200000002
movq %rcx, 0x10(%r15)
movl %eax, 0x18(%r15)
movaps 0x58df(%rip), %xmm0     # 0x71a0
leaq 0x20(%rsp), %r12
movaps %xmm0, (%r12)
leaq 0x30(%rsp), %r13
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x4034
movl 0x10(%r15), %edx
movl $0x2c, %r8d
movq %r12, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
movl $0x1, %r9d
callq 0x6030
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41eb
movaps %xmm0, %xmm2
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
movl $0x30, %esi
xorl %edi, %edi
callq 0x61fc
movq %rsp, %r15
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
leaq 0x10(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x41fb
movl $0x36, %r8d
movq %r15, %rdi
movq %r12, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
movl $0x1, %r9d
callq 0x6030
addq $0x190, %rsp            # imm = 0x190
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop