Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
IMatrixConverter.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7
8#pragma once
9
10#include <alien/core/backend/BackEnd.h>
12#include <alien/utils/ObjectWithTrace.h>
13
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17namespace Alien
18{
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
35{
36 public:
40 typedef Alien::BackEndId BackEndId;
41
42 public:
44 virtual ~IMatrixConverter() {}
45
46 public:
51 virtual BackEndId sourceBackend() const = 0;
52
57 virtual BackEndId targetBackend() const = 0;
58
64 virtual void convert(const IMatrixImpl* sourceImpl, IMatrixImpl* targetImpl) const = 0;
65
66 public:
75 template <typename T>
76 static T& cast(IMatrixImpl* impl,[[maybe_unused]] BackEndId backend)
77 {
78 ALIEN_ASSERT((impl != NULL), ("Null implementation"));
79 ALIEN_ASSERT((impl->backend() == backend), ("Bad backend"));
80 T* t = dynamic_cast<T*>(impl);
81 ALIEN_ASSERT((t != NULL), ("Bad dynamic cast"));
82 return *t;
83 }
84
93 template <typename T>
94 static const T& cast(const IMatrixImpl* impl,[[maybe_unused]] BackEndId backend)
95 {
96 ALIEN_ASSERT((impl != NULL), ("Null implementation"));
97 ALIEN_ASSERT((impl->backend() == backend), ("Bad backend"));
98 const T* t = dynamic_cast<const T*>(impl);
99 ALIEN_ASSERT((t != NULL), ("Bad dynamic cast"));
100 return *t;
101 }
102};
103
104template<typename SourceTagT,
105 typename TargetTagT>
107{
108public:
109 using SourceMatrixType = typename AlgebraTraits<SourceTagT>::matrix_type;
110 using TargetMatrixType = typename AlgebraTraits<TargetTagT>::matrix_type;
112 virtual ~MatrixConverterT() {}
113
114 virtual void convert(SourceMatrixType const& source, TargetMatrixType& target) const = 0 ;
115};
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
118
119} // namespace Alien
120
121/*---------------------------------------------------------------------------*/
122/*---------------------------------------------------------------------------*/
IMatrixImpl.h.
Matrices converter.
virtual void convert(const IMatrixImpl *sourceImpl, IMatrixImpl *targetImpl) const =0
Convert a matrix from one format to another.
virtual BackEndId sourceBackend() const =0
Get the source backend id.
virtual ~IMatrixConverter()
Free resources.
Alien::BackEndId BackEndId
Type of matrix backend.
static const T & cast(const IMatrixImpl *impl, BackEndId backend)
Const cast a matrix implementation in its actual type.
virtual BackEndId targetBackend() const =0
Get the target backend id.
Alien::IMatrixImpl IMatrixImpl
Type of matrix implementation.
static T & cast(IMatrixImpl *impl, BackEndId backend)
Cast a matrix implementation in its actual type.
Interface to handle abstract matrices implementation.
Definition IMatrixImpl.h:47
virtual BackEndId backend() const
Definition IMatrixImpl.h:94
virtual ~MatrixConverterT()
Free resources.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17