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

Appearance settings

Commit a8850b5

Browse filesBrowse files
committed
Add a test that shows how to copy data from a byte array into a float64 NDArray
1 parent 766b1cb commit a8850b5
Copy full SHA for a8850b5

File tree

Expand file treeCollapse file tree

1 file changed

+24
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-0
lines changed

‎test/Numpy.UnitTest/NumpyTest.cs

Copy file name to clipboardExpand all lines: test/Numpy.UnitTest/NumpyTest.cs
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,30 @@ public async Task AsscalarRemovedInNumpyV1_23()
961961
Assert.AreEqual(143d, new NDarray<double>(new[] { 143d }).item());
962962
}
963963

964+
[TestMethod]
965+
public async Task IssueByMaLichtenegger()
966+
{
967+
// byte array als uint32 array
968+
var bytes = new byte[] { 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0 };
969+
var uints =np.zeros(new Shape(3), np.uint32);
970+
Console.WriteLine(uints.repr);
971+
var ctypes = uints.PyObject.ctypes;
972+
long ptr = ctypes.data;
973+
Marshal.Copy(bytes, 0, new IntPtr(ptr), bytes.Length);
974+
Console.WriteLine(uints.repr);
975+
Assert.AreEqual("array([1, 2, 3], dtype=uint32)", uints.repr);
976+
// byte array als float64 array
977+
bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0 };
978+
var doubles = np.zeros(new Shape(2), np.float64);
979+
Console.WriteLine(doubles.repr);
980+
ctypes = doubles.PyObject.ctypes;
981+
ptr = ctypes.data;
982+
Marshal.Copy(bytes, 0, new IntPtr(ptr), bytes.Length);
983+
Console.WriteLine(doubles.repr);
984+
Assert.IsTrue(doubles[0].asscalar<double>() != 0);
985+
Assert.IsTrue(doubles[1].asscalar<double>() == 0);
986+
}
987+
964988
// TODO: https://docs.scipy.org/doc/numpy/user/basics.indexing.html?highlight=slice#structural-indexing-tools
965989
// TODO: https://docs.scipy.org/doc/numpy/user/basics.indexing.html?highlight=slice#assigning-values-to-indexed-arrays
966990
// TODO: https://docs.scipy.org/doc/numpy/user/basics.indexing.html?highlight=slice#dealing-with-variable-numbers-of-indices-within-programs

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.