Beispiel #1
0
# Copyright (C) 2012 Bjarne Grimstad ([email protected]).
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Add the SPLINTER directory to the search path, so we can include it
from os import sys, path, remove
sys.path.append(
    path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))

##### Start of the example #####
import splinter

# This must be done if splinter could not locate the shared library
splinter.load("/home/anders/SPLINTER/build/release/libsplinter-1-4.so")

# Create a new, empty DataTable
d = splinter.DataTable()

# Populate it with samples
for i in range(10):
    for j in range(10):
        d.addSample([i, j], i * j)

# Save the samples for use later
d.save("test.datatable")

# Create DataTable from saved
d2 = splinter.DataTable("test.datatable")
Beispiel #2
0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


# Add the SPLINTER directory to the search path, so we can include it
from os import sys, path, remove
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))


##### Start of the example #####
import splinter

# This must be done if splinter could not locate the shared library
splinter.load("/home/anders/SPLINTER/build/release/libsplinter-1-4.so")

# Create a new, empty DataTable
d = splinter.DataTable()

# Populate it with samples
for i in range(10):
	for j in range(10):
		d.addSample([i,j], i*j)

# Save the samples for use later
d.save("test.datatable")

# Create DataTable from saved
d2 = splinter.DataTable("test.datatable")
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Add the SPLINTER directory to the search path, so we can include it
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from os import sys, path, remove
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
import splinter

# Only for dev purposes
# splinter.load("/home/bjarne/Code/C++/splinter4/splinter/bin/Release/libsplinter-3-0.so")
splinter.load("/home/anders/SPLINTER/build/debug/libsplinter-3-0.so")


# Example with two variables
def f(x):
    return x[0]*x[1]

x1 = np.arange(-5, 5, 0.25)
x2 = np.arange(-5, 5, 0.25)
X1, X2 = np.meshgrid(x1, x2)
Y = np.sqrt(X1 ** 2 + X2 ** 2)

data = []
x = []
y = []
for i in range(len(x1)):
Beispiel #4
0
# Copyright (C) 2012 Bjarne Grimstad ([email protected]).
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Add the SPLINTER directory to the search path, so we can include it
import numpy as np
import matplotlib.pyplot as plt
from os import sys, path, remove
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
import splinter

# Only for dev purposes
# splinter.load("/home/bjarne/Code/C++/splinter4/splinter/bin/Release/libsplinter-3-0.so")
splinter.load("/home/anders/SPLINTER/build/debug/libsplinter-3-0.so")


# Example with one variable
def f1(x):
    return -1. + 2 * x + 0.1 * (x**2) + 10 * np.random.rand(1)[0]


x = np.arange(0, 11, 1)
y = np.zeros((len(x), ))
for i in range(len(x)):
    y[i] = f1(x[i])

# Piecewise constant B-spline that interpolates the data
b0 = splinter.BSplineBuilder(x, y, degree=0).build()
Beispiel #5
0
# The temp file is then read and the data is returned to Pickle.                  #
# When unpickling the data we get from Pickle is written to a temporary file      #
# which is then read by the SPLINTER backend.                                     #
#                                                                                 #
# This is a hack and tested for 5 minutes before I went to bed, so use with care. #
###################################################################################

import pickle
import copyreg
import tempfile

import splinter

# TODO: Change me
splinter.load(
    "/home/awenhaug/projects/splinter/build/splinter-python/lib/linux/x86-64/libsplinter-3-0.so"
)


def constructor(serialized_data) -> splinter.BSpline:
    print(f"Unpickling BSpline")
    with tempfile.NamedTemporaryFile() as temp:
        with open(temp.name, "wb") as f:
            f.write(serialized_data)

        return splinter.BSpline(temp.name)


def reducer(bspline: splinter.BSpline):
    print(f"Pickling BSpline")
    with tempfile.NamedTemporaryFile() as temp: