Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ArrayShape.cc
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/* ArrayShape.cc (C) 2000-2023 */
9/* */
10/* Represents the shape of an array. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArrayShape.h"
15
16#include "arcane/utils/ArgumentException.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/CheckedConvert.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29ArrayShape::
30ArrayShape(Span<const Int32> v)
31{
32 _set(v.smallView());
33}
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
40{
41 if (nb_dim < 0 || nb_dim >= MAX_NB_DIMENSION)
42 ARCANE_THROW(ArgumentException, "Bad value for argument 'nb_value'");
43 m_nb_dim = nb_dim;
44}
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49void ArrayShape::
51{
52 Int32 vsize = v.size();
53 if (vsize >= MAX_NB_DIMENSION)
54 ARCANE_FATAL("Bad size '{0}' for shape. Maximum size is {1}", vsize, MAX_NB_DIMENSION);
55 m_nb_dim = CheckedConvert::toInt32(vsize);
56 for (Int32 i = 0; i < vsize; ++i)
57 m_dims[i] = v[i];
58}
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
65{
66 _set(dims.smallView());
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72bool ArrayShape::
73_isEqual(const ArrayShape& s1, const ArrayShape& s2)
74{
75 if (s1.m_nb_dim != s2.m_nb_dim)
76 return false;
77 for (Int32 i = 0; i < s1.m_nb_dim; ++i) {
78 if (s1.m_dims[i] != s2.m_dims[i])
79 return false;
80 }
81 return true;
82}
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
86
87void ArrayShape::
88_print(std::ostream& o) const
89{
90 o << "{ ";
91 for (Int32 i = 0; i < m_nb_dim; ++i) {
92 if (i != 0)
93 o << ", ";
94 o << m_dims[i];
95 }
96 o << " }";
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102} // End namespace Arcane
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Array shape.
Definition ArrayShape.h:42
void setNbDimension(Int32 nb_value)
Sets the rank of the shape.
Definition ArrayShape.cc:39
void setDimensions(Span< const Int32 > dims)
Sets the number and values of the dimensions.
Definition ArrayShape.cc:64
View of an array of elements of type T.
Definition Span.h:805
constexpr view_type smallView()
Constant view of this view.
Definition Span.h:392
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Definition Span.h:327
View of an array of elements of type T.
Definition Span.h:635
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int32_t Int32
Signed integer type of 32 bits.