Skip to content

Commit 5c606ee

Browse files
committed
Revert "gh-146151: Add support for complex arrays in the array module (#146237)"
This reverts commit 0e3b3b8.
1 parent 2a07ff9 commit 5c606ee

5 files changed

Lines changed: 30 additions & 291 deletions

File tree

Doc/library/array.rst

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
--------------
1010

1111
This module defines an object type which can compactly represent an array of
12-
basic values: characters, integers, floating-point numbers, complex numbers. Arrays are mutable :term:`sequence`
12+
basic values: characters, integers, floating-point numbers. Arrays are mutable :term:`sequence`
1313
types and behave very much like lists, except that the type of objects stored in
1414
them is constrained. The type is specified at object creation time by using a
1515
:dfn:`type code`, which is a single character. The following type codes are
@@ -48,11 +48,6 @@ defined:
4848
+-----------+--------------------+-------------------+-----------------------+-------+
4949
| ``'d'`` | double | float | 8 | |
5050
+-----------+--------------------+-------------------+-----------------------+-------+
51-
| ``'F'`` | float complex | complex | 8 | \(4) |
52-
+-----------+--------------------+-------------------+-----------------------+-------+
53-
| ``'D'`` | double complex | complex | 16 | \(4) |
54-
+-----------+--------------------+-------------------+-----------------------+-------+
55-
5651

5752
Notes:
5853

@@ -79,15 +74,6 @@ Notes:
7974

8075
.. versionadded:: 3.15
8176

82-
(4)
83-
Complex types (``F`` and ``D``) are available unconditionally,
84-
regardless on support for complex types (the Annex G of the C11 standard)
85-
by the C compiler.
86-
As specified in the C11 standard, each complex type is represented by a
87-
two-element C array containing, respectively, the real and imaginary parts.
88-
89-
.. versionadded:: 3.15
90-
9177
.. seealso::
9278

9379
The :ref:`ctypes <ctypes-fundamental-data-types>` and
@@ -171,10 +157,9 @@ The module defines the following type:
171157
.. method:: byteswap()
172158

173159
"Byteswap" all items of the array. This is only supported for values which are
174-
1, 2, 4, 8 or 16 bytes in size; for other types of values, :exc:`RuntimeError` is
160+
1, 2, 4, or 8 bytes in size; for other types of values, :exc:`RuntimeError` is
175161
raised. It is useful when reading data from a file written on a machine with a
176-
different byte order. Note, that for complex types the order of
177-
components (the real part, followed by imaginary part) is preserved.
162+
different byte order.
178163

179164

180165
.. method:: count(value, /)

Doc/whatsnew/3.15.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,6 @@ argparse
678678
array
679679
-----
680680

681-
* Support the :c:expr:`float complex` and :c:expr:`double complex` C types:
682-
formatting characters ``'F'`` and ``'D'`` respectively.
683-
(Contributed by Sergey B Kirpichev in :gh:`146151`.)
684-
685681
* Support half-floats (16-bit IEEE 754 binary interchange format): formatting
686682
character ``'e'``.
687683
(Contributed by Sergey B Kirpichev in :gh:`146238`.)

Lib/test/test_array.py

Lines changed: 7 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ArraySubclassWithKwargs(array.array):
3131
def __init__(self, typecode, newarg=None):
3232
array.array.__init__(self)
3333

34-
typecodes = 'uwbBhHiIlLfdqQFDe'
34+
typecodes = 'uwbBhHiIlLfdqQe'
3535

3636
class MiscTest(unittest.TestCase):
3737

@@ -113,14 +113,10 @@ def __index__(self):
113113
UTF16_BE = 19
114114
UTF32_LE = 20
115115
UTF32_BE = 21
116-
IEEE_754_FLOAT_COMPLEX_LE = 22
117-
IEEE_754_FLOAT_COMPLEX_BE = 23
118-
IEEE_754_DOUBLE_COMPLEX_LE = 24
119-
IEEE_754_DOUBLE_COMPLEX_BE = 25
120-
IEEE_754_FLOAT16_LE = 26
121-
IEEE_754_FLOAT16_BE = 27
116+
IEEE_754_FLOAT16_LE = 22
117+
IEEE_754_FLOAT16_BE = 23
122118

123-
MACHINE_FORMAT_CODE_MAX = 27
119+
MACHINE_FORMAT_CODE_MAX = 23
124120

125121

126122
class ArrayReconstructorTest(unittest.TestCase):
@@ -147,7 +143,7 @@ def test_error(self):
147143
self.assertRaises(ValueError, array_reconstructor,
148144
array.array, "b", UNKNOWN_FORMAT, b"")
149145
self.assertRaises(ValueError, array_reconstructor,
150-
array.array, "b", MACHINE_FORMAT_CODE_MAX + 1, b"")
146+
array.array, "b", 22, b"")
151147
self.assertRaises(ValueError, array_reconstructor,
152148
array.array, "d", 16, b"a")
153149

