Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
NumArrayData.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/* NumArrayData.cc (C) 2000-2024 */
9/* */
10/* Data of type 'NumArray'. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
15#include "arccore/base/Ref.h"
16
17#include "arcane/utils/NumArray.h"
18#include "arcane/utils/NotSupportedException.h"
19#include "arcane/utils/Real2.h"
20#include "arcane/utils/Real2x2.h"
21#include "arcane/utils/Real3.h"
22#include "arcane/utils/Real3x3.h"
23#include "arcane/utils/IHashAlgorithm.h"
24#include "arcane/utils/NotImplementedException.h"
25#include "arcane/utils/ArgumentException.h"
26#include "arcane/utils/FatalErrorException.h"
27#include "arcane/utils/ITraceMng.h"
28#include "arcane/utils/CheckedConvert.h"
29#include "arcane/utils/ArrayShape.h"
30
31#include "arccore/base/Span2.h"
32
33#include "arcane/core/datatype/DataAllocationInfo.h"
34#include "arcane/core/datatype/IDataOperation.h"
35#include "arcane/core/datatype/DataStorageTypeInfo.h"
36#include "arcane/core/datatype/DataStorageBuildInfo.h"
37#include "arcane/core/datatype/DataTypeTraits.h"
38
39#include "arcane/core/ISerializer.h"
40#include "arcane/core/IData.h"
41#include "arcane/core/IDataVisitor.h"
42
43#include "arcane/core/internal/IDataInternal.h"
44
45#include "arcane/impl/SerializedData.h"
46#include "arcane/impl/DataStorageFactory.h"
47
48/*---------------------------------------------------------------------------*/
49/*---------------------------------------------------------------------------*/
50
51namespace Arcane
52{
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56
57namespace
58{
59 const Int64 SERIALIZE2_MAGIC_NUMBER = 0x923abd20;
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
68template <class DataType, int RankValue>
70: public IData
71{
72 public:
73
75 using ExtentType = typename MDDimType<RankValue>::DimType;
76
77 public:
78
81
84
87
90};
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
98template <class DataType, int RankValue>
99class NumArrayDataT
101, public INumArrayDataT<DataType, RankValue>
102{
104 class Impl;
105 friend Impl;
106
107 public:
108
109 typedef NumArrayDataT<DataType, RankValue> ThatClass;
110 typedef INumArrayDataT<DataType, RankValue> DataInterfaceType;
111 using ExtentType = typename MDDimType<RankValue>::DimType;
112
113 public:
114
116 : public IDataInternal
117 {
118 public:
119
120 void computeHash(DataHashInfo&) override
121 {
123 }
124 };
125
126 public:
127
128 explicit NumArrayDataT(ITraceMng* trace);
129 explicit NumArrayDataT(const DataStorageBuildInfo& dsbi);
131 ~NumArrayDataT() override;
132
133 public:
134
135 Integer dimension() const override { return 2; }
136 Integer multiTag() const override { return 0; }
138 void serialize(ISerializer* sbuf, IDataOperation* operation) override;
139 void serialize(ISerializer* sbuf, Int32ConstArrayView ids, IDataOperation* operation) override;
140 MDSpan<DataType, ExtentType> view() override { return m_value.mdspan(); }
141 MDSpan<const DataType, ExtentType> view() const override { return m_value.mdspan(); }
142 void resize(Integer new_size) override;
143 IData* clone() override { return _cloneTrue(); }
144 IData* cloneEmpty() override { return _cloneTrueEmpty(); };
145 Ref<IData> cloneRef() override { return makeRef(_cloneTrue()); }
146 Ref<IData> cloneEmptyRef() override { return makeRef(_cloneTrueEmpty()); }
147 DataStorageTypeInfo storageTypeInfo() const override;
149 {
150 auto* d = _cloneTrue();
151 return makeRef(d);
152 }
154 {
155 auto* d = _cloneTrueEmpty();
156 return makeRef(d);
157 }
158 void fillDefault() override;
159 void setName(const String& name) override;
160 Ref<ISerializedData> createSerializedDataRef(bool use_basic_type) const override;
162 void assignSerializedData(const ISerializedData* sdata) override;
163 void copy(const IData* data) override;
164 void swapValues(IData* data) override;
165 void computeHash(IHashAlgorithm* algo, ByteArray& output) const override;
166 ArrayShape shape() const override { return m_shape; }
167 void setShape(const ArrayShape& new_shape) override { m_shape = new_shape; }
168 void setAllocationInfo(const DataAllocationInfo& v) override { m_allocation_info = v; }
169 DataAllocationInfo allocationInfo() const override { return m_allocation_info; }
170 void visit(IArray2DataVisitor*)
171 {
172 ARCANE_THROW(NotSupportedException, "Can not visit array2 data with NumArray data");
173 }
174 void visit(IDataVisitor* visitor) override
175 {
176 ARCANE_UNUSED(visitor);
177 ARCANE_THROW(NotImplementedException, "visit(IDataVisitor*)");
178 }
180 {
181 ARCANE_THROW(NotSupportedException, "Can not visit scalar data with NumArray data");
182 }
184 {
185 ARCANE_THROW(NotSupportedException, "Can not visit array data with NumArray data");
186 }
188 {
189 ARCANE_THROW(NotSupportedException, "Can not visit array2 data with NumArray data");
190 }
191 IDataInternal* _commonInternal() override { return &m_internal; }
192
193 public:
194
195 void swapValuesDirect(ThatClass* true_data);
196
197 public:
198
199 static DataStorageTypeInfo staticStorageTypeInfo();
200
201 private:
202
204 ITraceMng* m_trace;
205 ArrayShape m_shape;
206 Internal m_internal;
207 DataAllocationInfo m_allocation_info;
208
209 private:
210
211 INumArrayDataT<DataType, RankValue>* _cloneTrue() const { return new ThatClass(*this); }
212 INumArrayDataT<DataType, RankValue>* _cloneTrueEmpty() const { return new ThatClass(m_trace); }
213 void _resizeDim1(Int32 dim1_size);
214 Int64 _getDim2Size() const;
215 Span2<DataType> _valueAsSpan2();
216 Span2<const DataType> _valueAsConstSpan2();
217};
218
219/*---------------------------------------------------------------------------*/
220/*---------------------------------------------------------------------------*/
221
222template <typename DataType, int RankValue> NumArrayDataT<DataType, RankValue>::
224: m_trace(trace)
225{
226}
227
228/*---------------------------------------------------------------------------*/
229/*---------------------------------------------------------------------------*/
230
231template <typename DataType, int RankValue> NumArrayDataT<DataType, RankValue>::
233: m_value(rhs.m_value)
234, m_trace(rhs.m_trace)
235, m_allocation_info(rhs.m_allocation_info)
236{
237}
238
239/*---------------------------------------------------------------------------*/
240/*---------------------------------------------------------------------------*/
241
242template <typename DataType, int RankValue> NumArrayDataT<DataType, RankValue>::
244: m_trace(dsbi.traceMng())
245{
246}
247
248/*---------------------------------------------------------------------------*/
249/*---------------------------------------------------------------------------*/
250
251template <typename DataType, int RankValue> NumArrayDataT<DataType, RankValue>::
253{
254}
255
256/*---------------------------------------------------------------------------*/
257/*---------------------------------------------------------------------------*/
258
259/*---------------------------------------------------------------------------*/
260/*---------------------------------------------------------------------------*/
261
262template <typename DataType, int RankValue> DataStorageTypeInfo NumArrayDataT<DataType, RankValue>::
264{
265 typedef DataTypeTraitsT<DataType> TraitsType;
266 eBasicDataType bdt = TraitsType::basicDataType();
267 Int32 nb_basic_type = TraitsType::nbBasicType();
268 Int32 dimension = RankValue;
269 Int32 multi_tag = 0;
270 String impl_name = "NumArray";
271 return DataStorageTypeInfo(bdt, nb_basic_type, dimension, multi_tag, impl_name);
272}
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
276
277template <typename DataType, int RankValue> DataStorageTypeInfo NumArrayDataT<DataType, RankValue>::
278storageTypeInfo() const
279{
280 return staticStorageTypeInfo();
281}
282
283/*---------------------------------------------------------------------------*/
284/*---------------------------------------------------------------------------*/
285
286template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
287_resizeDim1(Int32 dim1_size)
288{
289 // Retrieves the dimensions of the 'NumArray' and only modifies the first one
290 auto extents = m_value.extents();
291 extents.setExtent0(dim1_size);
292 m_value.resize(extents.dynamicExtents());
293}
294
295/*---------------------------------------------------------------------------*/
296/*---------------------------------------------------------------------------*/
297
298template <typename DataType, int RankValue> Int64
299NumArrayDataT<DataType, RankValue>::
300_getDim2Size() const
301{
302 // Retrieves the dimensions of the 'NumArray' and considers 'dim2_size' to be
303 // the product of the number of elements of the dimensions after the first.
304 auto extents = m_value.extents();
305 auto std_extents = extents.asStdArray();
306 Int64 dim2_size = 1;
307 for (Integer i = 0; i < RankValue; ++i)
308 dim2_size *= std_extents[i];
309 return dim2_size;
310}
311
312/*---------------------------------------------------------------------------*/
313/*---------------------------------------------------------------------------*/
314
315// WARNING: Will not work if there are 'strides'
316template <typename DataType, int RankValue> Span2<DataType>
319{
320 Int64 dim1_size = m_value.dim1Size();
321 Int64 dim2_size = _getDim2Size();
322 Span2<DataType> value_as_span2(m_value.to1DSpan().data(), dim1_size, dim2_size);
323 return value_as_span2;
324}
325
326/*---------------------------------------------------------------------------*/
327/*---------------------------------------------------------------------------*/
328
329// WARNING: Will not work if there are 'strides'
330// TODO: to be removed, but for this it is necessary to be able to convert a Span<T> into
331// a Span<const T> and this is not yet possible with arccore.
332template <typename DataType, int RankValue> Span2<const DataType>
335{
336 Int64 dim1_size = m_value.dim1Size();
337 Int64 dim2_size = _getDim2Size();
338 Span2<const DataType> value_as_span2(m_value.to1DSpan().data(), dim1_size, dim2_size);
339 return value_as_span2;
340}
341
342/*---------------------------------------------------------------------------*/
343/*---------------------------------------------------------------------------*/
344
345template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
346resize(Integer new_size)
347{
348 _resizeDim1(new_size);
349}
350
351/*---------------------------------------------------------------------------*/
352/*---------------------------------------------------------------------------*/
353
354template <typename DataType, int RankValue> Ref<ISerializedData>
356createSerializedDataRef(bool use_basic_type) const
357{
358 using BasicType = typename DataTypeTraitsT<DataType>::BasicType;
359
360 Int64 nb_count = 1;
361 eDataType data_type = dataType();
362 Int64 type_size = sizeof(DataType);
363
364 if (use_basic_type) {
365 nb_count = 1; //DataTypeTraitsT<DataType>::nbBasicType();
367 type_size = sizeof(BasicType);
368 }
369
370 Int64 nb_element = m_value.totalNbElement();
371 Int64 nb_base_element = nb_element * nb_count;
372 Int64 full_size = nb_base_element * type_size;
373 const Byte* bt = reinterpret_cast<const Byte*>(m_value.to1DSpan().data());
374 Span<const Byte> base_values(bt, full_size);
375 auto extents = m_value.extents();
376 auto std_extents = extents.asStdArray();
377 const Int32 nb_extent = CheckedConvert::toInt32(std_extents.size());
378 UniqueArray<Int64> dimensions(nb_extent);
379 for (Int32 i = 0; i < nb_extent; ++i)
380 dimensions[i] = std_extents[i];
381 auto sd = arcaneCreateSerializedDataRef(data_type, base_values.size(), RankValue, nb_element,
382 nb_base_element, false, dimensions, shape());
383 sd->setConstBytes(base_values);
384 return sd;
385}
386
387/*---------------------------------------------------------------------------*/
388/*---------------------------------------------------------------------------*/
389
390template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
392{
393 using BasicType = typename DataTypeTraitsT<DataType>::BasicType;
394
395 eDataType data_type = sdata->baseDataType();
397
398 if (data_type != dataType() && data_type == base_data_type)
399 ARCANE_FATAL("Bad serialized type");
400
401 bool is_multi_size = sdata->isMultiSize();
402 if (is_multi_size)
403 ARCANE_FATAL("Can not allocate multi-size array");
404
405 // Converted to Int32
406 Int64ConstArrayView sdata_extents = sdata->extents();
407 std::array<Int32, RankValue> numarray_extents;
408 for (Int32 i = 0; i < RankValue; ++i)
409 numarray_extents[i] = CheckedConvert::toInt32(sdata_extents[i]);
410 auto extents = ArrayExtents<ExtentType>::fromSpan(numarray_extents);
411 m_value.resize(extents.dynamicExtents());
412
413 Byte* byte_data = reinterpret_cast<Byte*>(m_value.to1DSpan().data());
414 Span<Byte> bytes_view(byte_data, sdata->memorySize());
415 sdata->setWritableBytes(bytes_view);
416}
417
418/*---------------------------------------------------------------------------*/
419/*---------------------------------------------------------------------------*/
420
421template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
423{
424 ARCANE_UNUSED(sdata);
425 // Nothing to do because \a sdata points directly to m_value
426}
427
428/*---------------------------------------------------------------------------*/
429/*---------------------------------------------------------------------------*/
430
431template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
432serialize(ISerializer* sbuf, IDataOperation* operation)
433{
434 // NOTE: This method is not yet operational
435
436 Integer nb_count = 1; //DataTypeTraitsT<DataType>::nbBasicType();
437 typedef typename DataTypeTraitsT<DataType>::BasicType BasicType;
438 //eDataType data_type = DataTypeTraitsT<BasicType>::type();
439
440 ISerializer::eMode mode = sbuf->mode();
441 if (mode == ISerializer::ModeReserve) {
442 // Reserves memory for
443 // - the magic number for verification
444 // - the number of elements in ids.
446 // Reserves memory for the number of elements in each dimension (i.e., RankValue)
447 sbuf->reserveSpan(eBasicDataType::Int32, RankValue);
448 // Reserves memory for the values
449 sbuf->reserveSpan(m_value.to1DSpan());
450 }
451 else if (mode == ISerializer::ModePut) {
452 Int64 total = m_value.totalNbElement();
453 Int64 n[2];
454 n[0] = SERIALIZE2_MAGIC_NUMBER;
455 n[1] = total;
456 sbuf->putSpan(Span<const Int64>(n, 2));
457 {
458 auto ext = m_value.extents().asStdArray();
459 sbuf->putSpan(Span<const Int32>(ext));
460 }
461 sbuf->putSpan(m_value.to1DSpan());
462 }
463 else if (mode == ISerializer::ModeGet) {
464 Int64 n[2] = { 0, 0 };
465 sbuf->getSpan(Span<Int64>(n, 2));
466 Int64 total = n[1];
467 if (n[0] != SERIALIZE2_MAGIC_NUMBER)
468 ARCANE_FATAL("Bad magic number");
469 Int32 extents_buf[RankValue];
470 SmallSpan<Int32> extents_span(extents_buf, RankValue);
471 sbuf->getSpan(extents_span);
472 Int32 count = extents_span[0];
473 switch (sbuf->readMode()) {
475 //m_trace->info() << "READ REPLACE count=" << count << " dim2_size=" << dim2_size;
476 m_value.resize(ArrayExtents<ExtentType>::fromSpan(extents_span).dynamicExtents());
477 if (operation)
478 ARCANE_THROW(NotImplementedException, "serialize(ReadReplace) with IDataOperation");
479 BasicType* bt = reinterpret_cast<BasicType*>(m_value.to1DSpan().data());
480 Span<BasicType> v(bt, total * nb_count);
481 sbuf->getSpan(v);
482 } break;
484 Int32 current_size = m_value.dim1Size();
485 // TODO: check that dim2_size has the same value as the input.
486 // Int64 dim2_size = _getDim2Size();
487 Int64 current_total = m_value.totalNbElement();
488 //m_trace->info() << "READ ADD NEW_SIZE=" << current_size << " COUNT=" << count
489 // << " dim2_size=" << dim2_size << " current_dim2_size=" << m_value.dim2Size()
490 // << " current_total=" << current_total << " read_elem=" << (total*nb_count);
491 _resizeDim1(current_size + count);
492 if (operation)
493 throw NotImplementedException(A_FUNCINFO, "serialize(ReadAdd) with IDataOperation");
494 BasicType* bt = reinterpret_cast<BasicType*>(m_value.to1DSpan().data() + current_total);
495 //m_trace->info() << "GET array nb_elem=" << (total*nb_count) << " sizeof=" << sizeof(BasicType);
496 Span<BasicType> v(bt, total * nb_count);
497 sbuf->getSpan(v);
498 } break;
499 }
500 }
501}
502
503/*---------------------------------------------------------------------------*/
504/*---------------------------------------------------------------------------*/
505
506template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
508{
509 ARCANE_UNUSED(operation);
510 // TODO: consolidate with serialize(sbuf,ids);
511
512 [[maybe_unused]] Integer nb_count = 1;
513 typedef typename DataTypeTraitsT<DataType>::BasicType BasicType;
515 ISerializer::eMode mode = sbuf->mode();
516 if (mode == ISerializer::ModeReserve) {
517 // Reserves memory for
518 // - the magic number for verification
519 // - the number of elements in ids.
520 // -
522 // Reserves memory for the number of elements in each dimension (i.e., RankValue)
523 sbuf->reserveSpan(eBasicDataType::Int32, RankValue);
524 // Reserves memory for the values
525 auto sub_extent = m_value.extents().removeFirstExtent();
526 sbuf->reserveSpan(data_type, sub_extent.totalNbElement() * ids.size());
527 }
528 else if (mode == ISerializer::ModePut) {
529 Int32 count = ids.size();
530 Int64 dim2_size = _getDim2Size();
531 Int64 total_nb_value = count * dim2_size;
532 Int64 total = total_nb_value;
533
534 Int64 n[3];
535 n[0] = SERIALIZE2_MAGIC_NUMBER;
536 n[1] = count;
537 n[2] = dim2_size;
538 /*m_trace->info() << "PUT COUNT = " << count << " total=" << total
539 << " dim1 (n[0])=" << n[0]
540 << " dim2 (n[1])=" << n[1]
541 << " count (n[2])=" << n[2]
542 << " magic=" << n[3]
543 << " this=" << this;*/
544 sbuf->putSpan(Span<const Int64>(n, 3));
545
546 {
547 auto ext = m_value.extents().asStdArray();
548 sbuf->putSpan(Span<const Int32>(ext));
549 }
550
551 UniqueArray<BasicType> v(total * nb_count);
552 Span2<const DataType> value_as_span2(_valueAsConstSpan2());
553 {
554 Integer index = 0;
555 for (Int32 i = 0, n = count; i < n; ++i) {
556 const BasicType* sub_a = reinterpret_cast<const BasicType*>(value_as_span2[ids[i]].data());
557 for (Int64 z = 0, iz = dim2_size * nb_count; z < iz; ++z) {
558 v[index] = sub_a[z];
559 ++index;
560 }
561 }
562 }
563
564 sbuf->putSpan(v);
565 }
566 else if (mode == ISerializer::ModeGet) {
567 switch (sbuf->readMode()) {
569 Int64 n[3] = { 0, 0, 0 };
570 sbuf->getSpan(Span<Int64>(n, 3));
571 Int32 count = CheckedConvert::toInt32(n[1]);
572 Int64 dim2_size = n[2];
573 Int64 total = count * dim2_size;
574 // One dim
575 /*m_trace->info() << "COUNT = " << count << " total=" << total
576 << " dim1 (n[0])=" << n[0]
577 << " dim1 current=" << m_value.dim1Size()
578 << " dim2 (n[1])=" << n[1]
579 << " dim2 current=" << m_value.dim2Size()
580 << " count (n[2])=" << n[2]
581 << " magic=" << n[3]
582 << " this=" << this;*/
583 if (n[1] != SERIALIZE2_MAGIC_NUMBER)
584 ARCANE_FATAL("Bad magic number");
585
586 Int32 extents_buf[RankValue];
587 Span<Int32> extents_span(extents_buf, RankValue);
588 sbuf->getSpan(extents_span);
589
590 // TODO: use extent to verify that the received array has the
591 // same number of elements in dimensions 2+.
592 Int64 current_dim2_size = _getDim2Size();
593
594 if (dim2_size != current_dim2_size) {
595 if (current_dim2_size != 0 && dim2_size != 0)
596 ARCANE_FATAL("serialized data should have the same dim2Size current={0} found={1}",
597 current_dim2_size, dim2_size);
598 else
599 _resizeDim1(m_value.dim1Size());
600 }
601 Int64 nb_value = count;
602 //Array<BasicType> v(total*nb_count);
603 UniqueArray<BasicType> base_value(total * nb_count);
604
605 sbuf->getSpan(base_value);
606
607 Span<DataType> data_value(reinterpret_cast<DataType*>(base_value.data()), nb_value * dim2_size);
608 UniqueArray<DataType> current_value;
609 Span<DataType> transformed_value;
610
611 Span2<DataType> value_as_span2(_valueAsSpan2());
612 // If a transformation is applied, perform the transformation in a
613 // temporary array 'current_value'.
614 if (operation && nb_value != 0) {
615 current_value.resize(data_value.size());
616
617 Int64 index = 0;
618 for (Int32 i = 0, n = count; i < n; ++i) {
619 Span<const DataType> a(value_as_span2[ids[i]]);
620 for (Int64 z = 0, iz = dim2_size; z < iz; ++z) {
621 current_value[index] = a[z];
622 ++index;
623 }
624 }
625
626 transformed_value = current_value.view();
627 operation->applySpan(transformed_value, data_value);
628 }
629 else {
630 transformed_value = data_value;
631 }
632
633 {
634 Int64 index = 0;
635 for (Int32 i = 0, n = count; i < n; ++i) {
636 Span<DataType> a(value_as_span2[ids[i]]);
637 for (Int64 z = 0, iz = dim2_size; z < iz; ++z) {
638 a[z] = transformed_value[index];
639 ++index;
640 }
641 }
642 }
643 } break;
645 ARCANE_THROW(NotImplementedException, "option 'ReadAdd'");
646 break;
647 }
648 }
649}
650
651/*---------------------------------------------------------------------------*/
652/*---------------------------------------------------------------------------*/
653
654template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
656{
657 m_value.fill(DataType());
658}
659
660/*---------------------------------------------------------------------------*/
661/*---------------------------------------------------------------------------*/
662
663template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
664setName(const String& name)
665{
666 ARCANE_UNUSED(name);
667}
668
669/*---------------------------------------------------------------------------*/
670/*---------------------------------------------------------------------------*/
671
672template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
673computeHash(IHashAlgorithm* algo, ByteArray& output) const
674{
675 // Calculates the hash function for the values
676 {
677 Span<const DataType> values = m_value.to1DSpan();
678 Int64 type_size = sizeof(DataType);
679 Int64 nb_element = values.size();
680 const Byte* ptr = reinterpret_cast<const Byte*>(values.data());
681 Span<const Byte> input(ptr, type_size * nb_element);
682 algo->computeHash64(input, output);
683 }
684
685 {
686 // Calculates the hash function for the number of elements
687 auto ext = m_value.extents().asStdArray();
688 auto input = asBytes(Span<const Int32>(ext));
689 algo->computeHash64(input, output);
690 }
691}
692
693/*---------------------------------------------------------------------------*/
694/*---------------------------------------------------------------------------*/
695
696template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
697copy(const IData* data)
698{
699 auto* true_data = dynamic_cast<const DataInterfaceType*>(data);
700 if (!true_data)
701 throw ArgumentException(A_FUNCINFO, "Can not cast 'IData' to 'INumArrayDataT'");
702 m_value.copy(true_data->view());
703}
704
705/*---------------------------------------------------------------------------*/
706/*---------------------------------------------------------------------------*/
707
708template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
709swapValues(IData* data)
710{
711 auto* true_data = dynamic_cast<ThatClass*>(data);
712 if (!true_data)
713 throw ArgumentException(A_FUNCINFO, "Can not cast 'IData' to 'NumArrayDataT'");
714 swapValuesDirect(true_data);
715}
716
717/*---------------------------------------------------------------------------*/
718/*---------------------------------------------------------------------------*/
719
720template <typename DataType, int RankValue> void NumArrayDataT<DataType, RankValue>::
721swapValuesDirect(ThatClass* true_data)
722{
723 m_value.swap(true_data->m_value);
724}
725
726/*---------------------------------------------------------------------------*/
727/*---------------------------------------------------------------------------*/
728
729extern "C++" void
730registerNumArrayDataFactory(IDataFactoryMng* dfm)
731{
732 DataStorageFactory<NumArrayDataT<Real, 1>>::registerDataFactory(dfm);
733 //DataStorageFactory<NumArrayDataT<Int16,1>>::registerDataFactory(dfm);
734 //DataStorageFactory<NumArrayDataT<Int32,1>>::registerDataFactory(dfm);
735 DataStorageFactory<NumArrayDataT<Int64, 1>>::registerDataFactory(dfm);
736
737 DataStorageFactory<NumArrayDataT<Real, 2>>::registerDataFactory(dfm);
738 //DataStorageFactory<NumArrayDataT<Int16,2>>::registerDataFactory(dfm);
739 //DataStorageFactory<NumArrayDataT<Int32,2>>::registerDataFactory(dfm);
740 DataStorageFactory<NumArrayDataT<Int64, 2>>::registerDataFactory(dfm);
741
742 DataStorageFactory<NumArrayDataT<Real, 3>>::registerDataFactory(dfm);
743 //DataStorageFactory<NumArrayDataT<Int16,2>>::registerDataFactory(dfm);
744 //DataStorageFactory<NumArrayDataT<Int32,2>>::registerDataFactory(dfm);
745 DataStorageFactory<NumArrayDataT<Int64, 3>>::registerDataFactory(dfm);
746
747 DataStorageFactory<NumArrayDataT<Real, 4>>::registerDataFactory(dfm);
748 //DataStorageFactory<NumArrayDataT<Int16,2>>::registerDataFactory(dfm);
749 //DataStorageFactory<NumArrayDataT<Int32,2>>::registerDataFactory(dfm);
750 DataStorageFactory<NumArrayDataT<Int64, 4>>::registerDataFactory(dfm);
751}
752
753/*---------------------------------------------------------------------------*/
754/*---------------------------------------------------------------------------*/
755
756} // End namespace Arcane
757
758/*---------------------------------------------------------------------------*/
759/*---------------------------------------------------------------------------*/
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS()
Macro to define methods managing counters of references.
Types and functions associated with the classes Span2Impl, Small2Span and Span2.
Management of references to a C++ class.
Array shape.
Definition ArrayShape.h:42
void resize(Int64 s)
Changes the number of elements in the array to s.
const T * data() const
Access to the root of the array without any protection.
ArrayView< T > view() const
Mutable view of this array.
constexpr Integer size() const noexcept
Number of elements in the array.
Information on data allocation.
Information for calculating data hash.
Information to construct an instance of 'IData'.
Type information for a data container.
Interface of the visitor pattern for a 2D array data item.
Interface of the visitor pattern for an array data item.
Internal part of IData.
Interface of an operation on a data.
Interface of the visitor pattern for a data item.
Interface of a data item.
Definition IData.h:34
Interface of a hashing algorithm.
virtual void computeHash64(Span< const Byte > input, ByteArray &output)
Calculates the hash value for the array input.
Interface of an 'IData' whose container is based on a 'NumArray'.
virtual Ref< ThatClass > cloneTrueEmptyRef()=0
Clone the data but without elements.
virtual MDSpan< const DataType, ExtentType > view() const =0
Constant view of the data.
virtual MDSpan< DataType, ExtentType > view()=0
View of the data.
virtual Ref< ThatClass > cloneTrueRef()=0
Clone the data.
Interface of the visitor pattern for a scalar data item.
Interface of a serialized data.
virtual eDataType baseDataType() const =0
Data type.
virtual Int64 memorySize() const =0
Indicates the number of bytes that must be allocated to store or read the data.
virtual void setWritableBytes(Span< Byte > bytes)=0
Positions the serialized values.
virtual Int64ConstArrayView extents() const =0
Array containing the number of elements for each dimension.
virtual bool isMultiSize() const =0
Indicates if it is a multi-size array. (only relevant if nbDimension()>1).
virtual eReadMode readMode() const =0
Read mode.
virtual void putSpan(Span< const Real > values)
Add the array values.
virtual eMode mode() const =0
Current operating mode.
@ ReadReplace
Replace current elements with those read.
@ ReadAdd
Add those read to the current elements.
virtual void getSpan(Span< Real > values)
Retrieve the array values.
virtual void reserveSpan(eBasicDataType dt, Int64 n)=0
Reserves memory for n values of dt.
Base class for multi-dimensional views.
void computeHash(DataHashInfo &) override
Calculates the hash of the data.
Implementation of an 'IData' whose container is based on a 'NumArray'.
void setShape(const ArrayShape &new_shape) override
Sets the array shape.
void copy(const IData *data) override
Copy the data data into the current instance.
Ref< ISerializedData > createSerializedDataRef(bool use_basic_type) const override
Serialize the data.
Integer dimension() const override
Dimension. 0 for a scalar, 1 for a mono-dim array, 2 for a bi-dim array.
Integer multiTag() const override
Multi-tag. 0 if not multiple, 1 if multiple, 2 if multiple for MultiArray variables (obsolete).
Ref< IData > cloneEmptyRef() override
Clone the data but without elements.
IData * clone() override
Clone the data. The created instance must be destroyed by the 'delete' operator.
void visitArray(IArrayDataVisitor *) override
Apply the visitor to the data.
Ref< DataInterfaceType > cloneTrueRef() override
Clone the data.
Ref< DataInterfaceType > cloneTrueEmptyRef() override
Clone the data but without elements.
void swapValues(IData *data) override
Swap the values of data with those of the instance.
void serialize(ISerializer *sbuf, IDataOperation *operation) override
Serializes the data by applying the operation.
IDataInternal * _commonInternal() override
Ref< IData > cloneRef() override
Clone the data.
NumArray< DataType, ExtentType > m_value
Data.
void fillDefault() override
Fills the data with its default value.
MDSpan< DataType, ExtentType > view() override
View of the data.
void assignSerializedData(const ISerializedData *sdata) override
Assign the serialized values sdata to the data.
IData * cloneEmpty() override
Clone the data but without elements. The created instance must be destroyed by the 'delete' operator.
eDataType dataType() const override
Data type.
MDSpan< const DataType, ExtentType > view() const override
Constant view of the data.
ArrayShape shape() const override
Array shape for a 1D or 2D data item.
void resize(Integer new_size) override
Resize the data.
void allocateBufferForSerializedData(ISerializedData *sdata) override
Allocate memory to read the serialized values sdata.
void computeHash(IHashAlgorithm *algo, ByteArray &output) const override
Compute a hash key on this data.
void setAllocationInfo(const DataAllocationInfo &v) override
Sets the allocation information.
void setName(const String &name) override
Sets the name of the data (internal).
void visitArray2(IArray2DataVisitor *) override
Apply the visitor to the data.
void visitScalar(IScalarDataVisitor *) override
Apply the visitor to the data.
DataAllocationInfo allocationInfo() const override
Allocation information.
DataStorageTypeInfo storageTypeInfo() const override
Information about the data container type.
void visit(IDataVisitor *visitor) override
Applies the visitor to the data.
Multi-dimensional arrays for numerical types accessible on accelerators.
Reference to an instance.
Thread-safe implementation of a reference counter.
View of an array of elements of type T.
Definition Span.h:805
constexpr __host__ __device__ ElementType * data()
Pointer to the allocated memory.
Definition Span2.h:196
View for a 2D array whose size is an 'Int64'.
Definition Span2.h:324
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
Definition Span.h:539
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
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Ref< ISerializedData > arcaneCreateSerializedDataRef(eDataType data_type, Int64 memory_size, Integer nb_dim, Int64 nb_element, Int64 nb_base_element, bool is_multi_size, Int64ConstArrayView dimensions)
Creates serialized data.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
Definition UtilsTypes.h:121
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
eBasicDataType
Type of a basic data item.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:480
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of non-modifiable bytes.
Definition Span.h:1032
unsigned char Byte
Type of a byte.
Definition BaseTypes.h:43
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
eDataType
Data type.
Definition DataTypes.h:41
std::int32_t Int32
Signed integer type of 32 bits.