Skip to content

Commit 7990c2c

Browse files
committed
Making the expand parameter an enum for convolutions
1 parent de9f3a1 commit 7990c2c

File tree

8 files changed

+101
-86
lines changed

8 files changed

+101
-86
lines changed

include/af/defines.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ typedef enum {
121121
AF_CONNECTIVITY_8 = 8
122122
} af_connectivity;
123123

124+
typedef enum {
125+
AF_CONV_DEFAULT,
126+
AF_CONV_EXPAND,
127+
} af_conv_mode;
128+
129+
typedef enum {
130+
AF_CONV_AUTO,
131+
AF_CONV_SPATIAL,
132+
AF_CONV_FREQ,
133+
} af_conv_domain;
134+
124135
typedef enum {
125136
AF_SAD = 0,
126137
AF_ZSAD, // 1
@@ -180,6 +191,7 @@ namespace af
180191
typedef af_match_type matchType;
181192
typedef af_cspace_t CSpace;
182193
typedef af_someenum_t SomeEnum; // Purpose of Addition: How to add Function example
194+
typedef af_conv_mode convMode;
183195

184196
const double NaN = std::numeric_limits<double>::quiet_NaN();
185197
const double Inf = std::numeric_limits<double>::infinity();

include/af/signal.h

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,12 @@ AFAPI array idft(const array& in);
308308
309309
\param[in] signal is the input signal
310310
\param[in] filter is the signal that shall be flipped for the convolution operation
311-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
311+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
312312
\return the convolved array
313313
314314
\ingroup signal_func_convolve
315315
*/
316-
AFAPI array convolve(const array& signal, const array& filter, bool expand=false);
316+
AFAPI array convolve(const array& signal, const array& filter, const convMode mode=AF_CONV_DEFAULT);
317317

318318
/**
319319
C++ Interface for separable convolution on two dimensional data
@@ -323,15 +323,15 @@ AFAPI array convolve(const array& signal, const array& filter, bool expand=false
323323
\param[in] signal is the input signal
324324
\param[in] col_filter is the signal that shall be along coloumns
325325
\param[in] row_filter is the signal that shall be along rows
326-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
326+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
327327
\return the convolved array
328328
329329
\note Separable convolution only supports two(ONE-to-ONE and MANY-to-ONE) batch modes from the ones described
330330
in the detailed description section.
331331
332332
\ingroup signal_func_convolve
333333
*/
334-
AFAPI array convolve(const array& col_filter, const array& row_filter, const array& signal, bool expand=false);
334+
AFAPI array convolve(const array& col_filter, const array& row_filter, const array& signal, const convMode mode=AF_CONV_DEFAULT);
335335

336336
/**
337337
C++ Interface for convolution on one dimensional data
@@ -340,12 +340,12 @@ AFAPI array convolve(const array& col_filter, const array& row_filter, const arr
340340
341341
\param[in] signal is the input signal
342342
\param[in] filter is the signal that shall be flipped for the convolution operation
343-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
343+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
344344
\return the convolved array
345345
346346
\ingroup signal_func_convolve1
347347
*/
348-
AFAPI array convolve1(const array& signal, const array& filter, bool expand=false);
348+
AFAPI array convolve1(const array& signal, const array& filter, const convMode mode=AF_CONV_DEFAULT);
349349

350350
/**
351351
C++ Interface for convolution on two dimensional data
@@ -354,12 +354,12 @@ AFAPI array convolve1(const array& signal, const array& filter, bool expand=fals
354354
355355
\param[in] signal is the input signal
356356
\param[in] filter is the signal that shall be flipped for the convolution operation
357-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
357+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
358358
\return the convolved array
359359
360360
\ingroup signal_func_convolve2
361361
*/
362-
AFAPI array convolve2(const array& signal, const array& filter, bool expand=false);
362+
AFAPI array convolve2(const array& signal, const array& filter, const convMode mode=AF_CONV_DEFAULT);
363363

364364
/**
365365
C++ Interface for convolution on three dimensional data
@@ -368,12 +368,12 @@ AFAPI array convolve2(const array& signal, const array& filter, bool expand=fals
368368
369369
\param[in] signal is the input signal
370370
\param[in] filter is the signal that shall be flipped for the convolution operation
371-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
371+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
372372
\return the convolved array
373373
374374
\ingroup signal_func_convolve3
375375
*/
376-
AFAPI array convolve3(const array& signal, const array& filter, bool expand=false);
376+
AFAPI array convolve3(const array& signal, const array& filter, const convMode mode=AF_CONV_DEFAULT);
377377

378378
/**
379379
C++ Interface for FFT-based convolution any(one through three) dimensional data
@@ -384,43 +384,43 @@ AFAPI array convolve3(const array& signal, const array& filter, bool expand=fals
384384
385385
\ingroup signal_func_fftconvolve
386386
*/
387-
AFAPI array fftconvolve(const array& signal, const array& filter, const bool expand=false);
387+
AFAPI array fftconvolve(const array& signal, const array& filter, const convMode mode=AF_CONV_DEFAULT);
388388

389389
/**
390390
C++ Interface for convolution on one dimensional data
391391
392392
\param[in] signal is the input signal
393393
\param[in] filter is the signal that shall be used for the convolution operation
394-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
394+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
395395
\return the convolved array
396396
397397
\ingroup signal_func_fftconvolve1
398398
*/
399-
AFAPI array fftconvolve1(const array& signal, const array& filter, const bool expand=false);
399+
AFAPI array fftconvolve1(const array& signal, const array& filter, const convMode mode=AF_CONV_DEFAULT);
400400

401401
/**
402402
C++ Interface for convolution on two dimensional data
403403
404404
\param[in] signal is the input signal
405405
\param[in] filter is the signal that shall be used for the convolution operation
406-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
406+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
407407
\return the convolved array
408408
409409
\ingroup signal_func_fftconvolve2
410410
*/
411-
AFAPI array fftconvolve2(const array& signal, const array& filter, const bool expand=false);
411+
AFAPI array fftconvolve2(const array& signal, const array& filter, const convMode mode=AF_CONV_DEFAULT);
412412

413413
/**
414414
C++ Interface for convolution on three dimensional data
415415
416416
\param[in] signal is the input signal
417417
\param[in] filter is the signal that shall be used for the convolution operation
418-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
418+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
419419
\return the convolved array
420420
421421
\ingroup signal_func_fftconvolve3
422422
*/
423-
AFAPI array fftconvolve3(const array& signal, const array& filter, const bool expand=false);
423+
AFAPI array fftconvolve3(const array& signal, const array& filter, const convMode mode=AF_CONV_DEFAULT);
424424

425425
}
426426
#endif
@@ -560,41 +560,41 @@ AFAPI af_err af_ifft3(af_array *out, af_array in, double norm_factor, dim_type o
560560
\param[out] out is convolved array
561561
\param[in] signal is the input signal
562562
\param[in] filter is the signal that shall be flipped for the convolution operation
563-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
563+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
564564
\return \ref AF_SUCCESS if the convolution is successful,
565565
otherwise an appropriate error code is returned.
566566
567567
\ingroup signal_func_convolve1
568568
*/
569-
AFAPI af_err af_convolve1(af_array *out, af_array signal, af_array filter, bool expand);
569+
AFAPI af_err af_convolve1(af_array *out, af_array signal, af_array filter, const af_conv_mode mode);
570570

571571
/**
572572
C Interface for convolution on two dimensional data
573573
574574
\param[out] out is convolved array
575575
\param[in] signal is the input signal
576576
\param[in] filter is the signal that shall be flipped for the convolution operation
577-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
577+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
578578
\return \ref AF_SUCCESS if the convolution is successful,
579579
otherwise an appropriate error code is returned.
580580
581581
\ingroup signal_func_convolve2
582582
*/
583-
AFAPI af_err af_convolve2(af_array *out, af_array signal, af_array filter, bool expand);
583+
AFAPI af_err af_convolve2(af_array *out, af_array signal, af_array filter, const af_conv_mode mode);
584584

585585
/**
586586
C Interface for convolution on three dimensional data
587587
588588
\param[out] out is convolved array
589589
\param[in] signal is the input signal
590590
\param[in] filter is the signal that shall be flipped for the convolution operation
591-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
591+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
592592
\return \ref AF_SUCCESS if the convolution is successful,
593593
otherwise an appropriate error code is returned.
594594
595595
\ingroup signal_func_convolve3
596596
*/
597-
AFAPI af_err af_convolve3(af_array *out, af_array signal, af_array filter, bool expand);
597+
AFAPI af_err af_convolve3(af_array *out, af_array signal, af_array filter, const af_conv_mode mode);
598598

599599
/**
600600
C Interface for separable convolution on two dimensional data
@@ -603,7 +603,7 @@ AFAPI af_err af_convolve3(af_array *out, af_array signal, af_array filter, bool
603603
\param[in] col_filter is filter that has to be applied along the coloumns
604604
\param[in] row_filter is filter that has to be applied along the rows
605605
\param[in] signal is the input array
606-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
606+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
607607
\return \ref AF_SUCCESS if the convolution is successful,
608608
otherwise an appropriate error code is returned.
609609
@@ -612,49 +612,49 @@ AFAPI af_err af_convolve3(af_array *out, af_array signal, af_array filter, bool
612612
613613
\ingroup signal_func_convolve
614614
*/
615-
AFAPI af_err af_convolve2_sep(af_array *out, af_array col_filter, af_array row_filter, af_array signal, bool expand);
615+
AFAPI af_err af_convolve2_sep(af_array *out, af_array col_filter, af_array row_filter, af_array signal, const af_conv_mode mode);
616616

617617
/**
618618
C Interface for FFT-based convolution on one dimensional data
619619
620620
\param[out] out is convolved array
621621
\param[in] signal is the input signal
622622
\param[in] filter is the signal that shall be used for the convolution operation
623-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
623+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
624624
\return \ref AF_SUCCESS if the convolution is successful,
625625
otherwise an appropriate error code is returned.
626626
627627
\ingroup signal_func_fftconvolve1
628628
*/
629-
AFAPI af_err af_fftconvolve1(af_array *out, af_array signal, af_array filter, const bool expand);
629+
AFAPI af_err af_fftconvolve1(af_array *out, af_array signal, af_array filter, const af_conv_mode mode);
630630

631631
/**
632632
C Interface for FFT-based convolution on two dimensional data
633633
634634
\param[out] out is convolved array
635635
\param[in] signal is the input signal
636636
\param[in] filter is the signal that shall be used for the convolution operation
637-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
637+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
638638
\return \ref AF_SUCCESS if the convolution is successful,
639639
otherwise an appropriate error code is returned.
640640
641641
\ingroup signal_func_fftconvolve2
642642
*/
643-
AFAPI af_err af_fftconvolve2(af_array *out, af_array signal, af_array filter, const bool expand);
643+
AFAPI af_err af_fftconvolve2(af_array *out, af_array signal, af_array filter, const af_conv_mode mode);
644644

645645
/**
646646
C Interface for FFT-based convolution on three dimensional data
647647
648648
\param[out] out is convolved array
649649
\param[in] signal is the input signal
650650
\param[in] filter is the signal that shall be used for the convolution operation
651-
\param[in] expand indicates if the convolution should be expanded or not(where output size equals input).
651+
\param[in] mode indicates if the convolution should be expanded or not(where output size equals input).
652652
\return \ref AF_SUCCESS if the convolution is successful,
653653
otherwise an appropriate error code is returned.
654654
655655
\ingroup signal_func_fftconvolve3
656656
*/
657-
AFAPI af_err af_fftconvolve3(af_array *out, af_array signal, af_array filter, const bool expand);
657+
AFAPI af_err af_fftconvolve3(af_array *out, af_array signal, af_array filter, const af_conv_mode mode);
658658

659659
#ifdef __cplusplus
660660
}

