source: sasview/src/sans/simulation/iqPy/libiqPy/tnt/tnt_array1d_utils.h @ aa639ea

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since aa639ea was aa639ea, checked in by Mathieu Doucet <doucetm@…>, 11 years ago

Move simulation code (unused)

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2*
3* Template Numerical Toolkit (TNT)
4*
5* Mathematical and Computational Sciences Division
6* National Institute of Technology,
7* Gaithersburg, MD USA
8*
9*
10* This software was developed at the National Institute of Standards and
11* Technology (NIST) by employees of the Federal Government in the course
12* of their official duties. Pursuant to title 17 Section 105 of the
13* United States Code, this software is not subject to copyright protection
14* and is in the public domain. NIST assumes no responsibility whatsoever for
15* its use by other parties, and makes no guarantees, expressed or implied,
16* about its quality, reliability, or any other characteristic.
17*
18*/
19
20#ifndef TNT_ARRAY1D_UTILS_H
21#define TNT_ARRAY1D_UTILS_H
22
23#include <cstdlib>
24#include <cassert>
25
26namespace TNT
27{
28
29
30template <class T>
31std::ostream& operator<<(std::ostream &s, const Array1D<T> &A)
32{
33    int N=A.dim1();
34
35#ifdef TNT_DEBUG
36        s << "addr: " << (void *) &A[0] << "\n";
37#endif
38    s << N << "\n";
39    for (int j=0; j<N; j++)
40    {
41       s << A[j] << "\n";
42    }
43    s << "\n";
44
45    return s;
46}
47
48template <class T>
49std::istream& operator>>(std::istream &s, Array1D<T> &A)
50{
51        int N;
52        s >> N;
53
54        Array1D<T> B(N);
55        for (int i=0; i<N; i++)
56                s >> B[i];
57        A = B;
58        return s;
59}
60
61
62
63template <class T>
64Array1D<T> operator+(const Array1D<T> &A, const Array1D<T> &B)
65{
66        int n = A.dim1();
67
68        if (B.dim1() != n )
69                return Array1D<T>();
70
71        else
72        {
73                Array1D<T> C(n);
74
75                for (int i=0; i<n; i++)
76                {
77                        C[i] = A[i] + B[i];
78                }
79                return C;
80        }
81}
82
83
84
85template <class T>
86Array1D<T> operator-(const Array1D<T> &A, const Array1D<T> &B)
87{
88        int n = A.dim1();
89
90        if (B.dim1() != n )
91                return Array1D<T>();
92
93        else
94        {
95                Array1D<T> C(n);
96
97                for (int i=0; i<n; i++)
98                {
99                        C[i] = A[i] - B[i];
100                }
101                return C;
102        }
103}
104
105
106template <class T>
107Array1D<T> operator*(const Array1D<T> &A, const Array1D<T> &B)
108{
109        int n = A.dim1();
110
111        if (B.dim1() != n )
112                return Array1D<T>();
113
114        else
115        {
116                Array1D<T> C(n);
117
118                for (int i=0; i<n; i++)
119                {
120                        C[i] = A[i] * B[i];
121                }
122                return C;
123        }
124}
125
126
127template <class T>
128Array1D<T> operator/(const Array1D<T> &A, const Array1D<T> &B)
129{
130        int n = A.dim1();
131
132        if (B.dim1() != n )
133                return Array1D<T>();
134
135        else
136        {
137                Array1D<T> C(n);
138
139                for (int i=0; i<n; i++)
140                {
141                        C[i] = A[i] / B[i];
142                }
143                return C;
144        }
145}
146
147
148
149
150
151
152
153
154
155template <class T>
156Array1D<T>&  operator+=(Array1D<T> &A, const Array1D<T> &B)
157{
158        int n = A.dim1();
159
160        if (B.dim1() == n)
161        {
162                for (int i=0; i<n; i++)
163                {
164                                A[i] += B[i];
165                }
166        }
167        return A;
168}
169
170
171
172
173template <class T>
174Array1D<T>&  operator-=(Array1D<T> &A, const Array1D<T> &B)
175{
176        int n = A.dim1();
177
178        if (B.dim1() == n)
179        {
180                for (int i=0; i<n; i++)
181                {
182                                A[i] -= B[i];
183                }
184        }
185        return A;
186}
187
188
189
190template <class T>
191Array1D<T>&  operator*=(Array1D<T> &A, const Array1D<T> &B)
192{
193        int n = A.dim1();
194
195        if (B.dim1() == n)
196        {
197                for (int i=0; i<n; i++)
198                {
199                                A[i] *= B[i];
200                }
201        }
202        return A;
203}
204
205
206
207
208template <class T>
209Array1D<T>&  operator/=(Array1D<T> &A, const Array1D<T> &B)
210{
211        int n = A.dim1();
212
213        if (B.dim1() == n)
214        {
215                for (int i=0; i<n; i++)
216                {
217                                A[i] /= B[i];
218                }
219        }
220        return A;
221}
222
223
224
225
226
227
228} // namespace TNT
229
230#endif
Note: See TracBrowser for help on using the repository browser.