From ff118eb2ba157c804919686a0a833179d0a0d0d6 Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Mon, 13 May 2019 22:10:34 +0200 Subject: [PATCH] Implement LambdaTransformer (#381) --- src/Preprocessing/LambdaTransformer.php | 30 +++++++++++++++++++ tests/Preprocessing/LambdaTransformerTest.php | 28 +++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/Preprocessing/LambdaTransformer.php create mode 100644 tests/Preprocessing/LambdaTransformerTest.php diff --git a/src/Preprocessing/LambdaTransformer.php b/src/Preprocessing/LambdaTransformer.php new file mode 100644 index 0000000..f6b5a8b --- /dev/null +++ b/src/Preprocessing/LambdaTransformer.php @@ -0,0 +1,30 @@ +lambda = $lambda; + } + + public function fit(array $samples, ?array $targets = null): void + { + // nothing to do + } + + public function transform(array &$samples, ?array &$targets = null): void + { + foreach ($samples as &$sample) { + $sample = call_user_func($this->lambda, $sample); + } + } +} diff --git a/tests/Preprocessing/LambdaTransformerTest.php b/tests/Preprocessing/LambdaTransformerTest.php new file mode 100644 index 0000000..6f46f3e --- /dev/null +++ b/tests/Preprocessing/LambdaTransformerTest.php @@ -0,0 +1,28 @@ +transform($samples); + + self::assertEquals([3, 7, 11], $samples); + } +}