MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / cov

Function cov

src/api/c/covariance.cpp:41–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40template<typename T, typename cType>
41static af_array cov(const af_array& X, const af_array& Y,
42 const af_var_bias bias) {
43 using weightType = typename baseOutType<cType>::type;
44 const Array<T> _x = getArray<T>(X);
45 const Array<T> _y = getArray<T>(Y);
46 Array<cType> xArr = cast<cType>(_x);
47 Array<cType> yArr = cast<cType>(_y);
48
49 dim4 xDims = xArr.dims();
50 dim_t N = (bias == AF_VARIANCE_SAMPLE ? xDims[0] - 1 : xDims[0]);
51
52 Array<cType> xmArr =
53 createValueArray<cType>(xDims, mean<T, weightType, cType>(_x));
54 Array<cType> ymArr =
55 createValueArray<cType>(xDims, mean<T, weightType, cType>(_y));
56 Array<cType> nArr = createValueArray<cType>(xDims, scalar<cType>(N));
57
58 Array<cType> diffX = arithOp<cType, af_sub_t>(xArr, xmArr, xDims);
59 Array<cType> diffY = arithOp<cType, af_sub_t>(yArr, ymArr, xDims);
60 Array<cType> mulXY = arithOp<cType, af_mul_t>(diffX, diffY, xDims);
61 Array<cType> redArr = reduce<af_add_t, cType, cType>(mulXY, 0);
62 xDims[0] = 1;
63 Array<cType> result = arithOp<cType, af_div_t>(redArr, nArr, xDims);
64
65 return getHandle<cType>(result);
66}
67
68af_err af_cov(af_array* out, const af_array X, const af_array Y,
69 const bool isbiased) {

Callers 2

covTestFunction · 0.50
TESTFunction · 0.50

Calls 1

dimsMethod · 0.45

Tested by

no test coverage detected