Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions tsflex/features/function_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
output_names: Optional[Union[List[str], str]] = None,
input_type: Optional[Union[np.array, pd.Series]] = np.array,
vectorized: bool = False,
parallel: bool = False,
**kwargs,
):
"""Create FuncWrapper instance."""
Expand All @@ -85,8 +86,10 @@ def __init__(
assert not (
vectorized & (input_type is not np.array)
), "The input_type must be np.array if vectorized is True!"
assert not (vectorized & parallel), "vectorized and parallel cannot be both True!"
self.input_type = input_type
self.vectorized = vectorized
self.parallel = parallel

self._freeze()

Expand Down
19 changes: 19 additions & 0 deletions tsflex/features/segmenter/strided_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from abc import ABC, abstractmethod
from collections import namedtuple
from typing import List, Optional, Tuple, TypeVar, Union
from multiprocess import Pool

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -444,6 +445,24 @@ def apply_func(self, func: FuncWrapper) -> pd.DataFrame:
# when combining into an array
out = out.T if out_type is tuple else out

elif func.parallel:
# Parallel function execution
with Pool() as pool:
out = np.array(
list(
pool.imap(
func,
*[
[
sc.values[sc.start_indexes[idx] : sc.end_indexes[idx]]
for idx in range(len(self.index))
]
for sc in self.series_containers
],
)
)
)

else:
# Sequential function execution (default)
out = np.array(
Expand Down