Skip to content

Instantly share code, notes, and snippets.

@nbecker
nbecker / test1.py
Created November 10, 2023 13:37
test1
#!/usr/bin/env python
# coding: utf-8
import os
os.environ["PATH"] += os.pathsep + '/usr/local/cuda-12.2/bin'
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' #supposed to suppress messages, but doesn't work
#import os
# use xla-lite (doesn't work for centroid for now)
#os.environ['TF_XLA_FLAGS']='--tf_xla_auto_jit=fusible'
@nbecker
nbecker / mandel.mojo
Created October 5, 2023 16:34
mandel test
alias width = 960
alias height = 960
alias MAX_ITERS = 200
alias min_x = -2.0
alias max_x = 0.6
alias min_y = -1.5
alias max_y = 1.5
# Compute the number of steps to escape.
@nbecker
nbecker / Complex.H
Last active June 16, 2023 11:38
xtensor_math
#ifndef Complex_H
#define Complex_H
#include <complex>
typedef std::complex<double> Complex;
typedef std::complex<double> complex_t;
typedef std::complex<float> complex64_t;
typedef std::complex<long double> complex256_t;
// decomplexify ---------------------------------------------------------------
@nbecker
nbecker / _array2.py
Created January 20, 2023 16:30
_array2.py
import numpy as np
#pythran export getArrayFactor (complex[:], float[:], float[:], float[:,:], float[:,:], float)
#pythran export getArrayFactor (complex[:], float[:], float[:], float, float, float)
def getArrayFactor(W, px, py, theta, phi, L):
theta = np.array (theta)
phi = np.array (phi)
N = px.shape[0]
AF = np.zeros(theta.shape, dtype=complex)
kx = np.sin(theta) * np.cos(phi) * 2.0 * np.pi / L
@nbecker
nbecker / _array.py
Last active December 27, 2022 13:26
pythran compiled by g++ produces wrong results, OK with clang
import numpy as np
#pythran export getArrayFactor (complex[:], float[:], float[:], float[:,:], float[:,:], float)
def getArrayFactor(W, px, py, theta, phi, L):
N = px.shape[0]
AF = np.zeros(theta.shape, dtype=complex)
kx = np.sin(theta) * np.cos(phi) * 2.0 * np.pi / L
ky = np.sin(theta) * np.sin(phi) * 2.0 * np.pi / L
for n in range(N):
AF += W[n] * np.exp(-1j * (kx * px[n] + ky * py[n]))
@nbecker
nbecker / baseline_2sps.py
Created May 5, 2022 17:58
baseline at 2 sample/symbol
#!/usr/bin/env python
# coding: utf-8
import numpy as np
from sionna.utils import QAMSource
from sionna.signal import Upsampling, Downsampling, RootRaisedCosineFilter, empirical_psd, empirical_aclr
beta = 0.1
span_in_symbols = 32
samples_per_symbol = 2
rrcf = RootRaisedCosineFilter(span_in_symbols, samples_per_symbol, beta, normalize=False)
mf = RootRaisedCosineFilter(span_in_symbols, samples_per_symbol, beta, normalize=False)
@nbecker
nbecker / crl.py
Created March 8, 2022 14:37
crl.py
from transonic import boost
import numpy as np
@boost
class crl:
k: float
aT: float
sum1: float
sum2: float
@nbecker
nbecker / constellation.py
Created December 23, 2021 15:49
transonic bounds check
import numpy as np
from transonic import boost
A = "complex[:]"
S = "int[:]"
@boost(boundscheck=True)
def call1 (map: A, s: int):
return map[s]
@nbecker
nbecker / orthogonal_mod.py
Created May 19, 2021 12:46
orthogonal_mod
import numpy as np
#pythran export orthogonal_mod (int[:], int)
#pythran export orthogonal_mod (int32[:], int)
def orthogonal_mod (x, nbits):
out = np.zeros ((len(x), 1<<nbits), dtype=complex)
for e in range (len (x)):
out[e,x[e]] = 1
return out
@nbecker
nbecker / errors.log
Created May 10, 2021 14:16
xtensor errors
from histogram2d_c.cc:6:
/home/nbecker/.local/include/xtensor/xtensor_config.hpp:87:43: error: 'XSIMD_DEFAULT_ALIGNMENT' was not declared in this scope; did you mean 'XTENSOR_DEFAULT_ALIGNMENT'?
87 | #define XTENSOR_DEFAULT_ALIGNMENT XSIMD_DEFAULT_ALIGNMENT
| ^~~~~~~~~~~~~~~~~~~~~~~
/home/nbecker/.local/include/xtensor/xtensor_config.hpp:87:43: note: in definition of macro 'XTENSOR_DEFAULT_ALIGNMENT'
87 | #define XTENSOR_DEFAULT_ALIGNMENT XSIMD_DEFAULT_ALIGNMENT
| ^~~~~~~~~~~~~~~~~~~~~~~
/home/nbecker/.local/include/xtensor/xstorage.hpp:1389:59: note: in expansion of macro 'XTENSOR_SELECT_ALIGN'
1389 | template <class T, std::size_t N, std::size_t Align = XTENSOR_SELECT_ALIGN(T)>
| ^~~~~~~~~~~~~~~~~~~~