Float and Int Linalg done, need to add tests
This commit is contained in:
parent
fab9a94593
commit
efed71e554
@ -104,3 +104,120 @@ instructionVectorFloatShove state = instructionShove state vectorFloat
|
|||||||
|
|
||||||
instructionVectorFloatShoveDup :: State -> State
|
instructionVectorFloatShoveDup :: State -> State
|
||||||
instructionVectorFloatShoveDup state = instructionShoveDup state vectorFloat
|
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
|
@ -109,118 +109,118 @@ instructionVectorIntShoveDup :: State -> State
|
|||||||
instructionVectorIntShoveDup state = instructionShoveDup state vectorChar
|
instructionVectorIntShoveDup state = instructionShoveDup state vectorChar
|
||||||
|
|
||||||
instructionVectorIntMean :: State -> State
|
instructionVectorIntMean :: State -> State
|
||||||
instructionVectorIntMean state@(State {_vectorInt = ivs, _float = fs}) =
|
instructionVectorIntMean state@(State {_vectorInt = vis, _float = fs}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _float = mean iv : fs}
|
(vi:vis') -> state {_vectorInt = vis', _float = mean vi : fs}
|
||||||
[] -> state -- Do nothing if _vectorInt is empty
|
[] -> state -- Do nothing if _vectorInt is empty
|
||||||
where
|
where
|
||||||
mean [] = 0
|
mean [] = 0
|
||||||
mean xs = fromIntegral (sum xs) / fromIntegral (length xs)
|
mean xs = fromIntegral (sum xs) / fromIntegral (length xs)
|
||||||
|
|
||||||
instructionVectorIntMax :: State -> State
|
instructionVectorIntMax :: State -> State
|
||||||
instructionVectorIntMax state@(State {_vectorInt = ivs, _int = is}) =
|
instructionVectorIntMax state@(State {_vectorInt = vis, _int = is}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _int = maximum iv : is}
|
(vi:vis') -> state {_vectorInt = vis', _int = maximum vi : is}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntMin :: State -> State
|
instructionVectorIntMin :: State -> State
|
||||||
instructionVectorIntMin state@(State {_vectorInt = ivs, _int = is}) =
|
instructionVectorIntMin state@(State {_vectorInt = vis, _int = is}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _int = minimum iv : is}
|
(vi:vis') -> state {_vectorInt = vis', _int = minimum vi : is}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntSum :: State -> State
|
instructionVectorIntSum :: State -> State
|
||||||
instructionVectorIntSum state@(State {_vectorInt = ivs, _int = is}) =
|
instructionVectorIntSum state@(State {_vectorInt = vis, _int = is}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _int = sum iv : is}
|
(vi:vis') -> state {_vectorInt = vis', _int = sum vi : is}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntMode :: State -> State
|
instructionVectorIntMode :: State -> State
|
||||||
instructionVectorIntMode state@(State {_vectorInt = ivs, _int = is}) =
|
instructionVectorIntMode state@(State {_vectorInt = vis, _int = is}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _int = mode iv : is}
|
(vi:vis') -> state {_vectorInt = vis', _int = mode vi : is}
|
||||||
[] -> state
|
[] -> state
|
||||||
where
|
where
|
||||||
mode [] = 0
|
mode [] = 0
|
||||||
mode xs = head $ maximumBy (comparing length) (group (sort xs))
|
mode xs = head $ maximumBy (comparing length) (group (sort xs))
|
||||||
|
|
||||||
instructionVectorIntNorm :: State -> State
|
instructionVectorIntNorm :: State -> State
|
||||||
instructionVectorIntNorm state@(State {_vectorInt = ivs, _float = fs}) =
|
instructionVectorIntNorm state@(State {_vectorInt = vis, _float = fs}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _float = realToFrac (norm (map fromIntegral iv)) : fs}
|
(vi:vis') -> state {_vectorInt = vis', _float = realToFrac (norm (map fromIntegral vi)) : fs}
|
||||||
[] -> state
|
[] -> state
|
||||||
where
|
where
|
||||||
norm xs = norm_2 (vector xs)
|
norm xs = norm_2 (vector xs)
|
||||||
|
|
||||||
instructionVectorIntCummulativeMean :: State -> State
|
instructionVectorIntCummulativeMean :: State -> State
|
||||||
instructionVectorIntCummulativeMean state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
|
instructionVectorIntCummulativeMean state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs, _vectorFloat = zipWith (/) (scanl1 (+) (map fromIntegral iv)) [1..] : fvs}
|
(vi:vis') -> state {_vectorInt = vis, _vectorFloat = zipWith (/) (scanl1 (+) (map fromIntegral vi)) [1..] : vfs}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntCummulativeSum :: State -> State
|
instructionVectorIntCummulativeSum :: State -> State
|
||||||
instructionVectorIntCummulativeSum state@(State {_vectorInt = ivs}) =
|
instructionVectorIntCummulativeSum state@(State {_vectorInt = vis}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = scanl1 (+) iv : ivs'}
|
(vi:vis') -> state {_vectorInt = scanl1 (+) vi : vis'}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntCummulativeMax :: State -> State
|
instructionVectorIntCummulativeMax :: State -> State
|
||||||
instructionVectorIntCummulativeMax state@(State {_vectorInt = ivs}) =
|
instructionVectorIntCummulativeMax state@(State {_vectorInt = vis}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = scanl1 maximum iv : ivs'}
|
(vi:vis') -> state {_vectorInt = scanl1 maximum vi : vis'}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntCummulativeMin :: State -> State
|
instructionVectorIntCummulativeMin :: State -> State
|
||||||
instructionVectorIntCummulativeMin state@(State {_vectorInt = ivs}) =
|
instructionVectorIntCummulativeMin state@(State {_vectorInt = vis}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = scanl1 minimum iv : ivs'}
|
(vi:vis') -> state {_vectorInt = scanl1 minimum vi : vis'}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntExp :: State -> State
|
instructionVectorIntExp :: State -> State
|
||||||
instructionVectorIntExp state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
|
instructionVectorIntExp state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _vectorFloat = map (exp . fromIntegral) iv : fvs}
|
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (exp . fromIntegral) vi : vfs}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
|
|
||||||
instructionVectorIntLog :: State -> State
|
instructionVectorIntLog :: State -> State
|
||||||
instructionVectorIntLog state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
|
instructionVectorIntLog state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _vectorFloat = map (log . fromIntegral) iv : fvs}
|
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (log . fromIntegral) vi : vfs}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntCos :: State -> State
|
instructionVectorIntCos :: State -> State
|
||||||
instructionVectorIntCos state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
|
instructionVectorIntCos state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _vectorFloat = map (cos . fromIntegral) iv : fvs}
|
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (cos . fromIntegral) vi : vfs}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntSin :: State -> State
|
instructionVectorIntSin :: State -> State
|
||||||
instructionVectorIntSin state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
|
instructionVectorIntSin state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _vectorFloat = map (sin . fromIntegral) iv : fvs}
|
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (sin . fromIntegral) vi : vfs}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntAbs :: State -> State
|
instructionVectorIntAbs :: State -> State
|
||||||
instructionVectorIntAbs state@(State {_vectorInt = ivs}) =
|
instructionVectorIntAbs state@(State {_vectorInt = vis}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = map abs iv : ivs'}
|
(vi:vis') -> state {_vectorInt = map abs vi : vis'}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntSquare :: State -> State
|
instructionVectorIntSquare :: State -> State
|
||||||
instructionVectorIntSquare state@(State {_vectorInt = ivs}) =
|
instructionVectorIntSquare state@(State {_vectorInt = vis}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = map (^2) iv : ivs'}
|
(vi:vis') -> state {_vectorInt = map (^2) vi : vis'}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntCube :: State -> State
|
instructionVectorIntCube :: State -> State
|
||||||
instructionVectorIntCube state@(State {_vectorInt = ivs}) =
|
instructionVectorIntCube state@(State {_vectorInt = vis}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = map (^3) iv : ivs'}
|
(vi:vis') -> state {_vectorInt = map (^3) vi : vis'}
|
||||||
[] -> state
|
[] -> state
|
||||||
|
|
||||||
instructionVectorIntSqrt :: State -> State
|
instructionVectorIntSqrt :: State -> State
|
||||||
instructionVectorIntSqrt state@(State {_vectorInt = ivs, _vectorFloat = fvs}) =
|
instructionVectorIntSqrt state@(State {_vectorInt = vis, _vectorFloat = vfs}) =
|
||||||
case ivs of
|
case vis of
|
||||||
(iv:ivs') -> state {_vectorInt = ivs', _vectorFloat = map (sqrt . fromIntegral) iv : fvs}
|
(vi:vis') -> state {_vectorInt = vis', _vectorFloat = map (sqrt . fromIntegral) vi : vfs}
|
||||||
[] -> state
|
[] -> state
|
Loading…
x
Reference in New Issue
Block a user