src/api/c/convolve.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,33 +130,33 @@ af_err convolve2_sep(af_array *out, af_array col_filter, af_array row_filter, af
130130
return AF_SUCCESS;
131131
}
132132

133-
af_err af_convolve1(af_array *out, af_array signal, af_array filter, bool expand)
133+
af_err af_convolve1(af_array *out, af_array signal, af_array filter, const af_conv_mode mode)
134134
{
135-
if (expand)
135+
if (mode == AF_CONV_EXPAND)
136136
return convolve<1, true >(out, signal, filter);
137137
else
138138
return convolve<1, false>(out, signal, filter);
139139
}
140140

141-
af_err af_convolve2(af_array *out, af_array signal, af_array filter, bool expand)
141+
af_err af_convolve2(af_array *out, af_array signal, af_array filter, const af_conv_mode mode)
142142
{
143-
if (expand)
143+
if (mode == AF_CONV_EXPAND)
144144
return convolve<2, true >(out, signal, filter);
145145
else
146146
return convolve<2, false>(out, signal, filter);
147147
}
148148

149-
af_err af_convolve3(af_array *out, af_array signal, af_array filter, bool expand)
149+
af_err af_convolve3(af_array *out, af_array signal, af_array filter, const af_conv_mode mode)
150150
{
151-
if (expand)
151+
if (mode == AF_CONV_EXPAND)
152152
return convolve<3, true >(out, signal, filter);
153153
else
154154
return convolve<3, false>(out, signal, filter);
155155
}
156156

