PHP-SDS First Thoughts

Some days have passed since my last contribution to PHP-SDS, but today I've returned, and my first step will be telling something about this project.

The name of this PHP library isn't very imaginative: "Scientific Data Structures". The data structures aren't scientific or unscientific :s , but there is an extension called "PHP-DS" (PHP Data Structures), which provides basic data structures, and PHP-SDS aims to provide "data-science related data structures"... so, that's it.

My idea was to port some features from three interesting Python projects to PHP: Pandas, Numpy and TensorFlow. The basic data structures that will be implemented are Matrix, DataFrame and Tensor (the "same" as Numpy's ndarray).

As today, almost all the meaningful features of the Tensor data structure have been developed in pure PHP, plus some basic features of the Matrix class.

So? Well, the actual code is pure PHP, but it is a sort of prototype/polyfill. I want to implemenet a PHP extension to boost performance for certain data related operations, and I want to implement that extension using Rust.

There are a lot of things to do, finishing the Matrix and DataFrame classes in the polyfill library, add some data importing/exporting features, and then start coding the extension using Rust. You're welcome if you want to become involved :) .

These are the main sources I'm using to obtain inspiration:

Tags: PHP, PHP-SDS, Rust, Data Engineering

Generating Colored Gosper Curves

Yesterday I finished a script to generate colored Gosper Curves. You can find it in Github, as a Gist: gosper_curve.py.

The main idea behind this code is to generate an ordered list of points using a L-system (a set of production rules combined with a mechanism for translating the generated strings into geometric structures).

One extra idea I've applied is to work with the HSL color space instead of the RGB color space, this way I can do a random walk over the Hue dimension (with "smooth" steps) keeping lightness and saturation as constants.

And this is one of the generated images:

Gosper Curve

Tags: Fractals, Geometry, Mathematics, Generative Art, Art

Dealing with precise timestamps in PHP

PHP does not offer any native class to implement timestamps with milliseconds or microseconds precision, the only "native" way to do it is working with the weird microtime function and/or the \MongoDate class (available through the mongo extension).

Using the \DateTime class is not enough, because it only can offer seconds precision, and using the \MongoDate class isn't a good idea if you aren't using MongoDB or if you care about coupling. In fact, the mongo extension will be deprecated in a few months in favour of a new extension that is in active development right now.

Because this, I've developed two Composer packages to allow using type hinting without increasing coupling and with less abstraction leaks:

Is my intention to modify the PHP-Jiffy library at the same time of the new MongoDB's extension release, so it will be very useful for people who likes moving fast to new software versions.

Tags: PHP, Timestamps, Doctrine, MongoDB