File indexing completed on 2025-01-18 09:57:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifndef G4ARRAYOPS_HH
0037 #define G4ARRAYOPS_HH
0038
0039 #include "globals.hh"
0040
0041 #include <vector>
0042
0043
0044
0045
0046
0047 namespace G4ArrayOps
0048 {
0049
0050 template<class T>
0051 void Set(G4int Elements, T* To, T Value)
0052 {
0053 for (G4int position = 0; position < Elements; position++) {
0054 To[position] = Value;
0055 }
0056 }
0057
0058
0059 template<class T>
0060 void Copy(G4int Elements, T* To, T* From)
0061 {
0062 for (G4int position = 0; position < Elements; position++) {
0063 To[position] = From[position];
0064 }
0065 }
0066
0067
0068
0069
0070 template<class T>
0071 void Add(G4int Elements, T* To, T* A1, T* A2 = nullptr)
0072 {
0073 if (A2 == nullptr) {
0074 A2 = To;
0075 }
0076
0077 for (G4int position = 0; position < Elements; position++) {
0078 To[position] = A2[position] + A1[position];
0079 }
0080 }
0081
0082
0083
0084
0085 template<class T>
0086 void Add(G4int Elements, T* To, T A1, T* A2 = NULL)
0087 {
0088 if (A2 == NULL) {
0089 A2 = To;
0090 }
0091
0092 for (G4int position = 0; position < Elements; position++) {
0093 To[position] = A1 + A2[position];
0094 }
0095 }
0096
0097
0098
0099
0100 template<class T>
0101 void Subtract(G4int Elements, T* To, T* Minuend, T* Subtrahend = NULL)
0102 {
0103 if (Subtrahend == NULL) {
0104 Subtrahend = Minuend;
0105 Minuend = To;
0106 }
0107
0108 for (G4int position = 0; position < Elements; position++) {
0109 To[position] = Minuend[position] - Subtrahend[position];
0110 }
0111 }
0112
0113
0114
0115
0116 template<class T>
0117 void Multiply(G4int Elements, T* To, T* M1, T* M2 = nullptr)
0118 {
0119 if (M2 == nullptr) {
0120 M2 = To;
0121 }
0122
0123 for (G4int position = 0; position < Elements; position++) {
0124 To[position] = M2[position] * M1[position];
0125 }
0126 }
0127
0128
0129
0130
0131 template<class T>
0132 void Multiply(G4int Elements, T* To, T M1, T* M2 = NULL)
0133 {
0134 if (M2 == NULL) {
0135 M2 = To;
0136 }
0137
0138 for (G4int position = 0; position < Elements; position++) {
0139 To[position] = M2[position] * M1;
0140 }
0141 }
0142
0143
0144
0145
0146 template<class T>
0147 void Divide(G4int Elements, T* To, T* Numerator, T* Denominator = NULL)
0148 {
0149 if (Denominator == NULL) {
0150 Denominator = Numerator;
0151 Numerator = To;
0152 }
0153
0154 for (G4int position = 0; position < Elements; position++) {
0155 To[position] = Numerator[position] / Denominator[position];
0156 }
0157 }
0158
0159
0160
0161
0162 template<class T>
0163 void Divide(G4int Elements, T* To, T Numerator, T* Denominator = NULL)
0164 {
0165 if (Denominator == nullptr) {
0166 Denominator = To;
0167 }
0168
0169 for (G4int position = 0; position < Elements; position++) {
0170 To[position] = Numerator / Denominator[position];
0171 }
0172 }
0173
0174 template<class T>
0175 void DeleteVectorOfPointers(std::vector<T>& Vector)
0176 {
0177 for (unsigned int i = 0; i < Vector.size(); i++) {
0178 delete Vector[i];
0179 }
0180
0181 delete &Vector;
0182 }
0183 }
0184
0185 #endif