<commit_before>///////////////////////////////////////////////////////////////////////////////
//
// File: StandardMatrix.hpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Interface classes for matrices
//
///////////////////////////////////////////////////////////////////////////////

#ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_STANDARD_MATRIX_HPP
#define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_STANDARD_MATRIX_HPP

#include <LibUtilities/LinearAlgebra/MatrixBase.hpp>
#include <LibUtilities/LinearAlgebra/FullMatrixStoragePolicy.hpp>
#include <LibUtilities/LinearAlgebra/DiagonalMatrixStoragePolicy.hpp>
#include <LibUtilities/LinearAlgebra/TriangularMatrixStoragePolicy.hpp>
#include <LibUtilities/LinearAlgebra/PointerWrapper.h>
#include <LibUtilities/LinearAlgebra/NekVectorFwd.hpp>
#include <LibUtilities/ExpressionTemplates/ExpressionTemplates.hpp>

namespace Nektar
{
     
    template<typename DataType, typename StorageType>
    class NekMatrix<DataType, StorageType, StandardMatrixTag> : public Matrix<DataType>
    {
        public:
            typedef Matrix<DataType> BaseType;
            typedef NekMatrix<DataType, StorageType, StandardMatrixTag> ThisType;
            typedef MatrixStoragePolicy<DataType, StorageType> StoragePolicy;
            typedef DataType NumberType;
            typedef typename StoragePolicy::PolicySpecificDataHolderType PolicySpecificDataHolderType;

            typedef typename StoragePolicy::GetValueReturnType GetValueType;
            typedef typename boost::call_traits<DataType>::const_reference ConstGetValueType;
            
        public:
            NekMatrix() :
                BaseType(0, 0),
                m_data(StoragePolicy::Initialize()),
                m_wrapperType(eCopy),
                m_policySpecificData(),
                m_transpose('N')
            {
            }
            
            NekMatrix(unsigned int rows, unsigned int columns, const PolicySpecificDataHolderType& policySpecificData = PolicySpecificDataHolderType()) :
                BaseType(rows, columns),
                m_data(StoragePolicy::Initialize(rows, columns, policySpecificData)),
                m_wrapperType(eCopy),
                m_policySpecificData(policySpecificData),
                m_transpose('N')
            {
            }

            NekMatrix(unsigned int rows, unsigned int columns, typename boost::call_traits<DataType>::const_reference initValue,
                      const PolicySpecificDataHolderType& policySpecificData = PolicySpecificDataHolderType()) :
                BaseType(rows, columns),
                m_data(StoragePolicy::Initialize(rows, columns, initValue, policySpecificData)),
                m_wrapperType(eCopy),
                m_policySpecificData(policySpecificData),
                m_transpose('N')
            {
            }
            
            NekMatrix(unsigned int rows, unsigned int columns, const DataType* data,
                      const PolicySpecificDataHolderType& policySpecificData = PolicySpecificDataHolderType()) :
                BaseType(rows, columns),
                m_data(StoragePolicy::Initialize(rows, columns, data, policySpecificData)),
                m_wrapperType(eCopy),
                m_policySpecificData(policySpecificData),
                m_transpose('N')
            {
            }
            
            NekMatrix(unsigned int rows, unsigned int columns, const ConstArray<OneD, DataType>& d,
                      const PolicySpecificDataHolderType& policySpecificData = PolicySpecificDataHolderType()) :
                BaseType(rows, columns),
                m_data(StoragePolicy::Initialize(rows, columns, d, policySpecificData)),
                m_wrapperType(eCopy),
                m_policySpecificData(policySpecificData),
                m_transpose('N')
            {
            }
            
            NekMatrix(unsigned int rows, unsigned int columns, const Array<OneD, DataType>& d, PointerWrapper wrapperType = eCopy,
                      const PolicySpecificDataHolderType& policySpecificData = PolicySpecificDataHolderType()) :
                BaseType(rows, columns),
                m_data(wrapperType == eCopy ? StoragePolicy::Initialize(rows, columns, d, policySpecificData) : d),
                m_wrapperType(wrapperType),
                m_policySpecificData(policySpecificData),
                m_transpose('N')
            {
            }
            
            NekMatrix(const ThisType& rhs) :
                BaseType(rhs),
                m_data(),
                m_wrapperType(rhs.m_wrapperType),
                m_policySpecificData(rhs.m_policySpecificData),
                m_transpose(rhs.m_transpose)
            {
                if( m_wrapperType == eCopy )
                {
                    m_data = StoragePolicy::Initialize(this->GetRows(), this->GetColumns(), m_policySpecificData);
                    CopyArray(rhs.m_data, m_data);
                }
                else
                {
                    m_data = rhs.m_data;
                }
            }
            
