Skip to content

Instantly share code, notes, and snippets.

View steve-s's full-sized avatar

Stepan Sindelar steve-s

View GitHub Profile
@steve-s
steve-s / gist:d0440cabd986a51852d25d159b9c3f59
Created October 8, 2018 08:58
raytracing volcano dataset in R
# Code taken from article: http://www.tylermw.com/throwing-shade/
# Author: Tyler Morgan-Wall
# License: GPLv3
volcanoshadow = matrix(1, ncol = ncol(volcano), nrow = nrow(volcano))
volc = list(x=1:nrow(volcano), y=1:ncol(volcano), z=volcano)
sunangle = 45 / 180*pi
angle = -90 / 180 * pi
diffangle = 90 / 180 * pi
@steve-s
steve-s / metaclass-issue.c
Created February 23, 2022 17:12
metaclass-wo-basicsize-issue
#include <Python.h>
#include <structmember.h>
typedef struct {
PyHeapTypeObject super;
int meta_magic;
int meta_member;
char some_more[64];
} DummyMeta;
#include "Python.h"
static PyObject *myabs(PyObject *self, PyObject *arg) {
return Py_Absolute(arg);
}
static PyMethodDef methods[] = {
{"myabs", myabs, METH_O, ""},
{NULL, NULL, 0, NULL}
};
typedef struct {
// ...
HPy (*ctx_Absolute)(HPyContext *ctx, HPy h1);
int (*ctx_IsTrue)(HPyContext *ctx, HPy h);
HPy (*ctx_Type_FromSpec)(HPyContext *ctx, HPyType_Spec *spec, HPyType_SpecParam *params);
// ...
} HPyContext;
// ...
python setup.py --hpy-abi=universal build_ext
def __bootstrap__():
from sys import modules
from hpy.universal import load
from pkg_resources import resource_filename
ext_filepath = resource_filename(__name__, 'kiwisolver.hpy.so')
m = load('kiwisolver', ext_filepath, debug=is_debug)
modules[__name__] = m
HPyAPI_FUNC int HPy_IsTrue(HPyContext *ctx, HPy h) {
return ctx->ctx_IsTrue ( ctx, h );
}
static inline int HPy_IsTrue(HPyContext *ctx, HPy h)
{
return PyObject_IsTrue(_h2py(h));
}
// In CPython ABI mode, HPy handles == PyObject*
static inline PyObject* _h2py(HPy h) {
return (PyObject*) h._i;
}
template<> inline
HPy BinaryAdd::operator()( HPyContext *ctx, Variable* first, double second, HPy h_first, HPy h_second )
{
HPy temp = BinaryMul()( ctx, first, 1.0, h_first, HPy_NULL );
if( HPy_IsNull(temp) )
return HPy_NULL;
return operator()( ctx, Term_AsStruct( ctx, temp ), second, temp, h_second );
}
template<> inline
HPy BinaryAdd::operator()( HPyContext *ctx, Variable* first, double second, HPy h_first, HPy h_second )
{
HPy temp = BinaryMul()( ctx, first, 1.0, h_first, HPy_NULL );
if( HPy_IsNull(temp) )
return HPy_NULL;
HPy result = operator()( ctx, Term_AsStruct( ctx, temp ), second, temp, h_second );
HPy_Close(ctx, temp);
return result;
}