提交 6dee58f9 编写于 作者: P peng.xu

Merge branch 'branch-0.5.0' into 'branch-0.5.0'

refine code

See merge request megasearch/milvus!689

Former-commit-id: 657055f806487253a110dffafbcc33b451e559b5
......@@ -765,8 +765,8 @@ NsgIndex::SetKnnGraph(Graph& g) {
}
// void NsgIndex::GetKnnGraphFromFile() {
// //std::string filename = "/home/zilliz/opt/workspace/wook/efanna_graph/tests/sift.1M.50NN.graph";
// std::string filename = "/home/zilliz/opt/workspace/wook/efanna_graph/tests/sift.50NN.graph";
// //std::string filename = "sift.1M.50NN.graph";
// std::string filename = "sift.50NN.graph";
//
// std::ifstream in(filename, std::ios::binary);
// unsigned k;
......
......@@ -9,12 +9,6 @@ cd cmake_build
INSTALL_PREFIX=$(pwd)/../../build
BOOST_PATH="/home/zilliz/opt/app/boost"
TBB_PATH="/home/zilliz/opt/app/tbb/tbb"
OPTION="-DBOOST_ROOT=$BOOST_PATH -DTBB_DIR=${TBB_PATH}"
# CMAKE_CMD="cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} ${OPTION} ../"
CMAKE_CMD="cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} ../"
${CMAKE_CMD}
......
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "knowhere/common/config.h"
int
main() {
knowhere::Config cfg;
cfg["size"] = size_t(199);
auto size = cfg.get_with_default("size", 123);
auto size_2 = cfg["size"].as<int>();
printf("%d", size_2);
}
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include <fstream>
#include <iostream>
#include "knowhere/index/index.h"
#include "test/utils.h"
//#include <gperftools/profiler.h>
void
load_data(std::string& filename, float*& data, unsigned& num,
unsigned& dim) { // load data with sift10K pattern
std::ifstream in(filename, std::ios::binary);
if (!in.is_open()) {
std::cout << "open file error" << std::endl;
exit(-1);
}
in.read((char*)&dim, 4);
in.seekg(0, std::ios::end);
std::ios::pos_type ss = in.tellg();
size_t fsize = (size_t)ss;
num = (unsigned)(fsize / (dim + 1) / 4);
data = new float[(size_t)num * (size_t)dim];
in.seekg(0, std::ios::beg);
for (size_t i = 0; i < num; i++) {
in.seekg(4, std::ios::cur);
in.read((char*)(data + i * dim), dim * 4);
}
in.close();
}
void
test_distance() {
std::vector<float> xb{1, 2, 3, 4};
std::vector<float> xq{2, 2, 3, 4};
float r = calculate(xb.data(), xq.data(), 4);
std::cout << r << std::endl;
}
int
main() {
test_distance();
BuildParams params;
params.search_length = 100;
params.candidate_pool_size = 100;
params.out_degree = 50;
float* data = nullptr;
int64_t* ids = nullptr;
unsigned ntotal, dim;
std::string filename = "/home/zilliz/opt/workspace/wook/efanna_graph/tests/siftsmall/siftsmall_base.fvecs";
// std::string filename = "/home/zilliz/opt/workspace/wook/efanna_graph/tests/sift/sift_base.fvecs";
load_data(filename, data, ntotal, dim);
assert(data);
// float x = calculate(data + dim * 0, data + dim * 62, dim);
// std::cout << x << std::endl;
NsgIndex index(dim, ntotal);
auto s = std::chrono::high_resolution_clock::now();
index.Build_with_ids(ntotal, data, ids, params);
auto e = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = e - s;
std::cout << "indexing time: " << diff.count() << "\n";
int k = 10;
int nq = 1000;
SearchParams s_params;
s_params.search_length = 50;
auto dist = new float[nq * k];
auto ids_b = new int64_t[nq * k];
s = std::chrono::high_resolution_clock::now();
// ProfilerStart("xx.prof");
index.Search(data, nq, dim, k, dist, ids_b, s_params);
// ProfilerStop();
e = std::chrono::high_resolution_clock::now();
diff = e - s;
std::cout << "search time: " << diff.count() << "\n";
for (int i = 0; i < k; ++i) {
std::cout << "id " << ids_b[i] << std::endl;
// std::cout << "dist " << dist[i] << std::endl;
}
delete[] dist;
delete[] ids_b;
return 0;
}
......@@ -107,13 +107,13 @@ TEST(UtilTest, COMMON_TEST) {
}
TEST(UtilTest, STRINGFUNCTIONS_TEST) {
std::string str = " test zilliz";
std::string str = " test str";
milvus::server::StringHelpFunctions::TrimStringBlank(str);
ASSERT_EQ(str, "test zilliz");
ASSERT_EQ(str, "test str");
str = "\"test zilliz\"";
str = "\"test str\"";
milvus::server::StringHelpFunctions::TrimStringQuote(str, "\"");
ASSERT_EQ(str, "test zilliz");
ASSERT_EQ(str, "test str");
str = "a,b,c";
std::vector<std::string> result;
......@@ -376,7 +376,7 @@ TEST(UtilTest, ROLLOUTHANDLER_TEST) {
std::ofstream file;
file.open(tmp.c_str());
file << "zilliz" << std::endl;
file << "test" << std::endl;
milvus::server::RolloutHandler(tmp.c_str(), 0, list[i]);
......@@ -386,7 +386,7 @@ TEST(UtilTest, ROLLOUTHANDLER_TEST) {
std::string tmp2;
file2 >> tmp2;
ASSERT_EQ(tmp2, "zilliz");
ASSERT_EQ(tmp2, "test");
}
boost::filesystem::remove_all(dir2);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册