示例#1
0
  JNIEXPORT jint JNICALL Java_edu_berkeley_bid_CUMATD_initSeq
  (JNIEnv *env, jobject obj, jobject jA, jint nrows, jint ncols)
  {
    int *A = (int*)getPointer(env, jA);

    return initSeq(A, nrows, ncols);
  }
示例#2
0
/*
 * Init instruction generation.
 */
jboolean
initInsnSequence(int localsz, int stacksz, errorInfo* einfo)
{
	/* Clear various counters */
	tmpslot = 0;
	maxTemp = 0;
	maxPush = 0;
	stackno = localsz + stacksz;
	npc = 0;

	initSeq();
	initRegisters();
	initSlots(stackno);

	/* Before generating code, try to guess how much space we'll need. */
	codeblock_size = ALLOCCODEBLOCKSZ;
	codeblock = gc_malloc(codeblock_size + CODEBLOCKREDZONE,
			      KGC_ALLOC_JIT_CODEBLOCK);
	if (codeblock == 0) {
		postOutOfMemory(einfo);
		return (false);
	}
	CODEPC = 0;
	
	return (true);
}
示例#3
0
文件: Reader.c 项目: denji/mdr
seq stringToSeq(bstring str)
{
    seq s = initSeq(str->slen);

    int x;
    for (x = 0; x < str->slen; x++)
    {
        setSeq(&s, x, (int)str->data[x]);
    }

    return s;
}
示例#4
0
bool Udp2MidiThread::go(Midi2UdpThread *midi2udp)
{
	this->midi2udp = midi2udp;
	
	// Initialize midi port
	bool res = initSeq();
	if(res == false) {
		return false;
	}
	
	// run thread
	if(!isRunning()) {
		start(LowPriority);
	}
	
	return true;
}
示例#5
0
bool Midi2UdpThread::go()
{
	// Initialize midi port
	bool res = initSeq();
	if(res == false) {
		return false;
	}
	
	// start expecing MIDI events
	npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
	pfd = (struct pollfd *)malloc(npfd * sizeof(struct pollfd));
	snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);
	
	// run thread
	if(!isRunning()) {
		start(LowPriority);
	}
	
	return true;
}
示例#6
0
文件: test.c 项目: manojo/lamp-dp-mt
int main(int argc, char **argv) {
  const char* s= "aacaaaccggguuuguu";

  initSeq("../vienna/rna_turner2004.par",s);

/*
  printf("%d -- /\n",ext_mismatch_energy(0, 9)); // dlr
  printf("%d -- /\n",termau_energy(0,9));
  printf("%d -- %d\n",sr_energy(0,9), E_stack(0,9)); // stack
  printf("%d -- %d\n",sr_energy(1,8), E_stack(1,8)); // hairpin
  printf("%d -- %d\n",hl_energy(2,7), E_Hairpin(4,_bp(2,7),3,6,"CUCAGG",c_P));
  */

/*
  int r =
    ext_mismatch_energy(0, 9) + termau_energy(0,9) + // dlr(0,9)
    sr_energy(0,9) + // stack(0,9)
    sr_energy(1,8) + hl_energy(2,7); // hairpin (1,8)

  printf("Result = %d (goal = -130)\n",r);
*/


  printf("CPU Result = %d\n",
    ext_mismatch_energy(1,16) + termau_energy(1,16)
  );

  printf("GPU Result = %d\n",
    ext_mismatch_energy(0,17) + termau_energy(0,17) +
    sr_energy(1,16)
  );




  freeSeq();
  return 0;
}
示例#7
0
文件: qlv2.cpp 项目: chagge/AI
double QL::playAnEpisode(bool toTrain) {
	double epScore = 0;
	int ftime = 1;

	while(!gameOver() && !interface->isTerminal()) {
		if(ftime == 1) {
			ftime = 0;
			epScore += initSeq();
		}
		int toAct = chooseAction(toTrain);
		double lastScore = repeatLastAction(ind2Act[toAct], numFrmStack, toTrain);
		epScore += lastScore;
		int reward = 0;
		if(lastScore != 0.0f) {
			reward = 1;
			if(lastScore < 0.0f) {
				reward = -1;
			}
		}

		if(toTrain) {
			History history = {(maxHistoryLen+lastHistInd-2)%maxHistoryLen, 
								reward, 
								toAct, 
								interface->isTerminal(), 
								(maxHistoryLen+lastHistInd-1)%maxHistoryLen};
			saveHistory(history);
			if(dExp.size() > info.memThreshold) {
				getAMiniBatch();
				learnWts();
			}
		}
	}
	interface->resetVals(1);
	return epScore;
}
示例#8
0
文件: Reader.c 项目: denji/mdr
/* Align two strings using dynamic programming. Based on an algorithm
 * described at http://www.biorecipes.com/DynProgBasic/code.html for aligning
 * sequences of DNA base pairs */
