/******************************************************* * Copyright (c) 2014, ArrayFire * All rights reserved. * * This file is distributed under 3-clause BSD license. * The complete license agreement can be obtained at: * http://arrayfire.com/licenses/BSD-3-Clause ********************************************************/ #include #include #include #include #include #include #include #include #include #include #include using af::dim4; using namespace detail; template static inline uint rank(const af_array in, double tol) { typedef typename af::dtype_traits::base_type BT; Array In = getArray(in); Array R = createEmptyArray(dim4()); // Scoping to get rid of q, r and t as they are not necessary { Array q = createEmptyArray(dim4()); Array r = createEmptyArray(dim4()); Array t = createEmptyArray(dim4()); qr(q, r, t, In); R = abs(r); } Array val = createValueArray(R.dims(), scalar(tol)); Array gt = logicOp(R, val, val.dims()); Array at = reduce(gt, 1); return reduce_all(at); } af_err af_rank(uint *out, const af_array in, const double tol) { try { ArrayInfo i_info = getInfo(in); if (i_info.ndims() > 2) { AF_ERROR("solve can not be used in batch mode", AF_ERR_BATCH); } af_dtype type = i_info.getType(); ARG_ASSERT(1, i_info.isFloating()); // Only floating and complex types uint output; switch(type) { case f32: output = rank(in, tol); break; case f64: output = rank(in, tol); break; case c32: output = rank(in, tol); break; case c64: output = rank(in, tol); break; default: TYPE_ERROR(1, type); } std::swap(*out, output); } CATCHALL; return AF_SUCCESS; }