def compute(self, env: Environment): e1 = env.find_object('e1') e2 = env.find_object('e2') if isinstance(e2, EmptyParamObj): if e1.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('x', '- x') res = [] for item in e1.items: res.append( atomic_subtract(Atomic(False, types.LogicalType()), item.value)) res = [VectorItem(None, el) for el in res] ret = VectorObj(res) return ret if e1.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('x', 'x - y') if e2.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('y', 'x - y') as_integer = False if e1.get_type().name == 'integer' and e2.get_type().name == 'integer': as_integer = True elif e1.get_type().name == 'integer' and e2.get_type( ).name == 'logical': as_integer = True elif e1.get_type().name == 'logical' and e2.get_type( ).name == 'integer': as_integer = True res = perform_op_on_vector_or_atomic( e1, e2, lambda l, r: cast_atomic(atomic_subtract(l, r), 'integer' if as_integer else 'double')) res = [VectorItem(None, el) for el in res] if len(res) == 0: t = get_more_important_vector_type(e1.get_type(), e2.get_type()) return VectorObj([], t) ret = VectorObj.create(res) return ret
def compute(self, params: List[Param], env: Environment): args = self.arrange_args(params) e1: Param = args['e1'] e2: Param = args['e2'] if e1.value.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('x', 'x ** y') if e2.value.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('y', 'x ** y') res = [] as_integer = False if e1.value.get_type().name == 'integer' and e2.value.get_type().name == 'integer': as_integer = True elif e1.value.get_type().name == 'integer' and e2.value.get_type().name == 'logical': as_integer = True elif e1.value.get_type().name == 'logical' and e2.value.get_type().name == 'integer': as_integer = True for l, r in concat_vectors(e1.value.items, e2.value.items): res.append(cast_atomic(atomic_mod(l.value, r.value), 'integer' if as_integer else 'double')) res = [VectorItem(None, el) for el in res] ret = VectorObj(res) return ret
def compute(self, env: Environment): e1 = env.find_object('e1') e2 = env.find_object('e2') if e1.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('x', 'x ** y') if e2.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('y', 'x ** y') as_integer = False if e1.get_type().name == 'integer' and e2.get_type().name == 'integer': as_integer = True elif e1.get_type().name == 'integer' and e2.get_type( ).name == 'logical': as_integer = True elif e1.get_type().name == 'logical' and e2.get_type( ).name == 'integer': as_integer = True res = perform_op_on_vector_or_atomic( e1, e2, lambda l, r: cast_atomic(atomic_mod(l, r), 'integer' if as_integer else 'double')) res = [VectorItem(None, el) for el in res] if len(res) == 0: t = get_more_important_vector_type(e1.get_type(), e2.get_type()) return VectorObj([], t) ret = VectorObj.create(res) return ret
def compute(self, env: Environment): ln: VectorObj = env.find_object('length') if ln.get_type().name not in ['double', 'integer']: raise errors.InvalidArg('length') if len(ln.items) != 1: raise errors.InvalidArg('length') val = ln.items[0][1] if val.is_inf: raise errors.R_RuntimeError('vector size cannot be infinite') elif val.is_na: raise errors.InvalidArg('length') elif val.is_nan: raise errors.R_RuntimeError('vector size cannot be NA/NaN') count = val.value items = [ VectorItem(None, Atomic(False, types.LogicalType())) for _ in range(int(count) * (-1 if val.is_neg else 1)) ] ret = VectorObj(items, types.LogicalType()) return ret
def compute(self, params: List[Param], env: Environment): args = self.arrange_args(params) e1: Param = args['x'] e2: Param = args['y'] if e1.value.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('x', 'x | y') if e2.value.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('y', 'x | y') res = VectorItem(None, atomic_or(e1.value.items[0].value, e2.value.items[0].value)) ret = VectorObj([res]) return ret
def compute(self, params: List[Param], env: Environment): args = self.arrange_args(params) e1: Param = args['x'] if e1.value.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgType() res = [] for item in e1.value.items: res.append(atomic_not(item.value)) res = [VectorItem(None, el) for el in res] ret = VectorObj(res) return ret
def compute(self, params: List[Param], env: Environment): args = self.arrange_args(params) e1: Param = args['x'] e2: Param = args['y'] if e1.value.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('x', 'x || y') if e2.value.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('y', 'x || y') res = [] for l, r in concat_vectors(e1.value.items, e2.value.items): res.append(atomic_or(l.value, r.value)) res = [VectorItem(None, el) for el in res] ret = VectorObj(res) return ret
def compute(self, env: Environment): e1 = env.find_object('x') if e1.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgType() res = [] if isinstance(e1, VectorObj): if len(e1.items) == 0: return VectorObj([], type(e1.get_type())()) for item in e1.items: res.append(atomic_not(item[1])) else: res.append(atomic_not(e1)) res = [VectorItem(None, el) for el in res] ret = VectorObj.create(res) return ret
def compute(self, params: List[Param], env: Environment): args = self.arrange_args(params) e1: Param = args['x'] e2: Param = args['y'] if e1.value.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('x', 'x && y') if e2.value.get_type().name not in ['double', 'logical', 'integer']: raise errors.InvalidArgTypeInArgs('y', 'x && y') res = [] try: for l, r in concat_vectors(e1.value.items, e2.value.items): res.append(atomic_and(l.value, r.value)) except UnsupportedVectorType as e: raise errors.InvalidArgTypeInArgs('x' if e.operand_index == 0 else 'y', 'x && y') res = [VectorItem(None, el) for el in res] ret = VectorObj(res) return ret