escript  Revision_
DataTagged.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 
18 #ifndef __ESCRIPT_DATATAGGED_H__
19 #define __ESCRIPT_DATATAGGED_H__
20 
21 #include "system_dep.h"
22 
23 #include "DataReady.h"
24 #include "DataTypes.h"
25 
26 #include <map>
27 #include <vector>
28 
29 namespace escript {
30 
31 class DataConstant;
32 
45 {
46  typedef DataReady parent;
47  public:
48 
49  //
50  // Types for the lists of tags and values.
51  typedef std::vector<int> TagListType;
52  typedef std::vector<DataTypes::RealVectorType::ElementType> FloatBatchType;
53  typedef std::vector<DataTypes::CplxVectorType::ElementType> CplxBatchType;
54 
55  //
56  // Map from a tag to an offset into the data array.
57  typedef std::map<int, int> DataMapType;
58 
71  explicit DataTagged(const FunctionSpace& what,
72  const DataTypes::ShapeType &shape,
73  const int tags[],
74  const DataTypes::RealVectorType& data);
75 
76 
77  explicit DataTagged(const FunctionSpace& what,
78  const DataTypes::ShapeType &shape,
79  const int tags[],
80  const DataTypes::CplxVectorType& data);
81 
82 
95  explicit DataTagged(const FunctionSpace& what,
96  const DataTypes::ShapeType &shape,
97  const TagListType& tags,
98  const DataTypes::RealVectorType& data);
99 
100  explicit DataTagged(const FunctionSpace& what,
101  const DataTypes::ShapeType &shape,
102  const TagListType& tags,
103  const DataTypes::CplxVectorType& data);
104 
105 
112  DataTagged(const DataTagged& other);
113 
121  explicit DataTagged(const DataConstant& other);
122 
133  explicit DataTagged(const FunctionSpace& what,
134  const DataTypes::ShapeType& shape,
135  const DataTypes::RealVectorType& defaultvalue,
136  const DataTagged* tagsource=0);
137 
138  explicit DataTagged(const FunctionSpace& what,
139  const DataTypes::ShapeType& shape,
140  const DataTypes::CplxVectorType& defaultvalue,
141  const DataTagged* tagsource=0);
142 
143 
148  inline virtual
150 
151  bool
152  isTagged() const
153  {
154  return true;
155  };
156 
160  bool
161  hasNaN() const;
162 
166  void
167  replaceNaN(DataTypes::real_t value);
168 
172  void
173  replaceNaN(DataTypes::cplx_t value);
174 
175 
176 
180  virtual
181  DataAbstract*
182  deepCopy() const;
183 
184 
197  virtual
199  getSampleDataByTag(int tag, DataTypes::real_t dummy=0);
200 
201  virtual
203  getSampleDataByTag(int tag, DataTypes::cplx_t dummy);
204 
205 
213  virtual
214  std::string
215  toString() const;
220  virtual
221  void
222  dump(const std::string fileName) const;
223 
229  virtual int
230  matrixInverse(DataAbstract* out) const;
231 
236  virtual
237  void
238  setToZero();
239 
246  virtual
247  int
248  getTagNumber(int dpno);
249 
262  virtual
264  getPointOffset(int sampleNo,
265  int dataPointNo) const;
266 
284  void
285  addTaggedValues(const TagListType& tagKeys,
286  const FloatBatchType& values,
287  const ShapeType& vShape);
288 
289 
306  void
307  addTaggedValues(const TagListType& tagKeys,
308  const DataTypes::RealVectorType& values,
309  const ShapeType& vShape);
310 
311 
312 
313 
326  void
327  addTaggedValue(int tagKey,
328  const DataTypes::ShapeType& pointshape,
329  const DataTypes::RealVectorType& value,
330  int dataOffset=0);
331 
332  void
333  addTaggedValue(int tagKey,
334  const DataTypes::ShapeType& pointshape,
335  const DataTypes::CplxVectorType& value,
336  int dataOffset=0);
337 
338 
349  void
350  addTag(int tagKey);
351 
364  void
365  setTaggedValue(int tagKey,
366  const DataTypes::ShapeType& pointshape,
367  const DataTypes::RealVectorType& value,
368  int dataOffset=0);
369 
370  void
371  setTaggedValue(int tagKey,
372  const DataTypes::ShapeType& pointshape,
373  const DataTypes::CplxVectorType& value,
374  int dataOffset=0);
375 
376 
388  getDataByTagRW(int tag, DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0);
389 
391  getDataByTagRO(int tag, DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0) const;
392 
393 
395  getDataByTagRW(int tag, DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy);
396 
398  getDataByTagRO(int tag, DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy) const;
399 
410  getOffsetForTag(int tag) const;
411 
412 
419  getVectorRW();
420 
422  getVectorRO() const;
423 
424 
426  getVectorRWC();
427 
429  getVectorROC() const;
430 
431 
433  getTypedVectorRW(DataTypes::real_t dummy);
434 
435  virtual const DataTypes::RealVectorType&
436  getTypedVectorRO(DataTypes::real_t dummy) const;
437 
439  getTypedVectorRW(DataTypes::cplx_t dummy);
440 
441  virtual const DataTypes::CplxVectorType&
442  getTypedVectorRO(DataTypes::cplx_t dummy) const;
443 
444 
445 
446 
447 
456  const DataMapType&
457  getTagLookup() const;
458 
470  bool
471  isCurrentTag(int tag) const;
472 
483  getDefaultValueRW(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0);
484 
486  getDefaultValueRO(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0) const;
487 
489  getDefaultValueRW(DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy);
490 
492  getDefaultValueRO(DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy) const;
493 
494 
495 
496 
505  virtual
507  getLength() const;
508 
519  virtual
520  DataAbstract*
521  getSlice(const DataTypes::RegionType& region) const;
522 
534  DataTagged(const DataTagged& other,
535  const DataTypes::RegionType& region);
536 
547  virtual
548  void
549  setSlice(const DataAbstract* other,
550  const DataTypes::RegionType& region);
551 
552 
560  virtual void
561  symmetric(DataAbstract* ev);
562 
570  virtual void
572 
580  virtual void
581  hermitian(DataAbstract* ev);
582 
590  virtual void
592 
600  virtual void
601  trace(DataAbstract* ev, int axis_offset);
602 
611  virtual void
612  swapaxes(DataAbstract* ev, int axis0, int axis1);
613 
621  virtual void
622  transpose(DataAbstract* ev, int axis_offset);
623 
631  virtual void
633 
645  virtual void
646  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
647 
648 
653  getDefaultOffset() const;
654 
658  size_t
659  getTagCount() const;
660 
661  void
662  complicate();
663 
664  protected:
665 
666  private:
667 
668  //
669  // The offset lookup table
670  DataMapType m_offsetLookup;
671 
672  //
673  // the offset to the default value
674  static const int m_defaultValueOffset = 0;
675 
676  // the actual data
679 
680 
681 };
682 
683 inline
684 bool
686 {
687  DataMapType::const_iterator pos(m_offsetLookup.find(tag));
688  return (pos!=m_offsetLookup.end());
689 }
690 
691 inline
694 {
695  return m_defaultValueOffset;
696 }
697 
698 inline
701 {
702  return getVectorRW()[i]; // getVectorRW has exclusive write checks
703 }
704 
705 inline
708 {
709  return getVectorRO()[i];
710 }
711 
712 inline
715 {
716  return getVectorRWC()[i]; // getVectorRW has exclusive write checks
717 }
718 
719 inline
722 {
723  return getVectorROC()[i];
724 }
725 
726 
727 
728 
729 inline
732 {
733  return m_offsetLookup;
734 }
735 
736 inline
739 {
740  return std::max(m_data_c.size(), m_data_r.size());
741 }
742 
743 } // end of namespace
744 
745 #endif // __ESCRIPT_DATATAGGED_H__
746 
Definition: FunctionSpace.h:34
bool isTagged() const
Definition: DataTagged.h:152
void eigenvalues(const DataTypes::RealVectorType &in, const DataTypes::ShapeType &inShape, typename DataTypes::RealVectorType::size_type inOffset, DataTypes::RealVectorType &ev, const DataTypes::ShapeType &evShape, typename DataTypes::RealVectorType::size_type evOffset)
solves a local eigenvalue problem
Definition: DataVectorOps.h:638
DataTypes::ShapeType ShapeType
Definition: DataAbstract.h:66
ElementType & reference
Definition: DataVectorAlt.h:50
DataTypes::CplxVectorType m_data_c
Definition: DataTagged.h:678
Definition: DataReady.h:35
DataTypes::vec_size_type size_type
Definition: DataVectorAlt.h:49
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:43
Definition: AbstractContinuousDomain.cpp:22
void transpose(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset, int axis_offset)
Transpose each data point of this Data object around the given axis.
Definition: DataVectorOps.h:342
DataConstant stores a single data point which represents the entire function space.
Definition: DataConstant.h:37
bool isCurrentTag(int tag) const
isCurrentTag
Definition: DataTagged.h:685
std::vector< DataTypes::RealVectorType::ElementType > FloatBatchType
Definition: DataTagged.h:52
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:42
Simulates a full dataset accessible via sampleNo and dataPointNo.
Definition: DataTagged.h:44
void symmetric(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset)
computes a symmetric matrix from your square matrix A: (A + transpose(A)) / 2
Definition: DataVectorOps.h:102
std::map< int, int > DataMapType
Definition: DataTagged.h:57
DataTypes::RealVectorType m_data_r
Definition: DataTagged.h:677
virtual DataTypes::RealVectorType::size_type getLength() const
getLength
Definition: DataTagged.h:738
void hermitian(const DataTypes::CplxVectorType &in, const DataTypes::ShapeType &inShape, DataTypes::CplxVectorType::size_type inOffset, DataTypes::CplxVectorType &ev, const DataTypes::ShapeType &evShape, DataTypes::CplxVectorType::size_type evOffset)
computes an hermitian matrix from your square matrix A: (A + adjoint(A)) / 2
Definition: DataVectorOps.cpp:915
DataMapType m_offsetLookup
Definition: DataTagged.h:670
DataTypes::RealVectorType::reference getDefaultValueRW(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0)
getDefaultValue
Definition: DataTagged.h:700
void swapaxes(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset, int axis0, int axis1)
swaps the components axis0 and axis1.
Definition: DataVectorOps.h:487
DataTypes::RealVectorType::size_type getDefaultOffset() const
Returns the offset in the structure which stores the default value.
Definition: DataTagged.h:693
DataTypes::RealVectorType::const_reference getDefaultValueRO(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0) const
Definition: DataTagged.h:707
#define V(_K_, _I_)
Definition: ShapeFunctions.cpp:120
std::vector< int > TagListType
Definition: DataTagged.h:51
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:53
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:29
void trace(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset, int axis_offset)
computes the trace of a matrix
Definition: DataVectorOps.h:241
DataReady parent
Definition: DataTagged.h:46
void antisymmetric(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset)
computes a antisymmetric matrix from your square matrix A: (A - transpose(A)) / 2 ...
Definition: DataVectorOps.h:151
Definition: DataAbstract.h:61
const ElementType & const_reference
Definition: DataVectorAlt.h:51
void eigenvalues_and_eigenvectors(const DataTypes::RealVectorType &in, const DataTypes::ShapeType &inShape, DataTypes::RealVectorType::size_type inOffset, DataTypes::RealVectorType &ev, const DataTypes::ShapeType &evShape, DataTypes::RealVectorType::size_type evOffset, DataTypes::RealVectorType &V, const DataTypes::ShapeType &VShape, DataTypes::RealVectorType::size_type VOffset, const double tol=1.e-13)
solves a local eigenvalue problem
Definition: DataVectorOps.h:746
const DataMapType & getTagLookup() const
getTagLookup
Definition: DataTagged.h:731
std::vector< DataTypes::CplxVectorType::ElementType > CplxBatchType
Definition: DataTagged.h:53
virtual ~DataTagged()
Destructor.
Definition: DataTagged.h:149
void antihermitian(const DataTypes::CplxVectorType &in, const DataTypes::ShapeType &inShape, typename DataTypes::CplxVectorType::size_type inOffset, DataTypes::CplxVectorType &ev, const DataTypes::ShapeType &evShape, typename DataTypes::CplxVectorType::size_type evOffset)
computes a antihermitian matrix from your square matrix A: (A - adjoint(A)) / 2
Definition: DataVectorOps.cpp:962
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:50