// Created by GS <sgazeos@gmail.com> at 12/20/2019
//
#include<op_boilerplate.h>
#include<ops/declarable/CustomOperations.h>
#include<ops/declarable/helpers/qr.h>
#if NOT_EXCLUDED(OP_qr)
namespacend4j{
namespaceops{
CUSTOM_OP_IMPL(qr,1,2,false,0,0){
autoinput=INPUT_VARIABLE(0);
autooutputQ=OUTPUT_VARIABLE(0);
autooutputR=OUTPUT_VARIABLE(1);
autofullMatricies=false;
if(block.getBArguments()->size())
fullMatricies=B_ARG(0);
REQUIRE_TRUE(input->rankOf()>=2,0,"qr: The rank of input array should not be less than 2, but %i is given",input->rankOf());
REQUIRE_TRUE((fullMatricies&&outputQ->sizeAt(-1)==input->sizeAt(-2))||(!fullMatricies&&outputQ->isSameShape(input)),0,"qr: The last dimmensions should be equal to result Q, but %i and %i are given",outputQ->sizeAt(-1),input->sizeAt(-2));
REQUIRE_TRUE((fullMatricies&&outputR->sizeAt(-1)==input->sizeAt(-1))||(!fullMatricies&&outputR->sizeAt(-1)==outputR->sizeAt(-2)),0,"qr: The last dimmensions should be equal to result R, but %i and %i are given",outputR->sizeAt(-1),input->sizeAt(-1));