fastFM icon indicating copy to clipboard operation
fastFM copied to clipboard

[WIP] Simplify C header (ffm.h)

Open ibayer opened this issue 9 years ago • 0 comments

The refactoring from issue #85 has to be completed first.

Motivation:

A lot of complicated code is required in fastFM/ffm.pyx to wrap the c structs cs_di and ffm_param (see fastFM/cff.pxd).

Basically the fastFM-core header fastFM-core/include/ffm.h should be refactored using ADTs [1] (for cs_di and ffm_param) so that the C lib can be call as suggested here.

Overview:

(fastFM-core): Forward declare the struts and provide factory function in order to remove implementation details from fastFM-core/include/ffm.h (see [0,1] for an example).

(fastFM): Adapt fastFM/ffm.pyx and fastFM/cff.pxd to the new ffm.h header.

1 Refactor C Interface:

  • [ ] (fastFM-core) Add C constructor for the structs cs_di, ffm_param.

in ffm.h


extern cs_di* InitSparseMatrix (... );
extern void DeleteSparseMatrix(cs_di* m);

extern ffm_param* CreateParam(...);
extern void DeleteParam(ffm_param *p);

the implementation goes into ffm.c

  • [ ] Write unit test for the constructor and destructor functions (add them to https://github.com/ibayer/fastFM-core/blob/master/src/tests/test_ffm_utils.c)

2 Use new C Interface:

  • [ ] (fastFM) Add the new functions to fastFM/cff.pxd.
  • [ ] (fastFM) Replace the struct wrapper (https://github.com/ibayer/fastFM/blob/master/fastFM/ffm.pyx#L22 etc. ) with the factory function one by one in fastFM/ffm.pyx.

3 Clean Up

  • [ ] (fastFM/fastFM-core) Drop the now unused struct from fastFM/cff.pxd and ffm.h.

[0] slide 15 http://www.slideshare.net/StefanusDuToit/cpp-con-2014-hourglass-interfaces-for-c-apis [1] http://inst.eecs.berkeley.edu/~selfpace/studyguide/9C.sg/Output/ADTs.in.C.html

ibayer avatar Jan 17 '17 15:01 ibayer