comparison pylearn/sandbox/scan_inputs_groups.py @ 852:d15683416ebf

some fix to the c code of FillMissing. It was not compiling.
author Frederic Bastien <nouiz@nouiz.org>
date Tue, 03 Nov 2009 09:50:54 -0500
parents db2c26a2c97c
children 08b3e827575a
comparison
equal deleted inserted replaced
851:ab7d598f5579 852:d15683416ebf
689 #for gcc 4.1 we also need '-funsafe-math-optimizations', not need for gcc 4.3. TODO find a way to return the value depending of the compiler used? 689 #for gcc 4.1 we also need '-funsafe-math-optimizations', not need for gcc 4.3. TODO find a way to return the value depending of the compiler used?
690 "-funsafe-math-optimizations" 690 "-funsafe-math-optimizations"
691 ] 691 ]
692 692
693 def c_headers(self): 693 def c_headers(self):
694 return ['"Python.h"', '"numpy/noprefix.h"', '<math.h>'] 694 return ['"Python.h"', '"numpy/noprefix.h"', '<math.h>', '<sstream>']
695 695
696 def c_support_code(self): 696 def c_support_code(self):
697 return """ 697 return """
698 using namespace std; 698 using namespace std;
699 """ 699 """
774 PyErr_SetString(PyExc_ValueError, "mask is not continuous in memory"); 774 PyErr_SetString(PyExc_ValueError, "mask is not continuous in memory");
775 %(fail)s; 775 %(fail)s;
776 } 776 }
777 } 777 }
778 778
779 assert(input->nd==value->nd==mask->nd); 779 if(input->nd!=value->nd || input->nd!=mask->nd){
780 PyErr_Format(PyExc_ValueError,
781 "FillMissing input have %%d dims, the mask have %%d dims and the value have %%d dims. They should all be equals \\n",
782 input->nd, value->nd, mask->nd);
783 %(fail)s;
784 }
780 #if %(self.fill_with_is_array)s 785 #if %(self.fill_with_is_array)s
781 if(input->nd==1){ 786 if(input->nd==1){
782 %(type)s* value_ = (%(type)s*)(value->data); 787 %(type)s* value_ = (%(type)s*)(value->data);
783 %(type)s* mask_ = (%(type)s*)(mask->data); 788 %(type)s* mask_ = (%(type)s*)(mask->data);
784 %(type)s* input_ = (%(type)s*)(input->data); 789 %(type)s* input_ = (%(type)s*)(input->data);
807 } 812 }
808 } 813 }
809 } 814 }
810 }else{//not implemented! 815 }else{//not implemented!
811 //SHOULD not happen as c_code should revert to the python version in that case 816 //SHOULD not happen as c_code should revert to the python version in that case
812 std:stringstream temp; 817 std::stringstream temp;
813 temp << "In FillMissing, we try to fill with an array and the input ndim is implemented only for 1 and 2. This case is not implemented."<<endl; 818 temp << "In FillMissing, we try to fill with an array and the input ndim is implemented only for 1 and 2. This case is not implemented."<<endl;
814 temp << " ndim="<<input->nd<<endl;; 819 temp << " ndim="<<input->nd<<endl;;
815 std::string param = temp.str(); 820 std::string param = temp.str();
816 PyErr_SetString(PyExc_ValueError, param.c_str()); 821 PyErr_SetString(PyExc_ValueError, param.c_str());
817 %(fail)s 822 %(fail)s
864 } 869 }
865 } 870 }
866 } 871 }
867 }else{//not implemented! 872 }else{//not implemented!
868 //SHOULD not happen as c_code should revert to the python version in that case 873 //SHOULD not happen as c_code should revert to the python version in that case
869 std:stringstream temp; 874 std::stringstream temp;
870 temp << "In FillMissing, we try to fill with a constant and the input ndim is implemented only for 1, 2 and 3."; 875 temp << "In FillMissing, we try to fill with a constant and the input ndim is implemented only for 1, 2 and 3.";
871 temp << " ndim="<<input->nd<<endl;; 876 temp << " ndim="<<input->nd<<endl;;
872 std::string param = temp.str(); 877 std::string param = temp.str();
873 PyErr_SetString(PyExc_ValueError, param.c_str()); 878 PyErr_SetString(PyExc_ValueError, param.c_str());
874 %(fail)s 879 %(fail)s