[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master fdb6183 019/125: Where operator implemented in
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master fdb6183 019/125: Where operator implemented in gal_data_arithmetic |
Date: |
Sun, 23 Apr 2017 22:36:28 -0400 (EDT) |
branch: master
commit fdb6183962df69ab6abaff56ed84321ab4c2a4eb
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Where operator implemented in gal_data_arithmetic
The `where' operator is now available in `gal_data_arithmetic' and thus the
Arithmetic program. Since it doesn't need to allocate an output array (the
output is one of its inputs) things were much easier than the other
functions.
Some minor typos were also corrected in the book.
---
doc/gnuastro.texi | 4 +-
lib/data-arithmetic-other.c | 148 ++++++++++++++++++++++++++++++++++++++++++++
lib/data-arithmetic-other.h | 3 +
lib/data.c | 12 +++-
lib/gnuastro/data.h | 3 -
5 files changed, 162 insertions(+), 8 deletions(-)
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 1ff5a92..785f822 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -8721,11 +8721,11 @@ one edge of the image, its blurred wings will be
present on the other
side of the convolved image. This is often termed as circular
convolution or cyclic convolution.
-So as long as we are dealing with convolution in the frequency domain,
+So, as long as we are dealing with convolution in the frequency domain,
there is nothing we can do about the image edges. The least we can do
is to eliminate the ghosts of the other side of the image. So, we add
zero valued pixels to both the input image and the kernel in both
-dimensions so the image that will be convolved has the a size equal to
+dimensions so the image that will be convolved has a size equal to
the sum of both images in each dimension. Of course, the effect of this
zero-padding is that the sides of the output convolved image will
become dark. To put it another way, the edges are going to drain the
diff --git a/lib/data-arithmetic-other.c b/lib/data-arithmetic-other.c
index 268a37a..43ebf35 100644
--- a/lib/data-arithmetic-other.c
+++ b/lib/data-arithmetic-other.c
@@ -463,3 +463,151 @@ data_arithmetic_binary_function_f(int operator, unsigned
char flags,
/* Return */
return o;
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/***********************************************************************/
+/*************** Where **************/
+/***********************************************************************/
+#define DO_WHERE_OPERATION(ITT, OT) { \
+ ITT *it=iftrue->array; \
+ OT *o=out->array, *of=out->array+out->size; \
+ if(iftrue->size==1) \
+ do *o = *c++ ? *it : *o; while(++o<of); \
+ else \
+ do { *o = *c++ ? *it : *o; ++it; } while(++o<of); \
+}
+
+
+
+
+
+#define WHERE_OUT_SET(OT) \
+ switch(iftrue->type) \
+ { \
+ case GAL_DATA_TYPE_UCHAR: \
+ DO_WHERE_OPERATION(unsigned char, OT); \
+ break; \
+ case GAL_DATA_TYPE_CHAR: \
+ DO_WHERE_OPERATION(char, OT); \
+ break; \
+ case GAL_DATA_TYPE_USHORT: \
+ DO_WHERE_OPERATION(unsigned short, OT); \
+ break; \
+ case GAL_DATA_TYPE_SHORT: \
+ DO_WHERE_OPERATION(short, OT); \
+ break; \
+ case GAL_DATA_TYPE_UINT: \
+ DO_WHERE_OPERATION(unsigned int, OT); \
+ break; \
+ case GAL_DATA_TYPE_INT: \
+ DO_WHERE_OPERATION(int, OT); \
+ break; \
+ case GAL_DATA_TYPE_ULONG: \
+ DO_WHERE_OPERATION(unsigned long, OT); \
+ break; \
+ case GAL_DATA_TYPE_LONG: \
+ DO_WHERE_OPERATION(long, OT); \
+ break; \
+ case GAL_DATA_TYPE_LONGLONG: \
+ DO_WHERE_OPERATION(LONGLONG, OT); \
+ break; \
+ case GAL_DATA_TYPE_FLOAT: \
+ DO_WHERE_OPERATION(float, OT); \
+ break; \
+ case GAL_DATA_TYPE_DOUBLE: \
+ DO_WHERE_OPERATION(double, OT); \
+ break; \
+ default: \
+ error(EXIT_FAILURE, 0, "type code %d not recognized for the " \
+ "`iftrue' dataset of `WHERE_OUT_SET'", iftrue->type); \
+ }
+
+
+
+
+
+void
+data_arithmetic_where(int operator, unsigned char flags, gal_data_t *out,
+ gal_data_t *cond, gal_data_t *iftrue)
+{
+ unsigned char *c=cond->array;
+
+ /* The condition operator has to be unsigned char. */
+ if(cond->type!=GAL_DATA_TYPE_UCHAR)
+ error(EXIT_FAILURE, 0, "the condition operand to "
+ "`data_arithmetic_where' must be an `unsigned char' type, but "
+ "the given condition operator has a `%s' type",
+ gal_data_type_string(cond->type));
+
+ /* The dimension and sizes of the out and condition data sets must be the
+ same. */
+ if(gal_data_dsize_is_different(out, cond))
+ error(EXIT_FAILURE, 0, "the output and condition data sets of the "
+ "`where' operator must be the same size");
+
+ /* Do the operation. */
+ switch(out->type)
+ {
+ case GAL_DATA_TYPE_UCHAR:
+ WHERE_OUT_SET(unsigned char);
+ break;
+ case GAL_DATA_TYPE_CHAR:
+ WHERE_OUT_SET(char);
+ break;
+ case GAL_DATA_TYPE_USHORT:
+ WHERE_OUT_SET(unsigned short);
+ break;
+ case GAL_DATA_TYPE_SHORT:
+ WHERE_OUT_SET(short);
+ break;
+ case GAL_DATA_TYPE_UINT:
+ WHERE_OUT_SET(unsigned int);
+ break;
+ case GAL_DATA_TYPE_INT:
+ WHERE_OUT_SET(int);
+ break;
+ case GAL_DATA_TYPE_ULONG:
+ WHERE_OUT_SET(unsigned long);
+ break;
+ case GAL_DATA_TYPE_LONG:
+ WHERE_OUT_SET(long);
+ break;
+ case GAL_DATA_TYPE_LONGLONG:
+ WHERE_OUT_SET(LONGLONG);
+ break;
+ case GAL_DATA_TYPE_FLOAT:
+ WHERE_OUT_SET(float);
+ break;
+ case GAL_DATA_TYPE_DOUBLE:
+ WHERE_OUT_SET(double);
+ break;
+ default:
+ error(EXIT_FAILURE, 0, "type code %d not recognized for the `out' "
+ "dataset of `data_arithmetic_where'", out->type);
+ }
+
+ /* Clean up if necessary. */
+ if(flags & GAL_DATA_ARITH_FREE)
+ {
+ gal_data_free(cond);
+ gal_data_free(iftrue);
+ }
+}
diff --git a/lib/data-arithmetic-other.h b/lib/data-arithmetic-other.h
index 2281bba..e47b407 100644
--- a/lib/data-arithmetic-other.h
+++ b/lib/data-arithmetic-other.h
@@ -38,5 +38,8 @@ gal_data_t *
data_arithmetic_binary_function_f(int operator, unsigned char flags,
gal_data_t *l, gal_data_t *r);
+void
+data_arithmetic_where(int operator, unsigned char flags, gal_data_t *out,
+ gal_data_t *cond, gal_data_t *iftrue);
#endif
diff --git a/lib/data.c b/lib/data.c
index 19e0fd3..41da34b 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -1529,7 +1529,7 @@ gal_data_t *
gal_data_arithmetic(int operator, unsigned char flags, ...)
{
va_list va;
- gal_data_t *d1, *d2, *out=NULL;
+ gal_data_t *d1, *d2, *d3, *out=NULL;
/* Prepare the variable arguments (starting after the flags argument). */
va_start(va, flags);
@@ -1566,6 +1566,14 @@ gal_data_arithmetic(int operator, unsigned char flags,
...)
if(flags & GAL_DATA_ARITH_FREE) gal_data_free(d1);
break;
+ case GAL_DATA_OPERATOR_WHERE:
+ d1 = va_arg(va, gal_data_t *); /* Output value/array. */
+ d2 = va_arg(va, gal_data_t *); /* Condition (unsigned char). */
+ d3 = va_arg(va, gal_data_t *); /* If true value/array. */
+ data_arithmetic_where(operator, flags, d1, d2, d3);
+ out=d1;
+ break;
+
/* Unary function operators. */
case GAL_DATA_OPERATOR_SQRT:
case GAL_DATA_OPERATOR_LOG:
@@ -1619,8 +1627,6 @@ gal_data_arithmetic(int operator, unsigned char flags,
...)
|| !strcmp(operator, "max")
|| !strcmp(operator, "average")
|| !strcmp(operator, "median")) alloppixs(p, operator);
- else if(!strcmp(operator, "not")) notfunc(p);
- else if(!strcmp(operator, "where")) where(p);
#endif
default:
diff --git a/lib/gnuastro/data.h b/lib/gnuastro/data.h
index ff84635..c0896e5 100644
--- a/lib/gnuastro/data.h
+++ b/lib/gnuastro/data.h
@@ -130,9 +130,6 @@ enum gal_data_alltypes
/* Operators not yet implemented in `gal_data_arithmetic':
-
- GAL_DATA_OPERATOR_WHERE
- GAL_DATA_OPERATOR_BITOCM
GAL_DATA_OPERATOR_ABS
GAL_DATA_OPERATOR_MINVAL
GAL_DATA_OPERATOR_MAXVAL
- [gnuastro-commits] master updated (a5aeb7d -> 3339b92), Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 3e05560 003/125: Corrected bad use of type in MakeProfiles, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 847d97e 007/125: Minor header inclusion corrections, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 591461c 015/125: Corrected occurance of "remainder" with modulo, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 1ea9ea2 009/125: Data structure mmap information updated, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 531c263 008/125: Operators treated as macros, not string, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ff9258a 006/125: Arithmetic with internal type conversion, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 5336d5c 024/125: Small but important corrections, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c2fcb3e 020/125: Absolute value operator in gal_data_arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master fdb6183 019/125: Where operator implemented in gal_data_arithmetic,
Mohammad Akhlaghi <=
- [gnuastro-commits] master 493bc6f 001/125: Defined new gnuastro/data.h header, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c6462d1 016/125: Type conversion operators in Arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c10c4be 002/125: Moved type code and alloc functions into data.h, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master a4c5b9d 012/125: Binary operator arithmetic works on uncompiled types, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ad2810d 029/125: Work started on getting text table information, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master bc57ade 021/125: Minimum and maximum value operators implemented, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 2dea9a7 011/125: All binary operator types set at configure time, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ff0b76d 018/125: New Data types section in book, bitwise not added, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c62b01e 031/125: Corrected incrementation issue with and and or operators, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 0a32a82 027/125: Any number of searched columns from FITS are read, Mohammad Akhlaghi, 2017/04/23