update VS project, fixed some bugs in dataset interface

This commit is contained in:
Guolin Ke 2016-11-08 18:56:02 +08:00
Родитель fa643b3d03
Коммит 4a6bdcbeeb
6 изменённых файлов: 81 добавлений и 45 удалений

Просмотреть файл

@ -396,45 +396,45 @@ inline void SortForPair(std::vector<T1>& keys, std::vector<T2>& values, size_t s
inline std::function<std::vector<double>(int row_idx)>
RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int float_type, int is_row_major) {
if (float_type == 0) {
const float* dptr = reinterpret_cast<const float*>(data);
const float* data_ptr = reinterpret_cast<const float*>(data);
if (is_row_major) {
return [&dptr, &num_col, &num_row](int row_idx) {
return [data_ptr, num_col, num_row](int row_idx) {
CHECK(row_idx < num_row);
std::vector<double> ret;
dptr += num_col * row_idx;
auto tmp_ptr = data_ptr + num_col * row_idx;
for (int i = 0; i < num_col; ++i) {
ret.push_back(static_cast<double>(*(dptr + i)));
ret.push_back(static_cast<double>(*(tmp_ptr + i)));
}
return ret;
};
} else {
return [&dptr, &num_col, &num_row](int row_idx) {
return [data_ptr, num_col, num_row](int row_idx) {
CHECK(row_idx < num_row);
std::vector<double> ret;
for (int i = 0; i < num_col; ++i) {
ret.push_back(static_cast<double>(*(dptr + num_row * i + row_idx)));
ret.push_back(static_cast<double>(*(data_ptr + num_row * i + row_idx)));
}
return ret;
};
}
} else {
const double* dptr = reinterpret_cast<const double*>(data);
const double* data_ptr = reinterpret_cast<const double*>(data);
if (is_row_major) {
return [&dptr, &num_col, &num_row](int row_idx) {
return [data_ptr, num_col, num_row](int row_idx) {
CHECK(row_idx < num_row);
std::vector<double> ret;
dptr += num_col * row_idx;
auto tmp_ptr = data_ptr + num_col * row_idx;
for (int i = 0; i < num_col; ++i) {
ret.push_back(static_cast<double>(*(dptr + i)));
ret.push_back(static_cast<double>(*(tmp_ptr + i)));
}
return ret;
};
} else {
return [&dptr, &num_col, &num_row](int row_idx) {
return [data_ptr, num_col, num_row](int row_idx) {
CHECK(row_idx < num_row);
std::vector<double> ret;
for (int i = 0; i < num_col; ++i) {
ret.push_back(static_cast<double>(*(dptr + num_row * i + row_idx)));
ret.push_back(static_cast<double>(*(data_ptr + num_row * i + row_idx)));
}
return ret;
};
@ -445,45 +445,45 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int float
inline std::function<std::vector<std::pair<int, double>>(int row_idx)>
RowPairFunctionFromDenseMatric(const void* data, int num_row, int num_col, int float_type, int is_row_major) {
if (float_type == 0) {
const float* dptr = reinterpret_cast<const float*>(data);
const float* data_ptr = reinterpret_cast<const float*>(data);
if (is_row_major) {
return [&dptr, &num_col, &num_row](int row_idx) {
return [data_ptr, num_col, num_row](int row_idx) {
CHECK(row_idx < num_row);
std::vector<std::pair<int, double>> ret;
dptr += num_col * row_idx;
auto tmp_ptr = data_ptr + num_col * row_idx;
for (int i = 0; i < num_col; ++i) {
ret.emplace_back(i, static_cast<double>(*(dptr + i)));
ret.emplace_back(i, static_cast<double>(*(tmp_ptr + i)));
}
return ret;
};
} else {
return [&dptr, &num_col, &num_row](int row_idx) {
return [data_ptr, num_col, num_row](int row_idx) {
CHECK(row_idx < num_row);
std::vector<std::pair<int, double>> ret;
for (int i = 0; i < num_col; ++i) {
ret.emplace_back(i, static_cast<double>(*(dptr + num_row * i + row_idx)));
ret.emplace_back(i, static_cast<double>(*(data_ptr + num_row * i + row_idx)));
}
return ret;
};
}
} else {
const double* dptr = reinterpret_cast<const double*>(data);
const double* data_ptr = reinterpret_cast<const double*>(data);
if (is_row_major) {
return [&dptr, &num_col, &num_row](int row_idx) {
return [data_ptr, num_col, num_row](int row_idx) {
CHECK(row_idx < num_row);
std::vector<std::pair<int, double>> ret;
dptr += num_col * row_idx;
auto tmp_ptr = data_ptr + num_col * row_idx;
for (int i = 0; i < num_col; ++i) {
ret.emplace_back(i, static_cast<double>(*(dptr + i)));
ret.emplace_back(i, static_cast<double>(*(tmp_ptr + i)));
}
return ret;
};
} else {
return [&dptr, &num_col, &num_row](int row_idx) {
return [data_ptr, num_col, num_row](int row_idx) {
CHECK(row_idx < num_row);
std::vector<std::pair<int, double>> ret;
for (int i = 0; i < num_col; ++i) {
ret.emplace_back(i, static_cast<double>(*(dptr + num_row * i + row_idx)));
ret.emplace_back(i, static_cast<double>(*(data_ptr + num_row * i + row_idx)));
}
return ret;
};
@ -494,28 +494,28 @@ RowPairFunctionFromDenseMatric(const void* data, int num_row, int num_col, int f
inline std::function<std::vector<std::pair<int, double>>(int idx)>
RowFunctionFromCSR(const int32_t* indptr, const int32_t* indices, const void* data, int float_type, uint64_t nindptr, uint64_t nelem) {
if (float_type == 0) {
const float* dptr = reinterpret_cast<const float*>(data);
return [&indptr, &indices, &dptr, &nindptr, &nelem](int idx) {
const float* data_ptr = reinterpret_cast<const float*>(data);
return [indptr, indices, data_ptr, nindptr, nelem](int idx) {
CHECK(idx + 1 < nindptr);
std::vector<std::pair<int, double>> ret;
int32_t start = indptr[idx];
int32_t end = indptr[idx + 1];
CHECK(start >= 0 && end < nelem);
for (int32_t i = start; i < end; ++i) {
ret.emplace_back(indices[i], dptr[i]);
for (int32_t i = start; i <= end; ++i) {
ret.emplace_back(indices[i], data_ptr[i]);
}
return ret;
};
} else {
const double* dptr = reinterpret_cast<const double*>(data);
return [&indptr, &indices, &dptr, &nindptr, &nelem](int idx) {
const double* data_ptr = reinterpret_cast<const double*>(data);
return [indptr, indices, data_ptr, nindptr, nelem](int idx) {
CHECK(idx + 1 < nindptr);
std::vector<std::pair<int, double>> ret;
int32_t start = indptr[idx];
int32_t end = indptr[idx + 1];
CHECK(start >= 0 && end < nelem);
CHECK(start >= 0 && end <= nelem);
for (int32_t i = start; i < end; ++i) {
ret.emplace_back(indices[i], dptr[i]);
ret.emplace_back(indices[i], data_ptr[i]);
}
return ret;
};
@ -525,28 +525,28 @@ RowFunctionFromCSR(const int32_t* indptr, const int32_t* indices, const void* da
inline std::function<std::vector<std::pair<int, double>>(int idx)>
ColumnFunctionFromCSC(const int32_t* col_ptr, const int32_t* indices, const void* data, int float_type, uint64_t ncol_ptr, uint64_t nelem) {
if (float_type == 0) {
const float* dptr = reinterpret_cast<const float*>(data);
return [&col_ptr, &indices, &dptr, &ncol_ptr, &nelem](int idx) {
const float* data_ptr = reinterpret_cast<const float*>(data);
return [col_ptr, indices, data_ptr, ncol_ptr, nelem](int idx) {
CHECK(idx + 1 < ncol_ptr);
std::vector<std::pair<int, double>> ret;
int32_t start = col_ptr[idx];
int32_t end = col_ptr[idx + 1];
CHECK(start >= 0 && end < nelem);
CHECK(start >= 0 && end <= nelem);
for (int32_t i = start; i < end; ++i) {
ret.emplace_back(indices[i], dptr[i]);
ret.emplace_back(indices[i], data_ptr[i]);
}
return ret;
};
} else {
const double* dptr = reinterpret_cast<const double*>(data);
return [&col_ptr, &indices, &dptr, &ncol_ptr, &nelem](int idx) {
const double* data_ptr = reinterpret_cast<const double*>(data);
return [col_ptr, indices, data_ptr, ncol_ptr, nelem](int idx) {
CHECK(idx + 1 < ncol_ptr);
std::vector<std::pair<int, double>> ret;
int32_t start = col_ptr[idx];
int32_t end = col_ptr[idx + 1];
CHECK(start >= 0 && end < nelem);
CHECK(start >= 0 && end <= nelem);
for (int32_t i = start; i < end; ++i) {
ret.emplace_back(indices[i], dptr[i]);
ret.emplace_back(indices[i], data_ptr[i]);
}
return ret;
};

Просмотреть файл

@ -33,6 +33,9 @@ Application::Application(int argc, char** argv)
if (config_.num_threads > 0) {
omp_set_num_threads(config_.num_threads);
}
if (config_.io_config.data_filename.size() == 0) {
Log::Fatal("No training/prediction data, application quit");
}
}
Application::~Application() {

Просмотреть файл

@ -186,10 +186,7 @@ void IOConfig::Set(const std::unordered_map<std::string, std::string>& params) {
CHECK(max_bin > 0);
GetInt(params, "num_class", &num_class);
GetInt(params, "data_random_seed", &data_random_seed);
if (!GetString(params, "data", &data_filename)) {
Log::Fatal("No training/prediction data, application quit");
}
GetString(params, "data", &data_filename);
GetInt(params, "verbose", &verbosity);
GetInt(params, "num_model_predict", &num_model_predict);
GetInt(params, "bin_construct_sample_cnt", &bin_construct_sample_cnt);

Просмотреть файл

@ -437,6 +437,7 @@ Dataset* DatasetLoader::CostructFromSampleData(std::vector<std::vector<double>>&
delete bin_mappers[i];
}
}
dataset->num_features_ = static_cast<int>(dataset->features_.size());
dataset->metadata_.Init(dataset->num_data_, dataset->num_class_, NO_SPECIFIC, NO_SPECIFIC);
return dataset;
}

Просмотреть файл

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LightGBM", "LightGBM.vcxproj", "{F31C0B5D-715E-4953-AA1B-8D2AEEE4344C}"
EndProject
@ -9,6 +9,7 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_mpi|x64 = Debug_mpi|x64
Debug|x64 = Debug|x64
DLL|x64 = DLL|x64
Release_mpi|x64 = Release_mpi|x64
Release|x64 = Release|x64
EndGlobalSection
@ -17,6 +18,8 @@ Global
{F31C0B5D-715E-4953-AA1B-8D2AEEE4344C}.Debug_mpi|x64.Build.0 = Debug_mpi|x64
{F31C0B5D-715E-4953-AA1B-8D2AEEE4344C}.Debug|x64.ActiveCfg = Debug|x64
{F31C0B5D-715E-4953-AA1B-8D2AEEE4344C}.Debug|x64.Build.0 = Debug|x64
{F31C0B5D-715E-4953-AA1B-8D2AEEE4344C}.DLL|x64.ActiveCfg = DLL|x64
{F31C0B5D-715E-4953-AA1B-8D2AEEE4344C}.DLL|x64.Build.0 = DLL|x64
{F31C0B5D-715E-4953-AA1B-8D2AEEE4344C}.Release_mpi|x64.ActiveCfg = Release_mpi|x64
{F31C0B5D-715E-4953-AA1B-8D2AEEE4344C}.Release_mpi|x64.Build.0 = Release_mpi|x64
{F31C0B5D-715E-4953-AA1B-8D2AEEE4344C}.Release|x64.ActiveCfg = Release|x64

Просмотреть файл

@ -9,6 +9,10 @@
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="DLL|x64">
<Configuration>DLL</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release_mpi|x64">
<Configuration>Release_mpi</Configuration>
<Platform>x64</Platform>
@ -35,6 +39,10 @@
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL|x64'" Label="Configuration">
<PlatformToolset>v120</PlatformToolset>
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
@ -71,6 +79,10 @@
<LibraryPath>$(MSMPI_LIB64);$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);</LibraryPath>
<TargetName>lightgbm</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DLL|x64'">
<IncludePath>..\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<TargetName>lib_lightgbm</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_mpi|x64'">
<ClCompile>
<PreprocessorDefinitions>USE_MPI</PreprocessorDefinitions>
@ -154,6 +166,26 @@
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DLL|x64'">
<ClCompile>
<PreprocessorDefinitions>USE_SOCKET;_MBCS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level4</WarningLevel>
<OpenMPSupport>true</OpenMPSupport>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
<WholeProgramOptimization>true</WholeProgramOptimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<OmitFramePointers>true</OmitFramePointers>
<FunctionLevelLinking>true</FunctionLevelLinking>
</ClCompile>
<Link>
<AdditionalDependencies>
</AdditionalDependencies>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\include\LightGBM\application.h" />
<ClInclude Include="..\include\LightGBM\bin.h" />