26 for (
int i = 0; i < size; i++)
29 if ( !((i+1) % width) || i+1 == size )
47 for (
int i = 0; i < size; i++)
49 os << operator[](i) <<
'\n';
62 for (
int i = 0; i < size; i++)
71 MFEM_ASSERT(size > 0,
"Array is empty with size " << size);
73 T max = operator[](0);
74 for (
int i = 1; i < size; i++)
76 if (max <
operator[](i))
88 MFEM_ASSERT(size > 0,
"Array is empty with size " << size);
90 T min = operator[](0);
91 for (
int i = 1; i < size; i++)
93 if (
operator[](i) < min)
106 T sum =
static_cast<T
>(0);
107 for (
int i = 0; i < size; i++)
117 static_assert(std::is_arithmetic<T>::value,
"Use with arithmetic types!");
118 const bool useDevice = UseDevice();
123 y[i] = std::abs(y[i]);
131 T sum =
static_cast<T
>(0);
132 for (
int i = 0; i < size; i++)
143 T val_prev = operator[](0), val;
144 for (
int i = 1; i < size; i++)
160 if (size < 2) {
return true; }
161 const T v0 = data[0];
162 for (
int i = 1; i < size; i++)
177 in.open(filename, std::ifstream::in);
178 MFEM_VERIFY(in.is_open(),
"File " << filename <<
" does not exist.");
186 int height = this->NumRows();
187 int width = this->NumCols();
189 for (
int i = 0; i < height; i++)
191 os <<
"[row " << i <<
"]\n";
192 for (
int j = 0; j < width; j++)
195 if ( (j+1) == width_ || (j+1) % width_ == 0 )
Dynamic 2D array using row-major layout.
void Load(std::istream &in, int fmt=0)
Read an Array2D from the stream in using format fmt.
void Print(std::ostream &out=mfem::out, int width=4)
Prints array to stream with width elements per row.
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void Load(std::istream &in, int fmt=0)
Read an Array from the stream in using format fmt. The format fmt can be:
bool IsConstant() const
Return true if all entries of the array are the same.
T Min() const
Find the minimal element in the array, using the comparison operator < for class T.
void PartialSum()
Fill the entries of the array with the cumulative sum of the entries.
int IsSorted() const
Return 1 if the array is sorted from lowest to highest. Otherwise return 0.
void Save(std::ostream &out, int fmt=0) const
Save the Array to the stream out using the format fmt. The format fmt can be:
void Abs()
Replace each entry of the array with its absolute value.
void Print(std::ostream &out=mfem::out, int width=4) const
Prints array to stream with width elements per row.
T Sum() const
Return the sum of all the array entries using the '+'' operator for class 'T'.
T * ReadWrite(Memory< T > &mem, int size, bool on_dev=true)
Get a pointer for read+write access to mem with the mfem::Device's DeviceMemoryClass,...
void forall_switch(bool use_dev, int N, lambda &&body)