Skip to content
Snippets Groups Projects
Commit 9dd6b0c0 authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

exo1

parent 14573d5d
No related merge requests found
Pipeline #8416 passed with stage
in 0 seconds
stages: helloworld:
- build
- test
- release
variables:
CONTAINER_TEST_IMAGE: boileaum/rosen:$CI_COMMIT_REF_NAME
CONTAINER_RELEASE_IMAGE: boileaum/rosen:latest
before_script:
- echo $DOCKERHUB_PASSWD | docker login -u boileaum --password-stdin
b:docker:
stage: build
tags:
- shell, docker
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE -f ./docker/Dockerfile-rosen .
- docker push $CONTAINER_TEST_IMAGE
t:helloworld:
stage: test
tags:
- shell, docker
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run $CONTAINER_TEST_IMAGE /bin/bash -c 'python test_helloworld.py'
t:rosen:
stage: test
tags:
- shell, docker
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run $CONTAINER_TEST_IMAGE /bin/bash -c 'pytest -v'
r:docker:
stage: release
tags: tags:
- shell, docker - shell, docker
script: script:
- docker pull $CONTAINER_TEST_IMAGE - echo "hello, world"
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
FROM python:3
MAINTAINER Matthieu Boileau <matthieu.boileau@math.unistra.fr>
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
RUN apt-get update --fix-missing && \
apt-get install -y \
vim
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN useradd -m -s /bin/bash euler
ENV HOME /home/euler
RUN chown -R euler:euler /home/euler
USER euler
WORKDIR $HOME
CMD /bin/bash
FROM boileaum/pythran:latest
MAINTAINER Matthieu Boileau <matthieu.boileau@math.unistra.fr>
ENV HOME /home/euler
ADD . $HOME/rosen
USER root
RUN chown -R euler:euler /home/euler
WORKDIR $HOME/rosen
USER euler
RUN make clean && make
CMD /bin/bash
version: '2'
services:
env:
build:
context: ../
dockerfile: docker/Dockerfile-pythran
image: boileaum/pythran:latest
user:
build:
context: ../
dockerfile: docker/Dockerfile-rosen
image: boileaum/rosen:latest
depends_on:
- env
#include <stdio.h>
int main(void)
{
printf("hello, world\n");
return 0;
}
.PHONY: clean pythran
all: C pythran
C:
gcc helloworld.c -o helloworld.e
pythran:
pythran rosenbrock.py -o rosenbrock_pythran.so
clean:
rm -rf *.o *.e *.so *.pyf *.pyc __pycache__
# -*- coding: utf-8 -*-
#runas import numpy as np; r = np.arange(0.,10., .01); rosen(r)
#bench import numpy as np; r = np.arange(50000000); rosen(r)
#pythran export rosen(int[])
#pythran export rosen(float[])
import numpy as np
def rosen(x):
t0 = 100 * (x[1:] - x[:-1] ** 2) ** 2
t1 = (1 - x[:-1]) ** 2
return np.sum(t0 + t1)
#!/bin/bash
docker run -ti --rm -v $(pwd):/home/euler boileaum/pythran:latest
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Test helloworld.c
"""
import os
assert os.popen('./helloworld.e', 'r').read() == "hello, world\n"
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Test Rosenbrock
"""
from rosenbrock_pythran import rosen as rosen_pythran
from rosenbrock import rosen as rosen_python
from pytest import mark, approx
import numpy as np
r_float = np.arange(0., 10., .01)
expect_float = 152089858.36719903
r_int = np.arange(50000000)
expect_int = 7842832767944603480
param = [(r_float, expect_float), (r_int, expect_int)]
@mark.parametrize('r, result', param)
def test_rosen_python(r, result):
assert rosen_python(r) == approx(result)
@mark.parametrize('r, result', param)
def test_rosen_pythran(r, result):
assert rosen_pythran(r) == approx(result)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment