Skip to content

Commit

Permalink
Add virtualenv test & fix some warnings (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsi authored and qinxuye committed Dec 21, 2018
1 parent 599819f commit 40aa47f
Show file tree
Hide file tree
Showing 43 changed files with 71 additions and 110 deletions.
18 changes: 14 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,30 @@ before_install:

# command to install dependencies
install:
- export DEFAULT_VENV=$VIRTUAL_ENV
- pip install -r requirements-dev.txt
- pip install -r requirements-extra.txt
- pip install coveralls
- pip install virtualenv coveralls
- virtualenv venv
- source venv/bin/activate
- pip install -r requirements.txt
- pip install pytest pytest-timeout
- if [ -z "$DEFAULT_VENV" ]; then deactivate; else source $DEFAULT_VENV/bin/activate; fi
- python setup.py build_ext -i

# command to run tests
script:
mkdir -p build &&
pytest --cov-report= --cov-config .coveragerc-tensor --cov=mars --timeout=1500 mars/tensor &&
pytest --cov-report= --cov-config .coveragerc-tensor --cov=mars --timeout=1500 -W ignore::PendingDeprecationWarning mars/tensor &&
mv .coverage build/.coverage.tensor.file &&
pytest --cov-report= --cov-config .coveragerc --cov=mars --timeout=1500 --forked
pytest --cov-report= --cov-config .coveragerc --cov=mars --timeout=1500 --forked -W ignore::PendingDeprecationWarning
$(find mars -maxdepth 1 -mindepth 1 -type d -not -path "mars/tensor" -not -path "*__pycache__*") &&
mv .coverage build/.coverage.main.file &&
coverage combine build/ && coverage report --fail-under=80
coverage combine build/ && coverage report --fail-under=80 &&
export DEFAULT_VENV=$VIRTUAL_ENV &&
source venv/bin/activate &&
pytest --timeout=1500 mars/tests/test_session.py &&
if [ -z "$DEFAULT_VENV" ]; then deactivate; else source $DEFAULT_VENV/bin/activate; fi

after_success:
- coveralls
Expand Down
7 changes: 0 additions & 7 deletions mars/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import uuid
import json
import time
import numpy as np

from .api import MarsAPI
from .scheduler.graph import GraphState
from .serialize import dataserializer


class LocalSession(object):
def __init__(self):
Expand Down
8 changes: 4 additions & 4 deletions mars/tensor/execution/indexing.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 1999-2018 Alibaba Group Holding Ltd.
#
#
# 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.
Expand All @@ -19,7 +19,7 @@


def _slice(ctx, chunk):
ctx[chunk.key] = ctx[chunk.inputs[0].key][chunk.op.slices]
ctx[chunk.key] = ctx[chunk.inputs[0].key][tuple(chunk.op.slices)]


def _index(ctx, chunk):
Expand Down
10 changes: 5 additions & 5 deletions mars/tensor/execution/optimizes/tests/test_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def testCompose(self):
test compose in build graph and optimize
"""

"""
r"""
graph(@: node, #: composed_node):
@ --> @ --> @ ========> #
Expand All @@ -51,7 +51,7 @@ def testCompose(self):
composed_nodes = graph.compose(keys=[chunks[1].key])
self.assertEqual(len(composed_nodes), 0)

"""
r"""
graph(@: node, #: composed_node):
@ @ @ @
Expand Down Expand Up @@ -97,7 +97,7 @@ def testCompose(self):

# test optimizer compose

"""
r"""
graph(@: node, S: Slice Chunk, #: composed_node):
@ @ @ @
Expand All @@ -123,7 +123,7 @@ def testCompose(self):
composed_nodes = optimizer.compose()
self.assertTrue(composed_nodes[0].composed == chunks[2:4])

"""
r"""
graph(@: node, S: Slice Chunk, #: composed_node):
@ --> @ --> S --> @ ========> # --> S --> @
Expand All @@ -142,7 +142,7 @@ def testCompose(self):
self.assertTrue(composed_nodes[0].composed == chunks[:2])
self.assertTrue(len(composed_nodes) == 1)

"""
r"""
graph(@: node, S: Slice Chunk, #: composed_node):
@ --> @ --> S --> @ --> @ ========> # --> S --> #
Expand Down
15 changes: 8 additions & 7 deletions mars/tensor/execution/reduction.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 1999-2018 Alibaba Group Holding Ltd.
#
#
# 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.
Expand Down Expand Up @@ -213,8 +213,9 @@ def _handle(ctx, chunk):
if xp != np:
inds = [xp.asarray(it) for it in inds]
inds.insert(axis, local_args)
vals = vals[inds]
arg = arg[inds]
inds_tuple = tuple(inds)
vals = vals[inds_tuple]
arg = arg[inds_tuple]
if keepdims:
vals = xp.expand_dims(vals, axis)
arg = xp.expand_dims(arg, axis)
Expand All @@ -241,7 +242,7 @@ def _handle(ctx, chunk):
if xp != np:
inds = [xp.asarray(it) for it in inds]
inds.insert(axis, local_args)
arg = arg[inds]
arg = arg[tuple(inds)]
if keepdims:
arg = xp.expand_dims(arg, axis)
ctx[chunk.key] = arg
Expand Down Expand Up @@ -310,7 +311,7 @@ def _count_nonzero(ctx, chunk):
slcs = [slice(None)] * chunk.inputs[0].ndim
for ax in chunk.op.axis:
slcs[ax] = np.newaxis
nz = xp.asarray(nz)[slcs]
nz = xp.asarray(nz)[tuple(slcs)]

ctx[chunk.key] = nz

Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/arithmetic/abs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _is_sparse(cls, x):

@infer_dtype(np.abs)
def abs(x, out=None, where=None, **kwargs):
"""
r"""
Calculate the absolute value element-wise.
Parameters
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/arithmetic/absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _is_sparse(cls, x):

@infer_dtype(np.absolute)
def absolute(x, out=None, where=None, **kwargs):
"""
r"""
Calculate the absolute value element-wise.
Parameters
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/arithmetic/exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _is_sparse(cls, x):

@infer_dtype(np.exp)
def exp(x, out=None, where=None, **kwargs):
"""
r"""
Calculate the exponential of all elements in the input tensor.
Parameters
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/arithmetic/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _is_sparse(cls, x1, x2):

@infer_dtype(np.power)
def power(x1, x2, out=None, where=None, **kwargs):
"""
r"""
First tensor elements raised to powers from second tensor, element-wise.
Raise each base in `x1` to the positionally-corresponding power in
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/arithmetic/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _is_sparse(cls, x):

@infer_dtype(np.sign)
def sign(x, out=None, where=None, **kwargs):
"""
r"""
Returns an element-wise indication of the sign of a number.
The `sign` function returns ``-1 if x < 0, 0 if x==0, 1 if x > 0``. nan
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/arithmetic/sinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _is_sparse(cls, x):

@infer_dtype(np.sinc)
def sinc(x, **kwargs):
"""
r"""
Return the sinc function.
The sinc function is :math:`\\sin(\\pi x)/(\\pi x)`.
Expand Down
4 changes: 2 additions & 2 deletions mars/tensor/expressions/base/corrcoef.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@


def corrcoef(x, y=None, rowvar=True):
"""
r"""
Return Pearson product-moment correlation coefficients.
Please refer to the documentation for `cov` for more detail. The
relationship between the correlation coefficient matrix, `R`, and the
covariance matrix, `C`, is
.. math:: R_{ij} = \\frac{ C_{ij} } { \\sqrt{ C_{ii} * C_{jj} } }
.. math:: R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } }
The values of `R` are between -1 and 1, inclusive.
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/linalg/norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _norm(r, ord, axis, keepdims):


def norm(x, ord=None, axis=None, keepdims=False):
"""
r"""
Matrix or vector norm.
This function is able to return one of eight different matrix norms,
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, a, b, chunks=None):


def beta(random_state, a, b, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a Beta distribution.
The Beta distribution is a special case of the Dirichlet distribution,
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/binomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, n, p, chunks=None):


def binomial(random_state, n, p, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a binomial distribution.
Samples are drawn from a binomial distribution with specified
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/chisquare.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, df, chunks=None):


def chisquare(random_state, df, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a chi-square distribution.
When `df` independent random variables, each with standard normal
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/dirichlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def tile(cls, op):


def dirichlet(random_state, alpha, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from the Dirichlet distribution.
Draw `size` samples of dimension k from a Dirichlet distribution. A
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/exponential.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, scale, chunks=None):


def exponential(random_state, scale=1.0, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from an exponential distribution.
Its probability density function is
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, shape, scale, chunks=None):


def gamma(random_state, shape, scale=1.0, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a Gamma distribution.
Samples are drawn from a Gamma distribution with specified parameters,
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/gumbel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, loc, scale, chunks=None):


def gumbel(random_state, loc=0.0, scale=1.0, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a Gumbel distribution.
Draw samples from a Gumbel distribution with specified location and
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/hypergeometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, ngood, nbad, nsample, chunks=None):


def hypergeometric(random_state, ngood, nbad, nsample, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a Hypergeometric distribution.
Samples are drawn from a hypergeometric distribution with specified
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/laplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, loc, scale, chunks=None):


def laplace(random_state, loc=0.0, scale=1.0, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from the Laplace or double exponential distribution with
specified location (or mean) and scale (decay).
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/logistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, loc, scale, chunks=None):


def logistic(random_state, loc=0.0, scale=1.0, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a logistic distribution.
Samples are drawn from a logistic distribution with specified
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/lognormal.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, mean, sigma, chunks=None):


def lognormal(random_state, mean=0.0, sigma=1.0, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a log-normal distribution.
Draw samples from a log-normal distribution with specified mean,
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/logseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, p, chunks=None):


def logseries(random_state, p, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a logarithmic series distribution.
Samples are drawn from a log series distribution with specified
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/negative_binomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, n, p, chunks=None):


def negative_binomial(random_state, n, p, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a negative binomial distribution.
Samples are drawn from a negative binomial distribution with specified
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/noncentral_chisquare.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, df, nonc, chunks=None):


def noncentral_chisquare(random_state, df, nonc, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a noncentral chi-square distribution.
The noncentral :math:`\chi^2` distribution is a generalisation of
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, loc, scale, chunks=None):


def normal(random_state, loc=0.0, scale=1.0, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw random samples from a normal (Gaussian) distribution.
The probability density function of the normal distribution, first
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/expressions/random/pareto.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __call__(self, a, chunks=None):


def pareto(random_state, a, size=None, chunks=None, gpu=None, **kw):
"""
r"""
Draw samples from a Pareto II or Lomax distribution with
specified shape.
Expand Down

0 comments on commit 40aa47f

Please sign in to comment.