Esempio n. 1
0
    def __mul__(self, other):
	if isParticleProperty(other):
	    if other.value_rank == 0:
		return ParticleTensor(self.universe,
                                      self.array*other.array[:,
                                                             Numeric.NewAxis,
                                                             Numeric.NewAxis])
	    else:
		raise TypeError, 'not yet implemented'
	elif isVector(other):
	    raise TypeError, 'not yet implemented'
	elif isTensor(other):
	    raise TypeError, 'not yet implemented'
	else:
	    return ParticleTensor(self.universe, self.array*other)
 def __mul__(self, other):
     if isParticleProperty(other):
         if self.universe != other.universe:
             raise ValueError('Variables are for different universes')
         if other.value_rank == 0:
             return ParticleTensor(
                 self.universe,
                 self.array * other.array[:, N.NewAxis, N.NewAxis])
         else:
             raise TypeError('not yet implemented')
     elif isVector(other):
         raise TypeError('not yet implemented')
     elif isTensor(other):
         raise TypeError('not yet implemented')
     else:
         return ParticleTensor(self.universe, self.array * other)
 def __mul__(self, other):
     if isParticleProperty(other):
         if self.universe != other.universe:
             raise ValueError('Variables are for different universes')
         if other.value_rank == 0:
             return ParticleTensor(self.universe,
                                   self.array*other.array[:,
                                                          N.NewAxis,
                                                          N.NewAxis])
         else:
             raise TypeError('not yet implemented')
     elif isVector(other):
         raise TypeError('not yet implemented')
     elif isTensor(other):
         raise TypeError('not yet implemented')
     else:
         return ParticleTensor(self.universe, self.array*other)
Esempio n. 4
0
    def __mul__(self, other):
	if isParticleProperty(other):
	    if other.value_rank == 0:
		return ParticleVector(self.universe,
				     self.array*other.array[:,Numeric.NewAxis])
	    elif other.value_rank == 1:
		return ParticleScalar(self.universe,
				      Numeric.add.reduce(self.array * \
							 other.array, -1))
	    else:
		raise TypeError, 'not yet implemented'
	elif isVector(other):
	    return ParticleScalar(self.universe,
                                  Numeric.add.reduce(
                                     self.array*other.array[Numeric.NewAxis,:],
                                      -1))
	elif isTensor(other):
	    raise TypeError, 'not yet implemented'
	else:
	    return ParticleVector(self.universe, self.array*other)
 def _checkCompatibility(self, other, allow_scalar=0):
     if isParticleProperty(other):
         if other.data_rank != self.data_rank:
             raise TypeError('Incompatible types')
         if self.universe != other.universe:
             raise ValueError('Variables are for different universes')
         if self.version != other.version:
             raise ValueError("Universe version numbers do not agree")
         if self.value_rank == other.value_rank:
             return self.return_class, other.array
         elif allow_scalar and (self.value_rank==0 or other.value_rank==0):
             if self.value_rank == 0:
                 return other.return_class, other.array
             else:
                 return self.return_class, other.array
         else:
             raise ValueError("Ranks do not match")
     elif isVector(other) or isTensor(other):
         if len(other.array.shape) > self.value_rank:
             raise TypeError('Incompatible types')
         return self.return_class, other.array
     else:
         return self.return_class, other
 def _checkCompatibility(self, other, allow_scalar=False):
     if isParticleProperty(other):
         if other.data_rank != self.data_rank:
             raise TypeError('Incompatible types')
         if self.universe != other.universe:
             raise ValueError('Variables are for different universes')
         if self.version != other.version:
             raise ValueError("Universe version numbers do not agree")
         if self.value_rank == other.value_rank:
             return self.return_class, other.array
         elif allow_scalar and (self.value_rank==0 or other.value_rank==0):
             if self.value_rank == 0:
                 return other.return_class, other.array
             else:
                 return self.return_class, other.array
         else:
             raise ValueError("Ranks do not match")
     elif isVector(other) or isTensor(other):
         if len(other.array.shape) > self.value_rank:
             raise TypeError('Incompatible types')
         return self.return_class, other.array
     else:
         return self.return_class, other