Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
de114be5
"python-package/vscode:/vscode.git/clone" did not exist on "f6ecd4de9bac7af0217b0b5e92c0321a3aaca740"
Commit
de114be5
authored
Nov 22, 2016
by
Guolin Ke
Browse files
add nullptr check for get_field
parent
a178b75b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
10 deletions
+40
-10
include/LightGBM/dataset.h
include/LightGBM/dataset.h
+28
-6
src/c_api.cpp
src/c_api.cpp
+1
-1
src/io/dataset.cpp
src/io/dataset.cpp
+11
-3
No files found.
include/LightGBM/dataset.h
View file @
de114be5
...
@@ -143,8 +143,13 @@ public:
...
@@ -143,8 +143,13 @@ public:
* \brief Get weights, if not exists, will return nullptr
* \brief Get weights, if not exists, will return nullptr
* \return Pointer of weights
* \return Pointer of weights
*/
*/
inline
const
float
*
weights
()
inline
const
float
*
weights
()
const
{
const
{
return
weights_
.
data
();
}
if
(
weights_
.
size
()
>
0
)
{
return
weights_
.
data
();
}
else
{
return
nullptr
;
}
}
/*!
/*!
* \brief Get data boundaries on queries, if not exists, will return nullptr
* \brief Get data boundaries on queries, if not exists, will return nullptr
...
@@ -153,8 +158,13 @@ public:
...
@@ -153,8 +158,13 @@ public:
* is the data indices for query i.
* is the data indices for query i.
* \return Pointer of data boundaries on queries
* \return Pointer of data boundaries on queries
*/
*/
inline
const
data_size_t
*
query_boundaries
()
inline
const
data_size_t
*
query_boundaries
()
const
{
const
{
return
query_boundaries_
.
data
();
}
if
(
query_boundaries_
.
size
()
>
0
)
{
return
query_boundaries_
.
data
();
}
else
{
return
nullptr
;
}
}
/*!
/*!
* \brief Get Number of queries
* \brief Get Number of queries
...
@@ -166,13 +176,25 @@ public:
...
@@ -166,13 +176,25 @@ public:
* \brief Get weights for queries, if not exists, will return nullptr
* \brief Get weights for queries, if not exists, will return nullptr
* \return Pointer of weights for queries
* \return Pointer of weights for queries
*/
*/
inline
const
float
*
query_weights
()
const
{
return
query_weights_
.
data
();
}
inline
const
float
*
query_weights
()
const
{
if
(
query_weights_
.
size
()
>
0
)
{
return
query_weights_
.
data
();
}
else
{
return
nullptr
;
}
}
/*!
/*!
* \brief Get initial scores, if not exists, will return nullptr
* \brief Get initial scores, if not exists, will return nullptr
* \return Pointer of initial scores
* \return Pointer of initial scores
*/
*/
inline
const
float
*
init_score
()
const
{
return
init_score_
.
data
();
}
inline
const
float
*
init_score
()
const
{
if
(
init_score_
.
size
()
>
0
)
{
return
init_score_
.
data
();
}
else
{
return
nullptr
;
}
}
/*! \brief Disable copy */
/*! \brief Disable copy */
Metadata
&
operator
=
(
const
Metadata
&
)
=
delete
;
Metadata
&
operator
=
(
const
Metadata
&
)
=
delete
;
...
...
src/c_api.cpp
View file @
de114be5
...
@@ -387,7 +387,7 @@ DllExport int LGBM_DatasetGetField(DatesetHandle handle,
...
@@ -387,7 +387,7 @@ DllExport int LGBM_DatasetGetField(DatesetHandle handle,
*
out_type
=
C_API_DTYPE_INT32
;
*
out_type
=
C_API_DTYPE_INT32
;
is_success
=
true
;
is_success
=
true
;
}
}
if
(
!
is_success
)
{
throw
std
::
runtime_error
(
"Field not found"
);
}
if
(
!
is_success
)
{
throw
std
::
runtime_error
(
"Field not found
or not exist
"
);
}
API_END
();
API_END
();
}
}
...
...
src/io/dataset.cpp
View file @
de114be5
...
@@ -101,7 +101,11 @@ bool Dataset::GetFloatField(const char* field_name, int64_t* out_len, const floa
...
@@ -101,7 +101,11 @@ bool Dataset::GetFloatField(const char* field_name, int64_t* out_len, const floa
}
else
{
}
else
{
return
false
;
return
false
;
}
}
if
(
*
out_ptr
!=
nullptr
)
{
return
true
;
return
true
;
}
else
{
return
false
;
}
}
}
bool
Dataset
::
GetIntField
(
const
char
*
field_name
,
int64_t
*
out_len
,
const
int
**
out_ptr
)
{
bool
Dataset
::
GetIntField
(
const
char
*
field_name
,
int64_t
*
out_len
,
const
int
**
out_ptr
)
{
...
@@ -109,11 +113,15 @@ bool Dataset::GetIntField(const char* field_name, int64_t* out_len, const int**
...
@@ -109,11 +113,15 @@ bool Dataset::GetIntField(const char* field_name, int64_t* out_len, const int**
name
=
Common
::
Trim
(
name
);
name
=
Common
::
Trim
(
name
);
if
(
name
==
std
::
string
(
"query"
)
||
name
==
std
::
string
(
"group"
))
{
if
(
name
==
std
::
string
(
"query"
)
||
name
==
std
::
string
(
"group"
))
{
*
out_ptr
=
metadata_
.
query_boundaries
();
*
out_ptr
=
metadata_
.
query_boundaries
();
*
out_len
=
num_
data_
;
*
out_len
=
meta
data_
.
num_queries
()
;
}
else
{
}
else
{
return
false
;
return
false
;
}
}
if
(
*
out_ptr
!=
nullptr
)
{
return
true
;
return
true
;
}
else
{
return
false
;
}
}
}
void
Dataset
::
SaveBinaryFile
(
const
char
*
bin_filename
)
{
void
Dataset
::
SaveBinaryFile
(
const
char
*
bin_filename
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment