-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathiir.cpp
More file actions
60 lines (50 loc) · 1.56 KB
/
iir.cpp
File metadata and controls
60 lines (50 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*******************************************************
* 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 <Array.hpp>
#include <arith.hpp>
#include <convolve.hpp>
#include <err_cuda.hpp>
#include <iir.hpp>
#include <kernel/iir.hpp>
#include <math.hpp>
#include <af/dim4.hpp>
using af::dim4;
namespace arrayfire {
namespace cuda {
template<typename T>
Array<T> iir(const Array<T> &b, const Array<T> &a, const Array<T> &x) {
AF_BATCH_KIND type = x.ndims() == 1 ? AF_BATCH_NONE : AF_BATCH_SAME;
if (x.ndims() != b.ndims()) {
type = (x.ndims() < b.ndims()) ? AF_BATCH_RHS : AF_BATCH_LHS;
}
// Extract the first N elements
Array<T> c = convolve<T, T>(x, b, type, 1, true);
dim4 cdims = c.dims();
cdims[0] = x.dims()[0];
c.resetDims(cdims);
int num_a = a.dims()[0];
if (num_a == 1) { return c; }
dim4 ydims = c.dims();
Array<T> y = createEmptyArray<T>(ydims);
if (a.ndims() > 1) {
kernel::iir<T, true>(y, c, a);
} else {
kernel::iir<T, false>(y, c, a);
}
return y;
}
#define INSTANTIATE(T) \
template Array<T> iir(const Array<T> &b, const Array<T> &a, \
const Array<T> &x);
INSTANTIATE(float)
INSTANTIATE(double)
INSTANTIATE(cfloat)
INSTANTIATE(cdouble)
} // namespace cuda
} // namespace arrayfire