In [1]:
import importlib
import theano.tensor as T
import sys, os
sys.path.append("/home/bl3/PycharmProjects/GeMpy/")
import GeoMig
#importlib.reload(GeoMig)
importlib.reload(GeoMig)
import numpy as np
os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
np.set_printoptions(precision = 2, linewidth= 130, suppress =  True)


test = GeoMig.GeoMigSim_pro2(c_o = np.float32(-0.58888888),range = np.float32(6))

#print (ref_p)

test.create_regular_grid_2D(0,10,0,10,100,100)
test.theano_set_2D()


/home/bl3/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:18: DeprecationWarning: stack(*tensors) interface is deprecated, use stack(tensors, axis=0) instead.

In [2]:
test.a.eval()


Out[2]:
array(6.0, dtype=float32)

In [30]:
layer_1 = np.array([[1,7],[5,7],[6,7], [9,8]], dtype = "float32")

layer_2 = np.array([[9.1,1],[9,1]], dtype = "float32")

dip_pos_1 = np.array([2,4,], dtype = "float32")
dip_pos_2 = np.array([6.,3.], dtype = "float32")
dip_pos_3 = np.array([8,4], dtype = "float32")
dip_angle_1 = float(250)
dip_angle_2 = float(70)

layers = np.asarray([layer_1,layer_2])
dips = np.asarray([dip_pos_1,dip_pos_2])#, dip_pos_3])
dips_angles = np.asarray([dip_angle_1, dip_angle_2], dtype="float32")
#print (dips_angles)
rest = np.vstack((i[1:] for i in layers))
ref = np.vstack((np.tile(i[0],(np.shape(i)[0]-1,1)) for i in layers))
dips_angles.dtype


Out[30]:
dtype('float32')

In [31]:
dips


Out[31]:
array([[ 2.,  4.],
       [ 6.,  3.]], dtype=float32)

In [32]:
rest = rest.astype("float32")
ref = ref.astype("float32")
dips = dips.astype("float32")
dips_angles = dips_angles.astype("float32")
type(dips_angles)


Out[32]:
numpy.ndarray

In [33]:
dips;

In [34]:
test.geoMigueller(dips,dips_angles,rest, ref)[4]


Out[34]:
array([[ 0.59,  0.13, -0.  ,  0.06,  0.13,  0.09,  0.07,  0.  ,  1.  ,  0.  ],
       [ 0.13,  0.59,  0.06, -0.  , -0.02, -0.  ,  0.  ,  0.01,  1.  ,  0.  ],
       [-0.  ,  0.06,  0.59,  0.01, -0.15, -0.2 , -0.21,  0.  ,  0.  ,  1.  ],
       [ 0.06, -0.  ,  0.01,  0.59,  0.09,  0.11,  0.  , -0.01,  0.  ,  1.  ],
       [ 0.13, -0.02, -0.15,  0.09,  1.87,  1.78,  0.99,  0.  ,  4.  ,  0.  ],
       [ 0.09, -0.  , -0.2 ,  0.11,  1.78,  1.99,  1.2 ,  0.  ,  5.  ,  0.  ],
       [ 0.07,  0.  , -0.21,  0.  ,  0.99,  1.2 ,  2.  ,  0.  ,  8.  ,  1.  ],
       [ 0.  ,  0.01,  0.  , -0.01,  0.  ,  0.  ,  0.  ,  0.  , -0.1 ,  0.  ],
       [ 1.  ,  1.  ,  0.  ,  0.  ,  4.  ,  5.  ,  8.  , -0.1 ,  0.  ,  0.  ],
       [ 0.  ,  0.  ,  1.  ,  1.  ,  0.  ,  0.  ,  1.  ,  0.  ,  0.  ,  0.  ]])

In [35]:
sol = test.geoMigueller(dips,dips_angles,rest, ref)[0]

In [36]:
np.set_printoptions(precision = 2 ,linewidth= 130, suppress =  True)

test.geoMigueller(dips,dips_angles,rest, ref)[0]


Out[36]:
array([ 0.12,  0.13,  0.13, ...,  0.03,  0.02,  0.02])

In [37]:
import matplotlib.pyplot as plt
% matplotlib inline
dip_pos_1_v = np.array([np.cos(np.deg2rad(dip_angle_1))*1,
                        np.sin(np.deg2rad(dip_angle_1))]) + dip_pos_1

dip_pos_2_v = np.array([np.cos(np.deg2rad(dip_angle_2))*1, 
                        np.sin(np.deg2rad(dip_angle_2))]) + dip_pos_2

plt.arrow(dip_pos_1[0],dip_pos_1[1], dip_pos_1_v[0]-dip_pos_1[0],
          dip_pos_1_v[1]-dip_pos_1[1], head_width = 0.2)
