Copyright | David Johnson (c) 2019-2020 |
---|---|
License | BSD 3 |
Maintainer | David Johnson <djohnson.m@gmail.com> |
Stability | Experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Arithmetic functions over Array
module Main where import qualified ArrayFire as A main :: IO () main = print $ A.scalar @Int 1 `A.add` A.scalar @Int 1 -- 2
Synopsis
- add :: AFType a => Array a -> Array a -> Array a
- addBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- sub :: AFType a => Array a -> Array a -> Array a
- subBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- mul :: AFType a => Array a -> Array a -> Array a
- mulBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- div :: AFType a => Array a -> Array a -> Array a
- divBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- lt :: AFType a => Array a -> Array a -> Array a
- ltBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- gt :: AFType a => Array a -> Array a -> Array a
- gtBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- le :: AFType a => Array a -> Array a -> Array a
- leBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- ge :: AFType a => Array a -> Array a -> Array a
- geBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- eq :: AFType a => Array a -> Array a -> Array a
- eqBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- neq :: AFType a => Array a -> Array a -> Array a
- neqBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- and :: AFType a => Array a -> Array a -> Array a
- andBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- or :: AFType a => Array a -> Array a -> Array a
- orBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- not :: AFType a => Array a -> Array a
- bitAnd :: AFType a => Array a -> Array a -> Array a
- bitAndBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- bitOr :: AFType a => Array a -> Array a -> Array a
- bitOrBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- bitXor :: AFType a => Array a -> Array a -> Array a
- bitXorBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- bitShiftL :: AFType a => Array a -> Array a -> Array a
- bitShiftLBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- bitShiftR :: AFType a => Array a -> Array a -> Array a
- bitShiftRBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- cast :: forall a b. (AFType a, AFType b) => Array a -> Array b
- minOf :: AFType a => Array a -> Array a -> Array a
- minOfBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- maxOf :: AFType a => Array a -> Array a -> Array a
- maxOfBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- clamp :: Array a -> Array a -> Array a -> Array a
- clampBatched :: Array a -> Array a -> Array a -> Bool -> Array a
- rem :: AFType a => Array a -> Array a -> Array a
- remBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- mod :: AFType a => Array a -> Array a -> Array a
- modBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- abs :: AFType a => Array a -> Array a
- arg :: AFType a => Array a -> Array a
- sign :: AFType a => Array a -> Array a
- round :: AFType a => Array a -> Array a
- trunc :: AFType a => Array a -> Array a
- floor :: AFType a => Array a -> Array a
- ceil :: AFType a => Array a -> Array a
- sin :: AFType a => Array a -> Array a
- cos :: AFType a => Array a -> Array a
- tan :: AFType a => Array a -> Array a
- asin :: AFType a => Array a -> Array a
- acos :: AFType a => Array a -> Array a
- atan :: AFType a => Array a -> Array a
- atan2 :: AFType a => Array a -> Array a -> Array a
- atan2Batched :: AFType a => Array a -> Array a -> Bool -> Array a
- cplx2 :: AFType a => Array a -> Array a -> Array a
- cplx2Batched :: AFType a => Array a -> Array a -> Bool -> Array a
- cplx :: AFType a => Array a -> Array a
- real :: AFType a => Array a -> Array a
- imag :: AFType a => Array a -> Array a
- conjg :: AFType a => Array a -> Array a
- sinh :: AFType a => Array a -> Array a
- cosh :: AFType a => Array a -> Array a
- tanh :: AFType a => Array a -> Array a
- asinh :: AFType a => Array a -> Array a
- acosh :: AFType a => Array a -> Array a
- atanh :: AFType a => Array a -> Array a
- root :: AFType a => Array a -> Array a -> Array a
- rootBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- pow :: AFType a => Array a -> Array a -> Array a
- powBatched :: AFType a => Array a -> Array a -> Bool -> Array a
- pow2 :: AFType a => Array a -> Array a
- exp :: AFType a => Array a -> Array a
- sigmoid :: AFType a => Array a -> Array a
- expm1 :: AFType a => Array a -> Array a
- erf :: AFType a => Array a -> Array a
- erfc :: AFType a => Array a -> Array a
- log :: AFType a => Array a -> Array a
- log1p :: AFType a => Array a -> Array a
- log10 :: AFType a => Array a -> Array a
- log2 :: AFType a => Array a -> Array a
- sqrt :: AFType a => Array a -> Array a
- cbrt :: AFType a => Array a -> Array a
- factorial :: AFType a => Array a -> Array a
- tgamma :: AFType a => Array a -> Array a
- lgamma :: AFType a => Array a -> Array a
- isZero :: AFType a => Array a -> Array a
- isInf :: (Real a, AFType a) => Array a -> Array a
- isNaN :: forall a. (AFType a, Real a) => Array a -> Array a
Documentation
Adds two Array
objects
>>>
A.scalar @Int 1 `A.add` A.scalar @Int 1
ArrayFire Array [1 1 1 1] 2
Adds two Array
objects
>>>
(A.scalar @Int 1 `A.addBatched` A.scalar @Int 1) True
ArrayFire Array [1 1 1 1] 2
Subtracts two Array
objects
>>>
A.scalar @Int 1 `A.sub` A.scalar @Int 1
ArrayFire Array [1 1 1 1] 0
Subtracts two Array
objects
>>>
(A.scalar @Int 1 `subBatched` A.scalar @Int 1) True
ArrayFire Array [1 1 1 1] 0
Multiply two Array
objects
>>>
A.scalar @Int 2 `mul` A.scalar @Int 2
ArrayFire Array [1 1 1 1] 4
Multiply two Array
objects
>>>
(A.scalar @Int 2 `mulBatched` A.scalar @Int 2) True
ArrayFire Array [1 1 1 1] 4
Divide two Array
objects
>>>
A.scalar @Int 6 `A.div` A.scalar @Int 3
ArrayFire Array [1 1 1 1] 2
Divide two Array
objects
>>>
(A.scalar @Int 6 `A.divBatched` A.scalar @Int 3) True
ArrayFire Array [1 1 1 1] 2
Not the values of an Array
>>>
A.not (A.scalar @Int 1)
ArrayFire Array [1 1 1 1] 0
Cast one Array
into another
>>>
A.cast (A.scalar @Int 1) :: Array Double
ArrayFire Array [1 1 1 1] 1.0000
Find the minimum of two Array
s
>>>
A.minOf (A.scalar @Int 1) (A.scalar @Int 0)
ArrayFire Array [1 1 1 1] 0
:: AFType a | |
=> Array a | First input |
-> Array a | Second input |
-> Bool | Use batch |
-> Array a | Result of minimum of |
Find the minimum of two Array
s
>>>
A.minOfBatched (A.scalar @Int 1) (A.scalar @Int 0) False
ArrayFire Array [1 1 1 1] 0
Find the maximum of two Array
s
>>>
A.maxOf (A.scalar @Int 1) (A.scalar @Int 0)
ArrayFire Array [1 1 1 1] 1
:: AFType a | |
=> Array a | First input |
-> Array a | Second input |
-> Bool | Use batch |
-> Array a | Result of maximum of |
Find the maximum of two Array
s
>>>
A.maxOfBatched (A.scalar @Int 1) (A.scalar @Int 0) False
ArrayFire Array [1 1 1 1] 1
Should take the clamp
>>>
clamp (A.scalar @Int 2) (A.scalar @Int 1) (A.scalar @Int 3)
ArrayFire Array [1 1 1 1] 2
:: Array a | First input |
-> Array a | Second input |
-> Array a | Third input |
-> Bool | Use batch |
-> Array a | Result of clamp |
Should take the clamp
>>>
(clampBatched (A.scalar @Int 2) (A.scalar @Int 1) (A.scalar @Int 3)) True
ArrayFire Array [1 1 1 1] 2
Find the remainder of two Array
s
>>>
A.rem (A.vector @Int 10 [1..]) (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0 0 0 0 0 0 0 0 0 0
:: AFType a | |
=> Array a | First input |
-> Array a | Second input |
-> Bool | Use batch |
-> Array a | Result of remainder |
Find the remainder of two Array
s
>>>
A.remBatched (A.vector @Int 10 [1..]) (vector @Int 10 [1..]) True
Take the absolute value of an array
>>>
A.abs (A.scalar @Int (-1))
ArrayFire Array [1 1 1 1] 1.0000
Find the arg of an array
>>>
A.arg (vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0 0 0 0 0 0 0 0 0 0
Find the sign of two Array
s
>>>
A.sign (vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Round the values in an Array
>>>
A.round (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000
Truncate the values of an Array
>>>
A.trunc (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000
Take the floor of all values in an Array
>>>
A.floor (A.vector @Int 10 [10,9..])
ArrayFire Array [10 1 1 1] 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000
Take the ceil of all values in an Array
>>>
A.ceil (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000
Take the sin of all values in an Array
>>>
A.sin (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794 0.6570 0.9894 0.4121 -0.5440
Take the cos of all values in an Array
>>>
A.cos (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.5403 -0.4161 -0.9900 -0.6536 0.2837 0.9602 0.7539 -0.1455 -0.9111 -0.8391
Take the tan of all values in an Array
>>>
A.tan (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 1.5574 -2.1850 -0.1425 1.1578 -3.3805 -0.2910 0.8714 -6.7997 -0.4523 0.6484
Take the asin of all values in an Array
>>>
A.asin (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 1.5708 nan nan nan nan nan nan nan nan nan
Take the acos of all values in an Array
>>>
A.acos (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.0000 nan nan nan nan nan nan nan nan nan
Take the atan of all values in an Array
>>>
A.atan (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.7854 1.1071 1.2490 1.3258 1.3734 1.4056 1.4289 1.4464 1.4601 1.4711
Take the atan2 of all values in an Array
>>>
A.atan2 (A.vector @Int 10 [1..]) (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.7854 0.7854 0.7854 0.7854 0.7854 0.7854 0.7854 0.7854 0.7854 0.7854
Take the atan2 of all values in an Array
>>>
A.atan2Batched (A.vector @Int 10 [1..]) (A.vector @Int 10 [1..]) True
ArrayFire Array [10 1 1 1] 0.7854 0.7854 0.7854 0.7854 0.7854 0.7854 0.7854 0.7854 0.7854 0.7854
Take the cplx2 of all values in an Array
>>>
A.cplx2 (A.vector @Int 10 [1..]) (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] (1.0000,1.0000) (2.0000,2.0000) (3.0000,3.0000) (4.0000,4.0000) (5.0000,5.0000) (6.0000,6.0000) (7.0000,7.0000) (8.0000,8.0000) (9.0000,9.0000) (10.0000,10.0000)
Take the cplx2Batched of all values in an Array
>>>
A.cplx2Batched (A..vector @Int 10 [1..]) (A.vector @Int 10 [1..]) True
ArrayFire Array [10 1 1 1] (1.0000,1.0000) (2.0000,2.0000) (3.0000,3.0000) (4.0000,4.0000) (5.0000,5.0000) (6.0000,6.0000) (7.0000,7.0000) (8.0000,8.0000) (9.0000,9.0000) (10.0000,10.0000)
Execute cplx
>>>
A.cplx (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] (1.0000,0.0000) (2.0000,0.0000) (3.0000,0.0000) (4.0000,0.0000) (5.0000,0.0000) (6.0000,0.0000) (7.0000,0.0000) (8.0000,0.0000) (9.0000,0.0000) (10.0000,0.0000)
Execute real
>>>
A.real (A.vector @Double 10 [1..])
ArrayFire Array [10 1 1 1] 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000
Execute imag
>>>
A.imag (A.vector @Double 10 [1..])
ArrayFire Array [10 1 1 1] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Execute conjg
>>>
A.conjg (A.vector @Double 10 [1..])
ArrayFire Array [10 1 1 1] 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000
Execute sinh
>>>
A.sinh (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 1.1752 3.6269 10.0179 27.2899 74.2032 201.7132 548.3161 1490.4788 4051.5419 11013.2329
Execute cosh
>>>
A.cosh (A.vector @Double 10 [1..])
ArrayFire Array [10 1 1 1] 1.5431 3.7622 10.0677 27.3082 74.2099 201.7156 548.3170 1490.4792 4051.5420 11013.2329
Execute tanh
>>>
A.tanh (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.7616 0.9640 0.9951 0.9993 0.9999 1.0000 1.0000 1.0000 1.0000 1.0000
Execute asinh
>>>
A.asinh (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.8814 1.4436 1.8184 2.0947 2.3124 2.4918 2.6441 2.7765 2.8934 2.9982
Execute acosh
>>>
A.acosh (A.vector @Double 10 [1..])
ArrayFire Array [10 1 1 1] 0.0000 1.3170 1.7627 2.0634 2.2924 2.4779 2.6339 2.7687 2.8873 2.9932
Execute atanh
>>>
A.atanh (A.vector @Double 10 [1..])
ArrayFire Array [10 1 1 1] inf nan nan nan nan nan nan nan nan nan
Execute root
>>>
A.root (A.vector @Double 10 [1..]) (A.vector @Double 10 [1..])
ArrayFire Array [10 1 1 1] 1.0000 1.4142 1.4422 1.4142 1.3797 1.3480 1.3205 1.2968 1.2765 1.2589
Execute rootBatched
>>>
A.rootBatched (vector @Double 10 [1..]) (vector @Double 10 [1..]) True
ArrayFire Array [10 1 1 1] 1.0000 1.4142 1.4422 1.4142 1.3797 1.3480 1.3205 1.2968 1.2765 1.2589
Execute pow
>>>
A.pow (A.vector @Int 10 [1..]) 2
ArrayFire Array [10 1 1 1] 1 4 9 16 25 36 49 64 81 100
:: AFType a | |
=> Array a | First input |
-> Array a | Second input |
-> Bool | Use batch |
-> Array a | Result of powBatched |
Execute powBatched
>>>
A.powBatched (A.vector @Int 10 [1..]) (A.constant @Int [1] 2) True
ArrayFire Array [10 1 1 1] 1 4 9 16 25 36 49 64 81 100
Raise an Array
to the second power
>>>
A.pow2 (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 2 4 8 16 32 64 128 256 512 1024
Execute exp on Array
>>>
A.exp (A.vector @Double 10 [1..])
ArrayFire Array [10 1 1 1] 2.7183 7.3891 20.0855 54.5982 148.4132 403.4288 1096.6332 2980.9580 8103.0839 22026.4658
Execute sigmoid on Array
>>>
A.sigmoid (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.7311 0.8808 0.9526 0.9820 0.9933 0.9975 0.9991 0.9997 0.9999 1.0000
Execute expm1
>>>
A.expm1 (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 1.7183 6.3891 19.0855 53.5981 147.4132 402.4288 1095.6332 2979.9580 8102.0840 22025.4648
Execute erf
>>>
A.erf (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.8427 0.9953 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
Execute erfc
>>>
A.erfc (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.1573 0.0047 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Execute log
>>>
A.log (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.0000 0.6931 1.0986 1.3863 1.6094 1.7918 1.9459 2.0794 2.1972 2.3026
Execute log1p
>>>
A.log1p (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.6931 1.0986 1.3863 1.6094 1.7918 1.9459 2.0794 2.1972 2.3026 2.3979
Execute log10
>>>
A.log10 (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.0000 0.3010 0.4771 0.6021 0.6990 0.7782 0.8451 0.9031 0.9542 1.0000
Execute log2
>>>
A.log2 (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.0000 1.0000 1.5850 2.0000 2.3219 2.5850 2.8074 3.0000 3.1699 3.3219
Execute sqrt
>>>
A.sqrt (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 1.0000 1.4142 1.7321 2.0000 2.2361 2.4495 2.6458 2.8284 3.0000 3.1623
Execute cbrt
>>>
A.cbrt (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 1.0000 1.2599 1.4422 1.5874 1.7100 1.8171 1.9129 2.0000 2.0801 2.1544
Execute factorial1
>>>
A.factorial1 (A.vector @Int 10 [1..])
Execute tgamma
>>>
'tgamma' (vector @Int 10 [1..])
Execute lgamma
>>>
A.lgamma (A.vector @Int 10 [1..])
ArrayFire Array [10 1 1 1] 0.0000 0.0000 0.6931 1.7918 3.1781 4.7875 6.5793 8.5252 10.6046 12.8018
Execute isZero
>>>
A.isZero (A.vector @CBool 10 (repeat 0))
ArrayFire Array [10 1 1 1] 1 1 1 1 1 1 1 1 1 1