Xmipp  v3.23.11-Nereus
xmipp_datatype.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Authors: Joaquin Oton (joton@cnb.csic.es)
3  *
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include <complex>
27 #include "xmipp_datatype.h"
28 #include "xmipp_error.h"
29 #include "utils/half.hpp"
30 
31 
32 // Get size of datatype
34 {
35  size_t size;
36 
37  switch ( type )
38  {
39  case DT_UHalfByte:
40  case DT_UChar:
41  case DT_SChar:
42  size = sizeof(char);
43  break;
44  case DT_UShort:
45  case DT_Short:
46  size = sizeof(short);
47  break;
48  case DT_UInt:
49  case DT_Int:
50  size = sizeof(int);
51  break;
52  case DT_ULong:
53  case DT_Long:
54  size = sizeof(long);
55  break;
56  case DT_Float:
57  size = sizeof(float);
58  break;
59  case DT_Double:
60  size = sizeof(double);
61  break;
62  case DT_CShort:
63  size = sizeof(std::complex<short>);
64  break;
65  case DT_CInt:
66  size = sizeof(std::complex<int>);
67  break;
68  case DT_CFloat:
69  size = sizeof(std::complex<float>);
70  break;
71  case DT_CDouble:
72  size = sizeof(std::complex<double>);
73  break;
74  case DT_Bool:
75  size = sizeof(bool);
76  break;
77  case DT_HalfFloat:
78  size = sizeof(half_float::half);
79  break;
80  default:
81  size = 0;
82  }
83 
84  return(size);
85 }
86 
88 DataType str2Datatype(const std::string & str)
89 {
90  DataType datatype;
91 
92  if(str=="uint8")
93  datatype = DT_UChar;
94  else if (str == "uhalfint8")
95  datatype = DT_UHalfByte;
96  else if (str=="int8")
97  datatype = DT_SChar;
98  else if (str=="uint16")
99  datatype = DT_UShort;
100  else if (str=="int16")
101  datatype = DT_Short;
102  else if (str=="uint32")
103  datatype = DT_UInt;
104  else if (str=="int32")
105  datatype = DT_Int;
106  else if (str=="long")
107  datatype = DT_Long;
108  else if (str=="float")
109  datatype = DT_Float;
110  else if (str=="double")
111  datatype = DT_Double;
112  else if (str=="cint16")
113  datatype = DT_CShort;
114  else if (str=="cint32")
115  datatype = DT_CInt;
116  else if (str=="cfloat")
117  datatype = DT_CFloat;
118  else if (str=="cdouble")
119  datatype = DT_CDouble;
120  else if (str=="bool")
121  datatype = DT_Bool;
122  else if (str=="half")
123  datatype = DT_HalfFloat;
124  else
125  REPORT_ERROR(ERR_TYPE_INCORRECT, "datatypeString2int; unknown datatype");
126 
127  return datatype;
128 }
129 
131 std::string datatype2Str(DataType datatype)
132 {
133  switch ( datatype )
134  {
135  case DT_UHalfByte:
136  return "uhalfint8";
137  case DT_UChar:
138  return "uint8";
139  case DT_SChar:
140  return "int8";
141  case DT_UShort:
142  return "uint16";
143  case DT_Short:
144  return "int16";
145  case DT_UInt:
146  return "uint32";
147  case DT_Int:
148  return "int32";
149  case DT_Long:
150  return "int64";
151  case DT_Float:
152  return "float";
153  case DT_Double:
154  return "double";
155  case DT_CShort:
156  return "cint16";
157  case DT_CInt:
158  return "cint32";
159  case DT_CFloat:
160  return "cfloat";
161  case DT_CDouble:
162  return "cdouble";
163  case DT_Bool:
164  return "bool";
165  case DT_HalfFloat:
166  return "half";
167  default:
168  return "unknown type";
169  }
170 }
171 
172 std::string datatype2StrLong(DataType datatype)
173 {
174  switch (datatype)
175  {
176  case DT_UHalfByte:
177  return "Unsigned 4 bit type (UHalfInt8)";
178  case DT_UChar:
179  return "Unsigned character or byte type (UInt8)";
180  case DT_SChar:
181  return "Signed character (Int8)";
182  case DT_UShort:
183  return "Unsigned short integer (UInt16)";
184  case DT_Short:
185  return "Signed short integer (Int16)";
186  case DT_UInt:
187  return "Unsigned integer (UInt32)";
188  case DT_Int:
189  return "Signed integer (Int32)";
190  case DT_Long:
191  return "Signed integer (4 or 8 byte, depending on system)";
192  case DT_Float:
193  return "Floating point (4-byte)";
194  case DT_Double:
195  return "Double precision floating point (8-byte)";
196  case DT_CShort:
197  return "Complex two-byte integer (4-byte)";
198  case DT_CInt:
199  return "Complex integer (8-byte)";
200  case DT_CFloat:
201  return "Complex floating point (8-byte)";
202  case DT_CDouble:
203  return "Complex floating point (16-byte)";
204  case DT_Bool:
205  return "Boolean (1-byte?)";
206  case DT_HalfFloat:
207  return "Half precision floating point (2-byte)";
208  case DT_Unknown:
209  return "Unknown data type";
210  default:
211  return "Undefined data type";
212  }
213 }
214 
std::string datatype2Str(DataType datatype)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
viol type
DataType
std::string datatype2StrLong(DataType datatype)
DataType str2Datatype(const std::string &str)
Incorrect type received.
Definition: xmipp_error.h:190
size_t gettypesize(DataType type)
Returns memory size of datatype.