plt.arrow(dip_pos_2[0],dip_pos_2[1],dip_pos_2_v[0]-dip_pos_2[0], 
          dip_pos_2_v[1]-dip_pos_2[1], head_width = 0.2)

plt.plot(layer_1[:,0],layer_1[:,1], "o")
plt.plot(layer_2[:,0],layer_2[:,1], "o")

plt.plot(layer_1[:,0],layer_1[:,1], )
plt.plot(layer_2[:,0],layer_2[:,1], )

plt.contour( sol.reshape(100,100) ,30,extent = (0,10,0,10) )
#plt.colorbar()
#plt.xlim(0,10)
#plt.ylim(0,10)
plt.title("GeoBulleter v 0.1")
print (dip_pos_1_v, dip_pos_2_v, layer_1)


[ 1.66  3.06] [ 6.34  3.94] [[ 1.  7.]
 [ 5.  7.]
 [ 6.  7.]
 [ 9.  8.]]

In [38]:
# random
layers = [np.random.uniform(0,10,(10,2)) for i in range(100)]
dips = np.random.uniform(0,10, (60,2))
dips_angles = np.random.normal(90,10, 60)
rest = (np.vstack((i[1:] for i in layers)))
ref = np.vstack((np.tile(i[0],(np.shape(i)[0]-1,1)) for i in layers))
rest;

In [48]:
import matplotlib.pyplot as plt
% matplotlib inline
plt.contour( sol.reshape(100,100) ,30,extent = (0,10,0,10) )


Out[48]:
<matplotlib.contour.QuadContourSet at 0x7ff54bfa5278>

CPU


In [17]:
%%timeit
sol = test.geoMigueller(dips,dips_angles,rest, ref)[0]


1 loop, best of 3: 5.81 s per loop

In [18]:
test.geoMigueller.profile.summary()


Function profiling
==================
  Message: /home/miguel/PycharmProjects/GeMpy/GeoMig.py:562
  Time in 5 calls to Function.__call__: 2.937774e+01s
  Time in Function.fn.__call__: 2.937736e+01s (99.999%)
  Time in thunks: 2.934835e+01s (99.900%)
  Total compile time: 1.559712e+00s
    Number of Apply nodes: 171
    Theano Optimizer time: 1.410723e+00s
       Theano validate time: 4.508591e-02s
    Theano Linker time (includes C, CUDA code generation/compiling): 9.198022e-02s
       Import time 0.000000e+00s

Time in all call to theano.grad() 0.000000e+00s
Time since theano import 132.105s
Class
---
<% time> <sum %> <apply time> <time per call> <type> <#call> <#apply> <Class name>
  83.6%    83.6%      24.529s       1.29e-01s     C      190      38   theano.tensor.elemwise.Elemwise
   6.4%    90.0%       1.889s       5.40e-02s     C       35       7   theano.tensor.elemwise.Sum
   5.1%    95.1%       1.496s       2.99e-02s     C       50      10   theano.tensor.blas.Dot22Scalar
   2.5%    97.6%       0.743s       1.86e-02s     C       40       8   theano.tensor.basic.Alloc
   2.3%   100.0%       0.682s       2.27e-02s     C       30       6   theano.tensor.basic.Join
   0.0%   100.0%       0.008s       1.55e-03s     Py       5       1   theano.tensor.nlinalg.MatrixInverse
   0.0%   100.0%       0.000s       2.76e-06s     C       95      19   theano.tensor.basic.Reshape
   0.0%   100.0%       0.000s       2.37e-06s     C       65      13   theano.tensor.subtensor.IncSubtensor
   0.0%   100.0%       0.000s       9.48e-07s     C      155      31   theano.tensor.elemwise.DimShuffle
   0.0%   100.0%       0.000s       2.77e-05s     Py       5       1   theano.tensor.extra_ops.FillDiagonal
   0.0%   100.0%       0.000s       2.34e-06s     C       55      11   theano.tensor.subtensor.Subtensor
   0.0%   100.0%       0.000s       1.37e-06s     C       60      12   theano.tensor.opt.MakeVector
   0.0%   100.0%       0.000s       1.14e-06s     C       30       6   theano.compile.ops.Shape_i
   0.0%   100.0%       0.000s       5.77e-06s     C        5       1   theano.tensor.blas_c.CGemv
   0.0%   100.0%       0.000s       7.71e-07s     C       30       6   theano.tensor.basic.ScalarFromTensor
   0.0%   100.0%       0.000s       1.19e-06s     C        5       1   theano.tensor.basic.AllocEmpty
   ... (remaining 0 Classes account for   0.00%(0.00s) of the runtime)

