Skip to content

Instantly share code, notes, and snippets.

@shu223
Created April 7, 2015 06:01
Show Gist options
  • Save shu223/b68bd4360eeb1b93b86e to your computer and use it in GitHub Desktop.
Save shu223/b68bd4360eeb1b93b86e to your computer and use it in GitHub Desktop.
Accelerate.frameworkを用いた平均値計算
//
// TTMArithmetic.m
//
// Copyright (c) 2015 Shuichi Tsutsumi. All rights reserved.
//
#import "TTMArithmetic.h"
@import Accelerate;
@implementation MOSArithmetic
- (double)mean:(NSArray *)values {
double x[[values count]];
for (int i=0; i<[values count]; i++) {
x[i] = [values[i] doubleValue];
}
double result = 0.0;
vDSP_meanvD(x, 1, &result, (vDSP_Length)[values count]);
return result;
}
- (float)meanf:(NSArray *)values {
float x[[values count]];
for (int i=0; i<[values count]; i++) {
x[i] = [values[i] floatValue];
}
float result = 0.0;
vDSP_meanv(x, 1, &result, (vDSP_Length)[values count]);
return result;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment