Skip to content

Commit

Permalink
Add Octave support and fix function name typos
Browse files Browse the repository at this point in the history
Updated `CMakeLists.txt` to include `OctaveOct` subdirectory and set up Octave configuration executable path. Defined new shared library `OctaveOct` with its source files and compilation properties.

Corrected function names in `app_api_implementation.c` from `matlabMaxGetInfinityDouble` and `matlabMaxGetNaNDouble` to `matlabMexGetInfinityDouble` and `matlabMexGetNaNDouble`. Updated function pointers in `IAppExtensionFunctions` structure accordingly.

Added `octlibczi.cpp` with functions for handling Octave data types and operations, including a new `IAppExtensionFunctions` structure for Octave.

Introduced new Octave function `helloworld` in `helloworld.cc` to print input/output argument counts and return empty matrices.

Included new Octave function `octlibczi` in `octlibczi.cpp` to process input arguments and print input/output argument counts.
  • Loading branch information
ptahmose committed Oct 13, 2024
1 parent 6b217db commit b9a01c9
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ add_subdirectory ("MEXlibCZI")

add_subdirectory("lib")
add_subdirectory("MatlabMex")

##set(OCTAVE_CONFIGEXECUTABLE_PATHHINT "D:/SW/octave-9.2.0-w64/mingw64/bin")
set(OCTAVE_CONFIGEXECUTABLE_PATHHINT "/d/SW/octave-9.2.0-w64/mingw64/bin/")
find_package(Octave)

add_subdirectory("OctaveOct")
8 changes: 4 additions & 4 deletions MatlabMex/app_api_implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ bool matlabMexIsNanOrInfSingle(float value)
return mxIsNaN(value) || mxIsInf(value);
}

double matlabMaxGetInfinityDouble(void)
double matlabMexGetInfinityDouble(void)
{
return mxGetInf();
}

