ningshuxia
2022-12-12 4f1314cb69a47c22e52f1efdc4b4be6c1d55143d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
// <copyright file="Vector.Operators.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
//
// Copyright (c) 2009-2013 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
 
using System;
using System.Runtime.CompilerServices;
 
namespace IStation.Numerics.LinearAlgebra
{
    public abstract partial class Vector<T>
    {
        /// <summary>
        /// Returns a <strong>Vector</strong> containing the same values of <paramref name="rightSide"/>.
        /// </summary>
        /// <remarks>This method is included for completeness.</remarks>
        /// <param name="rightSide">The vector to get the values from.</param>
        /// <returns>A vector containing the same values as <paramref name="rightSide"/>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
        public static Vector<T> operator +(Vector<T> rightSide)
        {
            return rightSide.Clone();
        }
 
        /// <summary>
        /// Returns a <strong>Vector</strong> containing the negated values of <paramref name="rightSide"/>.
        /// </summary>
        /// <param name="rightSide">The vector to get the values from.</param>
        /// <returns>A vector containing the negated values as <paramref name="rightSide"/>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
        public static Vector<T> operator -(Vector<T> rightSide)
        {
            return rightSide.Negate();
        }
 
        /// <summary>
        /// Adds two <strong>Vectors</strong> together and returns the results.
        /// </summary>
        /// <param name="leftSide">One of the vectors to add.</param>
        /// <param name="rightSide">The other vector to add.</param>
        /// <returns>The result of the addition.</returns>
        /// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
        public static Vector<T> operator +(Vector<T> leftSide, Vector<T> rightSide)
        {
            return leftSide.Add(rightSide);
        }
 
        /// <summary>
        /// Adds a scalar to each element of a vector.
        /// </summary>
        /// <param name="leftSide">The vector to add to.</param>
        /// <param name="rightSide">The scalar value to add.</param>
        /// <returns>The result of the addition.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
        public static Vector<T> operator +(Vector<T> leftSide, T rightSide)
        {
            return leftSide.Add(rightSide);
        }
 
        /// <summary>
        /// Adds a scalar to each element of a vector.
        /// </summary>
        /// <param name="leftSide">The scalar value to add.</param>
        /// <param name="rightSide">The vector to add to.</param>
        /// <returns>The result of the addition.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
        public static Vector<T> operator +(T leftSide, Vector<T> rightSide)
        {
            return rightSide.Add(leftSide);
        }
 
        /// <summary>
        /// Subtracts two <strong>Vectors</strong> and returns the results.
        /// </summary>
        /// <param name="leftSide">The vector to subtract from.</param>
        /// <param name="rightSide">The vector to subtract.</param>
        /// <returns>The result of the subtraction.</returns>
        /// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
        public static Vector<T> operator -(Vector<T> leftSide, Vector<T> rightSide)
        {
            return leftSide.Subtract(rightSide);
        }
 
        /// <summary>
        /// Subtracts a scalar from each element of a vector.
        /// </summary>
        /// <param name="leftSide">The vector to subtract from.</param>
        /// <param name="rightSide">The scalar value to subtract.</param>
        /// <returns>The result of the subtraction.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
        public static Vector<T> operator -(Vector<T> leftSide, T rightSide)
        {
            return leftSide.Subtract(rightSide);
        }
 
        /// <summary>
        /// Subtracts each element of a vector from a scalar.
        /// </summary>
        /// <param name="leftSide">The scalar value to subtract from.</param>
        /// <param name="rightSide">The vector to subtract.</param>
        /// <returns>The result of the subtraction.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
        public static Vector<T> operator -(T leftSide, Vector<T> rightSide)
        {
            return rightSide.SubtractFrom(leftSide);
        }
 
        /// <summary>
        /// Multiplies a vector with a scalar.
        /// </summary>
        /// <param name="leftSide">The vector to scale.</param>
        /// <param name="rightSide">The scalar value.</param>
        /// <returns>The result of the multiplication.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
        public static Vector<T> operator *(Vector<T> leftSide, T rightSide)
        {
            return leftSide.Multiply(rightSide);
        }
 
        /// <summary>
        /// Multiplies a vector with a scalar.
        /// </summary>
        /// <param name="leftSide">The scalar value.</param>
        /// <param name="rightSide">The vector to scale.</param>
        /// <returns>The result of the multiplication.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
        public static Vector<T> operator *(T leftSide, Vector<T> rightSide)
        {
            return rightSide.Multiply(leftSide);
        }
 
        /// <summary>
        /// Computes the dot product between two <strong>Vectors</strong>.
        /// </summary>
        /// <param name="leftSide">The left row vector.</param>
        /// <param name="rightSide">The right column vector.</param>
        /// <returns>The dot product between the two vectors.</returns>
        /// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
        public static T operator *(Vector<T> leftSide, Vector<T> rightSide)
        {
            return leftSide.DotProduct(rightSide);
        }
 
        /// <summary>
        /// Divides a scalar with a vector.
        /// </summary>
        /// <param name="dividend">The scalar to divide.</param>
        /// <param name="divisor">The vector.</param>
        /// <returns>The result of the division.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="divisor"/> is <see langword="null" />.</exception>
        public static Vector<T> operator /(T dividend, Vector<T> divisor)
        {
            return divisor.DivideByThis(dividend);
        }
 
        /// <summary>
        /// Divides a vector with a scalar.
        /// </summary>
        /// <param name="dividend">The vector to divide.</param>
        /// <param name="divisor">The scalar value.</param>
        /// <returns>The result of the division.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
        public static Vector<T> operator /(Vector<T> dividend, T divisor)
        {
            return dividend.Divide(divisor);
        }
 
