This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "quad-tree.h" | |
| #include <math.h> | |
| #include <stdlib.h> | |
| struct qnode_t { | |
| struct point_t pt; | |
| struct qnode_t *children[4]; | |
| }; | |
| struct qtree_t { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define CUDA_KERNEL_GUARD(i, n) for(int i = blockIdx.x * blockDim.x + threadIdx.x; i < n; i += blockDim.x * gridDim.x) | |
| __global__ | |
| void saxpy(int n, float a, float *x, float *y) { | |
| CUDA_KERNEL_GUARD(i, n) { | |
| y[i] = a * x[i] + y[i]; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defface paren-face | |
| '((((class color) (background dark)) | |
| (:foreground "grey80")) | |
| (((class color) (background light)) | |
| (:foreground "grey40"))) | |
| "Face used to dim parentheses.") | |
| (defface paren-face-2 | |
| '((((class color) (background dark)) | |
| (:foreground "grey40")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * here is a way I try to self-explain the CUDA execution configuration model. | |
| * this makes me think flexiblly when writing CUDA codes. | |
| * | |
| * @blackball | |
| */ | |
| /* | |
| normally, we write kernel function like this. | |
| note, __global__ means this function will be called from host codes, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* @TODO A simple optimization is to concatenate all sub strings into one big string. | |
| * this will save some memory and probably make accessing more efficient. | |
| */ | |
| /* char value to binary string look-up table, generated by Python */ | |
| static const char* _convTab[256] = { | |
| "00000000","00000001","00000010","00000011","00000100","00000101","00000110","00000111", | |
| "00001000","00001001","00001010","00001011","00001100","00001101","00001110","00001111", | |
| "00010000","00010001","00010010","00010011","00010100","00010101","00010110","00010111", | |
| "00011000","00011001","00011010","00011011","00011100","00011101","00011110","00011111", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <assert.h> | |
| typedef double real; | |
| static inline real | |
| variance(const real *vec, const int len) { | |
| /* iteratove variance calculation */ | |
| register real oldm, newm, olds, news; | |
| assert( vec && (len > 0)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Simple Lisp tree implementation. | |
| * Adopted from http://nakkaya.com/2010/08/24/a-micro-manual-for-lisp-implemented-in-c/ | |
| * | |
| * @blackball | |
| */ | |
| #include <ctype.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| static void | |
| _merge(int *labels, int n, int src, int dst) { | |
| for (int i = 0; i < n; ++i) { | |
| if (labels[i] == src) | |
| labels[i] = dst; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Find K-smallest value in array use a simplified max-heap */ | |
| /* | |
| 0. Build a max-heap(MH) for the first K elements | |
| 1. For each element after the Kth element, compare it with the root of MH | |
| 0. If the element is smaller than the root, make it root and heapify^1 MH | |
| 1. Else ignore it. | |
| 2. Finally, MH has K-smallest elements. | |
| Complexity: O(K + (n-K)log(K) + Klog(K)), the last Klog(K) for sorted^2 ouput. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; overide the default changing font size bindings | |
| ;; to make changing more subtle | |
| (defun local-increase-font-size () | |
| (interactive) | |
| (set-face-attribute 'default | |
| nil | |
| :height | |
| (ceiling (* 1.03 (face-attribute 'default :height))))) | |
| (defun local-decrease-font-size () |