Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ junit-*.xml
__pycache__

brainiak/fcma/cython_blas.c
brainiak/eventseg/_utils.c
31 changes: 31 additions & 0 deletions brainiak/eventseg/_utils.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from libc.math cimport log
import numpy as np
cimport numpy as np

def masked_log(x):
"""x is a 1D numpy array"""
"""returns -Inf for x <=0 and log(x) otherwise"""
y = np.empty(x.shape, dtype=x.dtype)
lim = x.shape[0]
for i in range(lim):
if x[i] <= 0:
y[i] = float('-inf')
else:
y[i] = log(x[i])
return y

8 changes: 6 additions & 2 deletions brainiak/eventseg/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import copy
from sklearn.base import BaseEstimator
from sklearn.utils.validation import check_is_fitted, check_array
import brainiak.eventseg.utils as utils

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -299,8 +300,11 @@ def _log(self, x):
log_ma: ndarray of floats
log of x, with x<=0 values replaced with -inf
"""
log_ma = np.ma.log(x).filled(float("-inf"))
return log_ma

xshape = x.shape
_x = x.flatten()
y = utils.masked_log(_x)
return y.reshape(xshape)

def find_events(self, testing_data, var=None, scramble=False):
"""Applies learned event segmentation to new testing dataset
Expand Down
3 changes: 0 additions & 3 deletions brainiak/hyperparamopt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
""" Hyper parameter optimization package """

import pyximport
pyximport.install()
55 changes: 18 additions & 37 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,23 @@
long_description = f.read()


class get_pybind_include(object):
"""Helper class to determine the pybind11 include path

The purpose of this class is to postpone importing pybind11
until it is actually installed, so that the ``get_include()``
method can be invoked. """

def __init__(self, user=False):
self.user = user

# Required by Cython
def __add__(self, x):
import pybind11
return pybind11.get_include(self.user) + x

def __str__(self):
import pybind11
return pybind11.get_include(self.user)

def endswith(self, x):
import pybind11
return pybind11.get_include(self.user).endswith(x)

def startswith(self, x):
import pybind11
return pybind11.get_include(self.user).startswith(x)

ext_modules = [
Extension(
'brainiak.factoranalysis.tfa_extension',
['brainiak/factoranalysis/tfa_extension.cpp'],
include_dirs=[
# Path to pybind11 headers
get_pybind_include(),
get_pybind_include(user=True)
],
),
Extension(
'brainiak.fcma.fcma_extension',
['brainiak/fcma/src/fcma_extension.cc'],
include_dirs=[
# Path to pybind11 headers
get_pybind_include(),
get_pybind_include(user=True)
],
),
Extension(
'brainiak.fcma.cython_blas',
['brainiak/fcma/cython_blas.pyx'],
),
Extension(
'brainiak.eventseg.utils',
['brainiak/eventseg/_utils.pyx'],
),
]


Expand Down Expand Up @@ -133,10 +100,24 @@ def build_extensions(self):
ext.extra_link_args.append(cpp_flag(self.compiler))
build_ext.build_extensions(self)

def finalize_options(self):
super().finalize_options()
import numpy
import pybind11
self.include_dirs.extend([
numpy.get_include(),
pybind11.get_include(user=True),
pybind11.get_include(),
])


setup(
name='brainiak',
use_scm_version=True,
setup_requires=[
'cython',
'numpy',
'pybind11>=1.7',
'setuptools_scm',
],
install_requires=[
Expand Down