From c1c7150d6bb74a4b1950d05853277f255f75e5db Mon Sep 17 00:00:00 2001 From: Montana Low Date: Mon, 24 Oct 2022 15:57:24 -0700 Subject: [PATCH] update tests w/ examples --- pgml-extension/Cargo.toml | 3 ++ pgml-extension/docker/entrypoint.sh | 4 +-- .../examples/binary_classification.sql | 5 +++- .../examples/image_classification.sql | 1 + pgml-extension/examples/joint_regression.sql | 1 + .../examples/multi_classification.sql | 1 + pgml-extension/examples/regression.sql | 2 +- pgml-extension/examples/transformers.sql | 2 ++ pgml-extension/examples/vectors.sql | 2 ++ pgml-extension/sql/setup_examples.sql | 28 +++++++++++++++++++ pgml-extension/tests/test.sql | 11 +++++++- 11 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 pgml-extension/sql/setup_examples.sql diff --git a/pgml-extension/Cargo.toml b/pgml-extension/Cargo.toml index 03dcc1a5c..43c3191cc 100644 --- a/pgml-extension/Cargo.toml +++ b/pgml-extension/Cargo.toml @@ -57,3 +57,6 @@ panic = "unwind" opt-level = 3 lto = "fat" codegen-units = 1 + +[profile.test] +opt-level = 3 diff --git a/pgml-extension/docker/entrypoint.sh b/pgml-extension/docker/entrypoint.sh index af6105d52..1e1b9ffe4 100644 --- a/pgml-extension/docker/entrypoint.sh +++ b/pgml-extension/docker/entrypoint.sh @@ -13,9 +13,7 @@ echo "Creating user and database..." (createdb -U postgres -h 127.0.0.1 pgml_development 2> /dev/null) || true echo "Installing pgml extension..." -psql -U postgres -h 127.0.0.1 pgml_development -c 'CREATE EXTENSION IF NOT EXISTS pgml' - -psql -U postgres -h 127.0.0.1 pgml_development -f tests/test.sql -P pager +psql -U postgres -h 127.0.0.1 pgml_development -f sql/setup_examples.sql -P pager echo "Ready!" if [[ ! -z $@ ]]; then diff --git a/pgml-extension/examples/binary_classification.sql b/pgml-extension/examples/binary_classification.sql index 3e461b408..edc7b7be7 100644 --- a/pgml-extension/examples/binary_classification.sql +++ b/pgml-extension/examples/binary_classification.sql @@ -1,5 +1,6 @@ -- Exit on error (psql) \set ON_ERROR_STOP true +\timing on SELECT pgml.load_dataset('breast_cancer'); @@ -45,7 +46,8 @@ SELECT malignant, pgml.predict( "worst fractal dimension" ] ) AS prediction -FROM pgml.breast_cancer +FROM pgml.breast_cancer +ORDER BY random() LIMIT 10; -- view raw class probabilities @@ -85,6 +87,7 @@ SELECT malignant, pgml.predict_proba( ] ) AS prediction FROM pgml.breast_cancer +ORDER BY random() LIMIT 10; -- diff --git a/pgml-extension/examples/image_classification.sql b/pgml-extension/examples/image_classification.sql index fa652e8ec..9f18ac258 100644 --- a/pgml-extension/examples/image_classification.sql +++ b/pgml-extension/examples/image_classification.sql @@ -11,6 +11,7 @@ -- Exit on error (psql) \set ON_ERROR_STOP true +\timing on SELECT pgml.load_dataset('digits'); diff --git a/pgml-extension/examples/joint_regression.sql b/pgml-extension/examples/joint_regression.sql index e784d762b..9ca8f9d41 100644 --- a/pgml-extension/examples/joint_regression.sql +++ b/pgml-extension/examples/joint_regression.sql @@ -4,6 +4,7 @@ -- Exit on error (psql) \set ON_ERROR_STOP true +\timing on SELECT pgml.load_dataset('linnerud'); diff --git a/pgml-extension/examples/multi_classification.sql b/pgml-extension/examples/multi_classification.sql index f28d5b709..9027d9f27 100644 --- a/pgml-extension/examples/multi_classification.sql +++ b/pgml-extension/examples/multi_classification.sql @@ -1,5 +1,6 @@ -- Exit on error (psql) \set ON_ERROR_STOP true +\timing on SELECT pgml.load_dataset('iris'); diff --git a/pgml-extension/examples/regression.sql b/pgml-extension/examples/regression.sql index 41a598a5a..28f6bd977 100644 --- a/pgml-extension/examples/regression.sql +++ b/pgml-extension/examples/regression.sql @@ -11,7 +11,7 @@ -- Exit on error (psql) \set ON_ERROR_STOP true -\timing +\timing on SELECT pgml.load_dataset('diabetes'); diff --git a/pgml-extension/examples/transformers.sql b/pgml-extension/examples/transformers.sql index 61b1a5c51..5965e319d 100644 --- a/pgml-extension/examples/transformers.sql +++ b/pgml-extension/examples/transformers.sql @@ -1,5 +1,7 @@ -- Exit on error (psql) \set ON_ERROR_STOP true +\timing on + SELECT pgml.transform( 'translation_en_to_fr', diff --git a/pgml-extension/examples/vectors.sql b/pgml-extension/examples/vectors.sql index 27b80cecd..5fd546e57 100644 --- a/pgml-extension/examples/vectors.sql +++ b/pgml-extension/examples/vectors.sql @@ -1,4 +1,6 @@ +-- Exit on error (psql) \set ON_ERROR_STOP true +\timing on -- Elementwise arithmetic w/ constants SELECT pgml.add(ARRAY[1.0, 2.0, 3.0], 3); diff --git a/pgml-extension/sql/setup_examples.sql b/pgml-extension/sql/setup_examples.sql new file mode 100644 index 000000000..af696af89 --- /dev/null +++ b/pgml-extension/sql/setup_examples.sql @@ -0,0 +1,28 @@ +--- +--- Create the extension and load sample data into a database. +--- +--- Usage: +--- +--- $ cargo pgx run --release +--- $ psql -P pager-off -h localhost -p 28813 -d pgml -f sql/setup_examples.sql +--- +\set ON_ERROR_STOP true +\timing on + +-- The intention is to only allow setup_examples.sql to run on a database that +-- has not had example data installed before, e.g. docker run. This should +-- error and stop the process if the extension is already present. +CREATE EXTENSION pgml; + +SELECT pgml.load_dataset('breast_cancer'); +SELECT pgml.load_dataset('diabetes'); +SELECT pgml.load_dataset('digits'); +SELECT pgml.load_dataset('iris'); +SELECT pgml.load_dataset('linnerud'); +SELECT pgml.load_dataset('wine'); + +\i examples/binary_classification.sql +\i examples/image_classification.sql +\i examples/joint_regression.sql +\i examples/multi_classification.sql +\i examples/regression.sql diff --git a/pgml-extension/tests/test.sql b/pgml-extension/tests/test.sql index afdd1a10f..c82bbd2c8 100644 --- a/pgml-extension/tests/test.sql +++ b/pgml-extension/tests/test.sql @@ -1,9 +1,18 @@ --- --- Test our functions. --- +--- Usage: +--- +--- $ cargo pgx run --release +--- $ psql -P pager-off -h localhost -p 28813 -d pgml -f tests/test.sql +--- \set ON_ERROR_STOP true +\timing on -\timing +-- Reset the test database to a clean state on each run. +DROP EXTENSION IF EXISTS pgml CASCADE; +DROP SCHEMA IF EXISTS pgml CASCADE; +CREATE EXTENSION pgml; SELECT pgml.load_dataset('breast_cancer'); SELECT pgml.load_dataset('diabetes'); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy