Made SciPy imports for sparse tallies optional

This commit is contained in:
wbinventor@gmail.com 2016-01-06 08:45:25 -05:00
parent d2c9e18082
commit 3eb10519ac
2 changed files with 11 additions and 2 deletions

View file

@ -10,7 +10,6 @@ from xml.etree import ElementTree as ET
import sys
import numpy as np
import scipy.sparse as sps
from openmc import Mesh, Filter, Trigger, Nuclide
from openmc.cross import CrossScore, CrossNuclide, CrossFilter
@ -323,6 +322,8 @@ class Tally(object):
# Convert NumPy arrays to SciPy sparse LIL matrices
if self.sparse:
import scipy.sparse as sps
self._sum = \
sps.lil_matrix(self._sum.flatten(), self._sum.shape)
self._sum_sq = \
@ -363,6 +364,8 @@ class Tally(object):
# Convert NumPy array to SciPy sparse LIL matrix
if self.sparse:
import scipy.sparse as sps
self._mean = \
sps.lil_matrix(self._mean.flatten(), self._mean.shape)
@ -385,6 +388,8 @@ class Tally(object):
# Convert NumPy array to SciPy sparse LIL matrix
if self.sparse:
import scipy.sparse as sps
self._std_dev = \
sps.lil_matrix(self._std_dev.flatten(), self._std_dev.shape)
@ -550,6 +555,8 @@ class Tally(object):
# Convert NumPy arrays to SciPy sparse LIL matrices
if sparse and not self.sparse:
import scipy.sparse as sps
if self._sum is not None:
self._sum = \
sps.lil_matrix(self._sum.flatten(), self._sum.shape)
@ -562,6 +569,7 @@ class Tally(object):
if self._std_dev is not None:
self._std_dev = \
sps.lil_matrix(self._std_dev.flatten(), self._std_dev.shape)
self._sparse = True
# Convert SciPy sparse LIL matrices to NumPy arrays

View file

@ -32,11 +32,12 @@ kwargs = {'name': 'openmc',
if have_setuptools:
kwargs.update({
# Required dependencies
'install_requires': ['numpy', 'h5py', 'matplotlib', 'scipy'],
'install_requires': ['numpy', 'h5py', 'matplotlib'],
# Optional dependencies
'extras_require': {
'pandas': ['pandas'],
'sparse' : ['scipy'],
'vtk': ['vtk', 'silomesh'],
'validate': ['lxml']
}})