From dc3a0072a2e849626ee0222d3d3570f9c54d1bb5 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Wed, 10 Jun 2020 23:51:01 +0200 Subject: [PATCH] functions: Add vector-boolean->01. --- functions.rkt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/functions.rkt b/functions.rkt index 76d0b01..5c3fc08 100644 --- a/functions.rkt +++ b/functions.rkt @@ -30,7 +30,8 @@ [random-boolean-function (-> number? procedure?)] [random-boolean-function/list (-> number? procedure?)] [tbf-w (-> tbf? (vectorof number?))] - [tbf-θ (-> tbf? number?)])) + [tbf-θ (-> tbf? number?)] + [vector-boolean->01 (-> (vectorof boolean?) (vectorof (or/c 0 1)))])) (module+ test (require rackunit)) @@ -236,3 +237,11 @@ ;;; Unicode shortcuts for accessing the elements of a TBF. (define tbf-w tbf-weights) (define tbf-θ tbf-threshold) + +;;; Converts a Boolean vector to a 0-1 vector. +(define (vector-boolean->01 bool-v) + (vector-map any->01 bool-v)) + +(module+ test + (test-case "boolean->0-1" + (check-equal? (vector-boolean->01 #(#t #f #f)) #(1 0 0))))