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

Поиск
Список
Период
Сортировка
От Enrico Sirola
Тема Re: arrays of floating point numbers / linear algebra operations into the DB
Дата
Msg-id 47A4AADC.5090308@gmail.com
обсуждение исходный текст
Ответ на Re: arrays of floating point numbers / linear algebra operations into the DB  ("Webb Sprague" <webb.sprague@gmail.com>)
Ответы Re: arrays of floating point numbers / linear algebra operations into the DB
Список 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 по дате отправления:

Предыдущее
От: "Rodrigo E. De León Plicet"
Дата:
Сообщение: Re: Oracle Analytical Functions
Следующее
От: "Aílsom F. Heringer"
Дата:
Сообщение: first message: SELECT FROM