9 tiny_vec_ref(Type *p_,
size_t n_) : p(p_), n(n_) {}
11 tiny_vec_ref &operator=(
const T &other) {
12 for(
size_t i = 0; i < n; i++) p[i] = other[i];
16 template <
class Type,
int n>
20 tiny_vec(
const tiny_vec &other) {
21 for(
int i=0; i<n; i++) data[i] = other.data[i];
23 tiny_vec(
const Type &other) {
24 for(
int i=0; i<n; i++) data[i] = other;
26 void resize(
size_t length){ }
27 int size()
const {
return n; }
28 Type operator[] (
size_t i)
const {
return data[i]; }
29 Type &operator[] (
size_t i) {
return data[i]; }
30 void setZero() {
for(
int i=0; i<n; i++) (*
this)[i] = 0;}
31 tiny_vec_ref<Type> segment(
size_t start,
size_t length) {
32 tiny_vec_ref<Type> ans(&(data[start]), length);
35 #define VBINARY_OPERATOR(OP) \ 36 tiny_vec operator OP (const tiny_vec &other) const { \ 38 for(int i=0; i<n; i++) ans.data[i] = data[i] OP other.data[i]; \ 41 template<class Scalar> \ 42 tiny_vec operator OP (const Scalar &other) const { \ 44 for(int i=0; i<n; i++) ans.data[i] = data[i] OP other; \ 51 #define VUNARY_OPERATOR(OP) \ 52 tiny_vec operator OP () const { \ 54 for(int i=0; i<n; i++) ans.data[i] = OP (*this).data[i]; \ 59 #define COMPOUND_ASSIGNMENT_OPERATOR(OP) \ 60 tiny_vec& operator OP (const Type &other) { \ 61 for(int i=0; i<n; i++) (*this).data[i] OP other; \ 64 tiny_vec& operator OP (const tiny_vec &other) { \ 65 for(int i=0; i<n; i++) (*this).data[i] OP other[i]; \ 68 COMPOUND_ASSIGNMENT_OPERATOR(+=)
69 COMPOUND_ASSIGNMENT_OPERATOR(-=)
70 COMPOUND_ASSIGNMENT_OPERATOR(*=)
71 COMPOUND_ASSIGNMENT_OPERATOR(/=)
76 for(
int i=0; i<n; i++) ans[i] = (*
this)[i];
82 template<
class Type,
int n>
83 tiny_vec<Type, n>
operator* (
const Type &x,
const tiny_vec<Type, n> &y) {
84 return y.operator* (x);
87 template<
class Type,
int n>
88 std::ostream &operator<<(std::ostream &os, tiny_vec<Type, n>
const &x) {
90 for(
int i=0; i < x.size(); i++) os << x[i] <<
" ";
Vector class used by TMB.
vector< Type > operator*(matrix< Type > A, vector< Type > x)