From 67ed23d9ca8b94ff2ccf2dc5dfae3e7e92c35b29 Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane Date: Fri, 7 Mar 2025 00:45:17 -0600 Subject: [PATCH] genericize int mean --- src/HushGP/Instructions/VectorIntInstructions.hs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/HushGP/Instructions/VectorIntInstructions.hs b/src/HushGP/Instructions/VectorIntInstructions.hs index 3b7fa14..4086b2f 100644 --- a/src/HushGP/Instructions/VectorIntInstructions.hs +++ b/src/HushGP/Instructions/VectorIntInstructions.hs @@ -1,7 +1,6 @@ {-# LANGUAGE TemplateHaskell #-} module HushGP.Instructions.VectorIntInstructions where -import Numeric.LinearAlgebra import HushGP.Instructions.GenericInstructions import HushGP.State import HushGP.TH @@ -334,14 +333,10 @@ instructionVectorIntInsertVectorInt :: State -> State instructionVectorIntInsertVectorInt = instructionVectorInsertVector vectorInt -- |Takes the mean of the top int vector and pushes the rounded int value --- to the int stack. No way to easily make this generic. +-- to the int stack. instructionVectorIntMean :: State -> State -instructionVectorIntMean state@(State {_int = is, _vectorInt = v1 : vs}) = state{_int = mean v1 : is, _vectorInt = vs} - where - mean :: [Integer] -> Integer - mean [] = 0 - mean xs = round $ sum (map (fromIntegral @Integer @Double) xs) / fromIntegral @Int @Double (length xs) -instructionVectorIntMean state = state +instructionVectorIntMean state@(State {_vectorInt = [] : vs}) = instructionVectorFuncVectorToPrim int vectorInt retZero state +instructionVectorIntMean state = instructionVectorFuncVectorToPrim int vectorInt (\xs -> round $ sum (map (fromIntegral @Integer @Double) xs) / fromIntegral @Int @Double (length xs)) state -- |Takes the maximum of the top int vector and pushes the int value -- to the int stack.