            #ifdef NEKTAR_USE_EXPRESSION_TEMPLATES
                template<typename ExpressionPolicyType>
                NekMatrix(const Expression<ExpressionPolicyType>& rhs) :
                    BaseType(rhs.GetMetadata().Rows, rhs.GetMetadata().Columns),
                    m_data(),
                    m_wrapperType(eCopy),
                    m_policySpecificData(),
                    m_transpose('N')
                {
                    BOOST_MPL_ASSERT(( boost::is_same<typename Expression<ExpressionPolicyType>::ResultType, NekMatrix<DataType, StorageType, StandardMatrixTag> > ));
                    m_data = StoragePolicy::Initialize(this->GetRows(), this->GetColumns(), m_policySpecificData);
                    rhs.Apply(*this);
                }
            #endif //NEKTAR_USE_EXPRESSION_TEMPLATES

            MatrixStorage GetStorageType() const 
            {
                return static_cast<MatrixStorage>(ConvertToMatrixStorageEnum<StorageType>::Value);
            }
            
            // TODO - Copy constructors from other types of matrices.
            
            ThisType& Assign(unsigned int newRows, unsigned int newColumns, Array<OneD, DataType>& data)
            {
                this->Resize(newRows, newColumns);
                m_wrapperType = eWrapper;
                m_policySpecificData = PolicySpecificDataHolderType();
                m_transpose = 'N';
                m_data = data;
            }
             
