Skip to content

Commit acba9c8

Browse files
committed
Add float16 tests
1 parent 4ff1a2f commit acba9c8

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

inst/extdata/test_float16.npy

152 Bytes
Binary file not shown.

inst/scripts/generate_test_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
np.save("inst/extdata/test_uint64_overflowing.npy", np.array([0, 1, 10, 100, 1000, 10000, 100000, 2**16, 2**32, 2**48, 2**63, 2**64 - 1], dtype="uint64"))
1515

1616
# Float types
17+
np.save("inst/extdata/test_float16.npy", np.array([1.5, -2.5, 3.14, 0.0, -1.0, 100.0, -100.0, 0.001, 1000, -1000, 1.2345, -9.8765], dtype="float16"))
1718
np.save("inst/extdata/test_float32.npy", np.array([1.5, -2.5, 3.14, 0.0, -1.0, 100.0, -100.0, 0.001, 1e6, -1e6, 1.23456, -9.87654], dtype="float32"))
1819
np.save("inst/extdata/test_float64.npy", np.array([1.5, -2.5, 3.14, 0.0, -1.0, 100.0, -100.0, 0.001, 1e6, -1e6, 1.23456789, -9.87654321], dtype="float64"))
1920

tests/testthat/test-read_npy.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ test_that("different types work", {
109109
)) |>
110110
expect_warning("overflow")
111111

112+
system.file("extdata", "test_float16.npy", package = "grumpy") |>
113+
read_npy() |>
114+
expect_no_condition() |>
115+
expect_equal(
116+
array(
117+
c(
118+
1.5,
119+
-2.5,
120+
3.14,
121+
0.0,
122+
-1.0,
123+
100.0,
124+
-100.0,
125+
0.001,
126+
1000.0,
127+
-1000.0,
128+
1.2345,
129+
-9.8765
130+
),
131+
dim = 12L
132+
),
133+
tolerance = 1e-3
134+
)
135+
112136
system.file("extdata", "test_float32.npy", package = "grumpy") |>
113137
read_npy() |>
114138
expect_no_condition() |>

0 commit comments

Comments
 (0)