Re: Create new instance of Python class in C
phil hunt enlightened us with: Why do you need to maske lots of copies? The puzzles are stored in a NxN list of strings. The strings contain all the numerals that that block can contain. So a 9x9 puzzle contains 81 strings 123456789 when it's empty. My creation function picks a block that isn't a given, and fixes it to one of it's possible values. It then tries to solve the puzzle. If it works, it's done creating the puzzle. If it doesn't work, it starts over again in a recursive manner. The solver solves the puzzle in-place. That means that if I want to keep the original puzzle (the one that could be solved), I have to make a copy. And when you say lots of what numbers do you mean? 100? 100? That depends a lot. The parts picks a block that isn't a given and fixes it to one if it's possible values are both randomized. Sometimes it's 100, sometimes it's 5. The reason I ask is I recently wrote a program to solve Sudoku puzzles, and IIRC it didn't make copies at all. My solver doesn't create copies either. The creator does. I think I'll change my algorithm to just solve the puzzle and don't care about the original minimal puzzle that could be solved. I'll create a fully solved puzzle, and then use another routine to remove givens at random until the required number of givens is left. Of course, still maintaining solvability. That last part would require copying, but not as much as in the current situation. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Create new instance of Python class in C
Hi people, I'm creating a program that can solve and create Sudoku puzzles. My creation function needs to make a lot of copies of a puzzle. Until now, I used copy.deepcopy(), but that's too slow. I want to implement such a copying function in C and use that instead. My idea about this is: - Get the data from a puzzle (a list containing lists containing strings) and make a copy of it. That's coded already. - Create a new SodokuPuzzle instance and assign the data to it. That last step can be done by passing the data to the constructor, so that's easy too once I know how to do that in C. My question is: how do I create a new instance in C of a class written in Python? I've searched Google, but found nothing of help. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: Create new instance of Python class in C
Sybren Stuvel wrote: Hi people, I'm creating a program that can solve and create Sudoku puzzles. My creation function needs to make a lot of copies of a puzzle. Until now, I used copy.deepcopy(), but that's too slow. I want to implement such a copying function in C and use that instead. My idea about this is: - Get the data from a puzzle (a list containing lists containing strings) and make a copy of it. That's coded already. - Create a new SodokuPuzzle instance and assign the data to it. That last step can be done by passing the data to the constructor, so that's easy too once I know how to do that in C. My question is: how do I create a new instance in C of a class written in Python? I've searched Google, but found nothing of help. Sybren Personally, I would try Psyco first, and consider Pyrex next. Are you sure your algorithm can't be optimized first, before you start trying to write this in C? -Don -- http://mail.python.org/mailman/listinfo/python-list
Re: Create new instance of Python class in C
djw enlightened us with: Personally, I would try Psyco first, and consider Pyrex next. Ok, I'll take a look at those. Are you sure your algorithm can't be optimized first, before you start trying to write this in C? I'm sure there will be optimizations, but profiling showed that the copying of the puzzles took the most time. Since the copy.deepcopy() function is implemented it Python, I'd thought it would get quite a speed boost when done in C instead. As a side-question: how would I go about compiling my C module in Windows, if I want to ship a Windows version? Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: Create new instance of Python class in C
On Fri, 9 Sep 2005 17:19:21 +0200, Sybren Stuvel [EMAIL PROTECTED] wrote: Hi people, I'm creating a program that can solve and create Sudoku puzzles. My creation function needs to make a lot of copies of a puzzle. Why do you need to maske lots of copies? And when you say lots of what numbers do you mean? 100? 100? The reason I ask is I recently wrote a program to solve Sudoku puzzles, and IIRC it didn't make copies at all. -- Email: zen19725 at zen dot co dot uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Create new instance of Python class in C
On Fri, 9 Sep 2005 18:50:26 +0200, Sybren Stuvel [EMAIL PROTECTED] wrote: djw enlightened us with: Personally, I would try Psyco first, and consider Pyrex next. Ok, I'll take a look at those. Are you sure your algorithm can't be optimized first, before you start trying to write this in C? I'm sure there will be optimizations, but profiling showed that the copying of the puzzles took the most time. Since the copy.deepcopy() function is implemented it Python, I'd thought it would get quite a speed boost when done in C instead. Can you use a different algorithm that doesn't make so many copies? -- Email: zen19725 at zen dot co dot uk -- http://mail.python.org/mailman/listinfo/python-list