blob: b940886054b856d4106bca1385f97be0e8c64dfa [file] [log] [blame]
/* ------------------------------------------------------------------------
* Dense cases
* ----------------------------------------------------------------------*/
drop table if exists mat;
CREATE TABLE mat (
row_id integer,
row_vec double precision[]
);
COPY mat (row_id, row_vec) FROM stdin delimiter '|';
1|{396,840,353,446,318,886,15,584,159,383}
2|{691,58,899,163,159,533,604,582,269,390}
3|{293,742,298,75,404,857,941,662,846,2}
4|{462,532,787,265,982,306,600,608,212,885}
5|{304,151,337,387,643,753,603,531,459,652}
6|{327,946,368,943,7,516,272,24,591,204}
7|{877,59,260,302,891,498,710,286,864,675}
8|{458,959,774,376,228,354,300,669,718,565}
9|{824,390,818,844,180,943,424,520,65,913}
10|{882,761,398,688,761,405,125,484,222,873}
11|{528,1,860,18,814,242,314,965,935,809}
12|{492,220,576,289,321,261,173,1,44,241}
13|{415,701,221,503,67,393,479,218,219,916}
14|{350,192,211,633,53,783,30,444,176,932}
15|{909,472,871,695,930,455,398,893,693,838}
16|{739,651,678,577,273,935,661,47,373,618}
\.
drop table if exists svd_u;
drop table if exists svd_v;
drop table if exists svd_s;
drop table if exists svd_summary;
select svd('mat', 'svd', 'row_id', 10, NULL, 'svd_summary');
select assert(
relative_error(array_agg(value order by row_id), array[6475.6723, 1875.1807, 1483.2523, 1159.7226, 1033.8609, 948.4374, 795.3796, 709.0862, 462.4738, 365.8752]) < 1e-6,
'SVD error: Wrong results!'
) from svd_s where value is not NULL;
/* ------------------------------------------------------------------------
* Sparse cases
* ----------------------------------------------------------------------*/
drop table if exists mat_sparse;
select matrix_sparsify('mat', 'row=row_id, val=row_vec', 'mat_sparse_same_column_names');
create table mat_sparse (i, j, v) as select * from mat_sparse_same_column_names;
-- create table mat_sparse (row_id, col_id, value) as select * from mat_sparse_same_column_names;
drop table if exists svd_u;
drop table if exists svd_v;
drop table if exists svd_s;
drop table if exists svd_summary;
select svd_sparse('mat_sparse', 'svd', 'i', 'j', 'v', 16, 10, 10, NULL, 'svd_summary');
select assert(
relative_error(array_agg(value order by row_id), array[6475.6723, 1875.1807, 1483.2523, 1159.7226, 1033.8609, 948.4374, 795.3796, 709.0862, 462.4738, 365.8752]) < 1e-6,
'SVD error: Wrong results!'
) from svd_s where value is not NULL;
drop table if exists svd_u;
drop table if exists svd_v;
drop table if exists svd_s;
drop table if exists svd_summary;
select svd_sparse_native('mat_sparse', 'svd', 'i', 'j', 'v', 16, 10, 10, NULL, 'svd_summary');
select assert(
relative_error(array_agg(value order by row_id), array[6475.6723, 1875.1807, 1483.2523, 1159.7226, 1033.8609, 948.4374, 795.3796, 709.0862, 462.4738, 365.8752]) < 1e-6,
'SVD error: Wrong results!'
) from svd_s where value is not NULL;
drop table if exists mat_block;
select matrix_blockize('mat', 'row=row_id, val=row_vec', 1000, 1000,
'mat_block', 'row=row_id, col=col_id, val=block');
SELECT * from mat_block;
drop table if exists svd_u;
drop table if exists svd_v;
drop table if exists svd_s;
drop table if exists svd_summary;
select svd_block('mat_block', 'svd', 10, NULL, 'svd_summary');
SELECT * FROM svd_s WHERE value is not null;
select assert(
relative_error(array_agg(value order by row_id), array[6475.6723, 1875.1807, 1483.2523, 1159.7226, 1033.8609, 948.4374, 795.3796, 709.0862, 462.4738, 365.8752]) < 1e-6,
'SVD error: Wrong results!'
) from svd_s where value is not NULL;