pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Avoid use of float arithmetic in bipartite_match.c.
5+ messages / 2 participants
[nested] [flat]
* pgsql: Avoid use of float arithmetic in bipartite_match.c.
@ 2015-08-23 17:02 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2015-08-23 17:02 UTC (permalink / raw)
To: pgsql-committers
Avoid use of float arithmetic in bipartite_match.c.
Since the distances used in this algorithm are small integers (not more
than the size of the U set, in fact), there is no good reason to use float
arithmetic for them. Use short ints instead: they're smaller, faster, and
require no special portability assumptions.
Per testing by Greg Stark, which disclosed that the code got into an
infinite loop on VAX for lack of IEEE-style float infinities. We don't
really care all that much whether Postgres can run on a VAX anymore,
but there seems sufficient reason to change this code anyway.
In passing, make a few other small adjustments to make the code match
usual Postgres coding style a bit better.
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/44ed65a545970829322098e22d10947e6d545d9a
Modified Files
--------------
src/backend/lib/bipartite_match.c | 75 +++++++++++++++++++++++--------------
src/include/lib/bipartite_match.h | 16 ++++----
2 files changed, 55 insertions(+), 36 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Avoid use of float arithmetic in bipartite_match.c.
@ 2015-08-23 17:02 Tom Lane <tgl@sss.pgh.pa.us>
2015-08-23 17:25 ` Re: pgsql: Avoid use of float arithmetic in bipartite_match.c. Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2015-08-23 17:02 UTC (permalink / raw)
To: pgsql-committers
Avoid use of float arithmetic in bipartite_match.c.
Since the distances used in this algorithm are small integers (not more
than the size of the U set, in fact), there is no good reason to use float
arithmetic for them. Use short ints instead: they're smaller, faster, and
require no special portability assumptions.
Per testing by Greg Stark, which disclosed that the code got into an
infinite loop on VAX for lack of IEEE-style float infinities. We don't
really care all that much whether Postgres can run on a VAX anymore,
but there seems sufficient reason to change this code anyway.
In passing, make a few other small adjustments to make the code match
usual Postgres coding style a bit better.
Branch
------
REL9_5_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/4022f94c350f96fc5feff0503d3e2f2f6f9086cc
Modified Files
--------------
src/backend/lib/bipartite_match.c | 75 +++++++++++++++++++++++--------------
src/include/lib/bipartite_match.h | 16 ++++----
2 files changed, 55 insertions(+), 36 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pgsql: Avoid use of float arithmetic in bipartite_match.c.
2015-08-23 17:02 pgsql: Avoid use of float arithmetic in bipartite_match.c. Tom Lane <tgl@sss.pgh.pa.us>
@ 2015-08-23 17:25 ` Andres Freund <andres@anarazel.de>
2015-08-23 17:30 ` Re: pgsql: Avoid use of float arithmetic in bipartite_match.c. Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: Andres Freund @ 2015-08-23 17:25 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers
Hi,
On 2015-08-23 17:02:35 +0000, Tom Lane wrote:
> Avoid use of float arithmetic in bipartite_match.c.
>
> Since the distances used in this algorithm are small integers (not more
> than the size of the U set, in fact), there is no good reason to use float
> arithmetic for them. Use short ints instead: they're smaller, faster, and
> require no special portability assumptions.
Yea, makes sense. Thanks.
> In passing, make a few other small adjustments to make the code match
> usual Postgres coding style a bit better.
Not sure why you replaced n by k? Anyway, it's not a complete
replacement afaics:
/*
* Given a bipartite graph consisting of nodes U numbered 1..nU, nodes V
* numbered 1..nV, and an adjacency map of undirected edges in the form
- * adjacency[u] = [n, v1, v2, v3, ... vn], we wish to find a "maximum
+ * adjacency[u] = [k, v1, v2, v3, ... vk], we wish to find a "maximum
* cardinality matching", which is defined as follows: a matching is a subset
* of the original edges such that no node has more than one edge, and a
* matching has maximum cardinality if there exists no other matching with a
the nodes are 1..n, so the adjacency list should be as well (or the
other way round).
Andres
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pgsql: Avoid use of float arithmetic in bipartite_match.c.
2015-08-23 17:02 pgsql: Avoid use of float arithmetic in bipartite_match.c. Tom Lane <tgl@sss.pgh.pa.us>
2015-08-23 17:25 ` Re: pgsql: Avoid use of float arithmetic in bipartite_match.c. Andres Freund <andres@anarazel.de>
@ 2015-08-23 17:30 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-08-23 17:44 ` Re: pgsql: Avoid use of float arithmetic in bipartite_match.c. Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2015-08-23 17:30 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-committers
Andres Freund <andres@anarazel.de> writes:
> Not sure why you replaced n by k?
I thought it was possible to confuse it with the "n"'s used in the
previous line to denote the graph sizes.
> the nodes are 1..n, so the adjacency list should be as well (or the
> other way round).
No, I meant them to be different. Do you think the other way is better?
regards, tom lane
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pgsql: Avoid use of float arithmetic in bipartite_match.c.
2015-08-23 17:02 pgsql: Avoid use of float arithmetic in bipartite_match.c. Tom Lane <tgl@sss.pgh.pa.us>
2015-08-23 17:25 ` Re: pgsql: Avoid use of float arithmetic in bipartite_match.c. Andres Freund <andres@anarazel.de>
2015-08-23 17:30 ` Re: pgsql: Avoid use of float arithmetic in bipartite_match.c. Tom Lane <tgl@sss.pgh.pa.us>
@ 2015-08-23 17:44 ` Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 5+ messages in thread
From: Andres Freund @ 2015-08-23 17:44 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers
On 2015-08-23 13:30:45 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > Not sure why you replaced n by k?
>
> I thought it was possible to confuse it with the "n"'s used in the
> previous line to denote the graph sizes.
>
> > the nodes are 1..n, so the adjacency list should be as well (or the
> > other way round).
>
> No, I meant them to be different. Do you think the other way is better?
Well, using the same index seemed to comfortably explain that the size
of the individual adjacency mappings depends on the number of nodes in
V. But for that to really make sense there'd need to be a different
indexes for U/V, which I now see wasn't the case case before
either. As currently used they'll be the same anyway...
- Andres
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2015-08-23 17:44 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-08-23 17:02 pgsql: Avoid use of float arithmetic in bipartite_match.c. Tom Lane <tgl@sss.pgh.pa.us>
2015-08-23 17:02 pgsql: Avoid use of float arithmetic in bipartite_match.c. Tom Lane <tgl@sss.pgh.pa.us>
2015-08-23 17:25 ` Andres Freund <andres@anarazel.de>
2015-08-23 17:30 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-08-23 17:44 ` Andres Freund <andres@anarazel.de>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox