예제 #1
0
파일: array.cpp 프로젝트: dsgipe/array
Arr concatinate(Arr& obj1, Arr& obj2,int dim){
    Arr ArrRtn;
    int M,N;
    //If the concatinate rows
    if (dim == 1){
        M = obj1.M;
        N = obj1.N+obj2.N;
    }else{//concatinate columns
        M = obj1.M+obj2.M;
        N = obj1.N;
    }
    ArrRtn.Init(0.0,M,N);
    //fill using first array
    for (int ii = 0; ii < obj1.N; ii++){
        for (int jj = 0; jj < obj1.M; jj++){
            ArrRtn.push(obj1.element(ii,jj),ii,jj);
        }
    } 
    //---------------------------------------------//
    //       fill using second array
    //---------------------------------------------//
    //concatinate rows
    if (dim == 1){
        for (int ii = obj1.N; ii < N; ii++){
            for (int jj = 0; jj < M; jj++){
                ArrRtn.push(obj2.element(ii-obj1.N,jj),ii,jj);
            }
        } 
    }else{//concatinate columns
        for (int ii = 0; ii < N; ii++){
            for (int jj = obj1.M; jj < M; jj++){
                ArrRtn.push(obj2.element(ii,jj-obj1.M),ii,jj);
            }
        } 
    }
    return ArrRtn;
}
예제 #2
0
파일: resolve.cpp 프로젝트: zeux/aike
static Arr<Variable*> resolveBindings(const vector<Variable*>& targets)
{
	if (targets.empty())
		return {};

	if (targets[0]->kind != Variable::KindFunction)
		return { targets[0] };

	Arr<Variable*> result;

	for (Variable* var: targets)
		if (var->kind == Variable::KindFunction)
			result.push(var);

	return result;
}
예제 #3
0
파일: typecheck.cpp 프로젝트: zeux/aike
static void typeCall(Output& output, Ast::Call* n, TypeConstraints* constraints)
{
	type(output, n->expr, constraints);

	for (auto& a: n->args)
		type(output, a, constraints);

	if (UNION_CASE(Ident, ne, n->expr))
	{
		if (constraints && ne->targets.size > 1)
		{
			vector<Ty*> args;

			for (auto& a: n->args)
				args.push_back(astType(a));

			constraints->rewrites += reduceCandidates(ne->targets, args);
		}
	}

	// This is important for vararg functions and generates nicer errors for argument count/type mismatch
	if (UNION_CASE(Function, fnty, astType(n->expr)))
	{
		if (isArgumentCountValid(fnty, n->args.size))
		{
			for (size_t i = 0; i < fnty->args.size; ++i)
				typeMustEqual(n->args[i], fnty->args[i], constraints, output);
		}
		else if (!constraints)
			output.error(n->location, "Expected %d arguments but given %d", int(fnty->args.size), int(n->args.size));

		n->type = fnty->ret;
	}
	else
	{
		Arr<Ty*> args;

		for (auto& a: n->args)
			args.push(astType(a));

		Ty* ret = UNION_NEW(Ty, Unknown, {});

		typeMustEqual(n->expr, UNION_NEW(Ty, Function, { args, ret }), constraints, output);

		n->type = ret;
	}
}
예제 #4
0
파일: array.cpp 프로젝트: dsgipe/array
//************************************************
Arr Arr::transpose(){
    //---------------------------------------------//
    // Transpose a row ordered array, arr,
    // Inputs:
    //     arr: 1d array in column ordered format
    //     nc:  number of columns
    //     nr:  number of rows
    // Returns:
    //     transpose of arr
    //---------------------------------------------//
    Arr RtnArray;
    RtnArray.Init(N,M);
    for (int ii = 0; ii < M; ii++){
        for (int jj = 0; jj <N; jj++){
            RtnArray.push(element(jj,ii),ii,jj);
        }
    }
    return RtnArray;

}
예제 #5
0
파일: typecheck.cpp 프로젝트: zeux/aike
static void typeLiteralTuple(Output& output, Ast::LiteralTuple* n, TypeConstraints* constraints)
{
	if (!n->type)
	{
		Arr<Ty*> fields;
		for (size_t i = 0; i < n->fields.size; ++i)
			fields.push(UNION_NEW(Ty, Unknown, {}));

		n->type = UNION_NEW(Ty, Tuple, { fields });
	}

	UNION_CASE(Tuple, tt, n->type);
	assert(tt);

	for (size_t i = 0; i < n->fields.size; ++i)
	{
		type(output, n->fields[i], constraints);

		typeMustEqual(n->fields[i], tt->fields[i], constraints, output);
	}
}