Click here to Skip to main content
15,910,083 members
Home / Discussions / C#
   

C#

 
GeneralRe: random selection from a list Pin
james bradbery5-Mar-12 17:56
james bradbery5-Mar-12 17:56 
GeneralRe: random selection from a list Pin
RobCroll6-Mar-12 20:07
RobCroll6-Mar-12 20:07 
AnswerRe: random selection from a list Pin
BobJanova5-Mar-12 22:17
BobJanova5-Mar-12 22:17 
GeneralRe: random selection from a list Pin
james bradbery10-Mar-12 18:22
james bradbery10-Mar-12 18:22 
QuestionSlope method optimisation Pin
A*****5-Mar-12 14:51
A*****5-Mar-12 14:51 
AnswerRe: Slope method optimisation Pin
RobCroll5-Mar-12 18:24
RobCroll5-Mar-12 18:24 
AnswerRe: Slope method optimisation Pin
A*****5-Mar-12 23:12
A*****5-Mar-12 23:12 
AnswerRe: Slope method optimisation Pin
Luc Pattyn5-Mar-12 19:30
sitebuilderLuc Pattyn5-Mar-12 19:30 
No you can't avoid the two loops, you need the averages first, then the deviations, which you can't get without knowing the averages first.

IMO all you can do is clean up your code a bit, by:
- getting rid of the nullables, GetType() and typeof;
- not calling vals.Length three times;
- returning just the slope as a double;
- not calculating the intercept, unless you really need it, and then maybe provide the intercept as an out parameter (this saves the allocation of the double[2] array).


BTW: using >>1 to divide by 2 does not really help; compilers are smart enough to emit decent code to divide by 2.

BTW2: I have some doubts about the correctness of your line
double x = (double)(((numValues * (numValues - 1)) >> 1) - ((offset * (offset - 1)) >> 1));
it doesn't agree with my intuition, e.g. changing the value of offset from 0 to 1 would not change x at all??


Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum

GeneralRe: Slope method optimisation Pin
A*****5-Mar-12 23:17
A*****5-Mar-12 23:17 
AnswerRe: Slope method optimisation Pin
BobJanova5-Mar-12 22:04
BobJanova5-Mar-12 22:04 
QuestionSemantic music engine Pin
Abdul Salam Shaikh5-Mar-12 8:49
Abdul Salam Shaikh5-Mar-12 8:49 
AnswerRe: Semantic music engine Pin
PIEBALDconsult5-Mar-12 8:52
mvePIEBALDconsult5-Mar-12 8:52 
AnswerRe: Semantic music engine Pin
Pete O'Hanlon5-Mar-12 8:54
mvePete O'Hanlon5-Mar-12 8:54 
QuestionReturn Value From Async Call Pin
Kevin Marois5-Mar-12 6:15
professionalKevin Marois5-Mar-12 6:15 
AnswerRe: Return Value From Async Call Pin
Pete O'Hanlon5-Mar-12 6:45
mvePete O'Hanlon5-Mar-12 6:45 
AnswerRe: Return Value From Async Call Pin
Luc Pattyn5-Mar-12 8:12
sitebuilderLuc Pattyn5-Mar-12 8:12 
AnswerRe: Return Value From Async Call Pin
SledgeHammer015-Mar-12 10:08
SledgeHammer015-Mar-12 10:08 
GeneralRe: Return Value From Async Call Pin
Dave Kreskowiak5-Mar-12 11:34
mveDave Kreskowiak5-Mar-12 11:34 
AnswerRe: Return Value From Async Call Pin
Mycroft Holmes5-Mar-12 14:46
professionalMycroft Holmes5-Mar-12 14:46 
AnswerRe: Return Value From Async Call Pin
BobJanova5-Mar-12 22:01
BobJanova5-Mar-12 22:01 
QuestionWinform linked to Entity Data Model Pin
pmcm5-Mar-12 5:25
pmcm5-Mar-12 5:25 
QuestionVB input box in C# Pin
glennPattonWork35-Mar-12 5:23
professionalglennPattonWork35-Mar-12 5:23 
AnswerRe: VB input box in C# Pin
Richard MacCutchan5-Mar-12 5:30
mveRichard MacCutchan5-Mar-12 5:30 
AnswerRe: VB input box in C# Pin
DaveyM695-Mar-12 7:02
professionalDaveyM695-Mar-12 7:02 
AnswerRe: VB input box in C# Pin
Luc Pattyn5-Mar-12 8:16
sitebuilderLuc Pattyn5-Mar-12 8:16 

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.