Repository navigation
Expand file tree
/
Copy pathNDArray.power.cs
More file actions
67 lines (54 loc) · 2.08 KB
/
Copy pathNDArray.power.cs
File metadata and controls
67 lines (54 loc) · 2.08 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using NumSharp.Core.Extensions;
namespace NumSharp.Core
{
public partial class NDArray
{
public NDArray power(ValueType exponent)
{
var powerArray = new NDArray(this.dtype,this.shape);
Array dataSysArr = this.Storage.GetData();
Array powerDataSysArr = powerArray.Storage.GetData();
switch (dataSysArr)
{
case double[] data :
{
var powerData = powerDataSysArr as double[];
for (int idx = 0; idx < data.Length;idx++)
powerData[idx] = Math.Pow(data[idx], (double)exponent);
break;
}
case float[] data :
{
var powerData = powerDataSysArr as float[];
for (int idx = 0; idx < data.Length;idx++)
powerData[idx] = Convert.ToSingle(Math.Pow(Convert.ToDouble(data[idx]), Convert.ToDouble(exponent)));
break;
}
case Complex[] data :
{
var powerData = powerDataSysArr as Complex[];
for (int idx = 0; idx < data.Length;idx++)
powerData[idx] = Complex.Pow(data[idx],Convert.ToDouble(exponent));
break;
}
case int[] data :
{
var powerData = powerDataSysArr as int[];
for (int idx = 0; idx < data.Length;idx++)
powerData[idx] = Convert.ToInt32(Math.Pow(Convert.ToDouble(data[idx]), Convert.ToDouble(exponent)));
break;
}
default :
{
throw new IncorrectTypeException();
}
}
return powerArray;
}
}
}