157-
af_err af_convolve2_sep(af_array *out, af_array signal, af_array col_filter, af_array row_filter, bool expand)
157+
af_err af_convolve2_sep(af_array *out, af_array signal, af_array col_filter, af_array row_filter, const af_conv_mode mode)
158158
{
159-
if (expand)
159+
if (mode == AF_CONV_EXPAND)
160160
return convolve2_sep<true >(out, signal, col_filter, row_filter);
161161
else
162162
return convolve2_sep<false>(out, signal, col_filter, row_filter);

src/api/c/fftconvolve.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ af_err fftconvolve(af_array *out, af_array signal, af_array filter, const bool e
8585
return AF_SUCCESS;
8686
}
8787

88-
af_err af_fftconvolve1(af_array *out, af_array signal, af_array filter, const bool expand)
88+
af_err af_fftconvolve1(af_array *out, af_array signal, af_array filter, const af_conv_mode mode)
8989
{
90-
return fftconvolve<1>(out, signal, filter, expand);
90+
return fftconvolve<1>(out, signal, filter, mode == AF_CONV_EXPAND);
9191
}
9292

93-
af_err af_fftconvolve2(af_array *out, af_array signal, af_array filter, const bool expand)
93+
af_err af_fftconvolve2(af_array *out, af_array signal, af_array filter, const af_conv_mode mode)
9494
{
95-
return fftconvolve<2>(out, signal, filter, expand);
95+
return fftconvolve<2>(out, signal, filter, mode == AF_CONV_EXPAND);
9696
}
9797

98-
af_err af_fftconvolve3(af_array *out, af_array signal, af_array filter, const bool expand)
98+
af_err af_fftconvolve3(af_array *out, af_array signal, af_array filter, const af_conv_mode mode)
9999
{
100-
return fftconvolve<3>(out, signal, filter, expand);
100+
return fftconvolve<3>(out, signal, filter, mode == AF_CONV_EXPAND);
101101
}

src/api/cpp/convolve.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,44 @@
1515
namespace af
1616
{
1717

18-
array convolve(const array& signal, const array& filter, bool expand)
18+
array convolve(const array& signal, const array& filter, const convMode mode)
1919
{
2020
unsigned sN = signal.numdims();
2121
unsigned fN = filter.numdims();
2222

2323
switch(std::min(sN,fN)) {
24-
case 1: return convolve1(signal, filter, expand);
25-
case 2: return convolve2(signal, filter, expand);
26-
case 3: return convolve3(signal, filter, expand);
27-
default: return convolve3(signal, filter, expand);
24+
case 1: return convolve1(signal, filter, mode);
25+
case 2: return convolve2(signal, filter, mode);
26+
case 3: return convolve3(signal, filter, mode);
27+
default: return convolve3(signal, filter, mode);
2828
}
2929
}
3030

31-
array convolve(const array& col_filter, const array& row_filter, const array& signal, bool expand)
31+
array convolve(const array& col_filter, const array& row_filter, const array& signal, const convMode mode)
3232
{
3333
af_array out = 0;
34-
AF_THROW(af_convolve2_sep(&out, col_filter.get(), row_filter.get(), signal.get(), expand));
34+
AF_THROW(af_convolve2_sep(&out, col_filter.get(), row_filter.get(), signal.get(), mode));
3535
return array(out);
3636
}
3737

38-
array convolve1(const array& signal, const array& filter, bool expand)
38+
array convolve1(const array& signal, const array& filter, const convMode mode)
3939
{
4040
af_array out = 0;
41-
AF_THROW(af_convolve1(&out, signal.get(), filter.get(), expand));
41+
AF_THROW(af_convolve1(&out, signal.get(), filter.get(), mode));
4242
return array(out);
4343
}
4444

45-
array convolve2(const array& signal, const array& filter, bool expand)
45+
array convolve2(const array& signal, const array& filter, const convMode mode)
4646
{
4747
af_array out = 0;
48-
AF_THROW(af_convolve2(&out, signal.get(), filter.get(), expand));
48+
AF_THROW(af_convolve2(&out, signal.get(), filter.get(), mode));
4949
return array(out);
5050
}
5151

52-
array convolve3(const array& signal, const array& filter, bool expand)
52+
array convolve3(const array& signal, const array& filter, const convMode mode)
5353
{
5454
af_array out = 0;
55-
AF_THROW(af_convolve3(&out, signal.get(), filter.get(), expand));
55+
AF_THROW(af_convolve3(&out, signal.get(), filter.get(), mode));
5656
return array(out);
5757
}
5858

0 commit comments

Comments
 (0)