escript  Revision_
DataTagged.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2017 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 
190  virtual
191  DataAbstract*
192  zeroedCopy() const;
193 
194 
207  virtual
209  getSampleDataByTag(int tag, DataTypes::real_t dummy=0);
210 
211  virtual
213  getSampleDataByTag(int tag, DataTypes::cplx_t dummy);
214 
215 
223  virtual
224  std::string
225  toString() const;
230  virtual
231  void
232  dump(const std::string fileName) const;
233 
239  virtual int
240  matrixInverse(DataAbstract* out) const;
241 
246  virtual
247  void
248  setToZero();
249 
256  virtual
257  int
258  getTagNumber(int dpno);
259 
272  virtual
274  getPointOffset(int sampleNo,
275  int dataPointNo) const;
276 
294  void
295  addTaggedValues(const TagListType& tagKeys,
296  const FloatBatchType& values,
297  const ShapeType& vShape);
298 
299 
316  void
317  addTaggedValues(const TagListType& tagKeys,
318  const DataTypes::RealVectorType& values,
319  const ShapeType& vShape);
320 
321 
322 
323 
336  void
337  addTaggedValue(int tagKey,
338  const DataTypes::ShapeType& pointshape,
339  const DataTypes::RealVectorType& value,
340  int dataOffset=0);
341 
342  void
343  addTaggedValue(int tagKey,
344  const DataTypes::ShapeType& pointshape,
345  const DataTypes::CplxVectorType& value,
346  int dataOffset=0);
347 
348 
359  void
360  addTag(int tagKey);
361 
374  void
375  setTaggedValue(int tagKey,
376  const DataTypes::ShapeType& pointshape,
377  const DataTypes::RealVectorType& value,
378  int dataOffset=0);
379 
380  void
381  setTaggedValue(int tagKey,
382  const DataTypes::ShapeType& pointshape,
383  const DataTypes::CplxVectorType& value,
384  int dataOffset=0);
385 
386 
398  getDataByTagRW(int tag, DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0);
399 
401  getDataByTagRO(int tag, DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0) const;
402 
403 
405  getDataByTagRW(int tag, DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy);
406 
408  getDataByTagRO(int tag, DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy) const;
409 
420  getOffsetForTag(int tag) const;
421 
422 
429  getVectorRW();
430 
432  getVectorRO() const;
433 
434 
436  getVectorRWC();
437 
439  getVectorROC() const;
440 
441 
443  getTypedVectorRW(DataTypes::real_t dummy);
444 
445  virtual const DataTypes::RealVectorType&
446  getTypedVectorRO(DataTypes::real_t dummy) const;
447 
449  getTypedVectorRW(DataTypes::cplx_t dummy);
450 
451  virtual const DataTypes::CplxVectorType&
452  getTypedVectorRO(DataTypes::cplx_t dummy) const;
453 
454 
455 
456 
457 
466  const DataMapType&
467  getTagLookup() const;
468 
480  bool
481  isCurrentTag(int tag) const;
482 
493  getDefaultValueRW(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0);
494 
496  getDefaultValueRO(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0) const;
497 
499  getDefaultValueRW(DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy);
500 
502  getDefaultValueRO(DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy) const;
503 
504 
505 
506 
515  virtual
517  getLength() const;
518 
529  virtual
530  DataAbstract*
531  getSlice(const DataTypes::RegionType& region) const;
532 
544  DataTagged(const DataTagged& other,
545  const DataTypes::RegionType& region);
546 
557  virtual
558  void
559  setSlice(const DataAbstract* other,
560  const DataTypes::RegionType& region);
561 
562 
570  virtual void
571  symmetric(DataAbstract* ev);
572 
580  virtual void
582 
590  virtual void
591  hermitian(DataAbstract* ev);
592 
600  virtual void
602 
610  virtual void
611  trace(DataAbstract* ev, int axis_offset);
612 
621  virtual void
622  swapaxes(DataAbstract* ev, int axis0, int axis1);
623 
631  virtual void
632  transpose(DataAbstract* ev, int axis_offset);
633 
641  virtual void
643 
655  virtual void
656  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
657 
658 
663  getDefaultOffset() const;
664 
668  size_t
669  getTagCount() const;
670 
671  void
672  complicate();
673 
674  protected:
675 
676  private:
677 
678  //
679  // The offset lookup table
680  DataMapType m_offsetLookup;
681 
682  //
683  // the offset to the default value
684  static const int m_defaultValueOffset = 0;
685 
686  // the actual data
689 
690 
691 };
692 
693 inline
694 bool
696 {
697  DataMapType::const_iterator pos(m_offsetLookup.find(tag));
698  return (pos!=m_offsetLookup.end());
699 }
700 
701 inline
704 {
705  return m_defaultValueOffset;
706 }
707 
708 inline
711 {
712  return getVectorRW()[i]; // getVectorRW has exclusive write checks
713 }
714 
715 inline
718 {
719  return getVectorRO()[i];
720 }
721 
722 inline
725 {
726  return getVectorRWC()[i]; // getVectorRW has exclusive write checks
727 }
728 
729 inline
732 {
733  return getVectorROC()[i];
734 }
735 
736 
737 
738 
739 inline
742 {
743  return m_offsetLookup;
744 }
745 
746 inline
749 {
750  return std::max(m_data_c.size(), m_data_r.size());
751 }
752 
753 } // end of namespace
754 
755 #endif // __ESCRIPT_DATATAGGED_H__
756 
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:688
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:695
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:687
virtual DataTypes::RealVectorType::size_type getLength() const
getLength
Definition: DataTagged.h:748
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:680
DataTypes::RealVectorType::reference getDefaultValueRW(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0)
getDefaultValue
Definition: DataTagged.h:710
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:703
DataTypes::RealVectorType::const_reference getDefaultValueRO(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0) const
Definition: DataTagged.h:717
#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:741
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