Re: arrays of floating point numbers / linear algebra operations into the DB

From: Enrico Sirola <enrico(dot)sirola(at)gmail(dot)com>
To: Webb Sprague <webb(dot)sprague(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org General" <pgsql-general(at)postgresql(dot)org>, mail(at)joeconway(dot)com, kleptog(at)svana(dot)org
Subject: Re: arrays of floating point numbers / linear algebra operations into the DB
Date: 2008-02-02 17:39:40
Message-ID: 47A4AADC.5090308@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Webb, Joe, Martijn

Webb Sprague ha scritto:
> On Feb 1, 2008 2:31 AM, Enrico Sirola <enrico(dot)sirola(at)gmail(dot)com> wrote:
>> Hello,
>> I'd like to perform linear algebra operations on float4/8 arrays
>
> Having avoided a bunch of real work wondering about linear algebra and
> PG, did you consider the Gnu Scientific Library ? We would still need
> to hook everything together, but it seems to do a lot of this, and is
> written in C, etc.

I experimented a bit today with cblas, and wrapped the blas function for
scaling a vector. The following session shows the usage:

create or replace function scale(float8, float8[])
returns float8[]
as '$libdir/linalg', 'scale'
language 'C' immutable strict;

sps_dev=# select scale(k, '{1,2,3}') from generate_series(1,10) k;
scale
------------
{1,2,3}
{2,4,6}
{3,6,9}
{4,8,12}
{5,10,15}
{6,12,18}
{7,14,21}
{8,16,24}
{9,18,27}
{10,20,30}
(10 rows)

sps_dev=# create operator * (leftarg=float8, rightarg=float8[],
procedure=scale);

sps_dev=# select k * '{1,2,3}'::float8[] from generate_series(1,10) k;
?column?
------------
{1,2,3}
{2,4,6}
{3,6,9}
{4,8,12}
{5,10,15}
{6,12,18}
{7,14,21}
{8,16,24}
{9,18,27}
{10,20,30}
(10 rows)

I'm quite proud, this is my first C extension function ;-)
I'd gladly post the code if it's ok for the list users. It's more or
less 100 lines of code. This approach seems promising...

By the way, Webb: I took a look at GSL and it seems to me that, from a
linear algebra point of view, it's basically cblas, so I'd use cblas
directly.
Please let me know your thoughts/advices,
e.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Aílsom F. Heringer 2008-02-02 17:43:15 first message: SELECT <column> FROM <t
Previous Message Rodrigo E. De León Plicet 2008-02-02 17:33:12 Re: Oracle Analytical Functions