Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Webb, Joe, Martijn

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


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux