Mercurial > octave-dspies
view examples/mex_demo.c @ 19006:2e0613dadfee draft
All calls to "find" use the same generic implementation (bug #42408, 42421)
* find.cc: Rewrite.
Move generic "find" logic to find.h
(Ffind) : Changed calls to find_nonzero_elem_idx to find_templated
Added unit test for bug #42421
* Array.cc (and .h) (Array::find): Deleted function. Replaced with find::find(Array)
from find.h
* Array.h: Added typedef for array_iterator (in nz-iterators.h) as
Array::iter_type
* DiagArray2.h: Added typedef for diag_iterator (in nz-iterators.h) as
DiagArray2::iter_type
* PermMatrix.h: Added typedef for perm_iterator (in nz-iterators.h) as
PermMatrix::iter_type
Also added typedef for bool as PermMatrix::element_type
(not octave_idx_type)
Added an nnz() function (which is an alias for perm_length) and a
perm_elem(i) function for retrieving the ith element of the permutation
* Sparse.h: Added typedef for sparse_iterator (in nz-iterators.h) as
Sparse::iter_type
Added a short comment documenting the the argument to the numel
function
* idx-vector.cc (idx_vector::idx_mask_rep::as_array): Changed Array.find to
find::find(Array) (in find.h)
* (new file) find.h
* (new file) interp-idx.h: Simple methods for converting between interpreter
index type and internal octave_idx_type/row-col pair
* (new file) min-with-nnz.h: Fast methods for taking an arbitrary matrix M and
an octave_idx_type n and finding min(M.nnz(), n)
* (new file) nz-iterators.h: Iterators for traversing (in column-major order)
the nonzero elements of any array or matrix backwards or forwards
* (new file) direction.h: Generic methods for simplifying code has to deal with
a "backwards or forwards" template argument
* build-sparse-tests.sh: Removed 5-return-value calls to "find" in unit-tests;
Admittedly this commit breaks this "feature" which was undocumented and only
partially supported to begin with (ie never worked for full matrices,
permutation matrices, or diagonal matrices)
author | David Spies <dnspies@gmail.com> |
---|---|
date | Tue, 17 Jun 2014 16:41:11 -0600 |
parents | 877b82d73ed9 |
children |
line wrap: on
line source
// mex_demo.c -- example of a dynamically linked function for Octave. // To use this file, your version of Octave must support dynamic // linking. To find out if it does, type the command // // octave_config_info ("ENABLE_DYNAMIC_LINKING") // // at the Octave prompt. Support for dynamic linking is included if // this expression returns the string "yes". // // To compile this file, type the command // // mkoctfile --mex mex_demo.c // // from within Octave or from the shell prompt. This will create a file // called mex_demo.mex that can be loaded by Octave. To test the mex_demo.mex // file, start Octave and type the command // // d = mex_demo ("easy as", 1, 2, 3) // // at the Octave prompt. Octave should respond by printing // // Hello, world! // I have 4 inputs and 1 output // d = 1.2346 // Additional samples of code are in the examples directory of the Octave // distribution. See also the chapter External Code Interface in the // documentation. #include "mex.h" // Every user function should include "mex.h" which imports the basic set of // function prototypes necessary for dynamically linked functions. In // particular, it will declare mexFunction which is used by every function // which will be visible to Octave. A mexFunction is visible in Octave under // the name of the source code file without the extension. // The four arguments to mexFunction are: // 1) The number of return arguments (# of left-hand side args). // 2) An array of pointers to return arguments. // 3) The number of input arguments (# of right-hand side args). // 4) An array of pointers to input arguments. void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { mexPrintf ("Hello, World!\n"); mexPrintf ("I have %d inputs and %d outputs\n", nrhs, nlhs); mxArray *v = mxCreateDoubleMatrix (1, 1, mxREAL); double *data = mxGetPr (v); *data = 1.23456789; plhs[0] = v; }