Float and Int Linalg done, need to add tests

This commit is contained in:
midxm6 2025-02-10 13:05:51 -06:00
parent fab9a94593
commit efed71e554
2 changed files with 171 additions and 54 deletions

View File

@ -104,3 +104,120 @@ instructionVectorFloatShove state = instructionShove state vectorFloat
instructionVectorFloatShoveDup :: State -> State
instructionVectorFloatShoveDup state = instructionShoveDup state vectorFloat
instructionVectorFloatMean :: State -> State
instructionVectorFloatMean state@(State {_vectorFloat = vfs, _float = fs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = vfs', _float = mean vf : fs}
[] -> state -- Do nothing if _vectorFloat is empty
where
mean [] = 0
mean xs = sum xs / fromIntegral (length xs)
instructionVectorFloatMax :: State -> State
instructionVectorFloatMax state@(State {_vectorFloat = vfs, _float = fs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = vfs', _float = maximum vf : fs}
[] -> state
instructionVectorFloatMin :: State -> State
instructionVectorFloatMin state@(State {_vectorFloat = vfs, _float = fs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = vfs', _float = minimum vf : fs}
[] -> state
instructionVectorFloatSum :: State -> State
instructionVectorFloatSum state@(State {_vectorFloat = vfs, _float = fs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = vfs', _float = sum vf : fs}
[] -> state
instructionVectorFloatMode :: State -> State
instructionVectorFloatMode state@(State {_vectorFloat = vfs, _float = fs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = vfs', _float = mode vf : fs}
[] -> state
where
mode [] = 0
mode xs = head $ maximumBy (comparing length) (group (sort xs))
instructionVectorFloatNorm :: State -> State
instructionVectorFloatNorm state@(State {_vectorFloat = vfs, _float = fs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = vfs', _float = realToFrac (norm vf) : fs}
[] -> state
where
norm xs = norm_2 (vector xs)
instructionVectorFloatCummulativeMean :: State -> State
instructionVectorFloatCummulativeMean state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = zipWith (/) (scanl1 (+) (map fromIntegral vf)) [1..] : vfs'}
[] -> state
instructionVectorFloatCummulativeSum :: State -> State
instructionVectorFloatCummulativeSum state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = scanl1 (+) vf : vfs'}
[] -> state
instructionVectorFloatCummulativeMax :: State -> State
instructionVectorFloatCummulativeMax state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = scanl1 maximum vf : vfs'}
[] -> state
instructionVectorFloatCummulativeMin :: State -> State
instructionVectorFloatCummulativeMin state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = scanl1 minimum vf : vfs'}
[] -> state
instructionVectorFloatExp :: State -> State
instructionVectorFloatExp state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = map exp vf : vfs'}
[] -> state
instructionVectorFloatLog :: State -> State
instructionVectorFloatLog state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = map log vf : vfs'}
[] -> state
instructionVectorFloatCos :: State -> State
instructionVectorFloatCos state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = map cos vf : vfs'}
[] -> state
instructionVectorFloatSin :: State -> State
instructionVectorFloatSin state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = map sin vf : vfs'}
[] -> state
instructionVectorFloatAbs :: State -> State
instructionVectorFloatAbs state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = map abs vf : vfs'}
[] -> state
instructionVectorFloatSquare :: State -> State
instructionVectorFloatSquare state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = map (^2) vf : vfs'}
[] -> state
instructionVectorFloatCube :: State -> State
instructionVectorFloatCube state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = map (^3) vf : vfs'}
[] -> state
instructionVectorFloatSqrt :: State -> State
instructionVectorFloatSqrt state@(State {_vectorFloat = vfs}) =
case vfs of
(vf:vfs') -> state {_vectorFloat = map (sqrt . fromIntegral) vf : vfs'}
[] -> state

View File

@ -109,118 +109,118 @@ instructionVectorIntShoveDup :: State -> State
instructionVectorIntShoveDup state = instructionShoveDup state vectorChar
instructionVectorIntMean :: State -> State
instructionVectorIntMean state@(State {_vectorInt = ivs, _float = fs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _float = mean iv : fs}
instructionVectorIntMean state@(State {_vectorInt = vis, _float = fs}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _float = mean vi : fs}
[] -> state -- Do nothing if _vectorInt is empty
where
mean [] = 0
mean xs = fromIntegral (sum xs) / fromIntegral (length xs)
instructionVectorIntMax :: State -> State
instructionVectorIntMax state@(State {_vectorInt = ivs, _int = is}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _int = maximum iv : is}
instructionVectorIntMax state@(State {_vectorInt = vis, _int = is}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _int = maximum vi : is}
[] -> state
instructionVectorIntMin :: State -> State
instructionVectorIntMin state@(State {_vectorInt = ivs, _int = is}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _int = minimum iv : is}
instructionVectorIntMin state@(State {_vectorInt = vis, _int = is}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _int = minimum vi : is}
[] -> state
instructionVectorIntSum :: State -> State
instructionVectorIntSum state@(State {_vectorInt = ivs, _int = is}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _int = sum iv : is}
instructionVectorIntSum state@(State {_vectorInt = vis, _int = is}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _int = sum vi : is}
[] -> state
instructionVectorIntMode :: State -> State
instructionVectorIntMode state@(State {_vectorInt = ivs, _int = is}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _int = mode iv : is}
instructionVectorIntMode state@(State {_vectorInt = vis, _int = is}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _int = mode vi : is}
[] -> state
where
mode [] = 0
mode xs = head $ maximumBy (comparing length) (group (sort xs))
instructionVectorIntNorm :: State -> State
instructionVectorIntNorm state@(State {_vectorInt = ivs, _float = fs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _float = realToFrac (norm (map fromIntegral iv)) : fs}
instructionVectorIntNorm state@(State {_vectorInt = vis, _float = fs}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _float = realToFrac (norm (map fromIntegral vi)) : fs}
[] -> state
where
norm xs = norm_2 (vector xs)
instructionVectorIntCummulativeMean :: State -> State
instructionVectorIntCummulativeMean state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs, _vectorFloat = zipWith (/) (scanl1 (+) (map fromIntegral iv)) [1..] : fvs}
instructionVectorIntCummulativeMean state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
case vis of
(vi:vis') -> state {_vectorInt = vis, _vectorFloat = zipWith (/) (scanl1 (+) (map fromIntegral vi)) [1..] : vfs}
[] -> state
instructionVectorIntCummulativeSum :: State -> State
instructionVectorIntCummulativeSum state@(State {_vectorInt = ivs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = scanl1 (+) iv : ivs'}
instructionVectorIntCummulativeSum state@(State {_vectorInt = vis}) =
case vis of
(vi:vis') -> state {_vectorInt = scanl1 (+) vi : vis'}
[] -> state
instructionVectorIntCummulativeMax :: State -> State
instructionVectorIntCummulativeMax state@(State {_vectorInt = ivs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = scanl1 maximum iv : ivs'}
instructionVectorIntCummulativeMax state@(State {_vectorInt = vis}) =
case vis of
(vi:vis') -> state {_vectorInt = scanl1 maximum vi : vis'}
[] -> state
instructionVectorIntCummulativeMin :: State -> State
instructionVectorIntCummulativeMin state@(State {_vectorInt = ivs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = scanl1 minimum iv : ivs'}
instructionVectorIntCummulativeMin state@(State {_vectorInt = vis}) =
case vis of
(vi:vis') -> state {_vectorInt = scanl1 minimum vi : vis'}
[] -> state
instructionVectorIntExp :: State -> State
instructionVectorIntExp state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _vectorFloat = map (exp . fromIntegral) iv : fvs}
instructionVectorIntExp state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (exp . fromIntegral) vi : vfs}
[] -> state
instructionVectorIntLog :: State -> State
instructionVectorIntLog state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _vectorFloat = map (log . fromIntegral) iv : fvs}
instructionVectorIntLog state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (log . fromIntegral) vi : vfs}
[] -> state
instructionVectorIntCos :: State -> State
instructionVectorIntCos state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _vectorFloat = map (cos . fromIntegral) iv : fvs}
instructionVectorIntCos state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (cos . fromIntegral) vi : vfs}
[] -> state
instructionVectorIntSin :: State -> State
instructionVectorIntSin state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _vectorFloat = map (sin . fromIntegral) iv : fvs}
instructionVectorIntSin state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (sin . fromIntegral) vi : vfs}
[] -> state
instructionVectorIntAbs :: State -> State
instructionVectorIntAbs state@(State {_vectorInt = ivs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = map abs iv : ivs'}
instructionVectorIntAbs state@(State {_vectorInt = vis}) =
case vis of
(vi:vis') -> state {_vectorInt = map abs vi : vis'}
[] -> state
instructionVectorIntSquare :: State -> State
instructionVectorIntSquare state@(State {_vectorInt = ivs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = map (^2) iv : ivs'}
instructionVectorIntSquare state@(State {_vectorInt = vis}) =
case vis of
(vi:vis') -> state {_vectorInt = map (^2) vi : vis'}
[] -> state
instructionVectorIntCube :: State -> State
instructionVectorIntCube state@(State {_vectorInt = ivs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = map (^3) iv : ivs'}
instructionVectorIntCube state@(State {_vectorInt = vis}) =
case vis of
(vi:vis') -> state {_vectorInt = map (^3) vi : vis'}
[] -> state
instructionVectorIntSqrt :: State -> State
instructionVectorIntSqrt state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
case ivs of
(iv:ivs') -> state {_vectorInt = ivs', _vectorFloat = map (sqrt . fromIntegral) iv : fvs}
instructionVectorIntSqrt state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
case vis of
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (sqrt . fromIntegral) vi : vfs}
[] -> state