Re: arrays of floating point numbers / linear algebra operations into the DB - Mailing list pgsql-general

From Enrico Sirola
Subject Re: arrays of floating point numbers / linear algebra operations into the DB
Date
Msg-id 47A4AADC.5090308@gmail.com
Whole thread Raw
In response to Re: arrays of floating point numbers / linear algebra operations into the DB  ("Webb Sprague" <webb.sprague@gmail.com>)
Responses Re: arrays of floating point numbers / linear algebra operations into the DB
List pgsql-general
Hi Webb, Joe, Martijn

Webb Sprague ha scritto:
> On Feb 1, 2008 2:31 AM, Enrico Sirola <enrico.sirola@gmail.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.


pgsql-general by date:

Previous
From: "Rodrigo E. De León Plicet"
Date:
Subject: Re: Oracle Analytical Functions
Next
From: "Aílsom F. Heringer"
Date:
Subject: first message: SELECT FROM