|
1 | 1 | #pragma once
|
2 | 2 |
|
| 3 | +#include <cstddef> |
| 4 | +#include <cstdint> |
| 5 | + |
3 | 6 | #if defined _WIN32 || defined __CYGWIN__
|
4 | 7 | # ifdef VW_RS_BUILDING_DLL
|
5 | 8 | # ifdef __GNUC__
|
|
25 | 28 | # endif
|
26 | 29 | #endif
|
27 | 30 |
|
28 |
| -// For operations which cannot fail under any circumstance (except out of memory) it is acceptable to omit the return code, and error holder. |
29 |
| -// If it is an operation which can fail, it must return an error code and accept the error message parameter for filling with failure info. |
| 31 | +// For operations which cannot fail under any circumstance (except out of memory) it is acceptable to omit the return |
| 32 | +// code, and error holder. If it is an operation which can fail, it must return an error code and accept the error |
| 33 | +// message parameter for filling with failure info. |
30 | 34 |
|
31 | 35 | extern "C"
|
32 | 36 | {
|
33 | 37 | static const int VW_STATUS_SUCCESS = 0;
|
34 | 38 | static const int VW_STATUS_FAIL = 1;
|
35 | 39 |
|
| 40 | + // Unfortunately a copy paste of the enum since bringing in the header is not |
| 41 | + // feasible and using externs would mean these are no longer constants |
| 42 | + enum class override_prediction_type_t : uint32_t |
| 43 | + { |
| 44 | + scalar, |
| 45 | + scalars, |
| 46 | + action_scores, |
| 47 | + pdf, |
| 48 | + action_probs, |
| 49 | + multiclass, |
| 50 | + multilabels, |
| 51 | + prob, |
| 52 | + multiclassprobs, // not in use (technically oaa.cc) |
| 53 | + decision_probs, |
| 54 | + action_pdf_value, |
| 55 | + active_multiclass, |
| 56 | + nopred |
| 57 | + }; |
| 58 | + |
36 | 59 | struct VWWorkspace;
|
37 | 60 | struct VWExample;
|
38 | 61 | struct VWErrorMessage;
|
| 62 | + struct VWMultiEx; |
39 | 63 |
|
40 |
| - DLL_PUBLIC struct VWErrorMessage* VWErrorMessageCreate() noexcept; |
41 |
| - DLL_PUBLIC void VWErrorMessageDelete(struct VWErrorMessage* error_message_handle) noexcept; |
| 64 | + struct VWActionScores; |
| 65 | + |
| 66 | + DLL_PUBLIC VWErrorMessage* VWErrorMessageCreate() noexcept; |
| 67 | + DLL_PUBLIC void VWErrorMessageDelete(VWErrorMessage* error_message) noexcept; |
42 | 68 | // If there was no error message set, a nullptr is returned.
|
43 |
| - DLL_PUBLIC const char* VWErrorMessageGetValue(const struct VWErrorMessage* error_message_handle) noexcept; |
44 |
| - DLL_PUBLIC void VWErrorMessageClearValue(struct VWErrorMessage* error_message_handle) noexcept; |
| 69 | + DLL_PUBLIC const char* VWErrorMessageGetValue(const VWErrorMessage* error_message) noexcept; |
| 70 | + DLL_PUBLIC void VWErrorMessageClearValue(VWErrorMessage* error_message) noexcept; |
45 | 71 |
|
46 |
| - DLL_PUBLIC int VWWorkspaceInitialize(const char* const* tokens, int count, struct VWWorkspace** output_handle, |
47 |
| - struct VWErrorMessage* error_message) noexcept; |
48 |
| - DLL_PUBLIC void VWWorkspaceDelete(struct VWWorkspace* workspace_handle) noexcept; |
| 72 | + DLL_PUBLIC int VWWorkspaceInitialize( |
| 73 | + const char* const* tokens, int count, VWWorkspace** output_handle, VWErrorMessage* error_message) noexcept; |
| 74 | + DLL_PUBLIC void VWWorkspaceDelete(VWWorkspace* workspace_handle) noexcept; |
49 | 75 |
|
50 |
| - DLL_PUBLIC int VWWorkspaceLearn(struct VWWorkspace* workspace_handle, struct VWExample* example_handle, struct VWErrorMessage* error_message_handle) noexcept; |
| 76 | + DLL_PUBLIC int VWWorkspaceSetupExample( |
| 77 | + const VWWorkspace* workspace_handle, VWExample* example_handle, VWErrorMessage* error_message) noexcept; |
| 78 | + DLL_PUBLIC int VWWorkspaceSetupMultiEx( |
| 79 | + const VWWorkspace* workspace_handle, VWMultiEx* example_handle, VWErrorMessage* error_message) noexcept; |
51 | 80 |
|
52 |
| - DLL_PUBLIC int VWWorkspaceGetPooledExample(struct VWWorkspace* workspace_handle, struct VWExample** output_handle, struct VWErrorMessage* error_message_handle) noexcept; |
53 |
| - DLL_PUBLIC int VWWorkspaceReturnPooledExample(struct VWWorkspace* workspace_handle, struct VWExample* example_handle, struct VWErrorMessage* error_message_handle) noexcept; |
| 81 | + DLL_PUBLIC int VWWorkspaceLearn( |
| 82 | + VWWorkspace* workspace_handle, VWExample* example_handle, VWErrorMessage* error_message) noexcept; |
| 83 | + DLL_PUBLIC int VWWorkspaceLearnMultiEx( |
| 84 | + VWWorkspace* workspace_handle, VWMultiEx* example_handle, VWErrorMessage* error_message) noexcept; |
| 85 | + // Will allocate a prediction based on the returned prediction_type. It must be deleted with the corresponding type |
| 86 | + // deleter. |
| 87 | + // TODO: tackle fact that predict sets test_only meaning that it is no longer able to be used in learn |
| 88 | + DLL_PUBLIC int VWWorkspacePredict(VWWorkspace* workspace_handle, VWExample* example_handle, void** prediction, |
| 89 | + uint32_t* prediction_type, VWErrorMessage* error_message) noexcept; |
| 90 | + // Will allocate a prediction based on the returned prediction_type. It must be deleted with the corresponding type |
| 91 | + // deleter. |
| 92 | + DLL_PUBLIC int VWWorkspacePredictMultiEx(VWWorkspace* workspace_handle, VWMultiEx* example_handle, void** prediction, |
| 93 | + uint32_t* prediction_type, VWErrorMessage* error_message) noexcept; |
54 | 94 |
|
55 |
| - DLL_PUBLIC struct VWExample* VWExampleCreate() noexcept; |
56 |
| - DLL_PUBLIC void VWExampleDelete(struct VWExample* example_handle) noexcept; |
57 |
| -} |
| 95 | + typedef VWExample* VWExampleFactoryFunc(void*); |
| 96 | + DLL_PUBLIC int VWWorkspaceParseDSJson(const VWWorkspace* workspace_handle, const char* json_string, size_t length, VWExampleFactoryFunc example_factory, void* example_factory_context, |
| 97 | + VWMultiEx* output_handle, VWErrorMessage* error_message) noexcept; |
58 | 98 |
|
| 99 | + DLL_PUBLIC VWExample* VWExampleCreate() noexcept; |
| 100 | + DLL_PUBLIC void VWExampleDelete(VWExample* example_handle) noexcept; |
| 101 | + DLL_PUBLIC void VWExampleClear(VWExample* example_handle) noexcept; |
| 102 | + |
| 103 | + DLL_PUBLIC VWMultiEx* VWMultiExCreate() noexcept; |
| 104 | + // If any examples are held in the container they will be deleted too. |
| 105 | + DLL_PUBLIC void VWMultiExDelete(VWMultiEx* example_handle) noexcept; |
| 106 | + DLL_PUBLIC size_t VWMultiGetLength(const VWMultiEx* example_handle) noexcept; |
| 107 | + // Returns a pointer to that example. |
| 108 | + DLL_PUBLIC int VWMultiGetExampleAt( |
| 109 | + VWMultiEx* example_handle, VWExample** example, size_t index, VWErrorMessage* error_message) noexcept; |
| 110 | + // Releases the example at the index. Removes it from the collection and its lifetime must be managed by the caller. |
| 111 | + DLL_PUBLIC int VWMultiReleaseExampleAt( |
| 112 | + VWMultiEx* example_handle, VWExample** example, size_t index, VWErrorMessage* error_message) noexcept; |
| 113 | + // Deletes the example at that index |
| 114 | + DLL_PUBLIC int VWMultiDeleteExampleAt( |
| 115 | + VWMultiEx* example_handle, size_t index, VWErrorMessage* error_message) noexcept; |
| 116 | + // Lifetime transfers to the multiex. Use index == size to push at end. |
| 117 | + DLL_PUBLIC int VWMultiInsertExampleAt( |
| 118 | + VWMultiEx* example_handle, VWExample* example, size_t index, VWErrorMessage* error_message) noexcept; |
| 119 | + |
| 120 | + DLL_PUBLIC void VWActionScoresDelete(VWActionScores* action_scores_handle) noexcept; |
| 121 | + DLL_PUBLIC void VWActionScoresGetLength(const VWActionScores* action_scores_handle, size_t* length) noexcept; |
| 122 | + DLL_PUBLIC int VWActionScoresGetValue(const VWActionScores* action_scores_handle, uint32_t* action, float* value, |
| 123 | + size_t index, VWErrorMessage* error_message) noexcept; |
| 124 | +} |
0 commit comments