MFEM v4.7.0
Finite element discretization library
|
Templated vector data type. More...
#include <tadvector.hpp>
Public Member Functions | |
TAutoDiffVector () | |
Default constructor for Vector. Sets size = 0 and data = NULL. | |
TAutoDiffVector (const TAutoDiffVector< dtype > &v) | |
Copy constructor. Allocates a new data array and copies the data. | |
TAutoDiffVector (const Vector &v) | |
TAutoDiffVector (int s) | |
Creates vector of size s. | |
TAutoDiffVector (dtype *_data, int _size) | |
Creates a vector referencing an array of doubles, owned by someone else. | |
void | Load (std::istream **in, int np, int *dim) |
Reads a vector from multiple files. | |
void | Load (std::istream &in, int Size) |
Load a vector from an input stream. | |
void | Load (std::istream &in) |
Load a vector from an input stream, reading the size from the stream. | |
void | SetSize (int s) |
Resize the vector to size s. | |
void | SetDataAndSize (dtype *d, int s) |
Set the Vector data and size. | |
void | NewDataAndSize (dtype *d, int s) |
Set the Vector data and size, deleting the old data, if owned. | |
void | MakeRef (TAutoDiffVector< dtype > &base, int offset, int size_) |
Reset the Vector to be a reference to a sub-vector of base. | |
void | MakeRef (TAutoDiffVector< dtype > &base, int offset) |
Reset the Vector to be a reference to a sub-vector of base without changing its current size. | |
void | Destroy () |
Destroy a vector. | |
int | Size () const |
Returns the size of the vector. | |
int | Capacity () const |
Return the size of the currently allocated data array. | |
dtype * | GetData () const |
Return a pointer to the beginning of the Vector data. | |
operator dtype * () | |
Conversion to double * . | |
operator const dtype * () const | |
Conversion to const double * . | |
bool | OwnsData () const |
Read the Vector data (host pointer) ownership flag. | |
void | StealData (dtype **p) |
Changes the ownership of the data; after the call the Vector is empty. | |
dtype * | StealData () |
Changes the ownership of the data; after the call the Vector is empty. | |
dtype & | Elem (int i) |
Access Vector entries. Index i = 0 .. size-1. | |
const dtype & | Elem (int i) const |
Read only access to Vector entries. Index i = 0 .. size-1. | |
dtype & | operator() (int i) |
Access Vector entries using () for 0-based indexing. | |
const dtype & | operator() (int i) const |
Read only access to Vector entries using () for 0-based indexing. | |
dtype | operator* (const dtype *v) const |
Dot product with a dtype * array. | |
dtype | operator* (const TAutoDiffVector< dtype > &v) const |
Return the inner-product. | |
dtype | operator* (const Vector &v) const |
TAutoDiffVector< dtype > & | operator= (const dtype *v) |
Copy Size() entries from v. | |
TAutoDiffVector< dtype > & | operator= (const TAutoDiffVector< dtype > &v) |
Copy assignment. | |
TAutoDiffVector< dtype > & | operator= (const Vector &v) |
template<typename ivtype > | |
TAutoDiffVector & | operator= (ivtype value) |
Redefine '=' for vector = constant. | |
template<typename ivtype > | |
TAutoDiffVector & | operator*= (ivtype c) |
template<typename ivtype > | |
TAutoDiffVector & | operator/= (ivtype c) |
TAutoDiffVector & | operator-= (const TAutoDiffVector< dtype > &v) |
template<typename ivtype > | |
TAutoDiffVector & | operator-= (ivtype v) |
TAutoDiffVector & | operator+= (const TAutoDiffVector< dtype > &v) |
template<typename ivtype > | |
TAutoDiffVector & | operator+= (ivtype v) |
template<typename ivtype , typename vtype > | |
TAutoDiffVector & | Add (const ivtype a, const vtype &v) |
(*this) += a * Va | |
template<typename ivtype , typename vtype > | |
TAutoDiffVector & | Set (const ivtype a, const vtype &v) |
(*this) = a * x | |
template<typename vtype > | |
void | SetVector (const vtype &v, int offset) |
void | Neg () |
(*this) = -(*this) | |
void | Swap (TAutoDiffVector< dtype > &other) |
Swap the contents of two Vectors. | |
~TAutoDiffVector () | |
Destroys vector. | |
void | Print (std::ostream &os=mfem::out, int width=8) const |
Prints vector to stream os with width entries per line. | |
void | Randomize (int seed=0) |
Set random values in the vector. | |
dtype | Norml2 () const |
Returns the l2 norm of the vector. | |
dtype | Normlinf () const |
Returns the l_infinity norm of the vector. | |
dtype | Norml1 () const |
Returns the l_1 norm of the vector. | |
Protected Attributes | |
dtype * | data |
int | size |
int | capacity |
Friends | |
template<typename vtype1 , typename vtype2 > | |
void | add (const vtype1 &v1, const vtype2 &v2, TAutoDiffVector< dtype > &v) |
Set v = v1 + v2. | |
template<typename vtype1 , typename vtype2 > | |
void | add (const vtype1 &v1, dtype alpha, const vtype2 &v2, TAutoDiffVector< dtype > &v) |
Set v = v1 + alpha * v2. | |
template<typename vtype1 , typename vtype2 > | |
void | add (const dtype a, const vtype1 &x, const dtype b, const vtype2 &y, TAutoDiffVector< dtype > &z) |
template<typename vtype1 , typename vtype2 > | |
void | add (const dtype a, const vtype1 &x, const vtype2 &y, TAutoDiffVector< dtype > &z) |
template<typename vtype1 , typename vtype2 > | |
void | subtract (const vtype1 &x, const vtype2 &y, TAutoDiffVector< dtype > &z) |
template<typename ivtype , typename vtype1 , typename vtype2 > | |
void | subtract (const ivtype a, const vtype1 &x, const vtype2 &y, TAutoDiffVector< dtype > &z) |
Templated vector data type.
The main goal of the TAutoDiffVector class is to serve as a data container for representing vectors in classes, methods, and functions utilized with automatic differentiation (AD). The functionality/interface is copied from the standard MFEM dense vector mfem::Vector. The basic idea is to utilize the templated vector class in combination with AD during the development phase. The AD parts can be replaced with optimized code once the initial development of the application is complete. The common interface between TAutoDiffVector and Vector will ease the transition from AD to hand-optimized code as it does not require a change in the interface or the code structure. TAutoDiffVector is intended to be utilized for dense serial vectors.
Definition at line 40 of file tadvector.hpp.
|
inline |
Default constructor for Vector. Sets size = 0 and data = NULL.
Definition at line 49 of file tadvector.hpp.
|
inline |
Copy constructor. Allocates a new data array and copies the data.
Definition at line 57 of file tadvector.hpp.
|
inline |
Definition at line 78 of file tadvector.hpp.
|
inlineexplicit |
Creates vector of size s.
Definition at line 101 of file tadvector.hpp.
|
inline |
Creates a vector referencing an array of doubles, owned by someone else.
The pointer _data can be NULL. The data array can be replaced later with SetData().
Definition at line 120 of file tadvector.hpp.
|
inline |
Destroys vector.
Definition at line 589 of file tadvector.hpp.
|
inline |
(*this) += a * Va
Definition at line 455 of file tadvector.hpp.
|
inline |
Return the size of the currently allocated data array.
It is always true that Capacity() >= Size().
Definition at line 250 of file tadvector.hpp.
|
inline |
Destroy a vector.
Definition at line 238 of file tadvector.hpp.
|
inline |
Access Vector entries. Index i = 0 .. size-1.
Definition at line 291 of file tadvector.hpp.
|
inline |
Read only access to Vector entries. Index i = 0 .. size-1.
Definition at line 293 of file tadvector.hpp.
|
inline |
Return a pointer to the beginning of the Vector data.
Definition at line 255 of file tadvector.hpp.
|
inline |
Load a vector from an input stream, reading the size from the stream.
Definition at line 168 of file tadvector.hpp.
|
inline |
Load a vector from an input stream.
Definition at line 156 of file tadvector.hpp.
|
inline |
Reads a vector from multiple files.
Definition at line 132 of file tadvector.hpp.
|
inline |
Reset the Vector to be a reference to a sub-vector of base without changing its current size.
Definition at line 231 of file tadvector.hpp.
|
inline |
Reset the Vector to be a reference to a sub-vector of base.
Definition at line 224 of file tadvector.hpp.
|
inline |
(*this) = -(*this)
Definition at line 488 of file tadvector.hpp.
|
inline |
Set the Vector data and size, deleting the old data, if owned.
The Vector does not assume ownership of the new data. The new size is also used as the new Capacity().
Definition at line 221 of file tadvector.hpp.
|
inline |
Returns the l_1 norm of the vector.
Definition at line 685 of file tadvector.hpp.
|
inline |
Returns the l2 norm of the vector.
Definition at line 637 of file tadvector.hpp.
|
inline |
Returns the l_infinity norm of the vector.
Definition at line 675 of file tadvector.hpp.
|
inline |
Conversion to const double *
.
Definition at line 268 of file tadvector.hpp.
|
inline |
Conversion to double *
.
Definition at line 263 of file tadvector.hpp.
|
inline |
Access Vector entries using () for 0-based indexing.
Definition at line 297 of file tadvector.hpp.
|
inline |
Read only access to Vector entries using () for 0-based indexing.
Definition at line 307 of file tadvector.hpp.
|
inline |
Dot product with a dtype *
array.
Definition at line 316 of file tadvector.hpp.
|
inline |
Return the inner-product.
Definition at line 327 of file tadvector.hpp.
|
inline |
Definition at line 338 of file tadvector.hpp.
|
inline |
Definition at line 394 of file tadvector.hpp.
|
inline |
Definition at line 433 of file tadvector.hpp.
|
inline |
Definition at line 444 of file tadvector.hpp.
|
inline |
Definition at line 413 of file tadvector.hpp.
|
inline |
Definition at line 424 of file tadvector.hpp.
|
inline |
Definition at line 404 of file tadvector.hpp.
|
inline |
Copy Size() entries from v.
Definition at line 350 of file tadvector.hpp.
|
inline |
Copy assignment.
Definition at line 362 of file tadvector.hpp.
|
inline |
Definition at line 372 of file tadvector.hpp.
|
inline |
Redefine '=' for vector = constant.
Definition at line 384 of file tadvector.hpp.
|
inline |
Read the Vector data (host pointer) ownership flag.
Definition at line 271 of file tadvector.hpp.
|
inline |
Prints vector to stream os with width entries per line.
Definition at line 592 of file tadvector.hpp.
|
inline |
Set random values in the vector.
Definition at line 619 of file tadvector.hpp.
|
inline |
(*this) = a * x
Definition at line 467 of file tadvector.hpp.
|
inline |
Set the Vector data and size.
The Vector does not assume ownership of the new data. The new size is
Definition at line 206 of file tadvector.hpp.
|
inline |
Resize the vector to size s.
If the new size is less than or equal to Capacity() then the internal data array remains the same. Otherwise, the old array is deleted, if owned, and a new array of size s is allocated without copying the previous content of the Vector.
Definition at line 183 of file tadvector.hpp.
|
inline |
Definition at line 478 of file tadvector.hpp.
|
inline |
Returns the size of the vector.
Definition at line 246 of file tadvector.hpp.
|
inline |
Changes the ownership of the data; after the call the Vector is empty.
Definition at line 283 of file tadvector.hpp.
|
inline |
Changes the ownership of the data; after the call the Vector is empty.
Definition at line 274 of file tadvector.hpp.
|
inline |
Swap the contents of two Vectors.
Definition at line 497 of file tadvector.hpp.
|
friend |
Definition at line 532 of file tadvector.hpp.
|
friend |
Definition at line 548 of file tadvector.hpp.
|
friend |
Set v = v1 + v2.
Definition at line 506 of file tadvector.hpp.
|
friend |
Set v = v1 + alpha * v2.
Definition at line 518 of file tadvector.hpp.
|
friend |
Definition at line 575 of file tadvector.hpp.
|
friend |
Definition at line 563 of file tadvector.hpp.
|
protected |
Definition at line 45 of file tadvector.hpp.
|
protected |
Definition at line 43 of file tadvector.hpp.
|
protected |
Definition at line 44 of file tadvector.hpp.