示例#1
0
    def __init__(self, A):
        if A.dtype.type is not numpy.float64:
            raise errors.UnsupportedError(
                "Only float64 matrices are supported.")
        if A.base is not None:
            raise errors.UnsupportedError(
                "Passing a numpy matrix view is not supported.")

        self._A = A
示例#2
0
        def __init__(self, A):
            if El.TagToType(A.tag) != ctypes.c_double:
                raise errors.UnsupportedError(
                    "Only double precision matrices are supported.")

            self._A = A
            self._dist_data = A.GetDistData()
            if self._dist_data.colDist == El.MC and self._dist_data.rowDist == El.MR:
                self._ctype = "DistMatrix"
                self._typeid = ""
            else:
                if self._dist_data.colDist == El.CIRC and self._dist_data.rowDist == El.CIRC:
                    self._ctype = "SharedMatrix"
                elif self._dist_data.colDist == El.STAR and self._dist_data.rowDist == El.STAR:
                    self._ctype = "RootMatrix"
                else:
                    tagmap = {
                        El.VC: "VC",
                        El.VR: "VR",
                        El.MC: "MC",
                        El.MR: "MR",
                        El.STAR: "STAR",
                        El.CIRC: "CIRC"
                    }
                    self._typeid = tagmap[
                        self._dist_data.colDist] + "_" + tagmap[
                            self._dist_data.rowDist]
                    self._ctype = "DistMatrix_" + self._typeid
示例#3
0
 def _baseinit(self, ttype, n, s, defouttype, forceppy):
     if defouttype is not None and not lib.map_to_ctor.has_key(defouttype):
         raise errors.UnsupportedError(
             "Unsupported default output type (%s)" % defouttype)
     self._ttype = ttype
     self._n = n
     self._s = s
     self._defouttype = defouttype
     self._ppy = (not _haslib) or forceppy
示例#4
0
        def __init__(self, A):
            if El.TagToType(A.tag) != ctypes.c_double:
                raise errors.UnsupportedError(
                    "Only double precision matrices are supported.")

            self._A = A
示例#5
0
    def apply(self, A, SA, dim=0):
        """
    Apply the transform on **A** along dimension **dim** and write
    result in **SA**. Note: for rowwise (aka right) sketching **A**
    is mapped to **A S^T**.

    :param A: Input matrix.
    :param SA: Ouptut matrix. If "None" then the output will be allocated.
    :param dim: Dimension to apply along. 0 - columnwise, 1 - rowwise.
                or can use "columnwise"/"rowwise", "left"/"right"
                default is columnwise
    :returns: SA
    """
        if dim == 0 or dim == "columnwise" or dim == "left":
            dim = 0
        if dim == "rowwise" or dim == "right":
            dim = 1
        if dim != 0 and dim != 1:
            raise ValueError(
                "Dimension must be either columnwise/rowwise or left/right or 0/1"
            )

        A = lib.adapt(A)

        # Allocate in case SA is not given, and then adapt it.
        if SA is None:
            if self._defouttype is None:
                ctor = A.getctor()
            else:
                ctor = lib.map_to_ctor[self._defouttype]

            if dim == 0:
                SA = ctor(self._s, A.getdim(1), A)
            if dim == 1:
                SA = ctor(A.getdim(0), self._s, A)
        SA = lib.adapt(SA)

        reqcomb = (self._ttype, A.ctype(), SA.ctype())
        if reqcomb not in SUPPORTED_SKETCH_TRANSFORMS:
            raise errors.UnsupportedError("Unsupported transform-input-output combination: " \
                                            + str(reqcomb))

        incomp, cinvert = A.iscompatible(SA)
        if incomp is not None:
            raise errors.UnsupportedError(
                "Input and output are incompatible: " + incomp)

        if A.getdim(dim) != self._n:
            raise errors.DimensionMistmatchError(
                "Sketched dimension is incorrect (input)")
        if SA.getdim(dim) != self._s:
            raise errors.DimensionMistmatchError(
                "Sketched dimension is incorrect (output)")
        if A.getdim(1 - dim) != SA.getdim(1 - dim):
            raise errors.DimensionMistmatchError(
                "Sketched dimension is incorrect (input != output)")

        if self._ppy:
            self._ppyapply(A.getobj(), SA.getobj(), dim)
        else:
            Aobj = A.ptr()
            SAobj = SA.ptr()
            if (Aobj == -1 or SAobj == -1):
                raise errors.InvalidObjectError(
                    "Invalid/unsupported object passed as A or SA")

            if cinvert:
                cdim = 1 - dim
            else:
                cdim = dim

            lib.callsl("sl_apply_sketch_transform", self._obj, \
                      A.ctype(), Aobj, SA.ctype(), SAobj, cdim+1)

            A.ptrcleaner()
            SA.ptrcleaner()

        return SA.getobj()