Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc1dab27

Browse files
authored
Add explicit tests for vararg call (#1805)
1 parent3cb2529 commitc1dab27

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

‎src/embed_tests/NumPyTests.cs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
usingSystem;
22
usingSystem.Collections.Generic;
3+
34
usingNUnit.Framework;
5+
46
usingPython.Runtime;
57
usingPython.Runtime.Codecs;
68

@@ -24,17 +26,6 @@ public void Dispose()
2426
[Test]
2527
publicvoidTestReadme()
2628
{
27-
dynamicnp;
28-
try
29-
{
30-
np=Py.Import("numpy");
31-
}
32-
catch(PythonException)
33-
{
34-
Assert.Inconclusive("Numpy or dependency not installed");
35-
return;
36-
}
37-
3829
Assert.AreEqual("1.0",np.cos(np.pi*2).ToString());
3930

4031
dynamicsin=np.sin;
@@ -55,40 +46,52 @@ public void TestReadme()
5546
[Test]
5647
publicvoidMultidimensionalNumPyArray()
5748
{
58-
PyObjectnp;
59-
try{
60-
np=Py.Import("numpy");
61-
}catch(PythonException){
62-
Assert.Inconclusive("Numpy or dependency not installed");
63-
return;
64-
}
65-
6649
vararray=new[,]{{1,2},{3,4}};
6750
varndarray=np.InvokeMethod("asarray",array.ToPython());
68-
Assert.AreEqual((2,2),ndarray.GetAttr("shape").As<(int,int)>());
51+
Assert.AreEqual((2,2),ndarray.GetAttr("shape").As<(int,int)>());
6952
Assert.AreEqual(1,ndarray[(0,0).ToPython()].InvokeMethod("__int__").As<int>());
7053
Assert.AreEqual(array[1,0],ndarray[(1,0).ToPython()].InvokeMethod("__int__").As<int>());
7154
}
7255

7356
[Test]
7457
publicvoidInt64Array()
7558
{
76-
PyObjectnp;
77-
try
78-
{
79-
np=Py.Import("numpy");
80-
}
81-
catch(PythonException)
82-
{
83-
Assert.Inconclusive("Numpy or dependency not installed");
84-
return;
85-
}
86-
8759
vararray=newlong[,]{{1,2},{3,4}};
8860
varndarray=np.InvokeMethod("asarray",array.ToPython());
8961
Assert.AreEqual((2,2),ndarray.GetAttr("shape").As<(int,int)>());
9062
Assert.AreEqual(1,ndarray[(0,0).ToPython()].InvokeMethod("__int__").As<long>());
9163
Assert.AreEqual(array[1,0],ndarray[(1,0).ToPython()].InvokeMethod("__int__").As<long>());
9264
}
65+
66+
[Test]
67+
publicvoidVarArg()
68+
{
69+
dynamiczX=np.array(new[,]{{1,2,3},{4,5,6},{8,9,0}});
70+
dynamicgrad=np.gradient(zX,4.0,5.0);
71+
dynamicgrad2=np.InvokeMethod("gradient",newPyObject[]{zX,newPyFloat(4.0),newPyFloat(5.0)});
72+
73+
Assert.AreEqual(4.125,grad[0].sum().__float__().As<double>(),0.001);
74+
Assert.AreEqual(-1.2,grad[1].sum().__float__().As<double>(),0.001);
75+
Assert.AreEqual(4.125,grad2[0].sum().__float__().As<double>(),0.001);
76+
Assert.AreEqual(-1.2,grad2[1].sum().__float__().As<double>(),0.001);
77+
}
78+
79+
#pragma warning disableIDE1006
80+
dynamicnp
81+
{
82+
get
83+
{
84+
try
85+
{
86+
returnPy.Import("numpy");
87+
}
88+
catch(PythonException)
89+
{
90+
Assert.Inconclusive("Numpy or dependency not installed");
91+
returnnull;
92+
}
93+
}
94+
}
95+
9396
}
9497
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp