23 template<
class T1,
class T2,
class Scalar >
29 PZError <<
"SAXPY error!" << std::endl
30 <<
"Vectors with different sizes #x = " << size
31 <<
", #y = " << y.
NElements() << std::endl;
37 for (
int ii = 0; ii < size; ii++) {
38 x[ ii ] += s * y[ ii ];
48 template<
class T1,
class Scalar >
56 for (
int ii = 0; ii < size; ii++) {
70 for (
int i = 0; i < a.
size(); i++) {
71 result[i] = a[i] - b[i];
84 for (
int i = 0; i < a.
size(); i++) {
108 PZError <<
"SDOT error!" << std::endl
109 <<
"Vectors with different sizes #x = " << size
110 <<
", #y = " << y.
NElements() << std::endl;
116 for (
int ii = 0; ii < size; ii++) {
117 sum += x[ii] * y[ii];
123 template <
class T1 >
131 for (
int i = 0; i < vec1.
size(); i++) {
132 dist += (vec1[i] - vec2[i])*(vec1[i] - vec2[i]);
151 T* found = std::find(static_cast<T*> (v), v + v.
NElements(), e);
153 int dist = distance(static_cast<T*> (v), found);
165 for (
int ii = 1; ii < nel; ii++) {
179 for (
int ii = 1; ii < nel; ii++) {
187 template<
class T,
int N >
189 int firstc, secondc, nfirst, nsecond;
194 while (firstc < nfirst && secondc < nsecond) {
195 while (firstc < nfirst && one[firstc] < two[secondc]) {
198 if (firstc == nfirst)
break;
199 while (secondc < nsecond && two[secondc] < one[firstc]) {
202 if (firstc < nfirst && secondc < nsecond && one[firstc] == two[secondc]) {
203 result.
Push(one[firstc]);
212 template<
class T,
int N >
214 int firstc, secondc, thirdc, nfirst, nsecond, nthird;
221 while (firstc < nfirst && secondc < nsecond && thirdc < nthird) {
222 while (firstc < nfirst && (one[firstc] < two[secondc] || one[firstc] < three[thirdc])) {
225 if (firstc == nfirst)
break;
226 while (secondc < nsecond && (two[secondc] < one[firstc] || two[secondc] < three[thirdc])) {
229 if (secondc == nsecond)
break;
230 while (thirdc < nthird && (three[thirdc] < one[firstc] || three[thirdc] < two[secondc])) {
233 if (firstc < nfirst && secondc < nsecond && thirdc < nthird && one[firstc] == two[secondc] && one[firstc] == three[thirdc]) {
234 result.
Push(one[firstc]);
248 for (
int i = 0; i < size; i++) {
249 res += one[i] * one[i];
257 if (x1.
size() != 3) {
260 if (x2.
size() != 3) {
263 if (result.
size() != 3) {
267 result[0] = x1[1] * x2[2] - x2[1] * x1[2];
268 result[1] = x1[2] * x2[0] - x2[2] * x1[0];
269 result[2] = x1[0] * x2[1] - x2[0] * x1[1];
279 PZError <<
"Dot error!" << std::endl
280 <<
"Vectors with different sizes #x1 = " << size
281 <<
", #x2 = " << x2.
NElements() << std::endl;
287 for (
int i = 0; i < size; ++i) {
288 result = result + x1[i] * x2[i];
295 #endif //PZVEC_EXTRAS_H TPZVec< T > & Sort(TPZVec< T > &v)
Sorting the elements into v.
TPZVec< T > & operator-=(TPZVec< T > &a, const TPZVec< T > &b)
substracts two vectors
int Find(TPZVec< T > &v, const T &e)
Finds if exists the element e into vector v.
double sdot(TPZVec< T1 > &x, TPZVec< T1 > &y)
Performs a sdot operation: dot <- Transpose[x] * y.
This class implements a simple vector storage scheme for a templated class T. Utility.
void saxpy(TPZVec< T1 > &x, const TPZVec< T2 > &y, Scalar s)
Performs a saxpy operation: x <- x + s * y.
TPZVec< T > operator-(const TPZVec< T > &a, const TPZVec< T > &b)
substracts two vectors
T Norm(const TPZVec< T > &one)
Gets commom elements into the one and two vectors.
int64_t size() const
Returns the number of elements of the vector.
void Push(const T object)
Pushes a copy of the object on the stack.
void Intersect(const TPZVec< T > &one, const TPZVec< T > &two, TPZStack< T, N > &result)
Gets commom elements into the one and two vectors.
#define DebugStop()
Returns a message to user put a breakpoint in.
T Max(TPZVec< T > &v)
Returns the maximum element into v.
void sscal(TPZVec< T1 > &x, const Scalar s)
Performs a sscal operation: x <- x * s.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
T * begin() const
Casting operator. Returns The fStore pointer.
T Min(TPZVec< T > &v)
Returns the minimum element into v.
T Dot(const TPZVec< T > &x1, const TPZVec< T > &x2)
REAL dist(TPZVec< T1 > &vec1, TPZVec< T1 > &vec2)
This class implements a stack object. Utility.
int64_t NElements() const
Returns the number of elements of the vector.
clarg::argString m("-m", "input matrix file name (text format)", "matrix.txt")
#define PZError
Defines the output device to error messages and the DebugStop() function.
void Cross(const TPZVec< T > &x1, const TPZVec< T > &x2, TPZVec< T > &result)