Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/.clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,*,-fuchsia-*,-cppcoreguidelines-*,-misc-misplaced-const,-hicpp-no-array-decay,-readability-implicit-bool-conversion,bugprone-*,performance-*,modernize-*,-llvm-header-guard,-hicpp-use-auto,-modernize-use-trailing-return-type,-hicpp-uppercase-literal-suffix,-hicpp-use-nullptr,-modernize-use-nullptr,-google-runtime-int,-llvm-include-order,-google-runtime-references,-readability-magic-numbers,-readability-isolate-declaration,-hicpp-vararg,-google-readability-todo,-bugprone-macro-parentheses,-misc-unused-using-decls,-readability-else-after-return,-hicpp-avoid-c-arrays,-modernize-avoid-c-arrays'
Checks: 'clang-diagnostic-*,clang-analyzer-*,*,-fuchsia-*,-cppcoreguidelines-*,-misc-misplaced-const,-hicpp-no-array-decay,-readability-implicit-bool-conversion,bugprone-*,performance-*,modernize-*,-llvm-header-guard,-hicpp-use-auto,-modernize-use-trailing-return-type,-hicpp-uppercase-literal-suffix,-hicpp-use-nullptr,-modernize-use-nullptr,-google-runtime-int,-llvm-include-order,-google-runtime-references,-readability-magic-numbers,-readability-isolate-declaration,-hicpp-vararg,-google-readability-todo,-bugprone-macro-parentheses,-misc-unused-using-decls,-readability-else-after-return,-hicpp-avoid-c-arrays,-modernize-avoid-c-arrays,-hicpp-braces-around-statements,-hicpp-noexcept-move'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: true
Expand Down
1 change: 0 additions & 1 deletion src/api/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ target_sources(c_api_interface
${CMAKE_CURRENT_SOURCE_DIR}/morph.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nearest_neighbour.cpp
${CMAKE_CURRENT_SOURCE_DIR}/norm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ops.hpp
${CMAKE_CURRENT_SOURCE_DIR}/optypes.hpp
${CMAKE_CURRENT_SOURCE_DIR}/orb.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pinverse.cpp
Expand Down
6 changes: 6 additions & 0 deletions src/api/c/anisotropic_diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
#include <type_traits>

using af::dim4;
using detail::arithOp;
using detail::Array;
using detail::cast;
using detail::createEmptyArray;
using detail::gradient;
using detail::reduce_all;

template<typename T>
af_array diffusion(const Array<float>& in, const float dt, const float K,
Expand Down
2 changes: 1 addition & 1 deletion src/api/c/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void assign(Array<Tout>& out, const vector<af_seq> seqs,

isVec &= in.isVector() || in.isScalar();

for (dim_t i = static_cast<dim_t>(ndims); i < in.ndims(); i++) {
for (auto i = static_cast<dim_t>(ndims); i < in.ndims(); i++) {
oDims[i] = 1;
}

Expand Down
83 changes: 51 additions & 32 deletions src/api/c/canny.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,70 @@
#include <vector>

using af::dim4;
using detail::arithOp;
using detail::Array;
using detail::cast;
using detail::convolve2;
using detail::createEmptyArray;
using detail::createHostDataArray;
using detail::createSubArray;
using detail::createValueArray;
using detail::histogram;
using detail::iota;
using detail::ireduce;
using detail::logicOp;
using detail::reduce;
using detail::reduce_all;
using detail::sobelDerivatives;
using detail::uchar;
using detail::uint;
using detail::unaryOp;
using detail::ushort;
using std::make_pair;
using std::pair;
using std::vector;

Array<float> gradientMagnitude(const Array<float>& gx, const Array<float>& gy,
const bool& isf) {
using detail::abs;
if (isf) {
Array<float> gx2 = detail::abs<float, float>(gx);
Array<float> gy2 = detail::abs<float, float>(gy);
return detail::arithOp<float, af_add_t>(gx2, gy2, gx2.dims());
Array<float> gx2 = abs<float, float>(gx);
Array<float> gy2 = abs<float, float>(gy);
return arithOp<float, af_add_t>(gx2, gy2, gx2.dims());
} else {
Array<float> gx2 = detail::arithOp<float, af_mul_t>(gx, gx, gx.dims());
Array<float> gy2 = detail::arithOp<float, af_mul_t>(gy, gy, gy.dims());
Array<float> sg =
detail::arithOp<float, af_add_t>(gx2, gy2, gx2.dims());
return detail::unaryOp<float, af_sqrt_t>(sg);
Array<float> gx2 = arithOp<float, af_mul_t>(gx, gx, gx.dims());
Array<float> gy2 = arithOp<float, af_mul_t>(gy, gy, gy.dims());
Array<float> sg = arithOp<float, af_add_t>(gx2, gy2, gx2.dims());
return unaryOp<float, af_sqrt_t>(sg);
}
}

Array<float> otsuThreshold(const Array<float>& supEdges,
const unsigned NUM_BINS, const float maxVal) {
Array<uint> hist =
detail::histogram<float, uint, false>(supEdges, NUM_BINS, 0, maxVal);
histogram<float, uint, false>(supEdges, NUM_BINS, 0, maxVal);

const af::dim4& hDims = hist.dims();
const dim4& hDims = hist.dims();

// reduce along histogram dimension i.e. 0th dimension
auto totals = reduce<af_add_t, uint, float>(hist, 0);

// tile histogram total along 0th dimension
auto ttotals = tile(totals, af::dim4(hDims[0]));
auto ttotals = tile(totals, dim4(hDims[0]));

// pixel frequency probabilities
auto probability =
arithOp<float, af_div_t>(cast<float, uint>(hist), ttotals, hDims);

std::vector<af_seq> seqBegin(4, af_span);
std::vector<af_seq> seqRest(4, af_span);
vector<af_seq> seqBegin(4, af_span);
vector<af_seq> seqRest(4, af_span);

seqBegin[0] = af_make_seq(0, static_cast<double>(hDims[0] - 1), 1);
seqRest[0] = af_make_seq(0, static_cast<double>(hDims[0] - 1), 1);

const af::dim4& iDims = supEdges.dims();
const dim4& iDims = supEdges.dims();

Array<float> sigmas = detail::createEmptyArray<float>(hDims);
Array<float> sigmas = createEmptyArray<float>(hDims);

for (unsigned b = 0; b < (NUM_BINS - 1); ++b) {
seqBegin[0].end = static_cast<double>(b);
Expand Down Expand Up @@ -109,7 +130,7 @@ Array<float> otsuThreshold(const Array<float>& supEdges,
auto op2 = arithOp<float, af_mul_t>(qL, qH, tdims);
auto sigma = arithOp<float, af_mul_t>(sqrd, op2, tdims);

std::vector<af_seq> sliceIndex(4, af_span);
vector<af_seq> sliceIndex(4, af_span);
sliceIndex[0] = {double(b), double(b), 1};

auto binRes = createSubArray<float>(sigmas, sliceIndex, false);
Expand All @@ -135,10 +156,11 @@ Array<float> normalize(const Array<float>& supEdges, const float minVal,
return arithOp<float, af_div_t>(diff, denom, supEdges.dims());
}

std::pair<Array<char>, Array<char>> computeCandidates(
const Array<float>& supEdges, const float t1, const af_canny_threshold ct,
const float t2) {
float maxVal = detail::reduce_all<af_max_t, float, float>(supEdges);
pair<Array<char>, Array<char>> computeCandidates(const Array<float>& supEdges,
const float t1,
const af_canny_threshold ct,
const float t2) {
float maxVal = reduce_all<af_max_t, float, float>(supEdges);
auto NUM_BINS = static_cast<unsigned>(maxVal);

auto lowRatio = createValueArray<float>(supEdges.dims(), t1);
Expand All @@ -155,10 +177,10 @@ std::pair<Array<char>, Array<char>> computeCandidates(
logicOp<char, af_and_t>(weak1, weak2, weak1.dims());
Array<char> strong =
logicOp<float, af_ge_t>(supEdges, T2, supEdges.dims());
return std::make_pair(strong, weak);
return make_pair(strong, weak);
};
default: {
float minVal = detail::reduce_all<af_min_t, float, float>(supEdges);
float minVal = reduce_all<af_min_t, float, float>(supEdges);
auto normG = normalize(supEdges, minVal, maxVal);
auto T2 = createValueArray<float>(supEdges.dims(), t2);
auto T1 = createValueArray<float>(supEdges.dims(), t1);
Expand All @@ -181,27 +203,24 @@ af_array cannyHelper(const Array<T>& in, const float t1,
const unsigned sw, const bool isf) {
static const vector<float> v{-0.11021f, -0.23691f, -0.30576f, -0.23691f,
-0.11021f};
Array<float> cFilter =
detail::createHostDataArray<float>(dim4(5, 1), v.data());
Array<float> rFilter =
detail::createHostDataArray<float>(dim4(1, 5), v.data());
Array<float> cFilter = createHostDataArray<float>(dim4(5, 1), v.data());
Array<float> rFilter = createHostDataArray<float>(dim4(1, 5), v.data());

// Run separable convolution to smooth the input image
Array<float> smt = detail::convolve2<float, float, false>(
cast<float, T>(in), cFilter, rFilter);
Array<float> smt =
convolve2<float, float, false>(cast<float, T>(in), cFilter, rFilter);

auto g = detail::sobelDerivatives<float, float>(smt, sw);
auto g = sobelDerivatives<float, float>(smt, sw);
Array<float> gx = g.first;
Array<float> gy = g.second;

Array<float> gmag = gradientMagnitude(gx, gy, isf);

Array<float> supEdges = detail::nonMaximumSuppression(gmag, gx, gy);
Array<float> supEdges = nonMaximumSuppression(gmag, gx, gy);

auto swpair = computeCandidates(supEdges, t1, ct, t2);

return getHandle(
detail::edgeTrackingByHysteresis(swpair.first, swpair.second));
return getHandle(edgeTrackingByHysteresis(swpair.first, swpair.second));
}

af_err af_canny(af_array* out, const af_array in, const af_canny_threshold ct,
Expand Down
22 changes: 15 additions & 7 deletions src/api/c/confidence_connected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@
#include <type_traits>

using af::dim4;
using std::array;
using common::createSpanIndex;
using detail::arithOp;
using detail::Array;
using detail::cast;
using detail::createValueArray;
using detail::reduce_all;
using detail::uchar;
using detail::uint;
using detail::ushort;
using std::conditional;
using std::is_same;
using std::sqrt;
Expand All @@ -34,12 +42,12 @@ using std::swap;
template<typename T>
Array<T> pointList(const Array<T>& in, const Array<uint>& x,
const Array<uint>& y) {
af_array xcoords = getHandle<uint>(x);
af_array ycoords = getHandle<uint>(y);
array<af_index_t, AF_MAX_DIMS> idxrs = {{{{xcoords}, false, false},
{{ycoords}, false, false},
common::createSpanIndex(),
common::createSpanIndex()}};
af_array xcoords = getHandle<uint>(x);
af_array ycoords = getHandle<uint>(y);
std::array<af_index_t, AF_MAX_DIMS> idxrs = {{{{xcoords}, false, false},
{{ycoords}, false, false},
createSpanIndex(),
createSpanIndex()}};

Array<T> retVal = detail::index(in, idxrs.data());

Expand Down
22 changes: 14 additions & 8 deletions src/api/c/corrcoef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@

#include <cmath>

using af::dim4;
using detail::arithOp;
using detail::Array;
using detail::cast;
using detail::intl;
using detail::reduce_all;
using detail::uchar;
using detail::uint;
using detail::uintl;
using detail::ushort;

template<typename Ti, typename To>
static To corrcoef(const af_array& X, const af_array& Y) {
Expand All @@ -35,16 +41,16 @@ static To corrcoef(const af_array& X, const af_array& Y) {
const dim4& dims = xIn.dims();
dim_t n = xIn.elements();

To xSum = detail::reduce_all<af_add_t, To, To>(xIn);
To ySum = detail::reduce_all<af_add_t, To, To>(yIn);
To xSum = reduce_all<af_add_t, To, To>(xIn);
To ySum = reduce_all<af_add_t, To, To>(yIn);

Array<To> xSq = detail::arithOp<To, af_mul_t>(xIn, xIn, dims);
Array<To> ySq = detail::arithOp<To, af_mul_t>(yIn, yIn, dims);
Array<To> xy = detail::arithOp<To, af_mul_t>(xIn, yIn, dims);
Array<To> xSq = arithOp<To, af_mul_t>(xIn, xIn, dims);
Array<To> ySq = arithOp<To, af_mul_t>(yIn, yIn, dims);
Array<To> xy = arithOp<To, af_mul_t>(xIn, yIn, dims);

To xSqSum = detail::reduce_all<af_add_t, To, To>(xSq);
To ySqSum = detail::reduce_all<af_add_t, To, To>(ySq);
To xySum = detail::reduce_all<af_add_t, To, To>(xy);
To xSqSum = reduce_all<af_add_t, To, To>(xSq);
To ySqSum = reduce_all<af_add_t, To, To>(ySq);
To xySum = reduce_all<af_add_t, To, To>(xy);

To result =
(n * xySum - xSum * ySum) / (std::sqrt(n * xSqSum - xSum * xSum) *
Expand Down
21 changes: 16 additions & 5 deletions src/api/c/covariance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@
#include "stats.h"

using af::dim4;
using detail::arithOp;
using detail::Array;
using detail::cast;
using detail::createValueArray;
using detail::intl;
using detail::mean;
using detail::reduce;
using detail::scalar;
using detail::uchar;
using detail::uint;
using detail::uintl;
using detail::ushort;

template<typename T, typename cType>
static af_array cov(const af_array& X, const af_array& Y, bool isbiased) {
Expand All @@ -42,12 +53,12 @@ static af_array cov(const af_array& X, const af_array& Y, bool isbiased) {
createValueArray<cType>(xDims, mean<T, weightType, cType>(_y));
Array<cType> nArr = createValueArray<cType>(xDims, scalar<cType>(N));

Array<cType> diffX = detail::arithOp<cType, af_sub_t>(xArr, xmArr, xDims);
Array<cType> diffY = detail::arithOp<cType, af_sub_t>(yArr, ymArr, xDims);
Array<cType> mulXY = detail::arithOp<cType, af_mul_t>(diffX, diffY, xDims);
Array<cType> redArr = detail::reduce<af_add_t, cType, cType>(mulXY, 0);
Array<cType> diffX = arithOp<cType, af_sub_t>(xArr, xmArr, xDims);
Array<cType> diffY = arithOp<cType, af_sub_t>(yArr, ymArr, xDims);
Array<cType> mulXY = arithOp<cType, af_mul_t>(diffX, diffY, xDims);
Array<cType> redArr = reduce<af_add_t, cType, cType>(mulXY, 0);
xDims[0] = 1;
Array<cType> result = detail::arithOp<cType, af_div_t>(redArr, nArr, xDims);
Array<cType> result = arithOp<cType, af_div_t>(redArr, nArr, xDims);

return getHandle<cType>(result);
}
Expand Down
17 changes: 15 additions & 2 deletions src/api/c/deconvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,21 @@
#include <vector>

using af::dim4;
using detail::arithOp;
using detail::Array;
using detail::cast;
using detail::cdouble;
using detail::cfloat;
using detail::createSubArray;
using detail::createValueArray;
using detail::logicOp;
using detail::padArrayBorders;
using detail::scalar;
using detail::select_scalar;
using detail::shift;
using detail::uchar;
using detail::uint;
using detail::ushort;
using std::array;
using std::vector;

Expand All @@ -54,7 +67,7 @@ const dim_t GREATEST_PRIME_FACTOR = 7;

template<typename T, typename CT>
Array<T> complexNorm(const Array<CT>& input) {
auto mag = abs<T, CT>(input);
auto mag = detail::abs<T, CT>(input);
auto TWOS = createValueArray(input.dims(), scalar<T>(2));
return arithOp<T, af_pow_t>(mag, TWOS, input.dims());
}
Expand Down Expand Up @@ -276,7 +289,7 @@ af_array invDeconv(const af_array in, const af_array ker, const float gamma,
auto Pc = conj(P);
auto numer = arithOp<CT, af_mul_t>(I, Pc, I.dims());
auto denom = denominator(I, P, gamma, algo);
auto absVal = abs<T, CT>(denom);
auto absVal = detail::abs<T, CT>(denom);
auto THRESH = createValueArray(I.dims(), scalar<T>(gamma));
auto cond = logicOp<T, af_ge_t>(absVal, THRESH, absVal.dims());
auto val = arithOp<CT, af_div_t>(numer, denom, numer.dims());
Expand Down
3 changes: 3 additions & 0 deletions src/api/c/det.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ using detail::Array;
using detail::cdouble;
using detail::cfloat;
using detail::createEmptyArray;
using detail::imag;
using detail::real;
using detail::scalar;

template<typename T>
T det(const af_array a) {
using namespace detail;
const Array<T> A = getArray<T>(a);

const int num = A.dims()[0];
Expand Down
4 changes: 2 additions & 2 deletions src/api/c/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ af_err af_get_device_count(int* nDevices) {

af_err af_get_device(int* device) {
try {
*device = getActiveDeviceId();
*device = static_cast<int>(getActiveDeviceId());
}
CATCHALL;
return AF_SUCCESS;
Expand Down Expand Up @@ -202,7 +202,7 @@ af_err af_set_device(const int device) {

af_err af_sync(const int device) {
try {
int dev = device == -1 ? getActiveDeviceId() : device;
int dev = device == -1 ? static_cast<int>(getActiveDeviceId()) : device;
detail::sync(dev);
}
CATCHALL;
Expand Down
1 change: 1 addition & 0 deletions src/api/c/exampleFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
// where your new function declaration
// is written

// NOLINTNEXTLINE(google-build-using-namespace)
using namespace detail; // detail is an alias to appropriate backend
// defined in backend.hpp. You don't need to
// change this
Expand Down
Loading