//                                               -*- C++ -*-
/**
 *  @file  SquareComplexMatrix.cxx
 *  @brief SquareComplexMatrix implements the classical mathematical square matrix
 *
 *  Copyright (C) 2005-2014 Airbus-EDF-Phimeca
 *
 *  This library is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @author schueller
 *  @date   2012-07-16 15:59:45 +0200 (Mon, 16 Jul 2012)
 */
#include "SquareComplexMatrix.hxx"
#include "HermitianMatrix.hxx"
#include "IdentityMatrix.hxx"

BEGIN_NAMESPACE_OPENTURNS

CLASSNAMEINIT(SquareComplexMatrix);

/* Default constructor */
SquareComplexMatrix::SquareComplexMatrix()
  : ComplexMatrix(0, 0)
{
  // Nothing to do
}


/* Constructor with size (dim, which is the same for nbRows_ and nbColumns_ )*/
SquareComplexMatrix::SquareComplexMatrix(const UnsignedLong dimension)
  : ComplexMatrix(dimension, dimension)
{
  // Nothing to do
}

/* Constructor from external collection */
/* If the dimensions of the matrix and of the collection */
/* do not match, either the collection is truncated */
/* or the rest of the matrix is filled with zeros */
SquareComplexMatrix::SquareComplexMatrix(const UnsignedLong dimension,
    const NumericalComplexCollection & elementsValues)
  : ComplexMatrix(dimension, dimension, elementsValues)
{
  // Nothing to do
}


/* Constructor with implementation */
SquareComplexMatrix::SquareComplexMatrix(const Implementation & i)
  : ComplexMatrix(i)
{
  // Nothing to do
}


/* String converter */
String SquareComplexMatrix::__repr__() const
{
  return OSS() << "class=" << getClassName()
         << " dimension=" << this->getDimension()
         << " implementation=" << getImplementation()->__repr__();
}

/* Get the dimension of the matrix */
const UnsignedLong SquareComplexMatrix::getDimension() const
{
  return getImplementation()->getDimension();
}

/* SquareComplexMatrix transpose */
SquareComplexMatrix SquareComplexMatrix::transpose () const
{
  // Quick return for empty or scalar SquareComplexMatrix
  if (getDimension() <= 1) return (*this);
  return Implementation(getImplementation()->transpose().clone());
}

SquareComplexMatrix SquareComplexMatrix::conjugate () const
{
  // Quick return for empty or scalar SquareComplexMatrix
  if (getDimension() <= 1) return (*this);
  return Implementation(getImplementation()->conjugate().clone());
}

SquareComplexMatrix SquareComplexMatrix::conjugateTranspose () const
{
  // Quick return for empty or scalar SquareComplexMatrix
  if (getDimension() <= 1) return (*this);
  return Implementation(getImplementation()->conjugateTranspose().clone());
}

/* Matrix additions (must have the same dimensions) */
SquareComplexMatrix SquareComplexMatrix::operator+ (const SquareComplexMatrix & m) const
{
  return Implementation((*getImplementation() + * (m.getImplementation()) ).clone());
}

SquareComplexMatrix SquareComplexMatrix::operator+ (const HermitianMatrix & m) const
{
  m.getImplementation()->hermitianize();
  return Implementation((*getImplementation() + * (m.getImplementation()) ).clone());
}

/* Matrix substractions (must have the same dimensions) */
SquareComplexMatrix SquareComplexMatrix::operator- (const SquareComplexMatrix & m) const
{
  return Implementation((*getImplementation() - * (m.getImplementation()) ).clone());
}

SquareComplexMatrix SquareComplexMatrix::operator- (const HermitianMatrix & m) const
{
  m.getImplementation()->hermitianize();
  return Implementation((*getImplementation() - * (m.getImplementation()) ).clone());
}

/* Matrix multiplications (must have consistent dimensions) */
SquareComplexMatrix SquareComplexMatrix::operator* (const SquareComplexMatrix & m) const
{
  return Implementation((getImplementation()->genProd(*(m.getImplementation())) ).clone());
}

ComplexMatrix SquareComplexMatrix::operator* (const ComplexMatrix & m) const
{
  return Implementation((getImplementation()->genProd(*(m.getImplementation())) ).clone());

}
SquareComplexMatrix SquareComplexMatrix::operator* (const HermitianMatrix & m) const
{
  return Implementation(getImplementation()->hermProd(*(m.getImplementation()), 'R').conjugateTranspose().clone());
}

SquareComplexMatrix SquareComplexMatrix::operator* (const IdentityMatrix & m) const
{
  return *this;
}


/* Multiplication with a NumericalPoint (must have consistent dimensions) */
SquareComplexMatrix::NumericalComplexCollection SquareComplexMatrix::operator * (const NumericalPoint & pt) const
{
  return getImplementation()->genVectProd(pt) ;
}

/* Multiplication with a NumericalPoint (must have consistent dimensions) */
SquareComplexMatrix::NumericalComplexCollection SquareComplexMatrix::operator * (const NumericalComplexCollection & pt) const
{
  return getImplementation()->genVectProd(pt) ;
}

SquareComplexMatrix::NumericalComplexCollection SquareComplexMatrix::operator * (const NumericalScalarCollection & pt) const
{
  return getImplementation()->genVectProd(pt) ;
}



/* Multiplication with a NumericalComplex */
SquareComplexMatrix SquareComplexMatrix::operator * (const NumericalComplex s) const
{
  return Implementation((*getImplementation() * s ).clone());
}

/* Division by a NumericalComplex*/
SquareComplexMatrix SquareComplexMatrix::operator / (const NumericalComplex s) const
{
  return Implementation((*getImplementation() / s ).clone());
}

/* SquareComplexMatrix integer power */
SquareComplexMatrix SquareComplexMatrix::power(const UnsignedLong n) const
{
  return Implementation(getImplementation()->genPower(n).clone());
}


END_NAMESPACE_OPENTURNS