@@ -199,15 +195,7 @@ def test_numbers(self):
199195
(['d'], IEEE_754_DOUBLE_LE, '<dddd',
200196
[9006104071832581.0, float('inf'), float('-inf'), -0.0]),
201197
(['d'], IEEE_754_DOUBLE_BE, '>dddd',
202-
[9006104071832581.0, float('inf'), float('-inf'), -0.0]),
203-
(['F'], IEEE_754_FLOAT_COMPLEX_LE, '<FFFF',
204-
[16711938.0j, float('inf'), complex('1-infj'), -0.0]),
205-
(['F'], IEEE_754_FLOAT_COMPLEX_BE, '>FFFF',
206-
[16711938.0j, float('inf'), complex('1-infj'), -0.0]),
207-
(['D'], IEEE_754_DOUBLE_COMPLEX_LE, '<DDDD',
208-
[9006104071832581.0j, float('inf'), complex('1-infj'), -0.0]),
209-
(['D'], IEEE_754_DOUBLE_COMPLEX_BE, '>DDDD',
210-
[9006104071832581.0j, float('inf'), complex('1-infj'), -0.0]),
198+
[9006104071832581.0, float('inf'), float('-inf'), -0.0])
211199
)
212200
for testcase in testcases:
213201
valid_typecodes, mformat_code, struct_fmt, values = testcase
@@ -295,7 +283,7 @@ def test_byteswap(self):
295283
example = self.example
296284
a = array.array(self.typecode, example)
297285
self.assertRaises(TypeError, a.byteswap, 42)
298-
if a.itemsize in (1, 2, 4, 8, 16):
286+
if a.itemsize in (1, 2, 4, 8):
299287
b = array.array(self.typecode, example)
300288
b.byteswap()
301289
if a.itemsize==1:
@@ -1541,54 +1529,6 @@ def test_byteswap(self):
15411529
b.byteswap()
15421530
self.assertEqual(a, b)
15431531

1544-
class CFPTest(NumberTest):
1545-
example = [-42j, 0, 42+1j, 1e5j, -1e10]
1546-
outside = 23
1547-
1548-
def assertEntryEqual(self, entry1, entry2):
1549-
self.assertAlmostEqual(entry1, entry2)
1550-
1551-
def test_cmp(self):
1552-
a = array.array(self.typecode, self.example)
1553-
self.assertIs(a == 42, False)
1554-
self.assertIs(a != 42, True)
1555-
1556-
self.assertIs(a == a, True)
1557-
self.assertIs(a != a, False)
1558-
self.assertIs(a < a, False)
1559-
self.assertIs(a <= a, True)
1560-
self.assertIs(a > a, False)
1561-
self.assertIs(a >= a, True)
1562-
1563-
self.assertIs(a == 2*a, False)
1564-
self.assertIs(a != 2*a, True)
1565-
self.assertIs(a < 2*a, True)
1566-
self.assertIs(a <= 2*a, True)
1567-
self.assertIs(a > 2*a, False)
1568-
self.assertIs(a >= 2*a, False)
1569-
1570-
def test_nan(self):
1571-
a = array.array(self.typecode, [float('nan')])
1572-
b = array.array(self.typecode, [float('nan')])
1573-
self.assertIs(a != b, True)
1574-
self.assertIs(a == b, False)
1575-
1576-
def test_byteswap(self):
1577-
a = array.array(self.typecode, self.example)
1578-
self.assertRaises(TypeError, a.byteswap, 42)
1579-
if a.itemsize in (1, 2, 4, 8):
1580-
b = array.array(self.typecode, self.example)
1581-
b.byteswap()
1582-
if a.itemsize == 1:
1583-
self.assertEqual(a, b)
1584-
else:
1585-
# On alphas treating the byte swapped bit patterns as
1586-
# floats/doubles results in floating-point exceptions
1587-
# => compare the 8bit string values instead
1588-
self.assertNotEqual(a.tobytes(), b.tobytes())
1589-
b.byteswap()
1590-
self.assertEqual(a, b)
1591-
15921532

15931533
class HalfFloatTest(FPTest, unittest.TestCase):
15941534
example = [-42.0, 0, 42, 1e2, -1e4]
@@ -1623,15 +1563,6 @@ def test_alloc_overflow(self):
16231563
self.fail("Array of size > maxsize created - MemoryError expected")
16241564

16251565

1626-
class ComplexFloatTest(CFPTest, unittest.TestCase):
1627-
typecode = 'F'
1628-
minitemsize = 8
1629-
1630-
class ComplexDoubleTest(CFPTest, unittest.TestCase):
1631-
typecode = 'D'
1632-
minitemsize = 16
1633-
1634-
16351566
class LargeArrayTest(unittest.TestCase):
16361567
typecode = 'b'
16371568

0 commit comments

Comments
 (0)