timedvisitor
[scilab.git] / scilab / modules / abstractSyntaxTree / src / cpp / run / run_OpExp.cpp
1 /*
2 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 *  Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
4 *
5 *  This file must be used under the terms of the CeCILL.
6 *  This source file is licensed as described in the file COPYING, which
7 *  you should have received as part of this distribution.  The terms
8 *  are also available at
9 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
13 #pragma comment(lib,"../../bin/libintl.lib")
14
15 #include "timer.hxx"
16 #include "runvisitor.hxx"
17 #include "execvisitor.hxx"
18 #include "timedvisitor.hxx"
19 #include "core_math.h"
20
21 #include "types_multiplication.hxx"
22 #include "types_addition.hxx"
23 #include "types_substraction.hxx"
24 #include "types_divide.hxx"
25 #include "types_power.hxx"
26
27 #include "context.hxx"
28 extern "C"
29 {
30         #include "localization.h"
31 }
32
33 using std::string;
34
35 namespace ast
36 {
37         template class RunVisitorT<ExecVisitor>;
38         template class RunVisitorT<TimedVisitor>;
39
40         template <class T>
41         void RunVisitorT<T>::visitprivate(const OpExp &e)
42         {
43                 ExecVisitor execMeL;
44                 ExecVisitor execMeR;
45
46                 symbol::Context *pContext = symbol::Context::getInstance();
47                 /*getting what to assign*/
48                 e.left_get().accept(execMeL);
49                 /*getting what to assign*/
50                 e.right_get().accept(execMeR);
51                 GenericType::RealType TypeL = execMeL.result_get()->getType();
52                 GenericType::RealType TypeR = execMeR.result_get()->getType();
53
54                 if(TypeL == GenericType::RealImplicitList)
55                 {
56                         ImplicitList* pIL = execMeL.result_get()->getAsImplicitList();
57                         if(pIL->computable())
58                         {
59                                 InternalType *pIT = pIL->extract_matrix();
60                                 execMeL.result_set(pIT);
61                                 TypeL = pIT->getType();
62                         }
63                 }
64
65                 if(TypeR == GenericType::RealImplicitList)
66                 {
67                         ImplicitList* pIL = execMeR.result_get()->getAsImplicitList();
68                         if(pIL->computable())
69                         {
70                                 InternalType *pIT = pIL->extract_matrix();
71                                 execMeR.result_set(pIT);
72                                 TypeR = pIT->getType();
73                         }
74                 }
75
76                 InternalType *pResult = NULL;
77                 switch(e.oper_get())
78                 {
79                 case OpExp::plus :
80                         {
81                                 if(TypeR == GenericType::RealDouble && TypeL == GenericType::RealDouble)
82                                 {
83                                         Double *pL = execMeL.result_get()->getAsDouble();
84                                         Double *pR = execMeR.result_get()->getAsDouble();
85
86                                         int iResult = AddDoubleToDouble(pL, pR, (Double**)&pResult);
87                                         if(iResult != 0)
88                                         {
89                                                 std::ostringstream os;
90                                                 os << "inconsistent row/column dimensions";
91                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
92                                                 throw os.str();
93                                         }
94                                         result_set(pResult);
95                                 }
96                                 else if(TypeL == GenericType::RealBool && TypeR == GenericType::RealBool)
97                                 {
98                                         //nothing to do, all in macro : %b_+_b
99                                 }
100                                 else if(TypeL == GenericType::RealString && TypeR == GenericType::RealString)
101                                 {
102                                         String *pL = execMeL.result_get()->getAsString();
103                                         String *pR = execMeR.result_get()->getAsString();
104
105                                         int iResult = AddStringToString(pL, pR, (String**)&pResult);
106
107                                         if(iResult != 0)
108                                         {
109                                                 std::ostringstream os;
110                                                 os << "inconsistent row/column dimensions";
111                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
112                                                 throw os.str();
113                                         }
114                                         result_set(pResult);
115                                 }
116                                 else if(TypeL == GenericType::RealInt && TypeR == GenericType::RealInt)
117                                 {
118                                 }
119                                 else if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealPoly)
120                                 {
121                                         Double *pL                              = execMeL.result_get()->getAsDouble();
122                                         MatrixPoly *pR          = execMeR.result_get()->getAsPoly();
123
124                                         int iResult = AddDoubleToPoly(pR, pL, (MatrixPoly**)&pResult);
125                                         if(iResult != 0)
126                                         {
127                                                 std::ostringstream os;
128                                                 os << "inconsistent row/column dimensions";
129                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
130                                                 throw os.str();
131                                         }
132                                         result_set(pResult);
133                                 }
134                                 else if(TypeL == GenericType::RealPoly && TypeR == GenericType::RealDouble)
135                                 {
136                                         Double *pR                              = execMeR.result_get()->getAsDouble();
137                                         MatrixPoly *pL          = execMeL.result_get()->getAsPoly();
138
139                                         int iResult = AddDoubleToPoly(pL, pR, (MatrixPoly**)&pResult);
140                                         if(iResult != 0)
141                                         {
142                                                 std::ostringstream os;
143                                                 os << "inconsistent row/column dimensions";
144                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
145                                                 throw os.str();
146                                         }
147                                         result_set(pResult);
148                                 }
149                                 else if(TypeL == GenericType::RealPoly && TypeR == GenericType::RealPoly)
150                                 {
151                                         MatrixPoly *pL  = execMeL.result_get()->getAsPoly();
152                                         MatrixPoly *pR  = execMeR.result_get()->getAsPoly();
153
154                                         int iResult = AddPolyToPoly(pL, pR, (MatrixPoly**)&pResult);
155                                         if(iResult != 0)
156                                         {
157                                                 if(iResult == 1)
158                                                 {
159                                                         std::ostringstream os;
160                                                         os << "inconsistent row/column dimensions";
161                                                         os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
162                                                         throw os.str();
163                                                 }
164                                                 else if(iResult == 2)
165                                                 {
166                                                         std::ostringstream os;
167                                                         os << "variables don't have the same formal variable";
168                                                         os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
169                                                         throw os.str();
170                                                 }
171                                         }
172                                         result_set(pResult);
173                                 }
174                                 break;
175                         }
176                 case OpExp::minus :
177                         {
178                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
179                                 {
180                                         Double *pL = execMeL.result_get()->getAsDouble();
181                                         Double *pR = execMeR.result_get()->getAsDouble();
182
183                                         int iResult = SubstractDoubleToDouble(pL, pR, (Double**)&pResult);
184                                         if(iResult != 0)
185                                         {
186                                                 std::ostringstream os;
187                                                 os << _("Inconsistent row/column dimensions.\n");
188                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
189                                                 throw os.str();
190                                         }
191                                         result_set(pResult);
192                                 }
193                                 else if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealPoly)
194                                 {
195                                         Double *pL                                      = execMeL.result_get()->getAsDouble();
196                                         MatrixPoly *pR                  = execMeR.result_get()->getAsPoly();
197
198                                         int iResult = SubstractPolyToDouble(pL, pR, (MatrixPoly**)&pResult);
199                                         if(iResult != 0)
200                                         {
201                                                 std::ostringstream os;
202                                                 os << _("Inconsistent row/column dimensions.\n");
203                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
204                                                 throw os.str();
205                                         }
206                                         result_set(pResult);
207                                 }
208                                 else if(TypeL == GenericType::RealPoly && TypeR == GenericType::RealDouble)
209                                 {
210                                         MatrixPoly *pL                  = execMeL.result_get()->getAsPoly();
211                                         Double *pR                                      = execMeR.result_get()->getAsDouble();
212
213                                         int iResult = SubstractDoubleToPoly(pL, pR, (MatrixPoly**)&pResult);
214                                         if(iResult != 0)
215                                         {
216                                                 std::ostringstream os;
217                                                 os << _("Inconsistent row/column dimensions.\n");
218                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
219                                                 throw os.str();
220                                         }
221                                         result_set(pResult);
222                                 }
223                                 else if(TypeL == GenericType::RealPoly && TypeR == GenericType::RealPoly)
224                                 {
225                                         MatrixPoly *pL                  = execMeL.result_get()->getAsPoly();
226                                         MatrixPoly *pR                  = execMeR.result_get()->getAsPoly();
227
228                                         int iResult = SubstractPolyToPoly(pL, pR, (MatrixPoly**)&pResult);
229                                         if(iResult != 0)
230                                         {
231                                                 std::ostringstream os;
232                                                 os << _("Inconsistent row/column dimensions.\n");
233                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
234                                                 throw os.str();
235                                         }
236                                         result_set(pResult);
237                                 }
238                                 else if(TypeL == GenericType::RealBool && TypeR == GenericType::RealBool)
239                                 {
240                                 }
241                                 else if(TypeL == GenericType::RealString && TypeR == GenericType::RealString)
242                                 {
243                                 }
244                                 else if(TypeL == GenericType::RealInt && TypeR == GenericType::RealInt)
245                                 {
246                                 }
247
248                                 break;
249                         }
250                 case OpExp::times:
251                         {
252                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
253                                 {
254                                         Double *pL                      = execMeL.result_get()->getAsDouble();
255                                         Double *pR                      = execMeR.result_get()->getAsDouble();
256
257                                         int iResult = MultiplyDoubleByDouble(pL, pR, (Double**)&pResult);
258                                         if(iResult)
259                                         {
260                                                 std::ostringstream os;
261                                                 os << _("Inconsistent row/column dimensions.\n");
262                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
263                                                 throw os.str();
264                                         }
265
266                                         result_set(pResult);
267                                 }
268                                 else if(TypeL == InternalType::RealDouble && TypeR == InternalType::RealPoly)
269                                 {
270                                         Double *pL                          = execMeL.result_get()->getAsDouble();
271                                         MatrixPoly *pR      = execMeR.result_get()->getAsPoly();
272
273                                         int iResult = MultiplyDoubleByPoly(pL, pR, (MatrixPoly**)&pResult);
274
275                                         if(iResult)
276                                         {
277                                                 std::ostringstream os;
278                                                 os << _("Inconsistent row/column dimensions.\n");
279                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
280                                                 throw os.str();
281                                         }
282
283                                         result_set(pResult);
284                                 }
285                                 else if(TypeL == InternalType::RealPoly && TypeR == InternalType::RealDouble)
286                                 {
287                                         MatrixPoly *pL      = execMeL.result_get()->getAsPoly();
288                                         Double *pR                          = execMeR.result_get()->getAsDouble();
289
290                                         int iResult = MultiplyPolyByDouble(pL, pR, (MatrixPoly**)&pResult);
291
292                                         if(iResult)
293                                         {
294                                                 std::ostringstream os;
295                                                 os << _("Inconsistent row/column dimensions.\n");
296                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
297                                                 throw os.str();
298                                         }
299
300                                         result_set(pResult);
301                                 }
302                                 else if(TypeL == InternalType::RealPoly && TypeR == InternalType::RealPoly)
303                                 {
304                                         MatrixPoly *pL      = execMeL.result_get()->getAsPoly();
305                                         MatrixPoly *pR                  = execMeR.result_get()->getAsPoly();
306
307                                         int iResult = MultiplyPolyByPoly(pL, pR, (MatrixPoly**)&pResult);
308
309                                         if(iResult)
310                                         {
311                                                 std::ostringstream os;
312                                                 os << _("Inconsistent row/column dimensions.\n");
313                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
314                                                 throw os.str();
315                                         }
316
317                                         result_set(pResult);
318                                 }
319                                 break;
320                         }
321                 case OpExp::divide:
322                         {
323                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
324                                 {
325                                         Double *pL                      = execMeL.result_get()->getAsDouble();
326                                         Double *pR                      = execMeR.result_get()->getAsDouble();
327
328                                         int iResult = DivideDoubleByDouble(pL, pR, (Double**)&pResult);
329                                         if(iResult)
330                                         {//manage errors
331                                                 std::ostringstream os;
332                                                 os << _("Inconsistent row/column dimensions.\n");
333                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
334                                                 throw os.str();
335                                         }
336                                         result_set(pResult);
337                                 }
338                                 else if(TypeL == GenericType::RealPoly && TypeR == GenericType::RealDouble)
339                                 {
340                                         MatrixPoly *pL  = execMeL.result_get()->getAsPoly();
341                                         Double *pR                      = execMeR.result_get()->getAsDouble();
342
343                                         int iResult = DividePolyByDouble(pL, pR, (MatrixPoly**)&pResult);
344                                         if(iResult)
345                                         {//manage errors
346                                                 std::ostringstream os;
347                                                 os << _("Inconsistent row/column dimensions.\n");
348                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
349                                                 throw os.str();
350                                         }
351
352                                         result_set(pResult);
353                                 }
354                                 else if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealPoly)
355                                 {
356                                         Double *pL                      = execMeL.result_get()->getAsDouble();
357                                         MatrixPoly *pR  = execMeR.result_get()->getAsPoly();
358
359                                         int iResult = DivideDoubleByPoly(pL, pR, (MatrixPoly**)&pResult);
360                                         if(iResult)
361                                         {//manage errors
362                                                 std::ostringstream os;
363                                                 os << _("Inconsistent row/column dimensions.\n");
364                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
365                                                 throw os.str();
366                                         }
367                                         result_set(pResult);
368                                 }
369
370                                 break;
371                         }
372                 case OpExp::dottimes :
373                         {
374                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
375                                 {
376                                         Double *pL                      = execMeL.result_get()->getAsDouble();
377                                         Double *pR                      = execMeR.result_get()->getAsDouble();
378
379                                         
380                                         int iResult = DotMultiplyDoubleByDouble(pL, pR, (Double**)&pResult);
381                                         if(iResult)
382                                         {
383                                                 std::ostringstream os;
384                                                 os << _("Inconsistent row/column dimensions.\n");
385                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
386                                                 throw os.str();
387                                         }
388
389                                         result_set(pResult);
390                                 }
391                                 break;
392                         }
393                 case OpExp::eq :
394                         {
395                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
396                                 {
397                                         Double *pL                      = execMeL.result_get()->getAsDouble();
398                                         Double *pR                      = execMeR.result_get()->getAsDouble();
399
400                                         if(pR->size_get() == 1)
401                                         {
402                                                 pResult                         = new Bool(pL->rows_get(), pL->cols_get());
403                                                 double dblRef   = pR->real_get(0,0);
404                                                 for(int i = 0 ; i < pL->rows_get() ; i++)
405                                                 {
406                                                         for(int j = 0 ; j < pL->cols_get() ; j++)
407                                                         {
408                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) == dblRef);
409                                                         }
410                                                 }
411                                         }
412                                         else if(pL->size_get() == 1)
413                                         {
414                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
415                                                 double dblRef   = pL->real_get(0,0);
416                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
417                                                 {
418                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
419                                                         {
420                                                                 pResult->getAsBool()->bool_set(i, j, dblRef == pR->real_get(i, j));
421                                                         }
422                                                 }
423                                         }
424                                         else if(pR->rows_get() == pL->rows_get() && pR->cols_get() == pL->cols_get())
425                                         {
426                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
427                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
428                                                 {
429                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
430                                                         {
431                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) == pR->real_get(i, j));
432                                                         }
433                                                 }
434                                         }
435                                         else
436                                         {
437                                                 pResult = new Bool(false);
438                                         }
439
440                                         result_set(pResult);
441                                 }
442                                 else if(TypeL == GenericType::RealString && TypeR == GenericType::RealString)
443                                 {
444                                         String *pL                      = execMeL.result_get()->getAsString();
445                                         String *pR                      = execMeR.result_get()->getAsString();
446
447                                         if(pL->size_get() == 1)
448                                         {
449                                                 pResult = new Bool(pR->rows_get(), pR->cols_get());
450
451                                                 char* pstL = pL->string_get()[0];
452                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
453                                                 {
454                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
455                                                         {
456                                                                 char* pstR = pR->string_get(i,j);
457                                                                 if(strcmp(pstL, pstR) == 0)
458                                                                 {
459                                                                         pResult->getAsBool()->bool_set(i,j,true);
460                                                                 }
461                                                                 else
462                                                                 {
463                                                                         pResult->getAsBool()->bool_set(i,j,false);
464                                                                 }
465                                                         }
466                                                 }
467                                         }
468                                         else if(pR->size_get() == 1)
469                                         {
470                                                 pResult = new Bool(pL->rows_get(), pL->cols_get());
471
472                                                 char* pstR = pR->string_get()[0];
473                                                 for(int i = 0 ; i < pL->rows_get() ; i++)
474                                                 {
475                                                         for(int j = 0 ; j < pL->cols_get() ; j++)
476                                                         {
477                                                                 char* pstL = pL->string_get(i,j);
478                                                                 if(strcmp(pstL, pstR) == 0)
479                                                                 {
480                                                                         pResult->getAsBool()->bool_set(i,j,true);
481                                                                 }
482                                                                 else
483                                                                 {
484                                                                         pResult->getAsBool()->bool_set(i,j,false);
485                                                                 }
486                                                         }
487                                                 }
488                                         }
489                                         else if(pL->rows_get() == pR->rows_get() && pL->cols_get() == pR->cols_get())
490                                         {
491                                                 pResult = new Bool(pL->rows_get(), pL->cols_get());
492
493                                                 for(int i = 0 ; i < pL->rows_get() ; i++)
494                                                 {
495                                                         for(int j = 0 ; j < pL->cols_get() ; j++)
496                                                         {
497                                                                 char* pstR = pR->string_get(i,j);
498                                                                 char* pstL = pL->string_get(i,j);
499                                                                 if(strcmp(pstL, pstR) == 0)
500                                                                 {
501                                                                         pResult->getAsBool()->bool_set(i,j,true);
502                                                                 }
503                                                                 else
504                                                                 {
505                                                                         pResult->getAsBool()->bool_set(i,j,false);
506                                                                 }
507                                                         }
508                                                 }
509                                         }
510                                         else
511                                         {
512                                                 pResult = new Bool(false);
513                                         }
514                                         result_set(pResult);
515                                 }
516                                 break;
517                         }
518                 case OpExp::ne :
519                         {
520                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
521                                 {
522                                         Double *pL                      = execMeL.result_get()->getAsDouble();
523                                         Double *pR                      = execMeR.result_get()->getAsDouble();
524
525                                         if(pR->size_get() == 1)
526                                         {
527                                                 pResult                         = new Bool(pL->rows_get(), pL->cols_get());
528                                                 double dblRef   = pR->real_get(0,0);
529                                                 for(int i = 0 ; i < pL->rows_get() ; i++)
530                                                 {
531                                                         for(int j = 0 ; j < pL->cols_get() ; j++)
532                                                         {
533                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) != dblRef);
534                                                         }
535                                                 }
536                                         }
537                                         else if(pL->size_get() == 1)
538                                         {
539                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
540                                                 double dblRef   = pL->real_get(0,0);
541                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
542                                                 {
543                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
544                                                         {
545                                                                 pResult->getAsBool()->bool_set(i, j, dblRef != pR->real_get(i, j));
546                                                         }
547                                                 }
548                                         }
549                                         else if(pR->rows_get() == pL->rows_get() && pR->cols_get() == pL->cols_get())
550                                         {
551                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
552                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
553                                                 {
554                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
555                                                         {
556                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) != pR->real_get(i, j));
557                                                         }
558                                                 }
559                                         }
560                                         else
561                                         {
562                                                 pResult = new Bool(false);
563                                         }
564
565                                         result_set(pResult);
566                                 }
567                                 break;
568                         }
569                 case OpExp::lt :
570                         {
571                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
572                                 {
573                                         Double *pL                      = execMeL.result_get()->getAsDouble();
574                                         Double *pR                      = execMeR.result_get()->getAsDouble();
575
576                                         if(pR->size_get() == 1)
577                                         {
578                                                 pResult                         = new Bool(pL->rows_get(), pL->cols_get());
579                                                 double dblRef   = pR->real_get(0,0);
580                                                 for(int i = 0 ; i < pL->rows_get() ; i++)
581                                                 {
582                                                         for(int j = 0 ; j < pL->cols_get() ; j++)
583                                                         {
584                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) < dblRef);
585                                                         }
586                                                 }
587                                         }
588                                         else if(pL->size_get() == 1)
589                                         {
590                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
591                                                 double dblRef   = pL->real_get(0,0);
592                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
593                                                 {
594                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
595                                                         {
596                                                                 pResult->getAsBool()->bool_set(i, j, dblRef < pR->real_get(i, j));
597                                                         }
598                                                 }
599                                         }
600                                         else if(pR->rows_get() == pL->rows_get() && pR->cols_get() == pL->cols_get())
601                                         {
602                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
603                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
604                                                 {
605                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
606                                                         {
607                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) < pR->real_get(i, j));
608                                                         }
609                                                 }
610                                         }
611                                         else
612                                         {
613                                                 pResult = new Bool(false);
614                                         }
615
616                                         result_set(pResult);
617                                 }
618                                 break;
619                         }
620                 case OpExp::le :
621                         {
622                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
623                                 {
624                                         Double *pL                      = execMeL.result_get()->getAsDouble();
625                                         Double *pR                      = execMeR.result_get()->getAsDouble();
626
627                                         if(pR->size_get() == 1)
628                                         {
629                                                 pResult                         = new Bool(pL->rows_get(), pL->cols_get());
630                                                 double dblRef   = pR->real_get(0,0);
631                                                 for(int i = 0 ; i < pL->rows_get() ; i++)
632                                                 {
633                                                         for(int j = 0 ; j < pL->cols_get() ; j++)
634                                                         {
635                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) <= dblRef);
636                                                         }
637                                                 }
638                                         }
639                                         else if(pL->size_get() == 1)
640                                         {
641                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
642                                                 double dblRef   = pL->real_get(0,0);
643                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
644                                                 {
645                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
646                                                         {
647                                                                 pResult->getAsBool()->bool_set(i, j, dblRef <= pR->real_get(i, j));
648                                                         }
649                                                 }
650                                         }
651                                         else if(pR->rows_get() == pL->rows_get() && pR->cols_get() == pL->cols_get())
652                                         {
653                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
654                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
655                                                 {
656                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
657                                                         {
658                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) <= pR->real_get(i, j));
659                                                         }
660                                                 }
661                                         }
662                                         else
663                                         {
664                                                 pResult = new Bool(false);
665                                         }
666
667                                         result_set(pResult);
668                                 }
669                                 break;
670                         }
671                 case OpExp::gt :
672                         {
673                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
674                                 {
675                                         Double *pL                      = execMeL.result_get()->getAsDouble();
676                                         Double *pR                      = execMeR.result_get()->getAsDouble();
677
678                                         if(pR->size_get() == 1)
679                                         {
680                                                 pResult                         = new Bool(pL->rows_get(), pL->cols_get());
681                                                 double dblRef   = pR->real_get(0,0);
682                                                 for(int i = 0 ; i < pL->rows_get() ; i++)
683                                                 {
684                                                         for(int j = 0 ; j < pL->cols_get() ; j++)
685                                                         {
686                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) > dblRef);
687                                                         }
688                                                 }
689                                         }
690                                         else if(pL->size_get() == 1)
691                                         {
692                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
693                                                 double dblRef   = pL->real_get(0,0);
694                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
695                                                 {
696                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
697                                                         {
698                                                                 pResult->getAsBool()->bool_set(i, j, dblRef > pR->real_get(i, j));
699                                                         }
700                                                 }
701                                         }
702                                         else if(pR->rows_get() == pL->rows_get() && pR->cols_get() == pL->cols_get())
703                                         {
704                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
705
706                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
707                                                 {
708                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
709                                                         {
710                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) > pR->real_get(i, j));
711                                                         }
712                                                 }
713                                         }
714                                         else
715                                         {
716                                                 pResult = new Bool(false);
717                                         }
718
719                                         result_set(pResult);
720                                 }
721                                 break;
722                         }
723                 case OpExp::ge :
724                         {
725                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
726                                 {
727                                         Double *pL                      = execMeL.result_get()->getAsDouble();
728                                         Double *pR                      = execMeR.result_get()->getAsDouble();
729
730                                         if(pR->size_get() == 1)
731                                         {
732                                                 pResult                         = new Bool(pL->rows_get(), pL->cols_get());
733                                                 double dblRef   = pR->real_get(0,0);
734                                                 for(int i = 0 ; i < pL->rows_get() ; i++)
735                                                 {
736                                                         for(int j = 0 ; j < pL->cols_get() ; j++)
737                                                         {
738                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) >= dblRef);
739                                                         }
740                                                 }
741                                         }
742                                         else if(pL->size_get() == 1)
743                                         {
744                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
745                                                 double dblRef   = pL->real_get(0,0);
746                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
747                                                 {
748                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
749                                                         {
750                                                                 pResult->getAsBool()->bool_set(i, j, dblRef >= pR->real_get(i, j));
751                                                         }
752                                                 }
753                                         }
754                                         else if(pR->rows_get() == pL->rows_get() && pR->cols_get() == pL->cols_get())
755                                         {
756                                                 pResult                         = new Bool(pR->rows_get(), pR->cols_get());
757                                                 for(int i = 0 ; i < pR->rows_get() ; i++)
758                                                 {
759                                                         for(int j = 0 ; j < pR->cols_get() ; j++)
760                                                         {
761                                                                 pResult->getAsBool()->bool_set(i, j, pL->real_get(i, j) >= pR->real_get(i, j));
762                                                         }
763                                                 }
764                                         }
765                                         else
766                                         {
767                                                 pResult = new Bool(false);
768                                         }
769
770                                         result_set(pResult);
771                                 }
772                                 break;
773                         }
774                 case OpExp::power :
775                         {
776                                 if(TypeL == GenericType::RealDouble && TypeR == GenericType::RealDouble)
777                                 {
778                                         Double *pL                      = execMeL.result_get()->getAsDouble();
779                                         Double *pR                      = execMeR.result_get()->getAsDouble();
780
781                                         int iResult = PowerDoubleByDouble(pL, pR, (Double**)&pResult);
782                                         if(iResult != 0)
783                                         {
784                                                 std::ostringstream os;
785                                                 os << _("Inconsistent row/column dimensions.\n");
786                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
787                                                 throw os.str();
788                                         }
789                                         result_set(pResult);
790                                 }
791                                 else if(TypeL == GenericType::RealPoly && TypeR == GenericType::RealDouble)
792                                 {
793                                         MatrixPoly *pL  = execMeL.result_get()->getAsPoly();
794                                         Double *pR                      = execMeR.result_get()->getAsDouble();
795
796                                         int iResult = PowerPolyByDouble(pL, pR, (MatrixPoly**)&pResult);
797                                         if(iResult != 0)
798                                         {
799                                                 std::ostringstream os;
800                                                 os << _("Inconsistent row/column dimensions.\n");
801                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
802                                                 throw os.str();
803                                         }
804                                         result_set(pResult);
805                                 }
806                                 else
807                                 {
808                                         throw _("Invalid input");
809                                 }
810                                 break;
811                         }
812                 default :
813                         break;
814                 }
815         }
816
817         template <class T>
818         void RunVisitorT<T>::visitprivate(const LogicalOpExp &e)
819         {
820                 T execMeL;
821                 T execMeR;
822
823                 symbol::Context *pContext = symbol::Context::getInstance();
824                 e.left_get().accept(execMeL);
825                 GenericType::RealType TypeL = execMeL.result_get()->getType();
826
827                 if(TypeL == GenericType::RealImplicitList)
828                 {
829                         ImplicitList* pIL = execMeL.result_get()->getAsImplicitList();
830                         if(pIL->computable())
831                         {
832                                 InternalType *pIT = pIL->extract_matrix();
833                                 execMeL.result_set(pIT);
834                                 TypeL = pIT->getType();
835                         }
836                 }
837
838
839                 InternalType *pResult = NULL;
840                 switch(e.oper_get())
841                 {
842                 case LogicalOpExp::logicalOr :
843                         {//
844                                 break;
845                         }
846                 case LogicalOpExp::logicalAnd :
847                         {
848                                 break;
849                         }
850                 case LogicalOpExp::logicalShortCutOr :
851                         {
852                                 if(TypeL == GenericType::RealBool)
853                                 {
854
855                                         Bool *pL        = execMeL.result_get()->getAsBool();
856                                         int *piL        = pL->bool_get();
857                                         int iL          = true;
858
859                                         for(int i = 0 ; i < pL->size_get() ; i++)
860                                         {
861                                                 if(piL[i] == 1)
862                                                 {
863                                                         iL = 1;
864                                                         break;
865                                                 }
866                                         }
867
868                                         if(iL)
869                                         {//we don't need to look at ohers exp
870                                                 pResult = new Bool(1);
871                                                 result_set(pResult);
872                                         }
873                                         else //look at others exp
874                                         {
875                                                 e.right_get().accept(execMeR);
876                                                 GenericType::RealType TypeR = execMeR.result_get()->getType();
877
878                                                 if(TypeR == GenericType::RealImplicitList)
879                                                 {
880                                                         ImplicitList* pIL = execMeR.result_get()->getAsImplicitList();
881                                                         if(pIL->computable())
882                                                         {
883                                                                 InternalType *pIT = pIL->extract_matrix();
884                                                                 execMeR.result_set(pIT);
885                                                                 TypeR = pIT->getType();
886                                                         }
887                                                 }
888
889                                                 if(TypeR == GenericType::RealBool)
890                                                 {
891                                                         Bool *pR        = execMeR.result_get()->getAsBool();
892                                                         int* piR = pR->bool_get();
893                                                         int* piL = pL->bool_get();
894
895                                                         if(pR->size_get() == 1)
896                                                         {
897                                                                 if(piR[0] == 1)
898                                                                 {
899                                                                         pResult = new Bool(1);
900                                                                         result_set(pResult);
901                                                                 }
902                                                                 else
903                                                                 {
904                                                                         int iState = 1;
905                                                                         for(int i = 0 ; i < pL->size_get() ; i++)
906                                                                         {
907                                                                                 if(piL[i] == 1)
908                                                                                 {
909                                                                                         iState = 0;
910                                                                                         break;
911                                                                                 }
912                                                                         }
913                                                                         pResult = new Bool(iState);
914                                                                         result_set(pResult);
915                                                                 }
916                                                         }
917                                                         else if(pL->size_get() == 1)
918                                                         {
919                                                                 if(piL[0] == 1)
920                                                                 {
921                                                                         pResult = new Bool(1);
922                                                                         result_set(pResult);
923                                                                 }
924                                                                 else
925                                                                 {
926                                                                         int iState = 1;
927                                                                         for(int i = 0 ; i < pR->size_get() ; i++)
928                                                                         {
929                                                                                 if(piR[i] == 0)
930                                                                                 {
931                                                                                         iState = 0;
932                                                                                         break;
933                                                                                 }
934                                                                         }
935                                                                         pResult = new Bool(iState);
936                                                                         result_set(pResult);
937                                                                 }
938                                                         }
939                                                         else if(pR->rows_get() == pL->rows_get() && pR->cols_get() == pL->cols_get())
940                                                         {
941                                                                 int* piB        = NULL;
942                                                                 int* piR        = pR->bool_get();
943                                                                 int* piL        = pL->bool_get();
944
945                                                                 pResult = new Bool(pR->rows_get(), pR->cols_get(), &piB);
946                                                                 for(int i = 0 ; i < pL->size_get(); i++)
947                                                                 {
948                                                                         piB[i] = (piR[i] == 1) || (piL[i] == 1);
949                                                                 }
950                                                                 result_set(pResult);
951                                                         }
952                                                         else
953                                                         {
954                                                                 std::ostringstream os;
955                                                                 os << _("Inconsistent row/column dimensions.\n");
956                                                                 os << ((Location)e.right_get().location_get()).location_string_get() << std::endl;
957                                                                 throw os.str();
958                                                         }
959                                                 }
960                                         }
961                                 }
962                                 else
963                                 {
964                                         //TODO YaSp : Overloading %*_g_*
965                                 }
966                                 break;
967                         }
968                 case LogicalOpExp::logicalShortCutAnd :
969                         {
970                                 break;
971                         }
972                 }
973         }
974 }
975