Repository navigation
Expand file tree
/
Copy pathGetGreeting.cs
More file actions
70 lines (67 loc) · 2.21 KB
/
Copy pathGetGreeting.cs
File metadata and controls
70 lines (67 loc) · 2.21 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
68
69
70
using System.Management.Automation;
using System.Collections.Generic;
using System.Linq;
using NumSharp.Core;
namespace NumSharp.PowerShell
{
[Cmdlet(VerbsCommon.New,"NDArray")]
[OutputType(typeof(NDArray<>))]
public class NewNDArray : Cmdlet
{
protected dynamic _NDArray;
[ValidateNotNull]
[Parameter(Position = 0, HelpMessage = "A collection of numbers")]
public IList<object> Array {get;set;}
[ValidateSet("float","double","int32","int64","Complex")]
[Parameter(Position = 1, HelpMessage = "The data type of NDArray")]
public string DataType {get;set;} = "double";
protected override void ProcessRecord()
{
switch (DataType)
{
case "float" :
{
float[] array = Array.Select(x => (float) x).ToArray();
_NDArray = new NumSharp.Core.NDArray<float>();
_NDArray.Data = array;
_NDArray.Shape = new Shape(array.Length);
break;
}
case "double" :
{
double[] array = Array.Select(x => (double) x).ToArray();
_NDArray = new NumSharp.Core.NDArray<double>();
_NDArray.Data = array;
_NDArray.Shape = new Shape(array.Length);
break;
}
default :
{
break;
}
}
WriteObject(_NDArray);
}
}
/// <summary>
/// A simple Cmdlet that outputs a greeting to the pipeline.
/// </summary>
[Cmdlet(VerbsCommon.Get, "Greeting")]
public class GetGreeting
: Cmdlet
{
/// <summary>
/// The name of the person to greet.
/// </summary>
[ValidateNotNullOrEmpty]
[Parameter(Position = 0, HelpMessage = "The name of the person to greet")]
public string Name { get; set; } = "Stranger";
/// <summary>
/// Perform Cmdlet processing.
/// </summary>
protected override void ProcessRecord()
{
WriteObject($"Hello, {Name}!");
}
}
}