Ejemplo n.º 1
0
    def tosptensor(self):
        """ returns the sptensor object
        that contains the same value with the tensor object."""

        length = len(self.shape)

        sub = tools.allIndices(self.shape)
        return sptensor.sptensor(
            sub,
            self.data.flatten().reshape(self.data.size, 1), self.shape)
Ejemplo n.º 2
0
 def tosptensor(self):
     """ returns the sptensor object
     that contains the same value with the tensor object."""
     
     length = len(self.shape);
     
     sub = tools.allIndices(self.shape);
     return sptensor.sptensor(
         sub,
         self.data.flatten().reshape(self.data.size, 1),
         self.shape);    
Ejemplo n.º 3
0
 def __eq__(self, oth):
     if(oth.__class__ == sptensor):
         if(self.shape != oth.shape):
             raise ValueError("Size Mismatch");
         sub1 = self.subs;
         sub2 = oth.subs;
         usub = union(sub1, sub2);
         ret = (tools.allIndices(oth.shape));
         
     elif(oth.__class__ == tensor):
         return self.__eq__(oth.tosptensor());
         
     elif(oth.__class__ == int or oth.__class__ == float or oth.__class__ == bool):
         newvals = (self.vals == oth);
         newvals = booltoint(newvals);
         return sptensor(self.subs, newvals, self.size);
         
     else:
         raise ValueError("error");
Ejemplo n.º 4
0
 def __eq__(self, oth):
     if(oth.__class__ == sptensor):
         if(self.shape != oth.shape):
             raise ValueError("Size Mismatch");
         sub1 = self.subs;
         sub2 = oth.subs;
         usub = union(sub1, sub2);
         ret = (tools.allIndices(oth.shape));
         
     elif(oth.__class__ == tensor):
         return self.__eq__(oth.tosptensor());
         
     elif(oth.__class__ == int or oth.__class__ == float or oth.__class__ == bool):
         newvals = (self.vals == oth);
         newvals = booltoint(newvals);
         return sptensor(self.subs, newvals, self.size);
         
     else:
         raise ValueError("error");
Ejemplo n.º 5
0
    def __eq__(self, oth):
        if oth.__class__ == sptensor:
            if self.shape != oth.shape:
                raise ValueError("Size Mismatch")
            sub1 = self.subs
            sub2 = oth.subs
            usub = union(sub1, sub2)
            ret = tools.allIndices(oth.shape)

        elif oth.__class__ == tensor:
            return self.__eq__(oth.tosptensor())

        elif oth.__class__ == int or oth.__class__ == float or oth.__class__ == bool:
            newvals = self.vals == oth
            newvals = booltoint(newvals)
            return sptensor(self.subs, newvals, self.size)

        else:
            raise ValueError("error")