void determineAlignment(seq s, seq t, int (*compare)(seq, seq, int, int), seq * alignSPtr, seq * alignTPtr)
{
    int n = s.alen;
    int m = t.alen;

    int cols = n + 1;
    int rows = m + 1;

    int ** D;
    int i, j;
    int x, y;

    int gapScore = 0;

    // Allocate memory for two integer arrays.
    int aryMemLen = m + n;
    seq alignS = initSeq(aryMemLen);
    seq alignT = initSeq(aryMemLen);

    int p;

    // Handle if one or both strings are empty.
    if (s.alen == 0 || t.alen == 0)
    {
        if (s.alen == 0)
        {
            // Fill S with gaps
            for (p = 0; p < s.alen; p++) alignS.val[p] = ALIGN_GAP;
        }
        else
        {
            // Fill S with normal mapping
            for (p = 0; p < s.alen; p++) alignS.val[p] = s.val[p];
        }

        if (t.alen == 0)
        {
            // Fill T with gaps
            for (p = 0; p < t.alen; p++) alignT.val[p] = ALIGN_GAP;
        }
        else
        {
            // Fill T with normal mapping
            for (p = 0; p < t.alen; p++) alignT.val[p] = t.val[p];
        }

        return;
    }


    // Regularly scheduled programming...

    // Allocate pointer memory for the first dimension of the matrix.
    D = malloc(rows * sizeof(int *));
    if (D == NULL)
    {
        free(D);
        printf("Memory allocation error.\n");
        exit(-1);
    }

    // Allocate integer memory for the second dimension of the matrix.
    for (x = 0; x < rows; x++)
    {
        D[x] = malloc(cols * sizeof(int));
        if (D[x] == NULL)
        {
            free(D[x]);
            printf("Memory allocation error.\n");
            exit(-1);
        }
    }

    // Initialize matrix to be filled with 0's.
    for (x = 0; x < rows; x++)
    {
        for (y = 0; y < cols; y++)
        {
            D[x][y] = 0;
        }
    }

    // Calculate values for first row.
    /*
    for (j = 0; j <= n; j++)
    {
        D[0][j] = gapScore * j;
    }
    */

    // Calculate values for first column.
    /*
    for (i = 0; i <= m; i++)
    {
        D[i][0] = gapScore * i;
    }
    */

    // Calculate inside of matrix.
    for (i = 1; i <= m; i++)
    {
        for (j = 1; j <= n; j++)
        {
            int match = D[i-1][j-1] + compare(s, t, j-1, i-1);
            int sGap = D[i][j-1] + gapScore;
            int tGap = D[i-1][j] + gapScore;
            int max = max3(match, sGap, tGap);
            D[i][j] = (max > 0 ? max : 0);
        }
    }

    /*
    for (x = 0; x < rows; x++)
    {
        for (y = 0; y < cols ; y++)
        {
            printf(" %i ", D[x][y]);
        }
        printf("\n");
    }
    */

    // Trace back through the matrix to find where we came from (which
    // represents the way to align the strings).

    i = m;
    j = n;

    while (i > 0 && j > 0)
    {
        if ((D[i][j] - compare(s, t, j-1, i-1)) == D[i-1][j-1])
        {
            // Both chars
            unshiftSeq(&alignS, s.val[j - 1]);
            unshiftSeq(&alignT, t.val[i - 1]);
            i--;
            j--;
        }
        else if (D[i][j] - gapScore == D[i][j-1])
        {
            // Gap in t/right
            unshiftSeq(&alignS, s.val[j - 1]);
            unshiftSeq(&alignT, ALIGN_GAP);
            j--;
        }
        else if (D[i][j] - gapScore == D[i-1][j])
        {
            // Gap in s/left
            unshiftSeq(&alignS, ALIGN_GAP);
            unshiftSeq(&alignT, t.val[i - 1]);
            i--;
        }
        else
        {
            printf("<GOB>I've made a huge mistake.</GOB>\n");
            exit(-1);
        }
    }

    if (j > 0)
    {
        while (j > 0)
        {
            // Gap in t/right
            unshiftSeq(&alignS, s.val[j - 1]);
            unshiftSeq(&alignT, ALIGN_GAP);
            j--;
        }
    }
    else if (i > 0)
    {
        while (i > 0)
        {
            // Gap in s/left
            unshiftSeq(&alignS, ALIGN_GAP);
            unshiftSeq(&alignT, t.val[i - 1]);
            i--;
        }
    }

    // Deallocate matrix memory.
    for (x = 0; x < rows; x++)
    {
        free(D[x]);
    }
    free(D);

    *alignSPtr = alignS;
    *alignTPtr = alignT;

    // DEBUG
    //printf("\nAlignment(%i, %i):\n%s\n%s\n", s->slen, t->slen, bstr2cstr(sAlign, '_'), bstr2cstr(tAlign, '_'));
}
示例#9
0
文件: Reader.c 项目: denji/mdr
void determineLineHighlighting(bstring a, bstring b, int ** maskPtrA, int ** maskPtrB)
{
    seq alignA = initSeq(a->slen * 1.5);
    seq alignB = initSeq(b->slen * 1.5);

    seq seqA = stringToSeq(a);
    seq seqB = stringToSeq(b);

    determineAlignment(seqA, seqB, &compareChars, &alignA, &alignB);

    assert(alignA.alen == alignB.alen);
    int len = alignA.alen;

    // Both sequences should be the same length. We'll just get the length of
    // one, which should be the upper limit needed for the masks.

    // Allocate memory for two integer masks.
    int * maskA = malloc(len * sizeof(int));
    if (maskA == NULL)
    {
        free(maskA);
        printf("Memory allocation error.\n");
        exit(-1);
    }

    int * maskB = malloc(len * sizeof(int));
    if (maskB == NULL)
    {
        free(maskB);
        printf("Memory allocation error.\n");
        exit(-1);
    }

    int i; // Position along the aligned sequences.

    int firstValueInBlockA = -1;
    int firstPosInBlockA = -1;
    int lastComparisonA = MASK_SAME;

    // Positions in each mask.
    int posA = 0;
    int posB = 0;

    for (i = 0; i < len; i++)
    {
        int currentComparisonA = compareStringPositions(alignA, alignB, i);
        int currentComparisonB = compareStringPositions(alignB, alignA, i);

        // Look ahead and back a place in the strings to see if we have an
        // isolated matching character among differences.
        if (currentComparisonA == MASK_SAME &&
            i > 0 &&
            i < len - 1 &&
            compareStringPositions(alignA, alignB, i - 1) != MASK_SAME &&
            compareStringPositions(alignA, alignB, i + 1) != MASK_SAME)
        {
            if (firstPosInBlockA > 0 && firstValueInBlockA == seqA.val[posA])
            {
                // Special case for when the char we are about to smooth is
                // actually at the beginning of the highlighted block.
                maskA[firstPosInBlockA] = MASK_SAME;
                currentComparisonA = MASK_DIFFERENT;
                //printf("%c|%c\n", seqA.val[posA-1], seqA.val[posA]);
            }
            else
            {
                // Pretend the matching characters are different to make the diff
                // look more readable.
                //printf("S");
                if (currentComparisonA != MASK_GAP) currentComparisonA = MASK_DIFFERENT;
                if (currentComparisonB != MASK_GAP) currentComparisonB = MASK_DIFFERENT;
            }
        }
        else {
            //printf("-");
        }

        // Entering region of difference.
        if (currentComparisonA != lastComparisonA &&
            currentComparisonA == MASK_DIFFERENT)
        {
            // Record position and value.
            firstValueInBlockA = seqA.val[posA];
            firstPosInBlockA = posA;
        }

        if (currentComparisonA != MASK_GAP)
        {
            maskA[posA] = currentComparisonA;
            posA++;
        }
        if (currentComparisonB != MASK_GAP)
        {
            maskB[posB] = currentComparisonB;
            posB++;
        }

        if (currentComparisonA != MASK_GAP)
        {
            lastComparisonA = currentComparisonA;
        }
    }
    //printf("\n");

    *maskPtrA = maskA;
    *maskPtrB = maskB;

    freeSeq(&seqA);
    freeSeq(&seqB);

    freeSeq(&alignA);
    freeSeq(&alignB);
}