/*
 * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
 *
 * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
 * property and proprietary rights in and to this material, related
 * documentation and any modifications thereto. Any use, reproduction,
 * disclosure or distribution of this material and related documentation
 * without an express license agreement from NVIDIA CORPORATION or
 * its affiliates is strictly prohibited.
 */

#pragma once

namespace __nvhpc_std {

namespace __lp = __lapack_std;

// Scaling/conjugate/transpose has been done before calling this!
template<class _SizeType,
         class _ElementTypeA,
         ::std::size_t ... _extA,
         class _LayoutA,
         class _AccessorA,
         class _ElementTypeB,
         ::std::size_t ... _extB,
         class _LayoutB,
         class _AccessorB>
void __copy_matrix_impl( __nvhpc_exec<__blas_exec_space> /* __exec */
                       , char __uplo
                       , std::mdspan< _ElementTypeA, std::extents<_SizeType, _extA ...>, _LayoutA, _AccessorA > __A
                       , std::mdspan< _ElementTypeB, std::extents<_SizeType, _extB ...>, _LayoutB, _AccessorB > __B
                       )
{
#ifdef STDBLAS_VERBOSE
    __STDBLAS_BACKEND_MESSAGE( lacpy, BLAS );
#endif
    static_assert (__A.rank() == 2);
    static_assert (__B.rank() == 2);

    using __valA_t = typename decltype(__A)::value_type;

    __lp::__lapack_lacpy( &__uplo
                        , __A.extent(0)
                        , __A.extent(1)
                        , __A.data_handle()
                        , std::linalg::__get_leading_dim( __A )
                        , __B.data_handle()
                        , std::linalg::__get_leading_dim( __B )
                        );
}

}