Ops
---
<% time> <sum %> <apply time> <time per call> <type> <#call> <#apply> <Op name>
  47.3%    47.3%      13.894s       2.78e+00s     C        5        1   Elemwise{Composite{(i0 * i1 * LT(Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4), i5) * Composite{(sqr(i0) * i0)}((i5 - Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4))) * ((i6 * sqr(Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4))) + i7 + (i8 * i5 * Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4))))}}[(0, 1)]
  28.1%    75.5%       8.253s       1.65e+00s     C        5        1   Elemwise{Composite{(i0 * ((LT(Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3), i4) * ((i5 + (i6 * Composite{(sqr(i0) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4))) + (i7 * Composite{((sqr(sqr(i0)) * sqr(i0)) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4)))) - ((i8 * sqr((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4))) + (i9 * Composite{(sqr(sqr(i0)) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4
   6.1%    81.6%       1.799s       1.20e-01s     C       15        3   Sum{axis=[0], acc_dtype=float64}
   5.1%    86.7%       1.496s       2.99e-02s     C       50       10   Dot22Scalar
   3.6%    90.3%       1.054s       2.11e-01s     C        5        1   Elemwise{Composite{sqrt(((i0 + i1) - i2))}}[(0, 2)]
   2.8%    93.0%       0.810s       1.62e-02s     C       50       10   Elemwise{sub,no_inplace}
   2.5%    95.6%       0.743s       1.86e-02s     C       40        8   Alloc
   2.3%    97.9%       0.682s       2.27e-02s     C       30        6   Join
   1.5%    99.4%       0.431s       2.87e-02s     C       15        3   Elemwise{mul,no_inplace}
   0.3%    99.7%       0.090s       4.51e-03s     C       20        4   Sum{axis=[1], acc_dtype=float64}
   0.2%    99.9%       0.054s       1.09e-02s     C        5        1   Elemwise{Composite{(i0 + ((i1 * i2) / i3) + i4)}}[(0, 0)]
   0.1%   100.0%       0.034s       1.70e-03s     C       20        4   Elemwise{sqr,no_inplace}
   0.0%   100.0%       0.008s       1.55e-03s     Py       5        1   MatrixInverse
   0.0%   100.0%       0.000s       2.76e-06s     C       95       19   Reshape{2}
   0.0%   100.0%       0.000s       2.77e-05s     Py       5        1   FillDiagonal
   0.0%   100.0%       0.000s       2.18e-05s     C        5        1   Elemwise{Composite{Switch(EQ(Composite{sqrt(((i0 + i1) - i2))}(i0, i1, i2), i3), i3, ((i4 * (((i5 * i6 * i7 * LT(Composite{sqrt(((i0 + i1) - i2))}(i0, i1, i2), i8) * Composite{(sqr((i0 - i1)) * (i0 - i1))}(i8, Composite{sqrt(((i0 + i1) - i2))}(i0, i1, i2)) * Composite{((i0 * i1) + i2 + (i3 * i4 * i5))}(i9, sqr(Composite{sqrt(((i0 + i1) - i2))}(i0, i1, i2)), i10, i11, i8, Composite{sqrt(((i0 + i1) - i2))}(i0, i1, i2))) / (sqr(Composite{sqr
   0.0%   100.0%       0.000s       1.37e-06s     C       60       12   MakeVector{dtype='int64'}
   0.0%   100.0%       0.000s       1.54e-05s     C        5        1   Elemwise{Composite{((((LT(Composite{sqrt(((i0 + i1) - i2))}(i0, i1, i2), i3) * ((i4 + (i5 * Composite{(sqr(i0) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i0, i1, i2) / i3))) + (i6 * Composite{((sqr(sqr(i0)) * sqr(i0)) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i0, i1, i2) / i3)))) - ((i7 * sqr((Composite{sqrt(((i0 + i1) - i2))}(i0, i1, i2) / i3))) + (i8 * Composite{(sqr(sqr(i0)) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i0, i1, i2) / i3))))
   0.0%   100.0%       0.000s       1.73e-06s     C       40        8   Subtensor{::, int64}
   0.0%   100.0%       0.000s       2.33e-06s     C       25        5   IncSubtensor{InplaceSet;int64:int64:, int64:int64:}
   ... (remaining 37 Ops account for   0.00%(0.00s) of the runtime)

Apply
------
<% time> <sum %> <apply time> <time per call> <#call> <id> <Apply name>
  47.3%    47.3%      13.894s       2.78e+00s      5   165   Elemwise{Composite{(i0 * i1 * LT(Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4), i5) * Composite{(sqr(i0) * i0)}((i5 - Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4))) * ((i6 * sqr(Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4))) + i7 + (i8 * i5 * Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4))))}}[(0, 1)](Subtensor{:int64:}.0, Join.0, Reshape{2}.0, Reshape{2}.0, Dot22Scalar.0, InplaceDimShuffle{x,x}.0, TensorConstant{(1, 1) of 3.0}, Elemwise{mul,no_inp
  28.1%    75.5%       8.253s       1.65e+00s      5   164   Elemwise{Composite{(i0 * ((LT(Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3), i4) * ((i5 + (i6 * Composite{(sqr(i0) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4))) + (i7 * Composite{((sqr(sqr(i0)) * sqr(i0)) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4)))) - ((i8 * sqr((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4))) + (i9 * Composite{(sqr(sqr(i0)) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4)))))) - (L
   4.6%    80.0%       1.346s       2.69e-01s      5   168   Sum{axis=[0], acc_dtype=float64}(Elemwise{Composite{(i0 * i1 * LT(Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4), i5) * Composite{(sqr(i0) * i0)}((i5 - Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4))) * ((i6 * sqr(Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4))) + i7 + (i8 * i5 * Composite{sqrt(((i0 + i1) - i2))}(i2, i3, i4))))}}[(0, 1)].0)
   3.6%    83.6%       1.054s       2.11e-01s      5    98   Elemwise{Composite{sqrt(((i0 + i1) - i2))}}[(0, 2)](Reshape{2}.0, Reshape{2}.0, Dot22Scalar.0)
   2.7%    86.3%       0.780s       1.56e-01s      5   105   Dot22Scalar(Reshape{2}.0, Positions of the points to interpolate.T, TensorConstant{2.0})
   2.5%    88.8%       0.742s       1.48e-01s      5   157   Alloc(CGemv{inplace}.0, Shape_i{0}.0, TensorConstant{1}, TensorConstant{1}, Elemwise{Add}[(0, 1)].0)
   2.3%    91.1%       0.682s       1.36e-01s      5   121   Join(TensorConstant{0}, Elemwise{sub,no_inplace}.0, Elemwise{sub,no_inplace}.0)
   1.5%    92.6%       0.430s       8.61e-02s      5   166   Elemwise{mul,no_inplace}(Subtensor{int64::}.0, Positions of the points to interpolate.T)
   1.4%    94.0%       0.410s       8.19e-02s      5   109   Elemwise{sub,no_inplace}(InplaceDimShuffle{0,x}.0, InplaceDimShuffle{1,0}.0)
   1.4%    95.4%       0.400s       8.00e-02s      5   108   Elemwise{sub,no_inplace}(InplaceDimShuffle{0,x}.0, InplaceDimShuffle{1,0}.0)
   1.2%    96.6%       0.361s       7.22e-02s      5    43   Dot22Scalar(Reference points for every layer, Positions of the points to interpolate.T, TensorConstant{2.0})
   1.2%    97.8%       0.360s       7.20e-02s      5   167   Sum{axis=[0], acc_dtype=float64}(Elemwise{Composite{(i0 * ((LT(Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3), i4) * ((i5 + (i6 * Composite{(sqr(i0) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4))) + (i7 * Composite{((sqr(sqr(i0)) * sqr(i0)) * i0)}((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4)))) - ((i8 * sqr((Composite{sqrt(((i0 + i1) - i2))}(i1, i2, i3) / i4))) + (i9 * Composite{(sqr(sqr(i0)) * i0)}((Composite{sqrt(((i0 + i1) - 
   1.2%    99.0%       0.355s       7.10e-02s      5    44   Dot22Scalar(Rest of the points of the layers, Positions of the points to interpolate.T, TensorConstant{2.0})
   0.3%    99.4%       0.094s       1.87e-02s      5   169   Sum{axis=[0], acc_dtype=float64}(Elemwise{mul,no_inplace}.0)
   0.3%    99.7%       0.090s       1.80e-02s      5    45   Sum{axis=[1], acc_dtype=float64}(Elemwise{sqr,no_inplace}.0)
   0.2%    99.8%       0.054s       1.09e-02s      5   170   Elemwise{Composite{(i0 + ((i1 * i2) / i3) + i4)}}[(0, 0)](Sum{axis=[0], acc_dtype=float64}.0, TensorConstant{(1,) of -1.75}, Sum{axis=[0], acc_dtype=float64}.0, InplaceDimShuffle{x}.0, Sum{axis=[0], acc_dtype=float64}.0)
   0.1%   100.0%       0.034s       6.79e-03s      5    11   Elemwise{sqr,no_inplace}(Positions of the points to interpolate)
   0.0%   100.0%       0.008s       1.55e-03s      5   155   MatrixInverse(IncSubtensor{InplaceSet;int64::, int64:int64:}.0)
   0.0%   100.0%       0.000s       9.94e-05s      5   134   Sum{axis=[1], acc_dtype=float64}(Elemwise{Sqr}[(0, 0)].0)
   0.0%   100.0%       0.000s       9.12e-05s      5   100   Alloc(Elemwise{sub,no_inplace}.0, TensorConstant{1}, TensorConstant{2}, Elemwise{Composite{Switch(EQ(i0, i1), (i0 // (-i0)), i0)}}.0, Shape_i{0}.0)
   ... (remaining 151 Apply instances account for 0.01%(0.00s) of the runtime)

Here are tips to potentially make your code run faster
                 (if you think of new ones, suggest them on the mailing list).
                 Test them first, as they are not guaranteed to always provide a speedup.
We don't know if amdlibm will accelerate this scalar op. deg2rad
  - Try installing amdlibm and set the Theano flag lib.amdlibm=True. This speeds up only some Elemwise operation.

In [ ]:

GPU


In [19]:
%%timeit
sol = test.geoMigueller(dips,dips_angles,rest, ref)[0]


10 loops, best of 3: 171 ms per loop

In [23]:
test.geoMigueller.profile.summary()


Function profiling
==================
  Message: /home/miguel/PycharmProjects/GeMpy/GeoMig.py:562
  Time in 43 calls to Function.__call__: 7.149101e+00s
  Time in Function.fn.__call__: 7.146105e+00s (99.958%)
  Time in thunks: 4.351497e+00s (60.868%)
  Total compile time: 2.354024e+00s
    Number of Apply nodes: 227
    Theano Optimizer time: 2.021928e+00s
       Theano validate time: 1.219668e-01s
    Theano Linker time (includes C, CUDA code generation/compiling): 2.757676e-01s
       Import time 0.000000e+00s

Time in all call to theano.grad() 0.000000e+00s
Time since theano import 281.359s
Class
---
<% time> <sum %> <apply time> <time per call> <type> <#call> <#apply> <Class name>
  86.8%    86.8%       3.779s       1.73e-02s     C      219       5   theano.sandbox.cuda.basic_ops.HostFromGpu
   6.5%    93.3%       0.282s       7.92e-04s     C      356       8   theano.sandbox.cuda.basic_ops.GpuAlloc
   2.4%    95.7%       0.103s       3.19e-05s     C     3235      73   theano.sandbox.cuda.basic_ops.GpuElemwise
   1.5%    97.2%       0.066s       2.48e-04s     C      266       6   theano.sandbox.cuda.basic_ops.GpuJoin
   0.7%    97.9%       0.030s       6.69e-05s     C      446      10   theano.sandbox.cuda.blas.GpuDot22Scalar
   0.5%    98.4%       0.021s       3.60e-05s     C      583      13   theano.sandbox.cuda.basic_ops.GpuIncSubtensor
   0.5%    98.8%       0.020s       6.53e-05s     C      307       7   theano.sandbox.cuda.basic_ops.GpuCAReduce
   0.4%    99.3%       0.019s       4.51e-04s     Py      43       1   theano.tensor.nlinalg.MatrixInverse
   0.3%    99.6%       0.014s       1.71e-05s     C      847      19   theano.sandbox.cuda.basic_ops.GpuReshape
   0.3%    99.9%       0.011s       3.20e-05s     C      356       8   theano.sandbox.cuda.basic_ops.GpuFromHost
   0.0%    99.9%       0.001s       8.66e-07s     C     1385      31   theano.sandbox.cuda.basic_ops.GpuDimShuffle
   0.0%    99.9%       0.001s       2.48e-05s     Py      45       1   theano.tensor.extra_ops.FillDiagonal
   0.0%   100.0%       0.001s       1.81e-06s     C      485      11   theano.sandbox.cuda.basic_ops.GpuSubtensor
   0.0%   100.0%       0.000s       8.73e-07s     C      534      12   theano.tensor.opt.MakeVector
   0.0%   100.0%       0.000s       1.27e-06s     C      358       8   theano.tensor.elemwise.Elemwise
   0.0%   100.0%       0.000s       8.67e-06s     C       43       1   theano.sandbox.cuda.blas.GpuGemv
   0.0%   100.0%       0.000s       8.26e-06s     C       45       1   theano.sandbox.cuda.basic_ops.GpuAllocEmpty
   0.0%   100.0%       0.000s       9.69e-07s     C      266       6   theano.compile.ops.Shape_i
   0.0%   100.0%       0.000s       7.56e-07s     C      268       6   theano.tensor.basic.ScalarFromTensor
   ... (remaining 0 Classes account for   0.00%(0.00s) of the runtime)

Ops
---
<% time> <sum %> <apply time> <time per call> <type> <#call> <#apply> <Op name>
  86.8%    86.8%       3.779s       1.73e-02s     C      219        5   HostFromGpu
   6.3%    93.1%       0.274s       1.54e-03s     C      178        4   GpuAlloc
   1.5%    94.7%       0.066s       2.48e-04s     C      266        6   GpuJoin
   0.7%    95.3%       0.030s       6.69e-05s     C      446       10   GpuDot22Scalar
   0.6%    95.9%       0.026s       6.52e-05s     C      401        9   GpuElemwise{sub,no_inplace}
   0.6%    96.5%       0.025s       7.23e-05s     C      352        8   GpuElemwise{Composite{(i0 * (i1 ** i2))},no_inplace}
   0.5%    97.1%       0.023s       5.15e-05s     C      444       10   GpuElemwise{Composite{Cast{float32}(LT(i0, i1))},no_inplace}
   0.4%    97.5%       0.019s       4.51e-04s     Py      43        1   MatrixInverse
   0.3%    97.8%       0.014s       1.71e-05s     C      847       19   GpuReshape{2}
   0.3%    98.2%       0.014s       1.09e-04s     C      129        3   GpuCAReduce{add}{1,0}
   0.3%    98.4%       0.011s       3.20e-05s     C      356        8   GpuFromHost
   0.2%    98.7%       0.011s       1.25e-04s     C       86        2   GpuElemwise{Composite{(i0 * sqr(i1))},no_inplace}
   0.2%    98.9%       0.010s       4.40e-05s     C      225        5   GpuIncSubtensor{InplaceSet;int64:int64:, int64:int64:}
   0.2%    99.1%       0.008s       4.40e-05s     C      178        4   GpuAlloc{memset_0=True}
   0.1%    99.2%       0.006s       3.35e-05s     C      178        4   GpuCAReduce{pre=sqr,red=add}{0,1}
   0.1%    99.3%       0.004s       3.97e-05s     C       90        2   GpuIncSubtensor{InplaceSet;int64:int64:, int64::}
   0.1%    99.4%       0.003s       3.70e-05s     C       90        2   GpuIncSubtensor{InplaceSet;int64::, int64:int64:}
   0.1%    99.4%       0.003s       6.39e-06s     C      444       10   GpuElemwise{Composite{sqrt(((i0 + i1) - i2))}}[(0, 2)]
   0.0%    99.5%       0.002s       3.50e-05s     C       45        1   GpuIncSubtensor{InplaceSet;int64, :int64:}
   0.0%    99.5%       0.001s       1.57e-05s     C       90        2   GpuElemwise{sqr,no_inplace}
   ... (remaining 56 Ops account for   0.50%(0.02s) of the runtime)

Apply
------
<% time> <sum %> <apply time> <time per call> <#call> <id> <Apply name>
  68.8%    68.8%       2.993s       6.96e-02s     43   215   HostFromGpu(GpuDimShuffle{1,0}.0)
  17.4%    86.2%       0.756s       1.76e-02s     43   122   HostFromGpu(GpuElemwise{Composite{sqrt(((i0 + i1) - i2))}}[(0, 2)].0)
   6.1%    92.3%       0.267s       6.21e-03s     43   211   GpuAlloc(GpuGemv{inplace}.0, Shape_i{0}.0, TensorConstant{1}, TensorConstant{1}, Elemwise{Add}[(0, 1)].0)
   1.2%    93.5%       0.053s       1.18e-03s     45   145   GpuJoin(TensorConstant{0}, GpuElemwise{sub,no_inplace}.0, GpuElemwise{Sub}[(0, 0)].0)
   0.7%    94.2%       0.028s       6.62e-04s     43   226   HostFromGpu(GpuElemwise{Composite{((((i0 * i1) / i2) + i3) + i4)}}[(0, 1)].0)
   0.4%    94.6%       0.019s       4.51e-04s     43   208   MatrixInverse(HostFromGpu.0)
   0.2%    94.8%       0.008s       1.84e-04s     43   112   GpuDot22Scalar(GpuReshape{2}.0, GpuDimShuffle{1,0}.0, TensorConstant{2.0})
   0.2%    95.0%       0.008s       1.82e-04s     43   141   GpuJoin(TensorConstant{0}, GpuElemwise{sub,no_inplace}.0, GpuElemwise{sub,no_inplace}.0)
   0.2%    95.2%       0.008s       1.78e-04s     43   184   GpuElemwise{Composite{Cast{float32}(LT(i0, i1))},no_inplace}(GpuElemwise{Composite{sqrt(((i0 + i1) - i2))}}[(0, 2)].0, GpuDimShuffle{x,x}.0)
   0.2%    95.3%       0.008s       1.67e-04s     45    32   GpuDot22Scalar(GpuFromHost.0, GpuDimShuffle{1,0}.0, TensorConstant{2.0})
   0.2%    95.5%       0.007s       1.54e-04s     43   118   GpuElemwise{sub,no_inplace}(GpuDimShuffle{0,x}.0, GpuDimShuffle{1,0}.0)
   0.1%    95.6%       0.006s       1.46e-04s     43   154   GpuElemwise{Composite{(i0 * (i1 ** i2))},no_inplace}(CudaNdarrayConstant{[[ 8.75]]}, GpuElemwise{TrueDiv}[(0, 0)].0, CudaNdarrayConstant{[[ 3.]]})
   0.1%    95.8%       0.006s       1.40e-04s     43   153   GpuElemwise{Composite{(i0 * (i1 ** i2))},no_inplace}(CudaNdarrayConstant{[[ 0.75]]}, GpuElemwise{TrueDiv}[(0, 0)].0, CudaNdarrayConstant{[[ 7.]]})
   0.1%    95.9%       0.006s       1.39e-04s     43   123   GpuElemwise{Composite{Cast{float32}(LT(i0, i1))},no_inplace}(GpuElemwise{Composite{sqrt(((i0 + i1) - i2))}}[(0, 2)].0, GpuDimShuffle{x,x}.0)
   0.1%    96.0%       0.006s       1.38e-04s     43   117   GpuElemwise{sub,no_inplace}(GpuDimShuffle{0,x}.0, GpuDimShuffle{1,0}.0)
   0.1%    96.2%       0.006s       1.36e-04s     43   148   GpuElemwise{Composite{(i0 * (i1 ** i2))},no_inplace}(CudaNdarrayConstant{[[ 8.75]]}, GpuElemwise{TrueDiv}[(0, 0)].0, CudaNdarrayConstant{[[ 3.]]})
   0.1%    96.3%       0.006s       1.33e-04s     43    39   GpuDot22Scalar(GpuFromHost.0, GpuDimShuffle{1,0}.0, TensorConstant{2.0})
   0.1%    96.4%       0.006s       1.33e-04s     43   146   GpuElemwise{Composite{(i0 * sqr(i1))},no_inplace}(CudaNdarrayConstant{[[ 7.]]}, GpuElemwise{TrueDiv}[(0, 0)].0)
   0.1%    96.6%       0.006s       1.25e-04s     45    86   GpuElemwise{sub,no_inplace}(GpuDimShuffle{x,0}.0, GpuReshape{2}.0)
   0.1%    96.7%       0.005s       1.23e-04s     43   116   GpuElemwise{Composite{Cast{float32}(LT(i0, i1))},no_inplace}(GpuElemwise{Composite{sqrt(((i0 + i1) - i2))}}[(0, 2)].0, GpuDimShuffle{x,x}.0)
   ... (remaining 207 Apply instances account for 3.31%(0.14s) of the runtime)

Here are tips to potentially make your code run faster
                 (if you think of new ones, suggest them on the mailing list).
                 Test them first, as they are not guaranteed to always provide a speedup.
  Sorry, no tip for today.

In [30]:
importlib.reload(GeoMig)
test = GeoMig.GeoMigSim_pro2()

In [42]:



Out[42]:
array([[ -5.88888884e-01,  -0.00000000e+00,  -0.00000000e+00, ...,
          0.00000000e+00,   1.00000000e+00,   0.00000000e+00],
       [ -0.00000000e+00,  -5.88888884e-01,   4.42373231e-02, ...,
          0.00000000e+00,   1.00000000e+00,   0.00000000e+00],
       [ -0.00000000e+00,   2.12696299e-01,  -5.88888884e-01, ...,
          0.00000000e+00,   1.00000000e+00,   0.00000000e+00],
       ..., 
       [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
          2.00000000e+00,  -6.06459351e+02,  -6.13501053e+01],
       [  1.00000000e+00,   1.00000000e+00,   1.00000000e+00, ...,
         -6.06459351e+02,   0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
         -6.13501053e+01,   0.00000000e+00,   0.00000000e+00]], dtype=float32)

In [17]:



---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-17-b0516f7436af> in <module>()
----> 1 theano.config.device="cpu"

/home/miguel/anaconda3/lib/python3.5/site-packages/theano/configparser.py in __set__(self, cls, val)
    329         if not self.allow_override and hasattr(self, 'val'):
    330             raise Exception(
--> 331                 "Can't change the value of this config parameter "
    332                 "after initialization!")
    333         # print "SETTING PARAM", self.fullname,(cls), val

Exception: Can't change the value of this config parameter after initialization!

In [1]:
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time

vlen = 10 * 30 * 768  # 10 x #cores x # threads per core
iters = 1000

rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
    r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')


[Elemwise{exp,no_inplace}(<TensorType(float32, vector)>)]
Looping 1000 times took 2.271379 seconds
Result is [ 1.23178029  1.61879337  1.52278066 ...,  2.20771813  2.29967761
  1.62323284]
Used the cpu

In [1]:
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time

vlen = 10 * 30 * 768  # 10 x #cores x # threads per core
iters = 1000

rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
    r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')


Using gpu device 0: GeForce GTX 970 (CNMeM is disabled, cuDNN not available)
[GpuElemwise{exp,no_inplace}(<CudaNdarrayType(float32, vector)>), HostFromGpu(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 0.353415 seconds
Result is [ 1.23178029  1.61879349  1.52278066 ...,  2.20771813  2.29967761
  1.62323296]
Used the gpu

In [18]:
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time

vlen = 10 * 30 * 768  # 10 x #cores x # threads per core
iters = 1000

rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
    r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')


[Elemwise{exp,no_inplace}(<TensorType(float32, vector)>)]
Looping 1000 times took 2.291412 seconds
Result is [ 1.23178029  1.61879337  1.52278066 ...,  2.20771813  2.29967761
  1.62323284]
Used the cpu

In [ ]:


In [759]:
np.set_printoptions(precision=2)
test.geoMigueller(dips,dips_angles,rest, ref)[1]


Out[759]:
array([[-0.59,  0.08,  0.  ,  0.07],
       [ 0.08, -0.59,  0.07,  0.  ],
       [ 0.  ,  0.12, -0.59,  0.13],
       [ 0.07,  0.  ,  0.13, -0.59]])

In [751]:
T.fill_diagonal?

In [758]:
import matplotlib.pyplot as plt
% matplotlib inline
dip_pos_1_v = np.array([np.cos(np.deg2rad(dip_angle_1))*1,
                        np.sin(np.deg2rad(dip_angle_1))]) + dip_pos_1

dip_pos_2_v = np.array([np.cos(np.deg2rad(dip_angle_2))*1, 
                        np.sin(np.deg2rad(dip_angle_2))]) + dip_pos_2

plt.arrow(dip_pos_1[0],dip_pos_1[1], dip_pos_1_v[0]-dip_pos_1[0],
          dip_pos_1_v[1]-dip_pos_1[1], head_width = 0.2)
plt.arrow(dip_pos_2[0],dip_pos_2[1],dip_pos_2_v[0]-dip_pos_2[0], 
          dip_pos_2_v[1]-dip_pos_2[1], head_width = 0.2)

plt.plot(layer_1[:,0],layer_1[:,1], "o")
plt.plot(layer_2[:,0],layer_2[:,1], "o")

plt.plot(layer_1[:,0],layer_1[:,1], )
plt.plot(layer_2[:,0],layer_2[:,1], )

plt.contour( sol.reshape(50,50) ,30,extent = (0,10,0,10) )
#plt.colorbar()
#plt.xlim(0,10)
#plt.ylim(0,10)
plt.title("GeoBulleter v 0.1")
print (dip_pos_1_v, dip_pos_2_v, layer_1)


[ 2.5   4.87] [ 6.34  3.94] [[ 1.  7.]
 [ 5.  7.]
 [ 6.  7.]
 [ 9.  8.]]

In [443]:
n = 10
#a = T.horizontal_stack(T.vertical_stack(T.ones(n),T.zeros(n)), T.vertical_stack(T.zeros(n), T.ones(n)))
a = T.zeros(n)

print (a.eval())
#U_G = T.horizontal_stack(([T.ones(n),T.zeros(n)],[T.zeros(n),T.ones(n)]))


[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]

In [6]:
T.stack?ö+aeg

In [ ]:
_squared_euclidean_distances2 = T.sqrt(
            (dips ** 2).sum(1).reshape((dips.shape[0], 1)) + (aux_Y ** 2).sum(1).reshape(
                (1, aux_Y.shape[0])) - 2 * dips.dot(aux_Y.T))

        _squared_euclidean_distances3 = T.sqrt(
            (dips ** 2).sum(1).reshape((dips.shape[0], 1)) + (aux_X ** 2).sum(1).reshape(
                (1, aux_X.shape[0])) - 2 * dips.dot(aux_X.T))

        h3 = T.vertical_stack(
            (dips[:, 0] - aux_Y[:, 0].reshape((aux_Y[:, 0].shape[0], 1))).T,
            (dips[:, 1] - aux_Y[:, 1].reshape((aux_Y[:, 1].shape[0], 1))).T
        )


        h4 = T.vertical_stack(
            (dips[:, 0] - aux_X[:, 0].reshape((aux_X[:, 0].shape[0], 1))).T,
            (dips[:, 1] - aux_X[:, 1].reshape((aux_X[:, 1].shape[0], 1))).T)

        r_3 = T.tile(_squared_euclidean_distances2, (2, 1))  # Careful with the number of dimensions
        r_4 = T.tile(_squared_euclidean_distances3, (2, 1))  # Careful with the number of dimensions

        _ans_d1_3 = (r_3 < self.a) * (
            -7 * (self.a - r_3) ** 3 * r_3 * (8 * self.a ** 2 + 9 * self.a * r_3 + 3 * r_3 ** 2) * 1) 
        / (4 * self.a ** 7)

        _ans_d1_4 = (r_4 < self.a) * (
            -7 * (self.a - r_4) ** 3 * r_4 * (8 * self.a ** 2 + 9 * self.a * r_4 + 3 * r_4 ** 2) * 1) 
        / (4 * self.a ** 7)

        _C_GI = (h3 / r_3 * _ans_d1_3 - h4 / r_4 * _ans_d1_4).T

        self._f_CGI = theano.function([dips, aux_X, aux_Y], _C_GI)