15 #ifndef included_Vector_h
16 #define included_Vector_h
18 #include "utils/Utilities.h"
70 bool copy_data =
true);
151 transform(std::function<
void(
const int size,
double* vector)> transformer);
164 std::function<
void(
const int size,
double* vector)> transformer)
const;
177 std::function<
void(
const int size,
double* vector)> transformer)
const;
190 std::function<
void(
const int size,
double* origVector,
double* resultVector)>
205 std::function<
void(
const int size,
double* origVector,
double* resultVector)>
219 if (
dim > d_alloc_size) {
221 CAROM_ERROR(
"Can not reallocate externally owned storage.");
228 d_vec =
new double [
dim] {0.0};
242 return d_distributed;
270 const Vector& other)
const;
312 std::unique_ptr<Vector>
316 plus(other, *result);
317 return std::unique_ptr<Vector>(result);
348 std::unique_ptr<Vector>
351 const Vector& other)
const
354 plusAx(factor, other, *result);
355 return std::unique_ptr<Vector>(result);
401 std::unique_ptr<Vector>
403 const Vector& other)
const
406 minus(other, *result);
407 return std::unique_ptr<Vector>(result);
435 std::unique_ptr<Vector>
440 mult(factor, *result);
441 return std::unique_ptr<Vector>(result);
470 CAROM_ASSERT((0 <= i) && (i <
dim()));
488 CAROM_ASSERT((0 <= i) && (i <
dim()));
528 void print(
const char * prefix)
const;
536 void write(
const std::string& base_file_name);
544 void read(
const std::string& base_file_name);
553 void local_read(
const std::string& base_file_name,
int rank);
659 const Vector & test_point);
666 const Vector & test_point);
double * getData() const
Get the vector data as a pointer.
void setSize(int dim)
Sets the length of the vector and reallocates storage if needed. All values are initialized to zero.
double & item(int i)
Non-const Vector member access.
void read(const std::string &base_file_name)
read Vector from (a) HDF file(s).
const double & operator()(int i) const
Const Vector member access.
Vector & operator-=(const Vector &rhs)
Subtraction operator.
bool distributed() const
Returns true if the Vector is distributed.
void print(const char *prefix) const
print Vector into (a) ascii file(s).
void distribute(const int local_dim)
Distribute this vector among MPI processes, based on the specified local dimension....
double norm() const
Form the norm of this.
double normalize()
Normalizes the Vector and returns its norm.
std::unique_ptr< Vector > minus(const Vector &other) const
Subtracts other and this and returns the result.
void write(const std::string &base_file_name)
write Vector into (a) HDF file(s).
const double & item(int i) const
Const Vector member access.
std::unique_ptr< Vector > plus(const Vector &other) const
Adds other and this and returns the result.
std::unique_ptr< Vector > plusAx(double factor, const Vector &other) const
Adds factor*other and this and returns the result.
Vector & operator=(const Vector &rhs)
Assignment operator.
double inner_product(const Vector &other) const
Inner product, reference form.
void plusEqAx(double factor, const Vector &other)
Adds factor*other to this.
void transform(Vector *&result, std::function< void(const int size, double *vector)> transformer) const
Transform a vector using a supplied function and store the results in another vector.
std::unique_ptr< Vector > mult(double factor) const
Multiplies this by the supplied constant and returns the result.
double norm2() const
Form the squared norm of this.
Vector & transform(std::function< void(const int size, double *vector)> transformer)
Transform the vector using a supplied function.
Vector & operator+=(const Vector &rhs)
Addition operator.
double localMin(int nmax=0)
Compute the local minimum of this.
void local_read(const std::string &base_file_name, int rank)
read read a single rank of a distributed Vector from (a) HDF file(s).
int dim() const
Returns the dimension of the Vector on this processor.
Vector & operator*=(const double &a)
Scaling operator.
void gather()
Gather all the distributed elements among MPI processes. This becomes not distributed after this func...
int getCenterPoint(const std::vector< const Vector * > &points, bool use_centroid)
Get center point of a group of points.
int getClosestPoint(const std::vector< const Vector * > &points, const Vector &test_point)
Get closest point to a test point among a group of points.