Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
NumArrayUtils.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/* NumArrayUtils.cc (C) 2000-2022 */
9/* */
10/* Utility functions for NumArray. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/NumArrayUtils.h"
15#include "arcane/utils/NumArray.h"
16#include "arcane/utils/IOException.h"
17
18#include "arcane/utils/internal/ValueConvertInternal.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
29{
30
31namespace
32{
33 template <typename DataType> void
34 _readFromText(NumArray<DataType, MDDim1>& num_array, std::istream& input)
35 {
37 if (builtInGetArrayValueFromStream(v, input))
38 ARCANE_THROW(IOException, "Error filling NumArray with text file");
39 MDSpan<DataType, MDDim1> data(v.data(), v.size());
40 num_array.resize(v.size());
41 num_array.copy(data);
42 }
43
44} // namespace
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
50extern "C++" ARCANE_UTILS_EXPORT void
51readFromText(NumArray<double, MDDim1>& v, std::istream& input)
52{
53 _readFromText(v, input);
54}
55
57extern "C++" ARCANE_UTILS_EXPORT void
58readFromText(NumArray<Int32, MDDim1>& v, std::istream& input)
59{
60 _readFromText(v, input);
61}
62
64extern "C++" ARCANE_UTILS_EXPORT void
65readFromText(NumArray<Int64, MDDim1>& v, std::istream& input)
66{
67 _readFromText(v, input);
68}
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73} // namespace Arcane::NumArrayUtils
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
Integer size() const
Number of elements in the vector.
const T * data() const
Access to the root of the array without any protection.
Exception when an input/output error is detected.
Definition IOException.h:34
Base class for multi-dimensional views.
Multi-dimensional arrays for numerical types accessible on accelerators.
void copy(SmallSpan< const DataType > rhs)
Copies the values from rhs into the instance.
void resize(Int32 dim1_size)
Resizes the array without keeping current values.
1D data vector with value semantics (STL style).
Utility functions for NumArray.
void readFromText(NumArray< double, MDDim1 > &v, std::istream &input)
Fills v with the values from input.