summaryrefslogtreecommitdiff
path: root/src/cython/cython/reader_utils.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'src/cython/cython/reader_utils.pyx')
-rw-r--r--src/cython/cython/reader_utils.pyx34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/cython/cython/reader_utils.pyx b/src/cython/cython/reader_utils.pyx
index e4572db0..6dde5286 100644
--- a/src/cython/cython/reader_utils.pyx
+++ b/src/cython/cython/reader_utils.pyx
@@ -3,7 +3,9 @@ from libcpp.vector cimport vector
from libcpp.string cimport string
from libcpp.map cimport map
from libcpp.pair cimport pair
-import os
+
+from os import path
+from numpy import array as np_array
"""This file is part of the Gudhi Library. The Gudhi library
(Geometric Understanding in Higher Dimensions) is a generic C++
@@ -11,7 +13,7 @@ import os
Author(s): Vincent Rouvreau
- Copyright (C) 2017 Inria
+ Copyright (C) 2019 Inria
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -48,7 +50,7 @@ def read_lower_triangular_matrix_from_csv_file(csv_file='', separator=';'):
:rtype: vector[vector[double]]
"""
if csv_file is not '':
- if os.path.isfile(csv_file):
+ if path.isfile(csv_file):
return read_matrix_from_csv_file(str.encode(csv_file), ord(separator[0]))
print("file " + csv_file + " not set or not found.")
return []
@@ -67,29 +69,31 @@ def read_persistence_intervals_grouped_by_dimension(persistence_file=''):
:rtype: map[int, vector[pair[double, double]]]
"""
if persistence_file is not '':
- if os.path.isfile(persistence_file):
+ if path.isfile(persistence_file):
return read_pers_intervals_grouped_by_dimension(str.encode(persistence_file))
print("file " + persistence_file + " not set or not found.")
return []
def read_persistence_intervals_in_dimension(persistence_file='', only_this_dim=-1):
"""Reads a file containing persistence intervals.
- Each line might contain 2, 3 or 4 values: [[field] dimension] birth death
- If `only_this_dim` = -1, dimension is ignored and all lines are returned.
- If `only_this_dim` is >= 0, only the lines where dimension = `only_this_dim`
- (or where dimension is not specified) are returned.
- The return value is an `vector[pair[birth, death]]`
- where `birth` a `double`, and `death` a `double`.
+ Each line of persistence_file might contain 2, 3 or 4 values:
+ [[field] dimension] birth death
Note: the function does not check that birth <= death.
:param persistence_file: A persistence file style name.
:type persistence_file: string
-
- :returns: The persistence pairs grouped by dimension.
- :rtype: map[int, vector[pair[double, double]]]
+ :param only_this_dim: The specific dimension. Default value is -1.
+ If `only_this_dim` = -1, dimension is ignored and all lines are returned.
+ If `only_this_dim` is >= 0, only the lines where dimension =
+ `only_this_dim` (or where dimension is not specified) are returned.
+ :type only_this_dim: int.
+
+ :returns: The persistence intervals.
+ :rtype: numpy array of dimension 2
"""
if persistence_file is not '':
- if os.path.isfile(persistence_file):
- return read_pers_intervals_in_dimension(str.encode(persistence_file), only_this_dim)
+ if path.isfile(persistence_file):
+ return np_array(read_pers_intervals_in_dimension(str.encode(
+ persistence_file), only_this_dim))
print("file " + persistence_file + " not set or not found.")
return []