            ThisType& operator=(const ThisType& rhs)
            {
                if( this != &rhs )
                {
                    BaseType::operator=(rhs);
                    m_policySpecificData = rhs.m_policySpecificData;
                    if( m_wrapperType == eCopy  )
                    {
                        // If the current vector is a matrix, then regardless of the rhs type 
                        // we just copy over the values, resizing if needed.
                        if( m_data.num_elements() != rhs.m_data.num_elements() )
                        {
                            m_data = Array<OneD, DataType>(rhs.m_data.num_elements());
                        }
                    }<commit_msg>Fixed compile error in assignment from shared array operator.<commit_after>///////////////////////////////////////////////////////////////////////////////
//
// File: StandardMatrix.hpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Interface classes for matrices
//
///////////////////////////////////////////////////////////////////////////////

#ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_STANDARD_MATRIX_HPP
#define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_STANDARD_MATRIX_HPP

#include <LibUtilities/LinearAlgebra/MatrixBase.hpp>
#include <LibUtilities/LinearAlgebra/FullMatrixStoragePolicy.hpp>
#include <LibUtilities/LinearAlgebra/DiagonalMatrixStoragePolicy.hpp>
#include <LibUtilities/LinearAlgebra/TriangularMatrixStoragePolicy.hpp>
#include <LibUtilities/LinearAlgebra/PointerWrapper.h>
#include <LibUtilities/LinearAlgebra/NekVectorFwd.hpp>
#include <LibUtilities/ExpressionTemplates/ExpressionTemplates.hpp>

namespace Nektar
{
     
    template<typename DataType, typename StorageType>
    class NekMatrix<DataType, StorageType, StandardMatrixTag> : public Matrix<DataType>
    {
        public:
            typedef Matrix<DataType> BaseType;
            typedef NekMatrix<DataType, StorageType, StandardMatrixTag> ThisType;
            typedef MatrixStoragePolicy<DataType, StorageType> StoragePolicy;
            typedef DataType NumberType;
            typedef typename StoragePolicy::PolicySpecificDataHolderType PolicySpecificDataHolderType;

            typedef typename StoragePolicy::GetValueReturnType GetValueType;
            typedef typename boost::call_traits<DataType>::const_reference ConstGetValueType;
            
        public:
            NekMatrix() :
                BaseType(0, 0),
                m_data(StoragePolicy::Initialize()),
                m_wrapperType(eCopy),
                m_policySpecificData(),
                m_transpose('N')
            {
            }
            
            NekMatrix(unsigned int rows, unsigned int columns, const PolicySpecificDataHolderType& policySpecificData = PolicySpecificDataHolderType()) :
                BaseType(rows, columns),
                m_data(StoragePolicy::Initialize(rows, columns, policySpecificData)),
                m_wrapperType(eCopy),
                m_policySpecificData(policySpecificData),
                m_transpose('N')
            {
            }

            NekMatrix(unsigned int rows, unsigned int columns, typename boost::call_traits<DataType>::const_reference initValue,
                      const PolicySpecificDataHolderType& policySpecificData = PolicySpecificDataHolderType()) :
                BaseType(rows, columns),
                m_data(StoragePolicy::Initialize(rows, columns, initValue, policySpecificData)),
                m_wrapperType(eCopy),
                m_policySpecificData(policySpecificData),
                m_transpose('N')
            {
            }
            
            NekMatrix(unsigned int rows, unsigned int columns, const DataType* data,
                      const PolicySpecificDataHolderType& policySpecificData = PolicySpecificDataHolderType()) :
                BaseType(rows, columns),
                m_data(StoragePolicy::Initialize(rows, columns, data, policySpecificData)),
                m_wrapperType(eCopy),
                m_policySpecificData(policySpecificData),
                m_transpose('N')
            {
            }
            
            NekMatrix(unsigned int rows, unsigned int columns, const ConstArray<OneD, DataType>& d,
                      const PolicySpecificDataHolderType& policySpecificData = PolicySpecificDataHolderType()) :
                BaseType(rows, columns),
                m_data(StoragePolicy::Initialize(rows, columns, d, policySpecificData)),
                m_wrapperType(eCopy),
                m_policySpecificData(policySpecificData),
                m_transpose('N')
            {
            }
            
            NekMatrix(unsigned int rows, unsigned int columns, const Array<OneD, DataType>& d, PointerWrapper wrapperType = eCopy,
                      const PolicySpecificDataHolderType& policySpecificData = PolicySpecificDataHolderType()) :
                BaseType(rows, columns),
                m_data(wrapperType == eCopy ? StoragePolicy::Initialize(rows, columns, d, policySpecificData) : d),
                m_wrapperType(wrapperType),
                m_policySpecificData(policySpecificData),
                m_transpose('N')
            {
            }
            
            NekMatrix(const ThisType& rhs) :
                BaseType(rhs),
                m_data(),
                m_wrapperType(rhs.m_wrapperType),
                m_policySpecificData(rhs.m_policySpecificData),
                m_transpose(rhs.m_transpose)
            {
                if( m_wrapperType == eCopy )
                {
                    m_data = StoragePolicy::Initialize(this->GetRows(), this->GetColumns(), m_policySpecificData);
                    CopyArray(rhs.m_data, m_data);
                }
                else
                {
                    m_data = rhs.m_data;
                }
            }
            
            #ifdef NEKTAR_USE_EXPRESSION_TEMPLATES
                template<typename ExpressionPolicyType>
                NekMatrix(const Expression<ExpressionPolicyType>& rhs) :
                    BaseType(rhs.GetMetadata().Rows, rhs.GetMetadata().Columns),
                    m_data(),
                    m_wrapperType(eCopy),
                    m_policySpecificData(),
                    m_transpose('N')
                {
                    BOOST_MPL_ASSERT(( boost::is_same<typename Expression<ExpressionPolicyType>::ResultType, NekMatrix<DataType, StorageType, StandardMatrixTag> > ));
                    m_data = StoragePolicy::Initialize(this->GetRows(), this->GetColumns(), m_policySpecificData);
                    rhs.Apply(*this);
                }
            #endif //NEKTAR_USE_EXPRESSION_TEMPLATES

            MatrixStorage GetStorageType() const 
            {
                return static_cast<MatrixStorage>(ConvertToMatrixStorageEnum<StorageType>::Value);
            }
            
            // TODO - Copy constructors from other types of matrices.
            
            ThisType& Assign(unsigned int newRows, unsigned int newColumns, Array<OneD, DataType>& data)
            {
                this->Resize(newRows, newColumns);
                m_wrapperType = eWrapper;
                m_policySpecificData = PolicySpecificDataHolderType();
                m_transpose = 'N';
                m_data = data;
                return *this;
            }
             
            ThisType& operator=(const ThisType& rhs)
            {
                if( this != &rhs )
                {
                    BaseType::operator=(rhs);
                    m_policySpecificData = rhs.m_policySpecificData;
                    if( m_wrapperType == eCopy  )
                    {
                        // If the current vector is a matrix, then regardless of the rhs type 
                        // we just copy over the values, resizing if needed.
                        if( m_data.num_elements() != rhs.m_data.num_elements() )
                        {
                            m_data = Array<OneD, DataType>(rhs.m_data.num_elements());
                        }
                    }
{'fraction_non_alphanumeric': 0.09469178082191781, 'fraction_numerical': 0.0006849315068493151, 'mean_word_length': 1.953641267700607, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2647535', 'n_tokens_mistral': 4344, 'n_tokens_neox': 4067, 'n_words': 1042}