mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-30 14:35:15 +02:00
symmetrify now falls back gracefully to numpy if weave fails
This commit is contained in:
parent
be8fa21cbc
commit
f9b6e0991c
2 changed files with 37 additions and 7 deletions
|
|
@ -19,4 +19,9 @@ dir=$HOME/tmp/GPy-datasets/
|
||||||
# if you have an anaconda python installation please specify it here.
|
# if you have an anaconda python installation please specify it here.
|
||||||
installed = False
|
installed = False
|
||||||
location = None
|
location = None
|
||||||
MKL = False # set this to true if you have the MKL optimizations installed
|
# set this to true if you have the MKL optimizations installed:
|
||||||
|
MKL = False
|
||||||
|
|
||||||
|
[weave]
|
||||||
|
#if true, try to use weave, and fall back to numpy. if false, just use numpy.
|
||||||
|
working = True
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,10 @@ from scipy import linalg, weave
|
||||||
import types
|
import types
|
||||||
import ctypes
|
import ctypes
|
||||||
from ctypes import byref, c_char, c_int, c_double # TODO
|
from ctypes import byref, c_char, c_int, c_double # TODO
|
||||||
# import scipy.lib.lapack
|
|
||||||
import scipy
|
import scipy
|
||||||
import warnings
|
import warnings
|
||||||
import os
|
import os
|
||||||
from config import *
|
from config import config
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
_scipyversion = np.float64((scipy.__version__).split('.')[:2])
|
_scipyversion = np.float64((scipy.__version__).split('.')[:2])
|
||||||
|
|
@ -521,6 +520,27 @@ def symmetrify(A, upper=False):
|
||||||
Take the square matrix A and make it symmetrical by copting elements from the lower half to the upper
|
Take the square matrix A and make it symmetrical by copting elements from the lower half to the upper
|
||||||
|
|
||||||
works IN PLACE.
|
works IN PLACE.
|
||||||
|
|
||||||
|
note: tries to use weave, falls back to a slower numpy version
|
||||||
|
"""
|
||||||
|
if config.getboolean('weave', 'working'):
|
||||||
|
try:
|
||||||
|
symmetrify_weave(A, upper)
|
||||||
|
except:
|
||||||
|
print "\n Weave compilation failed. Falling back to (slower) numpy implementation\n"
|
||||||
|
config.set('weave', 'working', False)
|
||||||
|
symmetrify_numpy(A, upper)
|
||||||
|
else:
|
||||||
|
symmetrify_numpy(A, upper)
|
||||||
|
|
||||||
|
|
||||||
|
def symmetrify_weave(A, upper=False):
|
||||||
|
"""
|
||||||
|
Take the square matrix A and make it symmetrical by copting elements from the lower half to the upper
|
||||||
|
|
||||||
|
works IN PLACE.
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
N, M = A.shape
|
N, M = A.shape
|
||||||
assert N == M
|
assert N == M
|
||||||
|
|
@ -563,10 +583,15 @@ def symmetrify(A, upper=False):
|
||||||
A += np.tril(tmp, -1).T
|
A += np.tril(tmp, -1).T
|
||||||
|
|
||||||
|
|
||||||
def symmetrify_murray(A):
|
def symmetrify_numpy(A, upper=False):
|
||||||
A += A.T
|
"""
|
||||||
nn = A.shape[0]
|
Force a matrix to be symmetric
|
||||||
A[[range(nn), range(nn)]] /= 2.0
|
"""
|
||||||
|
triu = np.triu_indices_from(A,k=1)
|
||||||
|
if upper:
|
||||||
|
A.T[triu] = A[triu]
|
||||||
|
else:
|
||||||
|
A[triu] = A.T[triu]
|
||||||
|
|
||||||
def cholupdate(L, x):
|
def cholupdate(L, x):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue