chromium/third_party/eigen3/src/Eigen/src/Core/util/BlasUtil.h

// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2009-2010 Gael Guennebaud <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef EIGEN_BLASUTIL_H
#define EIGEN_BLASUTIL_H

// This file contains many lightweight helper classes used to
// implement and control fast level 2 and level 3 BLAS-like routines.

// IWYU pragma: private
#include "../InternalHeaderCheck.h"

namespace Eigen {

namespace internal {

// forward declarations
template <typename LhsScalar, typename RhsScalar, typename Index, typename DataMapper, int mr, int nr,
          bool ConjugateLhs = false, bool ConjugateRhs = false>
struct gebp_kernel;

template <typename Scalar, typename Index, typename DataMapper, int nr, int StorageOrder, bool Conjugate = false,
          bool PanelMode = false>
struct gemm_pack_rhs;

template <typename Scalar, typename Index, typename DataMapper, int Pack1, int Pack2, typename Packet, int StorageOrder,
          bool Conjugate = false, bool PanelMode = false>
struct gemm_pack_lhs;

template <typename Index, typename LhsScalar, int LhsStorageOrder, bool ConjugateLhs, typename RhsScalar,
          int RhsStorageOrder, bool ConjugateRhs, int ResStorageOrder, int ResInnerStride>
struct general_matrix_matrix_product;

template <typename Index, typename LhsScalar, typename LhsMapper, int LhsStorageOrder, bool ConjugateLhs,
          typename RhsScalar, typename RhsMapper, bool ConjugateRhs, int Version = Specialized>
struct general_matrix_vector_product;

template <typename From, typename To>
struct get_factor {};

get_factor<Scalar, typename NumTraits<Scalar>::Real>;

template <typename Scalar, typename Index>
class BlasVectorMapper {};

template <typename Scalar, typename Index, int AlignmentType, int Incr = 1>
class BlasLinearMapper;

BlasLinearMapper<Scalar, Index, AlignmentType>;

// Lightweight helper class to access matrix coefficients.
template <typename Scalar, typename Index, int StorageOrder, int AlignmentType = Unaligned, int Incr = 1>
class blas_data_mapper;

// TMP to help PacketBlock store implementation.
// There's currently no known use case for PacketBlock load.
// The default implementation assumes ColMajor order.
// It always store each packet sequentially one `stride` apart.
template <typename Index, typename Scalar, typename Packet, int n, int idx, int StorageOrder>
struct PacketBlockManagement {};

// PacketBlockManagement specialization to take care of RowMajor order without ifs.
PacketBlockManagement<Index, Scalar, Packet, n, idx, RowMajor>;

PacketBlockManagement<Index, Scalar, Packet, n, -1, StorageOrder>;

PacketBlockManagement<Index, Scalar, Packet, n, -1, RowMajor>;

blas_data_mapper<Scalar, Index, StorageOrder, AlignmentType, 1>;

// Implementation of non-natural increment (i.e. inner-stride != 1)
// The exposed API is not complete yet compared to the Incr==1 case
// because some features makes less sense in this case.
template <typename Scalar, typename Index, int AlignmentType, int Incr>
class BlasLinearMapper {};

template <typename Scalar, typename Index, int StorageOrder, int AlignmentType, int Incr>
class blas_data_mapper {};

// lightweight helper class to access matrix coefficients (const version)
template <typename Scalar, typename Index, int StorageOrder>
class const_blas_data_mapper : public blas_data_mapper<const Scalar, Index, StorageOrder> {};

/* Helper class to analyze the factors of a Product expression.
 * In particular it allows to pop out operator-, scalar multiples,
 * and conjugate */
template <typename XprType>
struct blas_traits {};

// pop conjugate
blas_traits<CwiseUnaryOp<scalar_conjugate_op<Scalar>, NestedXpr>>;

// pop scalar multiple
blas_traits<CwiseBinaryOp<scalar_product_op<Scalar>, const CwiseNullaryOp<scalar_constant_op<Scalar>, Plain>, NestedXpr>>;
blas_traits<CwiseBinaryOp<scalar_product_op<Scalar>, NestedXpr, const CwiseNullaryOp<scalar_constant_op<Scalar>, Plain>>>;
blas_traits<CwiseBinaryOp<scalar_product_op<Scalar>, const CwiseNullaryOp<scalar_constant_op<Scalar>, Plain1>, const CwiseNullaryOp<scalar_constant_op<Scalar>, Plain2>>>;

// pop opposite
blas_traits<CwiseUnaryOp<scalar_opposite_op<Scalar>, NestedXpr>>;

// pop/push transpose
blas_traits<Transpose<NestedXpr>>;

blas_traits<const T>;

template <typename T, bool HasUsableDirectAccess = blas_traits<T>::HasUsableDirectAccess>
struct extract_data_selector {};

extract_data_selector<T, false>;

template <typename T>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const typename T::Scalar* extract_data(const T& m) {}

/**
 * \c combine_scalar_factors extracts and multiplies factors from GEMM and GEMV products.
 * There is a specialization for booleans
 */
template <typename ResScalar, typename Lhs, typename Rhs>
struct combine_scalar_factors_impl {};
combine_scalar_factors_impl<bool, Lhs, Rhs>;

template <typename ResScalar, typename Lhs, typename Rhs>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ResScalar combine_scalar_factors(const ResScalar& alpha, const Lhs& lhs,
                                                                       const Rhs& rhs) {}
template <typename ResScalar, typename Lhs, typename Rhs>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE ResScalar combine_scalar_factors(const Lhs& lhs, const Rhs& rhs) {}

}  // end namespace internal

}  // end namespace Eigen

#endif  // EIGEN_BLASUTIL_H