Skip to content

Commit 9981adb

Browse files
committed
Add __name__ to prettify test output
1 parent f19efb5 commit 9981adb

File tree

8 files changed

+28
-22
lines changed

8 files changed

+28
-22
lines changed

src/gfloat/block.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ def block_size_bytes(self) -> int:
4747
assert bits % 8 == 0
4848
return bits // 8
4949

50+
@property
51+
def __name__(self) -> str:
52+
return self.name
53+
5054
def __str__(self) -> str:
51-
return f"{self.name}"
55+
return f"BlockFormatInfo:{self.name})"
5256

5357

5458
def decode_block(fi: BlockFormatInfo, block: Iterable[int]) -> Iterable[float]:

src/gfloat/formats.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#: FormatInfo for IEEE-754 Binary32 format
77
format_info_binary32 = FormatInfo(
8-
name="binary32",
8+
name="format_info_binary32",
99
k=32,
1010
precision=24,
1111
emax=127,
@@ -19,7 +19,7 @@
1919

2020
#: FormatInfo for IEEE-754 Binary16 format
2121
format_info_binary16 = FormatInfo(
22-
name="binary16",
22+
name="format_info_binary16",
2323
k=16,
2424
precision=11,
2525
emax=15,
@@ -33,7 +33,7 @@
3333

3434
#: FormatInfo for Google BFloat16 format
3535
format_info_bfloat16 = FormatInfo(
36-
name="bfloat16",
36+
name="format_info_bfloat16",
3737
k=16,
3838
precision=8,
3939
emax=127,
@@ -47,7 +47,7 @@
4747

4848
#: FormatInfo for OCP E5M2 format
4949
format_info_ocp_e5m2 = FormatInfo(
50-
name="ocp_e5m2",
50+
name="format_info_ocp_e5m2",
5151
k=8,
5252
precision=3,
5353
emax=15,
@@ -61,7 +61,7 @@
6161

6262
#: FormatInfo for OCP E4M3 format
6363
format_info_ocp_e4m3 = FormatInfo(
64-
name="ocp_e4m3",
64+
name="format_info_ocp_e4m3",
6565
k=8,
6666
precision=4,
6767
emax=8,
@@ -75,7 +75,7 @@
7575

7676
#: FormatInfo for OCP MX E2M3 format
7777
format_info_ocp_e2m3 = FormatInfo(
78-
name="ocp_e2m3",
78+
name="format_info_ocp_e2m3",
7979
k=6,
8080
precision=4,
8181
emax=2,
@@ -89,7 +89,7 @@
8989

9090
#: FormatInfo for OCP MX E3M2 format
9191
format_info_ocp_e3m2 = FormatInfo(
92-
name="ocp_e3m2",
92+
name="format_info_ocp_e3m2",
9393
k=6,
9494
precision=3,
9595
emax=4,
@@ -103,7 +103,7 @@
103103

104104
#: FormatInfo for OCP MX E2M1 format
105105
format_info_ocp_e2m1 = FormatInfo(
106-
name="ocp_e2m1",
106+
name="format_info_ocp_e2m1",
107107
k=4,
108108
precision=2,
109109
emax=2,
@@ -117,7 +117,7 @@
117117

118118
#: FormatInfo for OCP MX E8M0 format
119119
format_info_ocp_e8m0 = FormatInfo(
120-
name="ocp_e8m0",
120+
name="format_info_ocp_e8m0",
121121
k=8,
122122
precision=1,
123123
emax=127,
@@ -131,7 +131,7 @@
131131

132132
#: FormatInfo for OCP MX INT8 format
133133
format_info_ocp_int8 = FormatInfo(
134-
name="ocp_int8",
134+
name="format_info_ocp_int8",
135135
k=8,
136136
precision=8,
137137
emax=0,
@@ -210,11 +210,11 @@ def format_info_p3109(precision: int) -> FormatInfo:
210210
# Block formats
211211

212212
format_info_mxfp8_e5m2 = BlockFormatInfo(
213-
"ocp_mxfp8_e5m2", format_info_ocp_e5m2, 32, format_info_ocp_e8m0
213+
"format_info_mxfp8_e5m2", format_info_ocp_e5m2, 32, format_info_ocp_e8m0
214214
)
215215

216216
format_info_mxfp8_e4m3 = BlockFormatInfo(
217-
"ocp_mxfp8_e4m3", format_info_ocp_e4m3, 32, format_info_ocp_e8m0
217+
"format_info_mxfp8_e4m3", format_info_ocp_e4m3, 32, format_info_ocp_e8m0
218218
)
219219

220220
format_info_mxfp6_e3m2 = BlockFormatInfo(

src/gfloat/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,5 +400,9 @@ def is_all_subnormal(self) -> bool:
400400
"""
401401
return (self.expBits == 0) and self.has_subnormals
402402

403+
@property
404+
def __name__(self) -> str:
405+
return self.name
406+
403407
def __str__(self) -> str:
404408
return f"{self.name}"

test/test_block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from gfloat.formats import *
88

99

10-
@pytest.mark.parametrize("fi", all_block_formats, ids=str)
10+
@pytest.mark.parametrize("fi", all_block_formats)
1111
def test_blocks(fi: BlockFormatInfo) -> None:
1212

1313
vals = np.linspace(-37.0, 42.0, 32)

test/test_decode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ def test_spot_check_ocp_int8() -> None:
183183
assert dec(0xFF) == -fi.smallest
184184

185185

186-
@pytest.mark.parametrize("fi", p3109_formats, ids=str)
186+
@pytest.mark.parametrize("fi", p3109_formats)
187187
def test_specials(fi: FormatInfo) -> None:
188188
assert fi.code_of_nan == 0x80
189189
assert fi.code_of_zero == 0x00
190190
assert fi.code_of_posinf == 0x7F
191191
assert fi.code_of_neginf == 0xFF
192192

193193

194-
@pytest.mark.parametrize("fi", all_formats, ids=str)
194+
@pytest.mark.parametrize("fi", all_formats)
195195
def test_specials_decode(fi: FormatInfo) -> None:
196196
dec = lambda v: decode_float(fi, v).fval
197197

@@ -240,7 +240,7 @@ def test_except(v: int) -> None:
240240
decode_float(format_info_binary16, v)
241241

242242

243-
@pytest.mark.parametrize("fi", [fi for fi in all_formats if fi.bits <= 8], ids=str)
243+
@pytest.mark.parametrize("fi", [fi for fi in all_formats if fi.bits <= 8])
244244
def test_dense(fi: FormatInfo) -> None:
245245
fvs = [decode_float(fi, i) for i in range(0, 2**fi.bits)]
246246

test/test_encode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from gfloat.formats import *
99

1010

11-
@pytest.mark.parametrize("fi", all_formats, ids=str)
11+
@pytest.mark.parametrize("fi", all_formats)
1212
def test_encode(fi: FormatInfo) -> None:
1313
dec = lambda v: decode_float(fi, v).fval
1414

@@ -27,7 +27,7 @@ def test_encode(fi: FormatInfo) -> None:
2727
np.testing.assert_equal(fv2.fval, fv.fval)
2828

2929

30-
@pytest.mark.parametrize("fi", all_formats, ids=str)
30+
@pytest.mark.parametrize("fi", all_formats)
3131
def test_encode_edges(fi: FormatInfo) -> None:
3232
assert encode_float(fi, fi.max) == fi.code_of_max
3333

test/test_microxcaling.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
(ElemFormat.fp6_e3m2, format_info_ocp_e3m2),
2626
(ElemFormat.fp4_e2m1, format_info_ocp_e2m1),
2727
],
28-
ids=str,
2928
)
3029
def test_mx(
3130
mx_round: str,

test/test_round.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ def test_round_e4m3() -> None:
117117
format_info_ocp_e4m3,
118118
*p3109_formats,
119119
],
120-
ids=str,
121120
)
122121
def test_round(fi: FormatInfo) -> None:
123122
"""
@@ -184,7 +183,7 @@ def test_round_ints(fi: FormatInfo, mldtype: Type) -> None:
184183
np.testing.assert_equal(val, mlval)
185184

186185

187-
@pytest.mark.parametrize("fi", all_formats, ids=str)
186+
@pytest.mark.parametrize("fi", all_formats)
188187
def test_round_roundtrip(fi: FormatInfo) -> None:
189188
if fi.bits <= 8:
190189
step = 1

0 commit comments

Comments
 (0)