Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

All power corrupts, but we need electricity.


devel / comp.lang.python / Re: To clarify how Python handles two equal objects

SubjectAuthor
* Re: To clarify how Python handles two equal objectsThomas Passin
`- Re: To clarify how Python handles two equal objectsDennis Lee Bieber

1
Re: To clarify how Python handles two equal objects

<mailman.1472.1673388409.20444.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=25494&group=comp.lang.python#25494

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: list1@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: To clarify how Python handles two equal objects
Date: Tue, 10 Jan 2023 16:59:59 -0500
Lines: 95
Message-ID: <mailman.1472.1673388409.20444.python-list@python.org>
References: <NLSGqyj--3-9@tutanota.com>
<CAPTjJmpiB5xK9PS311yHKEj1_qg_F4B7BXwEt_mbQeLKeph_Fw@mail.gmail.com>
<NLSPZV8--7-9@tutanota.com>
<31d2ed67-d710-cbb9-5e44-0872a07747c5@mrabarnett.plus.com>
<59d349a8-508c-cc7d-c833-d309d888d4c2@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de G1gHrvJOeL81ZfMgAfZx1QJvAcZGqujSU+r386pGsRHw==
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=IgCgbuMB;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'containing': 0.05; 'math':
0.05; 'row': 0.05; '2023': 0.07; 'arrays': 0.07; 'else:': 0.09;
'language,': 0.09; 'matrix': 0.09; 'numpy': 0.09; 'say:': 0.09;
'subject:how': 0.09; 'subject:two': 0.09; 'types.': 0.09;
'subject:Python': 0.12; 'url:mailman': 0.15; '>>>>': 0.16;
'assumption': 0.16; 'chrisa': 0.16; 'cpython,': 0.16; 'encounter':
0.16; 'equal.': 0.16; 'heavily': 0.16; 'iteration': 0.16;
'missing?': 0.16; 'numpy.': 0.16; 'object,': 0.16; 'operations,':
0.16; 'pointers': 0.16; 'received:10.0.0': 0.16; 'received:64.90':
0.16; 'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'speedup': 0.16; 'spot': 0.16;
'wrote:': 0.16; 'python': 0.16; 'pm,': 0.19; 'to:addr:python-
list': 0.20; 'language': 0.21; 'way.': 0.22; 'code': 0.23; "i'd":
0.24; 'anything': 0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'url-
ip:188.166/16': 0.25; '11,': 0.26; 'object': 0.26; 'done': 0.28;
'>>>': 0.28; 'example,': 0.28; 'header:User-Agent:1': 0.30; 'url-
ip:188/8': 0.31; 'think': 0.32; 'assume': 0.32; 'lists,': 0.32;
'objects': 0.32; 'python-list': 0.32; 'received:10.0': 0.32;
'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'said,': 0.32; 'but':
0.32; 'there': 0.33; 'same': 0.34; 'header:In-Reply-To:1': 0.34;
'handling': 0.35; 'reflect': 0.35; 'cases': 0.36; 'possibly':
0.36; 'those': 0.36; 'necessarily': 0.37; "it's": 0.37; 'others':
0.37; 'thanks': 0.38; 'two': 0.39; 'list': 0.39; 'use': 0.39;
'wed,': 0.39; 'happen': 0.40; 'years.': 0.40; 'both': 0.40;
'something': 0.40; 'want': 0.40; 'reference': 0.60; 'provide':
0.60; '10,': 0.61; 'detail': 0.61; 'skip:o 10': 0.61; 'great':
0.63; 'your': 0.64; 'well': 0.65; 'entire': 0.67;
'header:Received:6': 0.67; 'received:64': 0.67; 'matter': 0.68;
'operations': 0.68; 'assembly': 0.69; 'remaining': 0.69;
'sequence': 0.69; 'terms': 0.70; 'speed': 0.71; 'longer': 0.71;
"you'll": 0.73; 'low': 0.74; 'yourself': 0.75; 'subsequent': 0.76;
'discovered': 0.80; 'pointer': 0.84; 'pointing': 0.84; 'type,':
0.84; 'type.': 0.84; 'affect': 0.91
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1673388000; a=rsa-sha256;
cv=none;
b=lwiawUEsPpGkSNayY4BhGAI5OMnBrMkm2t9iIxoaE0FJoofHZaS+By9YjWHDhr9WGrozs8
+IDeNih5zw/QVn6CyyG7YTubnPBfO6DapjfIGo8RXd7WSImHSuabi29uJPDSw35IdSvUKp
Hf4Vjg5aezfcYbPwPSZzbw2uV6F3hlyIovVF7UbNIJiyG7zOYbQz0XTvrMpl9ebwNFtfwI
YmSy3PRStkIu7cacFJV6EqwNt9JDPG6bmDCJXCDcjgQ46+VZ1VYZhzBwgdOFSOo/JIl0cs
TDajdcOrDgDsDkjZYGZ8SvJ+V647dQkjVAUyUSQgkJTJycpqqanbRISkY38PjQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1673388000;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=2g1NFU+Ijl9kuUFJyAqsIw8G6hvdGSDIL82OMcA3rRc=;
b=y2aOI4HqpIJzZiS6HH9A3LRsDFZAGjK8k5ep0hZX7+iulwZVA8tFipAWt6sBriVZyBSG5Y
CFG4kUitwH0u07ee2NzfHRg0uzIMglkIJko2RIaeyMqMB6cMM3hKF2OfPlYB2GDJPti5X5
GhfKi/3b/f7iKfpNfM6dm9OTL08+u06nGRledrPUhY/zO3aD/oy+RST53KsSeGWEr8gUvc
0W1cHCCGrf+hapIEa3ZciMdZdJYaEGn+5IZhRuKLCOKFE7WNHs8E7B5rVrX+ojYl3vAnSp
BEsmn7dyo8AQjCp3JwZzqFFauQw5wrR/bRxyTTkW/uXrwh9ff/42not4+67rLw==
ARC-Authentication-Results: i=1; rspamd-7cf955c847-n5jdc;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Befitting-Harbor: 39997af7180166bb_1673388001092_2337904320
X-MC-Loop-Signature: 1673388001092:2619562794
X-MC-Ingress-Time: 1673388001092
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1673388000;
bh=2g1NFU+Ijl9kuUFJyAqsIw8G6hvdGSDIL82OMcA3rRc=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=IgCgbuMBCN9ukgZMTwqvXu7z5i5kzCD9I0YDtoyUpn6n2KOr9h9Vd1tVAJg5d3NyG
1RhlfOKK/MPQBgENja4CEOo7Kf6KRyxJrvfdQ7Y5gdNSCdDI6p3FEK6JAeqUblf6QZ
kFZTzgGx7IO4sOuQ8zaHKVGcZtkvJACSlNsE/7P3G85PqgWyDfi0YyVvFKkC1k21vB
zSUQFxnWZ8Fv/Dj6ApfEXReLHYZM6IwuW54KRb9sSmuoklBNAPHRi9Zu6Uonl2X6tY
XeRvYD2RvKthBo47EA1C2l9XZOfuzdZUbb58NVUjROfJfO1YhoBMZjqJWnjXtD1+XT
4GsGXtsLJ3PJw==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <31d2ed67-d710-cbb9-5e44-0872a07747c5@mrabarnett.plus.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <59d349a8-508c-cc7d-c833-d309d888d4c2@tompassin.net>
X-Mailman-Original-References: <NLSGqyj--3-9@tutanota.com>
<CAPTjJmpiB5xK9PS311yHKEj1_qg_F4B7BXwEt_mbQeLKeph_Fw@mail.gmail.com>
<NLSPZV8--7-9@tutanota.com>
<31d2ed67-d710-cbb9-5e44-0872a07747c5@mrabarnett.plus.com>
 by: Thomas Passin - Tue, 10 Jan 2023 21:59 UTC

Just to add a possibly picky detail to what others have said, Python
does not have an "array" type. It has a "list" type, as well as some
other, not necessarily mutable, sequence types.

If you want to speed up list and matrix operations, you might use NumPy.
Its arrays and matrices are heavily optimized for fast processing and
provide many useful operations on them. No use calling out to C code
yourself when NumPy has been refining that for many years.

On 1/10/2023 4:10 PM, MRAB wrote:
> On 2023-01-10 20:41, Jen Kris via Python-list wrote:
>>
>> Thanks for your comments.  I'd like to make one small point.  You say:
>>
>> "Assignment in Python is a matter of object references. It's not
>> "conform them as long as they remain equal". You'll have to think in
>> terms of object references the entire way."
>>
>> But where they have been set to the same object, an operation on one
>> will affect the other as long as they are equal (in Python).  So I
>> will have to conform them in those cases because Python will reflect
>> any math operation in both the array and the matrix.
>>
> It's not a 2D matrix, it's a 1D list containing references to 1D lists,
> each of which contains references to Python ints.
>
> In CPython, references happen to be pointers, but that's just an
> implementation detail.
>
>>
>>
>> Jan 10, 2023, 12:28 by rosuav@gmail.com:
>>
>>> On Wed, 11 Jan 2023 at 07:14, Jen Kris via Python-list
>>> <python-list@python.org> wrote:
>>>
>>>>
>>>> I am writing a spot speedup in assembly language for a short but
>>>> computation-intensive Python loop, and I discovered something about
>>>> Python array handling that I would like to clarify.
>>>>
>>>> For a simplified example, I created a matrix mx1 and assigned the
>>>> array arr1 to the third row of the matrix:
>>>>
>>>> mx1 = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
>>>> arr1 = mx1[2]
>>>>
>>>> The pointers to these are now the same:
>>>>
>>>> ida = id(mx1[2]) - 140260325306880
>>>> idb = id(arr1) - 140260325306880
>>>>
>>>> That’s great because when I encounter this in assembly or C, I can
>>>> just borrow the pointer to row 3 for the array arr1, on the
>>>> assumption that they will continue to point to the same object.
>>>> Then when I do any math operations in arr1 it will be reflected in
>>>> both arrays because they are now pointing to the same array:
>>>>
>>>
>>> That's not an optimization; what you've done is set arr1 to be a
>>> reference to that object.
>>>
>>>> But on the next iteration we assign arr1 to something else:
>>>>
>>>> arr1 = [ 10, 11, 12 ]
>>>> idc = id(arr1) – 140260325308160
>>>> idd = id(mx1[2]) – 140260325306880
>>>>
>>>> Now arr1 is no longer equal to mx1[2], and any subsequent operations
>>>> in arr1 will not affect mx1.
>>>>
>>>
>>> Yep, you have just set arr1 to be a completely different object.
>>>
>>>> So where I’m rewriting some Python code in a low level language, I
>>>> can’t assume that the two objects are equal because that equality
>>>> will not remain if either is reassigned.  So if I do some operation
>>>> on one array I have to conform the two arrays for as long as they
>>>> remain equal, I can’t just do it in one operation because I can’t
>>>> rely on the objects remaining equal.
>>>>
>>>> Is my understanding of this correct?  Is there anything I’m missing?
>>>>
>>>
>>> Assignment in Python is a matter of object references. It's not
>>> "conform them as long as they remain equal". You'll have to think in
>>> terms of object references the entire way.
>>>
>>> ChrisA
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>>
>>
>

Re: To clarify how Python handles two equal objects

<9f1urhdjteo73ei30bhicg69hvl5cc9tni@4ax.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=25518&group=comp.lang.python#25518

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 11 Jan 2023 18:55:08 +0000
From: wlfraed@ix.netcom.com (Dennis Lee Bieber)
Newsgroups: comp.lang.python
Subject: Re: To clarify how Python handles two equal objects
Date: Wed, 11 Jan 2023 13:55:09 -0500
Organization: IISS Elusive Unicorn
Message-ID: <9f1urhdjteo73ei30bhicg69hvl5cc9tni@4ax.com>
References: <NLSGqyj--3-9@tutanota.com> <CAPTjJmpiB5xK9PS311yHKEj1_qg_F4B7BXwEt_mbQeLKeph_Fw@mail.gmail.com> <NLSPZV8--7-9@tutanota.com> <31d2ed67-d710-cbb9-5e44-0872a07747c5@mrabarnett.plus.com> <59d349a8-508c-cc7d-c833-d309d888d4c2@tompassin.net> <mailman.1472.1673388409.20444.python-list@python.org>
User-Agent: ForteAgent/8.00.32.1272
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 14
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-xQ4VrXerW8dJ8nKWWL7a7aO1HoX/olyYaEp2dFH9AkjRFK8UkOFpe+zWtalKo3eY/KIGQkEbg8G0kQf!rKzBBWVo0arzG1Q1y6Fti6F8vX6JGgZUDm4YySKECoG+2gQmkMptQVzcotojj16NjjAPDaKH
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
 by: Dennis Lee Bieber - Wed, 11 Jan 2023 18:55 UTC

On Tue, 10 Jan 2023 16:59:59 -0500, Thomas Passin <list1@tompassin.net>
declaimed the following:

>Just to add a possibly picky detail to what others have said, Python
>does not have an "array" type. It has a "list" type, as well as some
>other, not necessarily mutable, sequence types.
>
However, it has long had https://docs.python.org/3/library/array.html

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/


devel / comp.lang.python / Re: To clarify how Python handles two equal objects

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor