Exemple #1
0
 def __init__(self,
              arg,
              shapein=None,
              shapeout=None,
              dtype=None,
              **keywords):
     if sp.issparse(arg):
         self.__class__ = pyoperators.linear.SparseOperator
         self.__init__(arg, dtype=None, **keywords)
         return
     if not isinstance(
             arg, (FSCMatrix, FSRMatrix, FSCBlockMatrix, FSRBlockMatrix,
                   FSCRotation2dMatrix, FSRRotation2dMatrix,
                   FSCRotation3dMatrix, FSRRotation3dMatrix)):
         raise TypeError('The input sparse matrix type is not recognised.')
     if isinstance(arg, (FSCMatrix, FSRMatrix)):
         if shapein is None:
             bshapein = keywords.pop('broadcastable_shapein',
                                     (arg.shape[1], ))
         else:
             shapein = tointtuple(shapein)
             test = np.cumprod(shapein) == arg.shape[1]
             try:
                 bshapein = shapein[:ilast(test, lambda x: x) + 1]
             except ValueError:
                 bshapein = (arg.shape[1], )
         self.broadcastable_shapein = bshapein
         if shapeout is None:
             bshapeout = keywords.pop('broadcastable_shapeout',
                                      (arg.shape[0], ))
         else:
             shapeout = tointtuple(shapeout)
             test = np.cumprod(shapeout) == arg.shape[0]
             try:
                 bshapeout = shapeout[:ilast(test, lambda x: x) + 1]
             except ValueError:
                 bshapeout = (arg.shape[0], )
         self.broadcastable_shapeout = bshapeout
     else:
         bs = arg.block_shape
         if shapein is None:
             if bs[1] == 1:
                 shapein = arg.shape[1]
             else:
                 shapein = arg.shape[1] // bs[1], bs[1]
         if shapeout is None:
             if bs[0] == 1:
                 shapeout = arg.shape[0]
             else:
                 shapeout = arg.shape[0] // bs[0], bs[0]
     pyoperators.linear.SparseBase.__init__(self,
                                            arg,
                                            dtype=dtype,
                                            shapein=shapein,
                                            shapeout=shapeout,
                                            **keywords)
     self.set_rule('T', self._rule_transpose)
     self.set_rule(('T', '.'), self._rule_pTp, CompositionOperator)
Exemple #2
0
 def __init__(self, arg, shapein=None, shapeout=None, dtype=None,
              **keywords):
     if sp.issparse(arg):
         self.__class__ = pyoperators.linear.SparseOperator
         self.__init__(arg, dtype=None, **keywords)
         return
     if not isinstance(arg, (FSCMatrix, FSRMatrix,
                             FSCBlockMatrix, FSRBlockMatrix,
                             FSCRotation2dMatrix, FSRRotation2dMatrix,
                             FSCRotation3dMatrix, FSRRotation3dMatrix)):
         raise TypeError('The input sparse matrix type is not recognised.')
     if isinstance(arg, (FSCMatrix, FSRMatrix)):
         if shapein is None:
             bshapein = keywords.pop('broadcastable_shapein',
                                     (arg.shape[1],))
         else:
             shapein = tointtuple(shapein)
             test = np.cumprod(shapein) == arg.shape[1]
             try:
                 bshapein = shapein[:ilast(test, lambda x: x) + 1]
             except ValueError:
                 bshapein = (arg.shape[1],)
         self.broadcastable_shapein = bshapein
         if shapeout is None:
             bshapeout = keywords.pop('broadcastable_shapeout',
                                      (arg.shape[0],))
         else:
             shapeout = tointtuple(shapeout)
             test = np.cumprod(shapeout) == arg.shape[0]
             try:
                 bshapeout = shapeout[:ilast(test, lambda x: x) + 1]
             except ValueError:
                 bshapeout = (arg.shape[0],)
         self.broadcastable_shapeout = bshapeout
     else:
         bs = arg.block_shape
         if shapein is None:
             if bs[1] == 1:
                 shapein = arg.shape[1]
             else:
                 shapein = arg.shape[1] // bs[1], bs[1]
         if shapeout is None:
             if bs[0] == 1:
                 shapeout = arg.shape[0]
             else:
                 shapeout = arg.shape[0] // bs[0], bs[0]
     pyoperators.linear.SparseBase.__init__(
         self, arg, dtype=dtype, shapein=shapein, shapeout=shapeout,
         **keywords)
     self.set_rule('T', self._rule_transpose)
     self.set_rule(('T', '.'), self._rule_pTp, CompositionOperator)
Exemple #3
0
def test_ifirst3():
    assert ifirst([1, 2, 2, 3], 2.0) == 1
    assert ilast([1, 2, 2, 3], 2.0) == 2
Exemple #4
0
def test_ifirst1():
    assert ifirst([1, 2, 3], lambda x: x > 1.5) == 1
    assert ilast([1, 2, 3], lambda x: x > 1.5) == 2
Exemple #5
0
def test_ifirst3():
    assert ifirst([1, 2, 2, 3], 2.) == 1
    assert ilast([1, 2, 2, 3], 2.) == 2
Exemple #6
0
def test_ifirst1():
    assert ifirst([1, 2, 3], lambda x: x > 1.5) == 1
    assert ilast([1, 2, 3], lambda x: x > 1.5) == 2