| | 16 | La solución que se propone sería crear un nuevo tipo de datos en TOL |
| | 17 | que podría llamarse {{{VectorRef}}} y que tendría funciones para ir añadiendo referencias a valores reales inscritos en distintos tipos de datos TOL. En principio se podrían crear referencias simples o masivas a datos de tipo |
| | 18 | |
| | 19 | * '''Real''' |
| | 20 | {{{ |
| | 21 | #!cpp |
| | 22 | //Creates a single reference to a Real variable |
| | 23 | VectorRef Ref.Real(Real x); |
| | 24 | }}} |
| | 25 | * '''Polyn''' |
| | 26 | {{{ |
| | 27 | #!cpp |
| | 28 | //Creates a single reference to a coefficient of a polynomial |
| | 29 | VectorRef Ref.Polyn.Coef(Polyn pol, Real deg)); |
| | 30 | //Creates a vectorial reference to all coefficients of a polynomial among a selection of degrees |
| | 31 | VectorRef Ref.Polyn.Extract(Polyn pol, Set degrees)); |
| | 32 | //Creates a vectorial reference to all coefficients of a polynomial |
| | 33 | VectorRef Ref.Polyn.Full(Polyn pol)); |
| | 34 | }}} |
| | 35 | * '''Matrix''' |
| | 36 | {{{ |
| | 37 | #!cpp |
| | 38 | //Creates a single reference to a cell in a Matrix |
| | 39 | VectorRef Ref.Matrix.Cell(Matrix mat, Real row, Real column)); |
| | 40 | //Creates a vectorial reference to all cells in a rectangle of a Matrix |
| | 41 | VectorRef Ref.Matrix.Minor(Matrix mat, Real fromRow, Real fromColumn, Real untilRow, Real untilColumns)); |
| | 42 | //Creates a vectorial reference to all cells in a subset of selected rows from a Matrix |
| | 43 | VectorRef Ref.Matrix.Rows(Matrix mat, Set rowIndexs)); |
| | 44 | //Creates a vectorial reference to all cells in a subset of selected coluns from a Matrix |
| | 45 | VectorRef Ref.Matrix.Columns(Matrix mat, Set colIndexs)); |
| | 46 | //Creates a vectorial reference to all cells in a Matrix |
| | 47 | VectorRef Ref.Matrix.Full(Matrix mat, Set colIndexs)); |
| | 48 | }}} |
| | 49 | * '''Matrix''' |
| | 50 | {{{ |
| | 51 | #!cpp |
| | 52 | //Creates a single reference to a Real element of a Set |
| | 53 | VectorRef Ref.Set.Element(Set set, Real numElement)); |
| | 54 | //Creates a vectorial reference to all selected elements of a Set |
| | 55 | VectorRef Ref.Set.Extract(Set set, Set indexes)); |
| | 56 | //Creates a vectorial reference to all selected elements of a Set with type Real |
| | 57 | VectorRef Ref.Set.Full(Set set)); |
| | 58 | //Creates a vectorial reference to all selected elements of a Set with type Real, Polyn or Matrix, and recursively in elements of type Set |
| | 59 | VectorRef Ref.Set.Deep(Set set)); |
| | 60 | |
| | 61 | }}} |
| | 62 | |
| | 63 | Sería necesario también disponer de algunas funciones para la definición de vectores de referencia a partir de otros mediante composición y extracción. |
| | 64 | {{{ |
| | 65 | #!cpp |
| | 66 | //Añade al primer vector de referecias las del segundo |
| | 67 | VectorRef Ref.Append(VectorRef a, VectorRef b); |
| | 68 | //Extrae las referencias seleccionadas |
| | 69 | VectorRef Ref.Extract(VectorRef a, Real indexes); |
| | 70 | }}} |
| | 71 | |
| | 72 | Para su uso con CINT haría falta una función de exportación |
| | 73 | |
| | 74 | {{{ |
| | 75 | #!cpp |
| | 76 | Real Cint.ExportRef(VectorRef a [, Text nameSpace=""]) |
| | 77 | }}} |
| | 78 | |
| | 79 | lo cual crearía en el ámbito global o el namespace especificado una instancia de la clase con el nombre de la variable exportada |
| | 80 | |
| | 81 | {{{ |
| | 82 | #!cpp |
| | 83 | class VectorRef |
| | 84 | { |
| | 85 | private: |
| | 86 | int s_; |
| | 87 | double** ref_; |
| | 88 | public: |
| | 89 | VectorRef(int s, double** ref) |
| | 90 | : s_(s), |
| | 91 | ref_(ref) |
| | 92 | {} |
| | 93 | ~VectorRef() {} |
| | 94 | |
| | 95 | int size() const; |
| | 96 | |
| | 97 | //zero based const array access |
| | 98 | const double & operator [] (int i) const { return (*ref_[i]); } |
| | 99 | //zero based non const array access |
| | 100 | double & operator [] (int i) { return (*ref_[i]); } |
| | 101 | |
| | 102 | //one based const array access |
| | 103 | const double & operator () (int i) const { return (*ref_[i-1]); } |
| | 104 | //one based non const array access |
| | 105 | double & operator () (int i) { return (*ref_[i-1]); } |
| | 106 | |
| | 107 | //set the referenced values from an std::vector |
| | 108 | void setValues(const std::vector<double>& v) |
| | 109 | { |
| | 110 | if(v.size()==s_) |
| | 111 | { |
| | 112 | int i; |
| | 113 | double* rf = ref_; |
| | 114 | for(i=0; i<s; i++, rf++) { *rf = v[i]; } |
| | 115 | } |
| | 116 | } |
| | 117 | //get the referenced values into a std::vector |
| | 118 | void getValues(std::vector<double>& v) const |
| | 119 | { |
| | 120 | if(v.size()==s_) |
| | 121 | { |
| | 122 | int i; |
| | 123 | double* rf = ref_; |
| | 124 | for(i=0; i<s; i++, rf++) { v[i] = *rf; } |
| | 125 | } |
| | 126 | }; |
| | 127 | |
| | 128 | //set the referenced values from a pointer to double |
| | 129 | void setValues(const double* v) |
| | 130 | { |
| | 131 | int i; |
| | 132 | double* rf = ref_; |
| | 133 | const double* v_ = ref_; |
| | 134 | for(i=0; i<s; i++, rf++, v_++) { *rf = *v_; } |
| | 135 | } |
| | 136 | //get the referenced values into a a pointer to double |
| | 137 | void getValues(double* v) const |
| | 138 | { |
| | 139 | int i; |
| | 140 | double* rf = ref_; |
| | 141 | const double* v_ = ref_; |
| | 142 | for(i=0; i<s; i++, rf++, v_++) { *v_ = *rf; } |
| | 143 | }; |
| | 144 | |
| | 145 | }}} |
| | 146 | |
| | 147 | |
| | 148 | Finalmente haría falta una función para lectura y escritura desde y a Matrix |
| | 149 | {{{ |
| | 150 | #!cpp |
| | 151 | //Devuelve una matriz columna con los valores referenciados |
| | 152 | Matrix v = Ref.Get(vr); |
| | 153 | //Modifica los valores referenciados haciéndolos iguales a los elementos de una matriz columna con el mismo número de elementos |
| | 154 | Real Ref.Put(vr,v*2); |
| | 155 | }}} |
| | 156 | |
| | 157 | De esta forma en cada iteración de un hipotético ciclo TOL sólo sería necesario llamar una vez a cada una de estas dos funciones. |