︙ | | | ︙ | |
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
dimension = dimension_;
data = [self allocMemoryForNItems: dimension
withSize: sizeof(float)];
for (i = 0; i < dimension; i++)
data[i] = va_arg(arguments, double);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|
|
|
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
dimension = dimension_;
data = [self allocMemoryForNItems: dimension
withSize: sizeof(float)];
for (i = 0; i < dimension; i++)
data[i] = (float)va_arg(arguments, double);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|
︙ | | | ︙ | |
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
{
return dimension;
}
- (BOOL)isEqual: (id)object
{
OFFloatVector *otherVector;
size_t i;
if (object->isa != isa)
return NO;
otherVector = object;
if (otherVector->dimension != dimension)
return NO;
for (i = 0; i < dimension; i++)
if (otherVector->data[i] != data[i])
return NO;
return YES;
}
- (uint32_t)hash
{
size_t i;
|
<
<
|
|
|
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
{
return dimension;
}
- (BOOL)isEqual: (id)object
{
OFFloatVector *otherVector;
if (object->isa != isa)
return NO;
otherVector = object;
if (otherVector->dimension != dimension)
return NO;
if (memcmp(otherVector->data, data, dimension * sizeof(float)))
return NO;
return YES;
}
- (uint32_t)hash
{
size_t i;
|
︙ | | | ︙ | |
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
OF_HASH_FINALIZE(hash);
return hash;
}
- copy
{
OFFloatVector *copy = [[isa alloc] init];
copy->dimension = dimension;
copy->data = [copy allocMemoryForNItems: dimension
withSize: sizeof(float)];
memcpy(copy->data, data, dimension * sizeof(float));
return copy;
}
- (OFString*)description
{
|
|
<
<
<
|
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
OF_HASH_FINALIZE(hash);
return hash;
}
- copy
{
OFFloatVector *copy = [[isa alloc] initWithDimension: dimension];
memcpy(copy->data, data, dimension * sizeof(float));
return copy;
}
- (OFString*)description
{
|
︙ | | | ︙ | |
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
* to be OFString*, so it can't be modified anyway. But not swizzling it
* would create a real copy each time -[copy] is called.
*/
description->isa = [OFString class];
return description;
}
- (float*)floatArray
{
return data;
}
- (void)addVector: (OFFloatVector*)vector
{
size_t i;
|
|
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
* to be OFString*, so it can't be modified anyway. But not swizzling it
* would create a real copy each time -[copy] is called.
*/
description->isa = [OFString class];
return description;
}
- (float*)cArray
{
return data;
}
- (void)addVector: (OFFloatVector*)vector
{
size_t i;
|
︙ | | | ︙ | |
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
float dotProduct;
size_t i;
if (vector->isa != isa || vector->dimension != dimension)
@throw [OFInvalidArgumentException newWithClass: isa
selector: _cmd];
dotProduct = 0.0;
for (i = 0; i < dimension; i++)
dotProduct += data[i] * vector->data[i];
return dotProduct;
}
- (float)magnitude
{
float magnitude;
size_t i;
magnitude = 0.0;
for (i = 0; i < dimension; i++)
magnitude += data[i] * data[i];
magnitude = sqrtf(magnitude);
return magnitude;
|
|
|
|
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
float dotProduct;
size_t i;
if (vector->isa != isa || vector->dimension != dimension)
@throw [OFInvalidArgumentException newWithClass: isa
selector: _cmd];
dotProduct = 0.0f;
for (i = 0; i < dimension; i++)
dotProduct += data[i] * vector->data[i];
return dotProduct;
}
- (float)magnitude
{
float magnitude;
size_t i;
magnitude = 0.0f;
for (i = 0; i < dimension; i++)
magnitude += data[i] * data[i];
magnitude = sqrtf(magnitude);
return magnitude;
|
︙ | | | ︙ | |