PSCF v1.1
product.h
1#ifndef UTIL_PRODUCT_H
2#define UTIL_PRODUCT_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/space/Vector.h>
12#include <util/space/Tensor.h>
13#include <complex>
14using std::complex;
15
16namespace Util
17{
18
22 inline float product(float a, float b)
23 { return a*b; }
24
28 inline double product(double a, double b)
29 { return a*b; }
30
34 inline double product(const Vector& a, const Vector& b)
35 { return a.dot(b); }
36
40 inline double product(const Tensor& a, const Tensor& b)
41 {
42 double sum = 0.0;
43 int i, j;
44 for (i = 0; i < Dimension; ++i) {
45 for (j = 0; j < Dimension; ++j) {
46 sum += a(i, j)*b(i, j);
47 }
48 }
49 return sum;
50 }
51
55 inline complex<float> product(complex<float> a, complex<float> b)
56 { return conj(a)*b; }
57
61 inline complex<double> product(complex<double> a, complex<double> b)
62 { return conj(a)*b; }
63
64}
65#endif
A Tensor represents a Cartesian tensor.
Definition: Tensor.h:33
A Vector is a Cartesian vector.
Definition: Vector.h:76
double dot(const Vector &v) const
Return dot product of this vector and vector v.
Definition: Vector.h:632
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
Utility classes for scientific computation.
Definition: accumulators.mod:1
float product(float a, float b)
Product for float Data.
Definition: product.h:22