Skip to content

Instantly share code, notes, and snippets.

View bernardelli's full-sized avatar

Rafael Bernardelli bernardelli

View GitHub Profile
@bernardelli
bernardelli / experiment_multitype.rs
Created March 8, 2022 20:35
Testing grounds for implementation of algorithms that support many numpy numeric types
use num_traits;
use numpy::{npyffi, DataType, PyArray, PyArray1, PyArrayDyn};
use pyo3::prelude::*;
use pyo3::{exceptions::PyValueError, AsPyPointer, PyDowncastError, PyResult};
//based on https://github.com/aleksander-mendoza/RustyNEAT/blob/42508c84d4564461067927fd1afb0db538a442fe/pylib/src/py_ndalgebra.rs#L763
#[pyfunction]
pub fn generic_test(input: &PyAny) -> PyResult<PyObject> {
let (dtype, shape) = pick_array_info(input)?;
@bernardelli
bernardelli / gravidade.cu
Last active August 24, 2021 14:42
Exemplo PyCuda + OpenGL
#include <cuda.h>
#include <curand.h>
#include <curand_kernel.h>
#define NTRIANGLES 20 // númetro de triângulos para desenhar cada círculo
#define RAIO_M1 0.001f // tamanho do raio para massa = 1 u
#define TIMESTEP_MS 50 // tempo entre os callbacks
#define G 0.00000005f // constante gravitacional fictícia
__device__ void generate_triangles(float2 pos, float m,
@bernardelli
bernardelli / py_mp_example.py
Created May 11, 2018 01:23
Create a cancelable python multiprocessing job batch with ETA
import numpy as np
from multiprocessing import Process, Manager, Value, Array
import time
import humanize
#actual computation
def f(a):
return a-1.0;
# obs: with such a simple computation, there will advantage will be no computation time advantage.