Vec operator /(const Vec &v, double s) { Vec result(v.Elts()); int i; for (i = 0; i < v.Elts(); i++) result[i] = v[i] / s; return (result); }
Vec operator -(const Vec &v) { Vec result(v.Elts()); int i; for (i = 0; i < v.Elts(); i++) result[i] = -v[i]; return (result); }
double dot(const Vec &a, const Vec &b) { Assert(a.Elts() == b.Elts(), "(Vec::dot) Vec sizes don't match"); double sum = 0; int i; for (i = 0; i < a.Elts(); i++) sum += a[i] * b[i]; return (sum); }
Vec operator /(const Vec &a, const Vec &b) { Assert(a.Elts() == b.Elts(), "(Vec::/) Vec sizes don't match"); Vec result(a.Elts()); int i; for (i = 0; i < a.Elts(); i++) result[i] = a[i] / b[i]; return (result); }
Mat oprod(const Vec &a, const Vec &b) // returns outerproduct of a and b: a * trans(b) { Mat result; Int i; result.SetSize(a.Elts(), b.Elts()); for (i = 0; i < a.Elts(); i++) result[i] = a[i] * b; return(result); }
bool operator !=(const Vec &a, const Vec &b) { int i; for (i = 0; i < a.Elts(); i++) if (a[i] != b[i]) return (1); return (0); }
Vec operator * (const Vec &v, const Mat &m) // v * m { Assert(v.Elts() == m.Rows(), "(Mat::v*m) vector/matrix sizes don't match"); Vec result(m.Cols(), vl_zero); Int i; for (i = 0; i < m.Rows(); i++) result += m[i] * v[i]; return(result); }
Vec operator * (const Mat &m, const Vec &v) { Assert(m.Cols() == v.Elts(), "(Mat::*v) matrix and vector sizes don't match"); Int i; Vec result(m.Rows()); for (i = 0; i < m.Rows(); i++) result[i] = dot(v, m[i]); return(result); }
Vec::Vec(const Vec &v) { Assert(v.data != 0, "(Vec) Can't construct from a null vector"); elts = v.Elts(); data = new double[elts]; #ifdef VL_USE_MEMCPY memcpy(data, v.Ref(), sizeof (double) * Elts()); #else for (int i = 0; i < Elts(); i++) data[i] = v[i]; #endif }