Skip to content

Commit

Permalink
perf: reduce cppcore initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkilic committed Sep 3, 2024
1 parent e9bcd51 commit 1d70b6b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
8 changes: 6 additions & 2 deletions efel/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,11 @@ def _initialise() -> None:
cppcore.Initialize(_settings.dependencyfile_path, "log")
# flush the GErrorString from previous runs by calling getgError()
cppcore.getgError()
_initSettings()

# Set the settings in the cppcore

def _initSettings() -> None:
"""Init the settings in cppcore."""
settings_attrs = vars(_settings)
for setting_name, setting_value in settings_attrs.items():
if isinstance(setting_value, bool):
Expand Down Expand Up @@ -356,7 +359,8 @@ def _get_feature_values_serial(
else:
raise Exception('stim_start or stim_end missing from trace')

_initialise()
cppcore.Clear()
_initSettings()

# Next set time, voltage and the stimulus start and end
for item in list(trace.keys()):
Expand Down
7 changes: 7 additions & 0 deletions efel/cppcore/cfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ cFeature::cFeature(const string& strDepFile, const string& outdir)
logger << "Using dependency file: " << strDepFile << endl;
}

void cFeature::clearMap()
{
mapIntData.clear();
mapDoubleData.clear();
mapStrData.clear();
}

template <typename T>
const vector<T> cFeature::getMapData(const string& strName,
const map<string, vector<T>>& mapData) {
Expand Down
35 changes: 18 additions & 17 deletions efel/cppcore/cfeature.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* Copyright (c) 2015, EPFL/Blue Brain Project
*
* This file is part of eFEL <https://github.com/BlueBrain/eFEL>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/* Copyright (c) 2015, EPFL/Blue Brain Project
*
* This file is part of eFEL <https://github.com/BlueBrain/eFEL>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef CFEATURE_H_
#define CFEATURE_H_

Expand Down Expand Up @@ -62,6 +62,7 @@ class cFeature {
string featuretype(string featurename);
string getGError();
void get_feature_names(vector<string>& feature_names);
void clearMap();

};

Expand Down
13 changes: 12 additions & 1 deletion efel/cppcore/cppcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ int Initialize(const char* strDepFile, const char* outdir) {
}
}

void Clear() {
if (pFeature != NULL) {
pFeature->clearMap();
}
}

static PyObject* CppCoreInitialize(PyObject* self, PyObject* args) {
char *depfilename, *outfilename;
if (!PyArg_ParseTuple(args, "ss", &depfilename, &outfilename)) {
Expand All @@ -64,6 +70,11 @@ static PyObject* CppCoreInitialize(PyObject* self, PyObject* args) {
return Py_BuildValue("");
}

static PyObject* CppCoreClear(PyObject* self, PyObject* args) {
Clear();
return Py_BuildValue("");
}

static vector<int> PyList_to_vectorint(PyObject* input) {
vector<int> result_vector;
int list_size;
Expand Down Expand Up @@ -293,7 +304,7 @@ static PyObject* getgerrorstr(PyObject* self, PyObject* args) {

static PyMethodDef CppCoreMethods[] = {
{"Initialize", CppCoreInitialize, METH_VARARGS, "Initialise CppCore."},

{"Clear", CppCoreClear, METH_NOARGS, "Clear CppCore."},
{"getFeature", getfeature, METH_VARARGS,
"Get a values associated with a feature. Takes a list() to be filled."},
{"getFeatureInt", getfeatureint, METH_VARARGS, "Get a integer feature."},
Expand Down

0 comments on commit 1d70b6b

Please sign in to comment.