pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Treating float arrays as vectors?
2+ messages / 2 participants
[nested] [flat]

* Treating float arrays as vectors?
@ 2021-06-17 14:13  Celia McInnis <celia.mcinnis@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Celia McInnis @ 2021-06-17 14:13 UTC (permalink / raw)
  To: pgsql-general

Hi:

I would love it if there was a vector data type in postgresql along with
such vector operations as addition, subtraction, scalar multiplication,
cross product, dot product, normalization, length and various sorts of
vector distances. So far I have been feeding my float arrays to plpython3u
to do these kinds of operations. Is there a better way I can get this
functionality?

Celia McInnis

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Treating float arrays as vectors?
@ 2021-06-17 16:08  Paul Jungwirth <pj@illuminatedcomputing.com>
  parent: Celia McInnis <celia.mcinnis@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Paul Jungwirth @ 2021-06-17 16:08 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 6/17/21 7:13 AM, Celia McInnis wrote:
> I would love it if there was a vector data type in postgresql along with 
> such vector operations as addition, subtraction, scalar multiplication, 
> cross product, dot product, normalization, length and various sorts of 
> vector distances.

I wrote an extension to define vector-based functions that take & return 
numeric arrays:

https://github.com/pjungwir/floatvec

It only has basic arithmetic, but matrix math functions could be added.

If you want aggregate functions instead I wrote another extension for that:

https://github.com/pjungwir/aggs_for_vecs

I haven't touched either in a while, but if you find they have problems 
on modern versions of Postgres, let me know and I should be able to get 
them updated quickly.

I experimented a bit with an AVX implementation, and it showed a 
worthwhile performance improvement, but I never got around to adding it 
to all functions, so it was just a proof-of-concept. I could dust that 
off if you're interested. But since the extension is C things are 
already pretty fast.

Yours,

-- 
Paul              ~{:-)
pj@illuminatedcomputing.com





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-06-17 16:08 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 14:13 Treating float arrays as vectors? Celia McInnis <celia.mcinnis@gmail.com>
2021-06-17 16:08 ` Paul Jungwirth <pj@illuminatedcomputing.com>

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