[Question] [Feature Request] __matmul__, Internal Type Hinting

Abierto
#271 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

Empieza revisando los bindings de Python relacionados con arrayfire.Array, set_backend(), clibrary.get() y af.get_devicr_info(), y después inspecciona cómo se exponen y prueban los métodos públicos existentes. Aclara si el proyecto quiere matmul, wrappers de runtime y anotaciones de tipos estáticas antes de cambiar nada. Se considera terminado cuando haya un alcance acordado, con tipado coherente y comportamiento verificado para la API pública seleccionada.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

I wanted to add support for @ operation in python. The __matmult__ operation, that's how it's overloaded, in the arrayfire.Array class.

It's a simple monkey patch on user code. But it'd be nice if it was official.

I went to my local source code and added it, but I wanted to start learning the internal more and maybe do some contribution. Just wondering if it's not redundant or unwanted.

I saw that the internal Python types aren't hinted properly.

The set_backend() takes a string, but that's primitive obsession. It should take a string litteral list.

from typing import Literal

backend: Literal["cuda", "opencl", "cpu"]

Or it should take an Enum.
And other functions.

or clibrary.get() returns a None. That's just due to Lazy Loading.

But a Typed Python interface could exist. Some wrapper python class might be needed so that the type of the exposed code is visible.

All of this would help learning by simply using the autocomplete features of the IDE or text editor.

I hope each backend offers at least some common interface. It should, as the goal of arrayfire is hardware agnostism.

So, every method should be discoverable by the linter at "code editing" time. Just put _ and __ if it's really private.

So get().af wouldn't cause false linting errors.

Anyway, I might get into it if I have time. It seems like a nice contribution, and a nitpick of mine.

the typing package nd TYPE/CHECKING, and simple wrappers are quite powerful.

However, I know that you might not want to expose internal details at all, and so might have purposly not the type hinting of everything. But it's also possible that doing so is just a tedious boilerplate. I'd be fine with doing said tedious boilerplate to make it easier to use and understand.

So, if it's by choice that there isn't any type hinting and wrapper, then I won't do it. But If it's something you'd be interested in, I might do some work on it.

Also there was a bug with af.get_devicr_info(), it seems to give the default device, not active device. Tested it with my cpu graphics card and amd graphics card on arch linux. I'll edit this section once I'm back on my PC. (Away right now).

Lenguaje dominante
Python
Estrellas
422
Forks
63
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de arrayfire/arrayfire-python

Todos los issues de arrayfire/arrayfire-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.