示例#1
0
    def _read(self, row_index_or_none, col_index_or_none, order, dtype, force_python_only, view_ok):
        if row_index_or_none is None and col_index_or_none is None and self._row0 is self._row1: #read all of a square ID
            return np.identity(self.row_count,dtype=dtype)
        else: #Non-square
            #!!! This is also less efficient than it could be because it create a big identity matrix and then slices it.

            #In about O(col_count + row_count) fill in zeros
            big = np.zeros([self.row_count,self.col_count],dtype=dtype)
            common = set([PstReader._makekey(x) for x in self.row]) & set([PstReader._makekey(x) for x in self.col])
            big[self.row_to_index(common),self.col_to_index(common)] = 1.0
            val, shares_memory = self._apply_sparray_or_slice_to_val(big, row_index_or_none, col_index_or_none, order, dtype, force_python_only)
            return val
示例#2
0
    def _read(self, row_index_or_none, col_index_or_none, order, dtype, force_python_only, view_ok):
        if row_index_or_none is None and col_index_or_none is None and self._row0 is self._row1: #read all of a square ID
            return np.identity(self.row_count,dtype=dtype)
        else: #Non-square
            #!!! This is also less efficient than it could be because it create a big identity matrix and then slices it.

            #In about O(col_count + row_count) fill in zeros
            big = np.zeros([self.row_count,self.col_count],dtype=dtype)
            common = set([PstReader._makekey(x) for x in self.row]) & set([PstReader._makekey(x) for x in self.col])
            big[self.row_to_index(common),self.col_to_index(common)] = 1.0
            val, shares_memory = self._apply_sparray_or_slice_to_val(big, row_index_or_none, col_index_or_none, order, dtype, force_python_only)
            return val
示例#3
0
    def _read(self, row_index_or_none, col_index_or_none, order, dtype,
              force_python_only, view_ok, num_threads):
        dtype = np.dtype(dtype)
        if row_index_or_none is None and col_index_or_none is None and self._row0 is self._row1:  #read all of a square ID
            val = np.identity(self.row_count, dtype=dtype)
            if (order == 'F' and not val.flags["F_CONTIGUOUS"]) or (
                    order == 'C' and not val.flags["C_CONTIGUOUS"]):
                val = val.T
            return val
        else:  #Non-square
            #!!! This is also less efficient than it could be because it create a big identity matrix and then slices it.

            #In about O(col_count + row_count) fill in zeros
            big = np.zeros([self.row_count, self.col_count], dtype=dtype)
            common = set([PstReader._makekey(x) for x in self.row]) & set(
                [PstReader._makekey(x) for x in self.col])
            big[self.row_to_index(common), self.col_to_index(common)] = 1.0
            val, shares_memory = self._apply_sparray_or_slice_to_val(
                big, row_index_or_none, col_index_or_none, order, dtype,
                force_python_only, num_threads)
            return val