        /// <summary>
        /// Pointwise divides two <strong>Vectors</strong>.
        /// </summary>
        /// <param name="dividend">The vector to divide.</param>
        /// <param name="divisor">The other vector.</param>
        /// <returns>The result of the division.</returns>
        /// <exception cref="ArgumentException">If <paramref name="dividend"/> and <paramref name="divisor"/> are not the same size.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
        public static Vector<T> operator /(Vector<T> dividend, Vector<T> divisor)
        {
            return dividend.PointwiseDivide(divisor);
        }
 
        /// <summary>
        /// Computes the remainder (% operator), where the result has the sign of the dividend,
        /// of each element of the vector of the given divisor.
        /// </summary>
        /// <param name="dividend">The vector whose elements we want to compute the remainder of.</param>
        /// <param name="divisor">The divisor to use.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
        public static Vector<T> operator %(Vector<T> dividend, T divisor)
        {
            return dividend.Remainder(divisor);
        }
 
        /// <summary>
        /// Computes the remainder (% operator), where the result has the sign of the dividend,
        /// of the given dividend of each element of the vector.
        /// </summary>
        /// <param name="dividend">The dividend we want to compute the remainder of.</param>
        /// <param name="divisor">The vector whose elements we want to use as divisor.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
        public static Vector<T> operator %(T dividend, Vector<T> divisor)
        {
            return divisor.RemainderByThis(dividend);
        }
 
        /// <summary>
        /// Computes the pointwise remainder (% operator), where the result has the sign of the dividend,
        /// of each element of two vectors.
        /// </summary>
        /// <param name="dividend">The vector whose elements we want to compute the remainder of.</param>
        /// <param name="divisor">The divisor to use.</param>
        /// <exception cref="ArgumentException">If <paramref name="dividend"/> and <paramref name="divisor"/> are not the same size.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
        public static Vector<T> operator %(Vector<T> dividend, Vector<T> divisor)
        {
            return dividend.PointwiseRemainder(divisor);
        }
 
        [SpecialName]
        public static Vector<T> op_DotMultiply(Vector<T> x, Vector<T> y)
        {
            return x.PointwiseMultiply(y);
        }
 
        [SpecialName]
        public static Vector<T> op_DotDivide(Vector<T> dividend, Vector<T> divisor)
        {
            return dividend.PointwiseDivide(divisor);
        }
 
        [SpecialName]
        public static Vector<T> op_DotPercent(Vector<T> dividend, Vector<T> divisor)
        {
            return dividend.PointwiseRemainder(divisor);
        }
 
        [SpecialName]
        public static Vector<T> op_DotHat(Vector<T> vector, Vector<T> exponent)
        {
            return vector.PointwisePower(exponent);
        }
 
        [SpecialName]
        public static Vector<T> op_DotHat(Vector<T> vector, T exponent)
        {
            return vector.PointwisePower(exponent);
        }
 
        /// <summary>
        /// Computes the sqrt of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Sqrt(Vector<T> x)
        {
            return x.PointwiseSqrt();
        }
 
        /// <summary>
        /// Computes the exponential of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Exp(Vector<T> x)
        {
            return x.PointwiseUnary(x.DoPointwiseExp);
        }
 
        /// <summary>
        /// Computes the log of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Log(Vector<T> x)
        {
            return x.PointwiseUnary(x.PointwiseLog);
        }
        /// <summary>
        /// Computes the log10 of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Log10(Vector<T> x)
        {
            return x.PointwiseLog10();
        }
 
        /// <summary>
        /// Computes the sin of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Sin(Vector<T> x)
        {
            return x.PointwiseSin();
        }
 
        /// <summary>
        /// Computes the cos of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Cos(Vector<T> x)
        {
            return x.PointwiseCos();
        }
 
        /// <summary>
        /// Computes the tan of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Tan(Vector<T> x)
        {
            return x.PointwiseTan();
        }
 
        /// <summary>
        /// Computes the asin of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Asin(Vector<T> x)
        {
            return x.PointwiseAsin();
        }
 
        /// <summary>
        /// Computes the acos of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Acos(Vector<T> x)
        {
            return x.PointwiseAcos();
        }
 
        /// <summary>
        /// Computes the atan of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Atan(Vector<T> x)
        {
            return x.PointwiseAtan();
        }
 
        /// <summary>
        /// Computes the sinh of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Sinh(Vector<T> x)
        {
            return x.PointwiseSinh();
        }
 
        /// <summary>
        /// Computes the cosh of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Cosh(Vector<T> x)
        {
            return x.PointwiseCosh();
        }
 
        /// <summary>
        /// Computes the tanh of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Tanh(Vector<T> x)
        {
            return x.PointwiseTanh();
        }
 
        /// <summary>
        /// Computes the absolute value of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Abs(Vector<T> x)
        {
            return x.PointwiseAbs();
        }
 
        /// <summary>
        /// Computes the floor of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Floor(Vector<T> x)
        {
            return x.PointwiseFloor();
        }
 
        /// <summary>
        /// Computes the ceiling of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Ceiling(Vector<T> x)
        {
            return x.PointwiseCeiling();
        }
 
        /// <summary>
        /// Computes the rounded value of a vector pointwise
        /// </summary>
        /// <param name="x">The input vector</param>
        /// <returns></returns>
        public static Vector<T> Round(Vector<T> x)
        {
            return x.PointwiseRound();
        }
    }
}