18 #ifndef DOUBLE_VECTOR_H
19 #define DOUBLE_VECTOR_H
30 #ifndef KMEANS_EPSILON
31 #define KMEANS_EPSILON 2.22045e-16
59 double* rawData =
data->c_ptr();
60 if (dataToMe.size() >=
size) {
61 for (
int i = 0; i <
size; i++) {
62 rawData[i] = dataToMe[i];
65 std::cout <<
"my size is " <<
size <<
", and input's size is " << dataToMe.size()
80 if (
data ==
nullptr) {
90 std::cout <<
"Error in DoubleVector: Cannot get the value at the pos " << i
101 std::cout <<
"Error in DoubleVector: Cannot assign the value " << val <<
"to the pos "
112 double* rawData =
data->c_ptr();
113 size_t mySize = this->
getSize();
114 for (
int i = 0; i < mySize; i++) {
115 norm += rawData[i] * rawData[i];
123 size_t mySize = this->
size;
124 double* rawData =
data->c_ptr();
127 for (
size_t i = 0; i < mySize; i++) {
128 dotSum += rawData[i] * otherRawData[i];
136 size_t mySize = this->
getSize();
137 size_t otherSize = other.
getSize();
138 double* rawData =
data->c_ptr();
140 if (mySize != otherSize) {
141 std::cout <<
"Error in DoubleVector: dot size doesn't match" << std::endl;
146 while (kv < mySize) {
147 double score = rawData[kv] - otherRawData[kv];
148 distance += score * score;
156 double* rawData =
data->c_ptr();
157 for (
int i = 0; i < this->
getSize(); i++) {
158 std::cout << i <<
": " << rawData[i] <<
"; ";
160 std::cout << std::endl;
167 double precision = 0.00001;
168 double myNorm =
norm;
169 double otherNorm = other.
norm;
170 double sumSquaredNorm = myNorm * myNorm + otherNorm * otherNorm;
171 double normDiff = myNorm - otherNorm;
173 double precisionBound1 =
175 if (precisionBound1 < precision) {
176 sqDist = sumSquaredNorm - 2.0 *
dot(other);
189 size_t mySize = this->
getSize();
195 double* rawData =
data->c_ptr();
197 int blockSize = 1024;
198 int numBlocks = mySize / blockSize;
199 int remainder = mySize % blockSize;
200 for (
int i = 0; i < numBlocks; i++) {
201 for (
int j = 0; j < blockSize; j++) {
202 rawData[i * blockSize + j] += otherRawData[i * blockSize + j];
205 for (
int i = 0; i < remainder; i++) {
206 rawData[numBlocks * blockSize + i] += otherRawData[numBlocks * blockSize + i];
214 std::cout <<
"Error in DoubleVector: division by zero" << std::endl;
217 size_t mySize = this->
getSize();
219 double* rawData =
data->c_ptr();
220 double* otherRawData = result->getRawData();
221 for (
int i = 0; i < mySize; i++) {
222 otherRawData[i] = rawData[i] / val;
231 double* rawData =
data->c_ptr();
232 size_t mySize = this->
getSize();
233 for (
int i = mySize - 1; i >= 0; i--) {
234 int j = rand() % mySize;
235 double tmp = rawData[j];
236 rawData[j] = rawData[i];
243 size_t mySize = this->
size;
244 size_t otherSize = other->getSize();
245 if (mySize != otherSize) {
249 double* otherRawData = other->getRawData();
250 for (
int i = 0; i < mySize; i++) {
251 if (rawData[i] != otherRawData[i]) {
DoubleVector & operator/(int val)
double getSquaredDistance(DoubleVector &other)
DoubleVector & randomizeInPlace()
Handle< Vector< double > > & getData()
bool equals(Handle< DoubleVector > &other)
double dot(DoubleVector &other)
DoubleVector & operator+(DoubleVector &other)
DoubleVector(size_t size)
Handle< Vector< double > > data
void setValues(std::vector< double > dataToMe)
void setDouble(int i, double val)
double getFastSquaredDistance(DoubleVector &other)