Click here to Skip to main content
15,889,266 members
Home / Discussions / C#
   

C#

 
GeneralRe: Generate sql select statement from another select statement Pin
Not Active18-Oct-09 16:24
mentorNot Active18-Oct-09 16:24 
GeneralRe: Generate sql select statement from another select statement Pin
AhmedMasum18-Oct-09 18:34
AhmedMasum18-Oct-09 18:34 
QuestionCode optimization Pin
tvbarnard18-Oct-09 2:14
tvbarnard18-Oct-09 2:14 
AnswerRe: Code optimization [modified] Pin
DaveyM6918-Oct-09 2:32
professionalDaveyM6918-Oct-09 2:32 
GeneralRe: Code optimization Pin
tvbarnard18-Oct-09 3:10
tvbarnard18-Oct-09 3:10 
GeneralRe: Code optimization Pin
DaveyM6918-Oct-09 3:25
professionalDaveyM6918-Oct-09 3:25 
AnswerRe: Code optimization Pin
Eddy Vluggen18-Oct-09 2:33
professionalEddy Vluggen18-Oct-09 2:33 
GeneralRe: Code optimization Pin
tvbarnard18-Oct-09 3:28
tvbarnard18-Oct-09 3:28 
Yes, that would be how it's done.

I have used a profiler, and it shows that my bottleneck is when I am processing each image array.

The code is very abstract, but I'll post it in any case.
unsafe
{
	fixed (int* pPosPoints = allFeatures[f].pointsPos, pNegPoints = allFeatures[f].pointsNeg)
	{
		for (int iP = 0; iP < boundPosImages; iP++)
		{
			featureValue = 0;
			fixed (double* pIntVec = posTrainingSet[iP].imageIntegralVectorDouble)
			{

				for (int i = 0; i < boundPointsPos; i++)
				{
					featureValue += *( pIntVec + *( pPosPoints + i ) );
				}
				for (int i = 0; i < boundPointsNeg; i++)
				{
					featureValue -= *( pIntVec + *( pNegPoints + i ) );
				}

				//classify:
				if (allFeatures[f].polarity)
				{
					if (featureValue < allFeatures[f].threshold)
						allFeatures[f].weightedError += posTrainingSet[iP].weight; //false postive
				}
				else if (allFeatures[f].threshold < featureValue)
					allFeatures[f].weightedError += posTrainingSet[iP].weight; //false postive
				}
			}


To explain: the "imageIntegralVectorDouble" is my image array which I have reshaped to a vector (so the vector is size 24x24= 576).

What is happening here is I am using a classifer that contains two arrays of points ("allFeatures[f].pointsPos" & "allFeatures[f].pointsNeg") that need to be either added or subtracted in that image. In other words each point is a location reference.

In this specific code, I decided to use pointers to reference the images and points (as can hopefully be seen)

What I might have left out from my original question (in order to prevent confusion) is that the system uses at least 200,000 classifiers, implying - each image has to be evaluated by all of those classifiers. Which makes the reason for trying to optimize the code fairly obvious.

Most of the processing time is spent on the first two for-loops. I suppose this is the area to try and optimize.

tvb

GeneralRe: Code optimization Pin
Eddy Vluggen18-Oct-09 3:37
professionalEddy Vluggen18-Oct-09 3:37 
GeneralRe: Code optimization Pin
tvbarnard18-Oct-09 3:52
tvbarnard18-Oct-09 3:52 
GeneralRe: Code optimization Pin
Luc Pattyn19-Oct-09 4:21
sitebuilderLuc Pattyn19-Oct-09 4:21 
GeneralRe: Code optimization Pin
tvbarnard19-Oct-09 5:09
tvbarnard19-Oct-09 5:09 
GeneralRe: Code optimization Pin
Luc Pattyn19-Oct-09 5:37
sitebuilderLuc Pattyn19-Oct-09 5:37 
GeneralRe: Code optimization Pin
tvbarnard19-Oct-09 6:02
tvbarnard19-Oct-09 6:02 
GeneralRe: Code optimization Pin
Luc Pattyn19-Oct-09 6:40
sitebuilderLuc Pattyn19-Oct-09 6:40 
GeneralRe: Code optimization Pin
tvbarnard19-Oct-09 6:55
tvbarnard19-Oct-09 6:55 
GeneralRe: Code optimization Pin
Luc Pattyn19-Oct-09 7:06
sitebuilderLuc Pattyn19-Oct-09 7:06 
GeneralRe: Code optimization Pin
tvbarnard19-Oct-09 7:41
tvbarnard19-Oct-09 7:41 
GeneralRe: Code optimization Pin
Luc Pattyn19-Oct-09 12:45
sitebuilderLuc Pattyn19-Oct-09 12:45 
AnswerRe: Code optimization Pin
tvbarnard20-Oct-09 1:33
tvbarnard20-Oct-09 1:33 
GeneralRe: Code optimization Pin
Luc Pattyn20-Oct-09 1:40
sitebuilderLuc Pattyn20-Oct-09 1:40 
GeneralRe: Code optimization Pin
tvbarnard20-Oct-09 6:50
tvbarnard20-Oct-09 6:50 
GeneralRe: Code optimization Pin
Luc Pattyn20-Oct-09 6:53
sitebuilderLuc Pattyn20-Oct-09 6:53 
GeneralRe: Code optimization Pin
tvbarnard20-Oct-09 6:55
tvbarnard20-Oct-09 6:55 
GeneralRe: Code optimization Pin
Luc Pattyn18-Oct-09 11:24
sitebuilderLuc Pattyn18-Oct-09 11:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.