Tensor Network Theory Library  Beta release 1.2.1
A library of routines for performing TNT-based operations
 All Data Structures Functions Variables Groups Pages
tntUtil.c
1 /*
2 Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
3 Date: $LastChangedDate: 2016-09-23 11:55:22 +0100 (Fri, 23 Sep 2016) $
4 (c) University of Oxford 2014
5 */
6 
7 #include "../headers/tnt_int.h"
8 #include "../headers/dec_public.h"
9 
17 void tntSysQNClearWarnOn(void) {
18 
19  TNT_ERR_RET_DEFS
20  extern int _tnt_QNClear_warning;
21 
22  _tnt_QNClear_warning -= 1;
23 }
24 
25 
36 
37  TNT_ERR_RET_DEFS
38  extern int _tnt_QNClear_warning;
39 
40  _tnt_QNClear_warning += 1;
41 }
42 
50 void tntClearReshapes(int val)
51 {
52 
53  TNTchangeChi(val);
54 
55  return;
56 }
57 
64 void tntPrintVersion(void)
65 {
66 #ifdef TNT_RDYNAMIC
67  _tnt_printf("TNT library, debug version %s\n", TNT_LIB_VERSION);
68 #else
69  _tnt_printf("TNT library, version %s\n", TNT_LIB_VERSION);
70 #endif
71  return;
72 }
73 
80 void tntQuietModeOn(void)
81 {
82  _tnt_quiet_mode_on();
83 
84  return;
85 }
86 
93 void tntQuietModeOff(void)
94 {
95  _tnt_quiet_mode_off();
96 
97  return;
98 }
99 
109 {
110  if (fabs(var.im/var.re) > TNT_COMP_TOL) {
111  return sqrt(var.re*var.re + var.im*var.im);
112  } else {
113  return var.re;
114  }
115 }
116 
123 tntComplex tntAtoC(const char * str) {
124  tntComplex cnumber = {0.0,0.0}; /* The complex number to return */
125  char *pch;
126  int iscomplex = 0;
127  char key[] = "+-";
128  unsigned posnk, posni; /* Position of the key that marks divider between real and complex part, Position of i marking imaginary number */
129  char restring[20], imstring[20]; /* Numbers that are the real and complex parts of the string */
130 
131  /* First check to see if there is both a real and imaginary part */
132  pch=strpbrk(str,key);
133  while (pch != NULL) {
134  posnk = pch-str;
135 
136  /* Check for first entry, or the sign being part of the exponenet */
137  if ((0 == posnk) || ('e' == str[posnk-1]) || ('E' == str[posnk-1])) {
138  pch=strpbrk(pch+1,key);
139  continue;
140  } else {
141  iscomplex = 1;
142  break;
143  }
144 
145  }
146 
147  if (iscomplex) {
148  /* find out where the imaginary part is */
149  pch = strchr(str,'i');
150  posni = pch-str;
151 
152  if (posni > posnk) {
153  /* imaginary part last */
154  strncpy(restring,str,posnk);
155  restring[posnk] = '\0';
156 
157  strncpy(imstring,str+posnk,posni-posnk);
158  imstring[posni-posnk] = '\0';
159 
160  } else {
161  /* imaginary part first */
162  strncpy(imstring,str,posni);
163  imstring[posni] = '\0';
164 
165  strcpy(restring,str+posnk);
166  }
167 
168  /* Assign real and imaginary parts to number to be returned */
169  cnumber.re = atof(restring);
170  cnumber.im = atof(imstring);
171 
172  } else {
173  /* Not a complex number - check whether purely real or purely imaginary */
174  pch=strchr(str,'i');
175  if (NULL == pch) {
176  /* i Not found, so it is a purely real number */
177  cnumber.re = atof(str);
178  cnumber.im = 0.0;
179  } else {
180  /* i has been found, so it is a purely imaginary number */
181  posni = pch-str+1; /* Position of i character */
182  strncpy(imstring,str,posni);
183  imstring[posni] = '\0'; /* Null character manually added */
184 
185  cnumber.im = atof(imstring);
186  cnumber.re = 0.0;
187  }
188  }
189 
190  return cnumber;
191 }
double tntComplexToReal(tntComplex var)
Definition: tntUtil.c:108
void tntQuietModeOff(void)
Definition: tntUtil.c:93
void tntQuietModeOn(void)
Definition: tntUtil.c:80
Definition: tnt.h:65
void tntClearReshapes(int val)
Definition: tntUtil.c:50
tntComplex tntAtoC(const char *str)
Definition: tntUtil.c:123
double re
Definition: tnt.h:66
void tntPrintVersion(void)
Definition: tntUtil.c:64
void tntSysQNClearWarnOn(void)
Definition: tntUtil.c:17
double im
Definition: tnt.h:67
void tntSysQNClearWarnOff(void)
Definition: tntUtil.c:35