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
from libc.stdlib cimport malloc, free, realloc | |
cdef struct Chair: | |
int size | |
cdef class Bench: | |
cdef Chair* chairs | |
cdef readonly int num_chairs | |
property chairs: |
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
# How to get gemm to work in Cython | |
# 1. suppose your data is Fortran contiguous (really ?) | |
# then blas supports this out of the box: | |
%%cython | |
cimport numpy as np | |
import numpy as np | |
from cpython cimport PyCapsule_GetPointer # PyCObject_AsVoidPtr |
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
%%cython | |
import cython | |
from cython cimport view | |
import numpy as np | |
cimport numpy as np | |
from cpython cimport PyCapsule_GetPointer # PyCObject_AsVoidPtr | |
from scipy.linalg.blas import fblas | |
REAL = np.float32 |
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
%%cython | |
import cython | |
import numpy as np | |
cimport numpy as np | |
from libc.math cimport exp | |
from libc.string cimport memset | |
from cpython cimport PyCapsule_GetPointer # PyCObject_AsVoidPtr |
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
import theano, theano.tensor as T, numpy as np | |
def _outer_substract(x, y): | |
x = x.dimshuffle(0, 1, 'x') | |
x = T.addbroadcast(x, 2) | |
return (x - y.T).T | |
def _gaussian_kernel(x, y, beta = 0.1): | |
K = _outer_substract(x,y) | |
return T.exp( -beta * K.norm(L=2,axis=1)) | |
x = T.matrix() |
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
# coding: utf-8 | |
# | |
# @author Jonathan Raiman | |
# @date 9th October 2014 | |
# | |
# Messing around with Stanford's GloVe words | |
# Download them [here](http://www-nlp.stanford.edu/projects/glove/) | |
import gzip, numpy as np, io |
NewerOlder