-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData.cpp
57 lines (41 loc) · 1.18 KB
/
Data.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "Data.h"
#pragma mark - Constructors and Destructors
Data::Data(int features) {
featureCount = features;
_features = (float*)malloc(sizeof(float)*features);
for (int i = 0; i < features; i++) {
_features[i] = 0;
}
}
Data::Data(int feature_count, float* features) {
featureCount = feature_count;
_features = (float*)malloc(sizeof(float)*feature_count);
for (int i = 0; i < feature_count; i++)
_features[i] = features[i];
}
Data::Data(const Data &oth) {
this->featureCount = oth.featureCount;
this->_features = (float*)malloc(sizeof(float)*oth.featureCount);
for (int i = 0; i < this->featureCount; i++)
this->_features[i] = oth._features[i];
}
Data::~Data() {
free(_features);
}
#pragma mark - Setters
void Data::setFeatures(int num_features, float* features) {
assert(num_features == featureCount);
for (int i = 0; i < num_features; i++)
_features[i] = features[i];
}
void Data::setFeaturesAtIndex(int index, float value) {
assert(index < featureCount);
_features[index] = value;
}
#pragma mark - Getters
float* Data::features() const {
return _features;
}
int Data::size() {
return featureCount;
}