Skip to content

How to infer appropriate dtype from uint to int and float to complex? #859

@34j

Description

@34j

I would like to compute $f(x) := xi$, $g(y) := y - 1$ where $i$ is an imaginary number, $x$ is float and $y$ is uint, using array-api. However, I am not sure what is the best way to implement it. Following the type promotion rules

def f(x: xp.array) -> xp.array:
	return x * xp.array(1j, dtype=xp.complex64 if x.dtype == xp.float32 else xp.complex128)

def g(x: xp.array) -> xp.array:
	return x - xp.array(1, dtype=xp.int16 if x.dtype == xp.uint8 else xp.int32 if x.dtype == xp.uint16 else  xp.int64)

This seems too redundant. What is the proper way to do this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy