Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

perf: reduce cppcore initialisation #410

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
perf: reduce cppcore initialisation
  • Loading branch information
ilkilic committed Sep 3, 2024
commit 1d70b6b26f33738e96815bc5b5615ef654766cf8
8 changes: 6 additions & 2 deletions efel/api.py
Original file line number Diff line number Diff line change
@@ -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):
@@ -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()):
7 changes: 7 additions & 0 deletions efel/cppcore/cfeature.cpp
Original file line number Diff line number Diff line change
@@ -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) {
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_

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

};

13 changes: 12 additions & 1 deletion efel/cppcore/cppcore.cpp
Original file line number Diff line number Diff line change
@@ -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)) {
@@ -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;
@@ -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."},
Loading