escript  Revision_
DataTagged.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2018 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 
179  virtual bool
180  hasInf() const;
181 
186  virtual void
187  replaceInf(DataTypes::real_t value);
188 
193  virtual void
194  replaceInf(DataTypes::cplx_t value);
195 
196 
200  virtual
201  DataAbstract*
202  deepCopy() const;
203 
204 
210  virtual
211  DataAbstract*
212  zeroedCopy() const;
213 
214 
227  virtual
229  getSampleDataByTag(int tag, DataTypes::real_t dummy=0);
230 
231  virtual
233  getSampleDataByTag(int tag, DataTypes::cplx_t dummy);
234 
235 
243  virtual
244  std::string
245  toString() const;
250  virtual
251  void
252  dump(const std::string fileName) const;
253 
259  virtual int
260  matrixInverse(DataAbstract* out) const;
261 
266  virtual
267  void
268  setToZero();
269 
276  virtual
277  int
278  getTagNumber(int dpno);
279 
292  virtual
294  getPointOffset(int sampleNo,
295  int dataPointNo) const;
296 
314  void
315  addTaggedValues(const TagListType& tagKeys,
316  const FloatBatchType& values,
317  const ShapeType& vShape);
318 
319 
336  void
337  addTaggedValues(const TagListType& tagKeys,
338  const DataTypes::RealVectorType& values,
339  const ShapeType& vShape);
340 
341 
342 
343 
356  void
357  addTaggedValue(int tagKey,
358  const DataTypes::ShapeType& pointshape,
359  const DataTypes::RealVectorType& value,
360  int dataOffset=0);
361 
362  void
363  addTaggedValue(int tagKey,
364  const DataTypes::ShapeType& pointshape,
365  const DataTypes::CplxVectorType& value,
366  int dataOffset=0);
367 
368 
379  void
380  addTag(int tagKey);
381 
394  void
395  setTaggedValue(int tagKey,
396  const DataTypes::ShapeType& pointshape,
397  const DataTypes::RealVectorType& value,
398  int dataOffset=0);
399 
400  void
401  setTaggedValue(int tagKey,
402  const DataTypes::ShapeType& pointshape,
403  const DataTypes::CplxVectorType& value,
404  int dataOffset=0);
405 
406 
418  getDataByTagRW(int tag, DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0);
419 
421  getDataByTagRO(int tag, DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0) const;
422 
423 
425  getDataByTagRW(int tag, DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy);
426 
428  getDataByTagRO(int tag, DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy) const;
429 
440  getOffsetForTag(int tag) const;
441 
442 
449  getVectorRW();
450 
452  getVectorRO() const;
453 
454 
456  getVectorRWC();
457 
459  getVectorROC() const;
460 
461 
463  getTypedVectorRW(DataTypes::real_t dummy);
464 
465  virtual const DataTypes::RealVectorType&
466  getTypedVectorRO(DataTypes::real_t dummy) const;
467 
469  getTypedVectorRW(DataTypes::cplx_t dummy);
470 
471  virtual const DataTypes::CplxVectorType&
472  getTypedVectorRO(DataTypes::cplx_t dummy) const;
473 
474 
475 
476 
477 
486  const DataMapType&
487  getTagLookup() const;
488 
500  bool
501  isCurrentTag(int tag) const;
502 
513  getDefaultValueRW(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0);
514 
516  getDefaultValueRO(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0) const;
517 
519  getDefaultValueRW(DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy);
520 
522  getDefaultValueRO(DataTypes::CplxVectorType::size_type i, DataTypes::cplx_t dummy) const;
523 
524 
525 
526 
535  virtual
537  getLength() const;
538 
549  virtual
550  DataAbstract*
551  getSlice(const DataTypes::RegionType& region) const;
552 
564  DataTagged(const DataTagged& other,
565  const DataTypes::RegionType& region);
566 
577  virtual
578  void
579  setSlice(const DataAbstract* other,
580  const DataTypes::RegionType& region);
581 
582 
590  virtual void
591  symmetric(DataAbstract* ev);
592 
600  virtual void
602 
610  virtual void
611  hermitian(DataAbstract* ev);
612 
620  virtual void
622 
630  virtual void
631  trace(DataAbstract* ev, int axis_offset);
632 
641  virtual void
642  swapaxes(DataAbstract* ev, int axis0, int axis1);
643 
651  virtual void
652  transpose(DataAbstract* ev, int axis_offset);
653 
661  virtual void
663 
675  virtual void
676  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
677 
678 
683  getDefaultOffset() const;
684 
688  size_t
689  getTagCount() const;
690 
691  void
692  complicate();
693 
694  protected:
695 
696  private:
697 
698  //
699  // The offset lookup table
700  DataMapType m_offsetLookup;
701 
702  //
703  // the offset to the default value
704  static const int m_defaultValueOffset = 0;
705 
706  // the actual data
709 
710 
711 };
712 
713 inline
714 bool
716 {
717  DataMapType::const_iterator pos(m_offsetLookup.find(tag));
718  return (pos!=m_offsetLookup.end());
719 }
720 
721 inline
724 {
725  return m_defaultValueOffset;
726 }
727 
728 inline
731 {
732  return getVectorRW()[i]; // getVectorRW has exclusive write checks
733 }
734 
735 inline
738 {
739  return getVectorRO()[i];
740 }
741 
742 inline
745 {
746  return getVectorRWC()[i]; // getVectorRW has exclusive write checks
747 }
748 
749 inline
752 {
753  return getVectorROC()[i];
754 }
755 
756 
757 
758 
759 inline
762 {
763  return m_offsetLookup;
764 }
765 
766 inline
769 {
770  return std::max(m_data_c.size(), m_data_r.size());
771 }
772 
773 } // end of namespace
774 
775 #endif // __ESCRIPT_DATATAGGED_H__
776 
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:708
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:715
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:707
virtual DataTypes::RealVectorType::size_type getLength() const
getLength
Definition: DataTagged.h:768
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:700
DataTypes::RealVectorType::reference getDefaultValueRW(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0)
getDefaultValue
Definition: DataTagged.h:730
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:723
DataTypes::RealVectorType::const_reference getDefaultValueRO(DataTypes::RealVectorType::size_type i, DataTypes::real_t dummy=0) const
Definition: DataTagged.h:737
#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:749
const DataMapType & getTagLookup() const
getTagLookup
Definition: DataTagged.h:761
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