double matlabMaxGetNaNDouble(void)
double matlabMexGetNaNDouble(void)
{
return mxGetNaN();
}
Expand Down Expand Up @@ -249,8 +249,8 @@ struct IAppExtensionFunctions g_appExtensionFunctions =
{
.pfn_IsNanOrInfDouble = matlabMexIsNanOrInfDouble,
.pfn_IsNanOrInfSingle = matlabMexIsNanOrInfSingle,
.pfn_GetInfDouble = matlabMaxGetInfinityDouble,
.pfn_GetNaNDouble = matlabMaxGetNaNDouble,
.pfn_GetInfDouble = matlabMexGetInfinityDouble,
.pfn_GetNaNDouble = matlabMexGetNaNDouble,
.pfn_GetData = matlabMexGetData,
.pfn_GetUint8s = matlabMexGetUint8s,
.pfn_GetInt8s = matlabMexGetInt8s,
Expand Down
11 changes: 11 additions & 0 deletions OctaveOct/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(octaveOctSourceFiles
"octlibczi.cpp"
)

add_library (OctaveOct SHARED
${octaveOctSourceFiles})

target_compile_features(OctaveOct PRIVATE c_std_11)
set_target_properties(OctaveOct PROPERTIES CXX_STANDARD 17)
target_include_directories(OctaveOct PRIVATE ${OCTAVE_INCLUDE_DIR}/../)
target_link_libraries(OctaveOct PRIVATE lib)
16 changes: 16 additions & 0 deletions OctaveOct/helloworld.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <octave/oct.h>

DEFUN_DLD(helloworld, args, nargout,
"Hello World Help String")
{
octave_stdout << "Hello World has "
<< args.length() << " input arguments and "
<< nargout << " output arguments.\n";

// Return empty matrices for any outputs
octave_value_list retval(nargout);
for (int i = 0; i < nargout; i++)
retval(i) = octave_value(Matrix());

return retval;
}
167 changes: 167 additions & 0 deletions OctaveOct/octlibczi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#include <octave/oct.h>
#include "../AppModel/include/app_api.h"
#include <array>

bool octaveOctIsNanOrInfDouble(double value)
{
return octave::math::isnan(value) != 0 || octave::math::isinf(value) != 0;
}

bool octaveOctIsNanOrInfSingle(float f)
{
return octave::math::isnan(f) != 0 || octave::math::isinf(f) != 0;
}

double octaveOctGetInfinityDouble(void)
{
return lo_ieee_inf_value();
}

double octaveOctGetNaNDouble(void)
{
return lo_ieee_nan_value();
}

void* octaveOctGetData(const Parameter* parameter)
{
return const_cast<void*>(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data());
}

uint8_t* octaveOctGetUint8s(const Parameter* parameter)
{
return (uint8_t*)(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data(mxUINT8_CLASS));
}

int8_t* octaveOctGetInt8s(const Parameter* parameter)
{
return (int8_t*)(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data(mxINT8_CLASS));
}

uint16_t* octaveOctGetUint16s(const Parameter* parameter)
{
return (uint16_t*)(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data(mxUINT16_CLASS));
}

int16_t* octaveOctGetInt16s(const Parameter* parameter)
{
return (int16_t*)(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data(mxINT16_CLASS));
}

uint32_t* octaveOctGetUint32s(const Parameter* parameter)
{
return (uint32_t*)(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data(mxUINT32_CLASS));
}

int32_t* octaveOctGetInt32s(const Parameter* parameter)
{
return (int32_t*)(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data(mxINT32_CLASS));
}

uint64_t* octaveOctGetUint64s(const Parameter* parameter)
{
return (uint64_t*)(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data(mxUINT64_CLASS));
}

int64_t* octaveOctGetInt64s(const Parameter* parameter)
{
return (int64_t*)(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data(mxINT64_CLASS));
}

double* octaveOctGetDoubles(const Parameter* parameter)
{
return (double*)(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data(mxDOUBLE_CLASS));
}

float* octaveOctGetSingles(const Parameter* parameter)
{
return (float*)(reinterpret_cast<octave_value*>(const_cast<Parameter*>(parameter))->mex_get_data(mxSINGLE_CLASS));
}

bool* octaveOctGetLogicals(const Parameter* parameter)
{
return (bool*)octaveOctGetData(parameter);
}

bool octaveOctIsNumeric(const Parameter* parameter)
{
return reinterpret_cast<const octave_value*>(parameter)->isnumeric();
}

bool octaveOctIsChar(const Parameter* parameter)
{
return reinterpret_cast<const octave_value*>(parameter)->is_string();
}

bool octaveOctIsSparse(const Parameter* parameter)
{
return reinterpret_cast<const octave_value*>(parameter)->issparse();
}

bool octaveOctIsStruct(const Parameter* parameter)
{
return reinterpret_cast<const octave_value*>(parameter)->isstruct();
}

Parameter* octaveOctCreateString(const char* string)
{
return (Parameter*)new octave_value(string);
}

void matlabReportErrorAndRaiseSignal(const char* identifier, const char* message)
{
mexErrMsgIdAndTxt(identifier, message);
}

char* matlabStrDupHostAllocated(const char* string)
{
size_t len = strlen(string);
char* msz = (char*)mxMalloc(len + 1);
memcpy(msz, string, len);
msz[len] = '\0';
return msz;
}


static struct IAppExtensionFunctions g_appExtensionFunctions =
{
octaveOctIsNanOrInfDouble,
octaveOctIsNanOrInfSingle,
octaveOctGetInfinityDouble,
octaveOctGetNaNDouble,
octaveOctGetData,
octaveOctGetUint8s,
octaveOctGetInt8s,
octaveOctGetUint16s,
octaveOctGetInt16s,
octaveOctGetUint32s,
octaveOctGetInt32s,
octaveOctGetUint64s,
octaveOctGetInt64s,
octaveOctGetDoubles,
octaveOctGetSingles,
octaveOctGetLogicals,
nullptr,
nullptr,
nullptr,
nullptr
};

constexpr int kMaxInputArguments = 20;

DEFUN_DLD(octlibczi, args, nargout,
"Hello World Help String")
{
int nargin = args.length();

std::array<Parameter, kMaxInputArguments> input_args;
for (int i = 0; i < nargin; ++i)
{
input_args[i] = (Parameter)&args(i);
}

auto arg0 = args(0);
octave_stdout << "Hello World has " << nargin
<< " input arguments and "
<< nargout << " output arguments.\n";
return octave_value_list();
}
Binary file added OctaveOct/octlibczi.oct
Binary file not shown.

0 comments on commit b9a01c9

Please sign in to comment.