python_code
stringlengths
0
1.02M
repo_name
stringlengths
9
48
file_path
stringlengths
5
114
# Test for gaussian kernel operation using LazyTensors. import time import math import torch from pykeops.torch import LazyTensor M, N, D, DV = 200, 300, 300, 1 dtype = torch.float32 sum_scheme = "block_sum" device_id = "cuda:0" if torch.cuda.is_available() else "cpu" do_warmup = False x = torch.rand(M, 1, D, dev...
keops-main
keopscore/keopscore/sandbox/chunks.py
import time import math import numpy as np from pykeops.numpy import LazyTensor, ComplexLazyTensor M, N, D = 1000, 1000, 3 dtype = "float32" do_warmup = False x = np.random.rand(M, 1, D).astype(dtype) + 1j * np.random.rand(M, 1, D).astype(dtype) y = np.random.rand(1, N, D).astype(dtype) + 1j * np.random.rand(1, N,...
keops-main
keopscore/keopscore/sandbox/complex_numpy.py
# Test for gaussian kernel operation using LazyTensors. import time import math import torch import numpy as np from pykeops.numpy import LazyTensor M, N, D, DV = 3000, 2000, 3, 1 dtype = np.float32 do_warmup = False x = np.random.rand(M, 1, D).astype(dtype) / math.sqrt(D) y = np.random.rand(1, N, D).astype(dtype...
keops-main
keopscore/keopscore/sandbox/lazytensor_gaussian_numpy_inplace.py
keops-main
keopscore/keopscore/binders/__init__.py
import os import keopscore.config.config from keopscore.config.config import get_build_folder from keopscore.utils.code_gen_utils import get_hash_name from keopscore.utils.misc_utils import KeOps_Error, KeOps_Message from keopscore.config.config import cpp_flags class LinkCompile: """ Base class for compilin...
keops-main
keopscore/keopscore/binders/LinkCompile.py
keops-main
keopscore/keopscore/binders/nvrtc/__init__.py
import os from ctypes import create_string_buffer, CDLL, c_int from os import RTLD_LAZY import sysconfig from keopscore.binders.LinkCompile import LinkCompile import keopscore.config from keopscore.config.config import ( cuda_version, jit_binary, cxx_compiler, nvrtc_flags, nvrtc_include, jit_so...
keops-main
keopscore/keopscore/binders/nvrtc/Gpu_link_compile.py
from keopscore.binders.LinkCompile import LinkCompile class Cpu_link_compile(LinkCompile): source_code_extension = "cpp" def __init__(self): LinkCompile.__init__(self) # these are used for command line compiling mode self.low_level_code_file = "".encode("utf-8") # actual dll...
keops-main
keopscore/keopscore/binders/cpp/Cpu_link_compile.py
keops-main
keopscore/keopscore/binders/cpp/__init__.py
from keopscore.config.chunks import dimchunk from keopscore.utils.code_gen_utils import GetDims, GetInds, Var_loader class Chunk_Mode_Constants: def __init__(self, red_formula): varloader = Var_loader(red_formula) self.red_formula = red_formula self.dimred = red_formula.dimred # dimensi...
keops-main
keopscore/keopscore/mapreduce/Chunk_Mode_Constants.py
from .cpu import * from ..config.config import use_cuda if use_cuda: from .gpu import *
keops-main
keopscore/keopscore/mapreduce/__init__.py
from keopscore.formulas.reductions import * from keopscore.formulas.GetReduction import GetReduction from keopscore.utils.code_gen_utils import Var_loader, new_c_varname, pointer, c_include class MapReduce: """ base class for map-reduce schemes """ def __init__( self, red_formula_stri...
keops-main
keopscore/keopscore/mapreduce/MapReduce.py
from .GpuAssignZero import GpuAssignZero from .GpuReduc1D import GpuReduc1D from .GpuReduc1D_chunks import GpuReduc1D_chunks from .GpuReduc1D_finalchunks import GpuReduc1D_finalchunks from .GpuReduc1D_ranges import GpuReduc1D_ranges from .GpuReduc1D_ranges_chunks import GpuReduc1D_ranges_chunks from .GpuReduc1D_ranges_...
keops-main
keopscore/keopscore/mapreduce/gpu/__init__.py
from keopscore import cuda_block_size from keopscore.config.chunks import dimfinalchunk from keopscore.binders.nvrtc.Gpu_link_compile import Gpu_link_compile from keopscore.formulas.reductions.Sum_Reduction import Sum_Reduction from keopscore.formulas.reductions.sum_schemes import * from keopscore.mapreduce.gpu.GpuAssi...
keops-main
keopscore/keopscore/mapreduce/gpu/GpuReduc1D_ranges_finalchunks.py
from keopscore import cuda_block_size from keopscore.config.chunks import dimchunk from keopscore.binders.nvrtc.Gpu_link_compile import Gpu_link_compile from keopscore.formulas.reductions.sum_schemes import * from keopscore.mapreduce.gpu.GpuAssignZero import GpuAssignZero from keopscore.mapreduce.MapReduce import MapRe...
keops-main
keopscore/keopscore/mapreduce/gpu/GpuReduc1D_ranges_chunks.py
from keopscore import cuda_block_size from keopscore.config.chunks import dimfinalchunk from keopscore.binders.nvrtc.Gpu_link_compile import Gpu_link_compile from keopscore.formulas.reductions.Sum_Reduction import Sum_Reduction from keopscore.formulas.reductions.sum_schemes import * from keopscore.mapreduce.gpu.GpuAssi...
keops-main
keopscore/keopscore/mapreduce/gpu/GpuReduc1D_finalchunks.py
from keopscore import cuda_block_size from keopscore.config.chunks import dimchunk from keopscore.binders.nvrtc.Gpu_link_compile import Gpu_link_compile from keopscore.formulas.reductions.sum_schemes import * from keopscore.mapreduce.gpu.GpuAssignZero import GpuAssignZero from keopscore.mapreduce.MapReduce import MapRe...
keops-main
keopscore/keopscore/mapreduce/gpu/GpuReduc1D_chunks.py
from keopscore.binders.nvrtc.Gpu_link_compile import Gpu_link_compile from keopscore.mapreduce.gpu.GpuAssignZero import GpuAssignZero from keopscore.mapreduce.MapReduce import MapReduce from keopscore.utils.code_gen_utils import ( c_variable, c_array, ) class GpuReduc1D(MapReduce, Gpu_link_compile): # cla...
keops-main
keopscore/keopscore/mapreduce/gpu/GpuReduc1D.py
from keopscore.binders.nvrtc.Gpu_link_compile import Gpu_link_compile from keopscore.formulas.reductions.sum_schemes import block_sum, kahan_scheme from keopscore.mapreduce.gpu.GpuAssignZero import GpuAssignZero from keopscore.mapreduce.MapReduce import MapReduce from keopscore.utils.code_gen_utils import c_variable, c...
keops-main
keopscore/keopscore/mapreduce/gpu/GpuReduc2D.py
from keopscore.binders.nvrtc.Gpu_link_compile import Gpu_link_compile from keopscore.mapreduce.gpu.GpuAssignZero import GpuAssignZero from keopscore.mapreduce.MapReduce import MapReduce from keopscore.utils.code_gen_utils import ( c_variable, c_array, c_include, ) class GpuReduc1D_ranges(MapReduce, Gpu_li...
keops-main
keopscore/keopscore/mapreduce/gpu/GpuReduc1D_ranges.py
from keopscore.binders.nvrtc.Gpu_link_compile import Gpu_link_compile from keopscore.mapreduce.MapReduce import MapReduce from keopscore.utils.code_gen_utils import ( c_include, c_zero_float, ) class GpuAssignZero(MapReduce, Gpu_link_compile): # class for generating the final C++ code, Gpu version de...
keops-main
keopscore/keopscore/mapreduce/gpu/GpuAssignZero.py
from keopscore import debug_ops_at_exec from keopscore.binders.cpp.Cpu_link_compile import Cpu_link_compile from keopscore.mapreduce.cpu.CpuAssignZero import CpuAssignZero from keopscore.mapreduce.MapReduce import MapReduce from keopscore.utils.code_gen_utils import c_include import keopscore class CpuReduc(MapReduce...
keops-main
keopscore/keopscore/mapreduce/cpu/CpuReduc.py
from .CpuReduc_ranges import CpuReduc_ranges from .CpuReduc import CpuReduc from .CpuAssignZero import CpuAssignZero
keops-main
keopscore/keopscore/mapreduce/cpu/__init__.py
from keopscore import debug_ops_at_exec from keopscore.binders.cpp.Cpu_link_compile import Cpu_link_compile from keopscore.mapreduce.MapReduce import MapReduce from keopscore.utils.code_gen_utils import ( c_include, c_zero_float, ) import keopscore class CpuAssignZero(MapReduce, Cpu_link_compile): # class...
keops-main
keopscore/keopscore/mapreduce/cpu/CpuAssignZero.py
from keopscore import debug_ops_at_exec from keopscore.binders.cpp.Cpu_link_compile import Cpu_link_compile from keopscore.mapreduce.cpu.CpuAssignZero import CpuAssignZero from keopscore.mapreduce.MapReduce import MapReduce from keopscore.utils.code_gen_utils import ( c_variable, c_array, c_include, ) impo...
keops-main
keopscore/keopscore/mapreduce/cpu/CpuReduc_ranges.py
from keopscore.utils.code_gen_utils import VectApply from keopscore.formulas.Operation import Operation from keopscore.utils.misc_utils import KeOps_Error class VectorizedScalarOp(Operation): # class for operations that are vectorized or broadcasted # scalar operations, # such as Exp(f), Cos(f), Mult(f,g)...
keops-main
keopscore/keopscore/formulas/VectorizedScalarOp.py
keops-main
keopscore/keopscore/formulas/checks.py
from .complex import * from .maths import * from .reductions import * from .variables import * from .autodiff import *
keops-main
keopscore/keopscore/formulas/__init__.py
from keopscore.utils.code_gen_utils import new_c_varname, c_array from keopscore.utils.Tree import Tree from keopscore import debug_ops, debug_ops_at_exec from keopscore.utils.misc_utils import KeOps_Error ################### ## Base class ################### class Operation(Tree): """Base class for all keops bu...
keops-main
keopscore/keopscore/formulas/Operation.py
import ast, inspect import keopscore.formulas from keopscore.utils.code_gen_utils import get_hash_name from keopscore.formulas.reductions import * from keopscore.formulas.maths import * from keopscore.formulas.complex import * from keopscore.formulas.variables import * from keopscore.formulas.autodiff import * class...
keops-main
keopscore/keopscore/formulas/GetReduction.py
from keopscore.formulas.Operation import Operation from keopscore.formulas.variables.Var import Var from keopscore.config.chunks import enable_chunk, dim_treshold_chunk, specdims_use_chunk class Chunkable_Op(Operation): def chunked_version(self, dimchk): chunked_args = [child.chunked_version(dimchk) for c...
keops-main
keopscore/keopscore/formulas/Chunkable_Op.py
from keopscore.utils.code_gen_utils import ComplexVectApply from keopscore.formulas.Operation import Operation from keopscore.utils.misc_utils import KeOps_Error class VectorizedComplexScalarOp(Operation): # class for operations that are vectorized or broadcasted # complex scalar operations, # such as Com...
keops-main
keopscore/keopscore/formulas/VectorizedComplexScalarOp.py
from .Grad import Grad from .Grad_WithSavedForward import Grad_WithSavedForward
keops-main
keopscore/keopscore/formulas/autodiff/__init__.py
# same as Grad with additional saved forward variable. This is only used for taking gradients of reductions operations. def Grad_WithSavedForward(red_formula, v, gradin, f0): return red_formula.DiffT(v, gradin, f0)
keops-main
keopscore/keopscore/formulas/autodiff/Grad_WithSavedForward.py
from keopscore.formulas import Var from keopscore.utils.code_gen_utils import GetInds from keopscore.utils.misc_utils import KeOps_Error # ///////////////////////////////////////////////////////////// # /// GRADIENT OPERATOR : Grad< F, V, Gradin > //// # ////////////////////////////////////////////////////...
keops-main
keopscore/keopscore/formulas/autodiff/Grad.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_for_loop from keopscore.formulas.complex.Real2Complex import Real2Complex from keopscore.formulas.complex.ComplexMult import ComplexMult from keopscore.utils.misc_utils import KeOps_Error # /////////////////////////////////...
keops-main
keopscore/keopscore/formulas/complex/ComplexRealScal.py
from keopscore.formulas.VectorizedComplexScalarOp import VectorizedComplexScalarOp from keopscore.utils.code_gen_utils import ( c_for_loop, new_c_varname, c_variable, ) from keopscore.utils.math_functions import keops_exp, keops_cos, keops_sin from keopscore.utils.code_gen_utils import c_variable from keops...
keops-main
keopscore/keopscore/formulas/complex/ComplexExp.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_zero_float, c_for_loop # ///////////////////////////////////////////////////////////////////////// # //// Imag2Complex //// # //////////////////////////////////////////////////////////////////...
keops-main
keopscore/keopscore/formulas/complex/Imag2Complex.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_zero_float, c_for_loop # ///////////////////////////////////////////////////////////////////////// # //// Real2Complex //// # //////////////////////////////////////////////////////////////////...
keops-main
keopscore/keopscore/formulas/complex/Real2Complex.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_for_loop from keopscore.formulas.complex.Imag2Complex import Imag2Complex from keopscore.utils.misc_utils import KeOps_Error # ///////////////////////////////////////////////////////////////////////// # //// ComplexIma...
keops-main
keopscore/keopscore/formulas/complex/ComplexImag.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_zero_float, c_for_loop from keopscore.utils.misc_utils import KeOps_Error # ///////////////////////////////////////////////////////////////////////// # //// ComplexSum //// # /////////////////...
keops-main
keopscore/keopscore/formulas/complex/ComplexSum.py
from keopscore.formulas.maths.Atan2 import Atan2 from keopscore.formulas.complex.ComplexReal import ComplexReal from keopscore.formulas.complex.ComplexImag import ComplexImag # ///////////////////////////////////////////////////////////////////////// # //// ComplexAngle //// # //////////...
keops-main
keopscore/keopscore/formulas/complex/ComplexAngle.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_for_loop from keopscore.formulas.complex.ComplexReal import ComplexReal from keopscore.formulas.complex.ComplexMult import ComplexMult from keopscore.formulas.complex.Conj import Conj from keopscore.utils.misc_utils import K...
keops-main
keopscore/keopscore/formulas/complex/ComplexSquareAbs.py
from keopscore.formulas.VectorizedComplexScalarOp import VectorizedComplexScalarOp # ///////////////////////////////////////////////////////////////////////// # //// ComplexSubtract //// # ///////////////////////////////////////////////////////////////////////// class ComplexSubtract(V...
keops-main
keopscore/keopscore/formulas/complex/ComplexSubtract.py
from .ComplexAbs import ComplexAbs from .ComplexAdd import ComplexAdd from .ComplexAngle import ComplexAngle from .ComplexDivide import ComplexDivide from .ComplexExp import ComplexExp from .ComplexExp1j import ComplexExp1j from .ComplexImag import ComplexImag from .ComplexMult import ComplexMult from .ComplexReal impo...
keops-main
keopscore/keopscore/formulas/complex/__init__.py
from keopscore.formulas.complex.ComplexSquareAbs import ComplexSquareAbs from keopscore.formulas.maths.Sqrt import Sqrt # ///////////////////////////////////////////////////////////////////////// # //// ComplexAbs //// # //////////////////////////////////////////////////////////////////...
keops-main
keopscore/keopscore/formulas/complex/ComplexAbs.py
from keopscore.formulas.complex.Real2Complex import Real2Complex from keopscore.formulas.complex.ComplexMult import ComplexMult from keopscore.formulas.complex.ComplexSquareAbs import ComplexSquareAbs from keopscore.formulas.complex.Conj import Conj from keopscore.formulas.maths.Inv import Inv # //////////////////////...
keops-main
keopscore/keopscore/formulas/complex/ComplexDivide.py
from keopscore.formulas.VectorizedComplexScalarOp import VectorizedComplexScalarOp from keopscore.formulas.complex.Conj import Conj # ///////////////////////////////////////////////////////////////////////// # //// ComplexMult //// # //////////////////////////////////////////////////////...
keops-main
keopscore/keopscore/formulas/complex/ComplexMult.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_for_loop from keopscore.formulas.complex.Real2Complex import Real2Complex from keopscore.utils.misc_utils import KeOps_Error # ///////////////////////////////////////////////////////////////////////// # //// ComplexRea...
keops-main
keopscore/keopscore/formulas/complex/ComplexReal.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_for_loop from keopscore.utils.misc_utils import KeOps_Error # ///////////////////////////////////////////////////////////////////////// # //// adjoint of ComplexSum //// # ////////////////////...
keops-main
keopscore/keopscore/formulas/complex/ComplexSumT.py
from keopscore.formulas.VectorizedComplexScalarOp import VectorizedComplexScalarOp # ///////////////////////////////////////////////////////////////////////// # //// Conj : complex conjugate //// # ///////////////////////////////////////////////////////////////////////// class Conj(Vec...
keops-main
keopscore/keopscore/formulas/complex/Conj.py
from keopscore.formulas.VectorizedComplexScalarOp import VectorizedComplexScalarOp # ///////////////////////////////////////////////////////////////////////// # //// ComplexAdd //// # ///////////////////////////////////////////////////////////////////////// class ComplexAdd(VectorizedC...
keops-main
keopscore/keopscore/formulas/complex/ComplexAdd.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_for_loop from keopscore.utils.math_functions import keops_sincos from keopscore.formulas.complex.Real2Complex import Real2Complex from keopscore.formulas.complex.Imag2Complex import Imag2Complex from keopscore.formulas.maths...
keops-main
keopscore/keopscore/formulas/complex/ComplexExp1j.py
from .IntCst import IntCst from .Var import Var from .Zero import Zero
keops-main
keopscore/keopscore/formulas/variables/__init__.py
from keopscore.utils.code_gen_utils import c_zero_float from keopscore.formulas.Operation import Operation class Zero(Operation): """zero operation : encodes a vector of zeros""" string_id = "Zero" def __init__(self, dim): super().__init__() self.dim = dim self.params = (dim,) ...
keops-main
keopscore/keopscore/formulas/variables/Zero.py
from keopscore.utils.code_gen_utils import cast_to, c_variable from keopscore.formulas.Operation import Operation from keopscore.formulas.variables.Zero import Zero class IntCst_Impl(Operation): # constant integer "operation" string_id = "IntCst" print_spec = "", "pre", 0 def __init__(self, val): ...
keops-main
keopscore/keopscore/formulas/variables/IntCst.py
from keopscore.utils.code_gen_utils import VectCopy from keopscore.formulas.Operation import Operation ####################### ## Var operation ####################### class Var(Operation): """Var operation class. Var(ind,dim,cat) is a symbolic object that encodes an input tensor in the call to the KeOp...
keops-main
keopscore/keopscore/formulas/variables/Var.py
from keopscore.formulas.Operation import Broadcast from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.maths.Scalprod import Scalprod from keopscore.formulas.maths.Square import Square from keopscore.formulas.variables.Zero import Zero from keopscore.utils.math_functions import ...
keops-main
keopscore/keopscore/formulas/maths/Mult.py
from keopscore.formulas.Operation import Operation from keopscore.formulas.maths.ArgMax import ArgMax from keopscore.formulas.maths.OneHot import OneHot from keopscore.utils.code_gen_utils import c_for_loop, c_if, value from keopscore.utils.misc_utils import KeOps_Error ############################ ###### Max ...
keops-main
keopscore/keopscore/formulas/maths/Max.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.utils.math_functions import keops_pow class Pow(VectorizedScalarOp): """the integer power vectorized operation Pow(f,m) where m is integer, computes f^m """ def __init__(self, f, m): super().__init__(f, params...
keops-main
keopscore/keopscore/formulas/maths/Pow.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import ( c_variable, c_for_loop, c_zero_float, ) from keopscore.utils.misc_utils import KeOps_Error # ///////////////////////////////////////////////////////////////////////// # //// Vector-matrix product b...
keops-main
keopscore/keopscore/formulas/maths/VecMatMult.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import value from keopscore.utils.misc_utils import KeOps_Error ############################ ###### ELEMENT EXTRACTION : Elem(f,m) (aka get_item) ##### ############################ class Elem(Operation): string_id = "...
keops-main
keopscore/keopscore/formulas/maths/Elem.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.maths.DiffClampInt import DiffClampInt from keopscore.utils.math_functions import keops_clampint class ClampInt(VectorizedScalarOp): """ClampInt(x,a,b) = a if x<a, x if a<=x<=b, b if b<x N.B. same as Clamp but a and b...
keops-main
keopscore/keopscore/formulas/maths/ClampInt.py
from keopscore.formulas.Operation import Broadcast from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.maths.Mult import Mult_Impl from keopscore.formulas.variables.IntCst import IntCst, IntCst_Impl from keopscore.formulas.variables.Zero import Zero ########################## ...
keops-main
keopscore/keopscore/formulas/maths/Add.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import ( c_variable, c_for_loop, c_zero_float, ) from keopscore.utils.misc_utils import KeOps_Error # ///////////////////////////////////////////////////////////////////////// # //// Matrix-vector product A x b ...
keops-main
keopscore/keopscore/formulas/maths/MatVecMult.py
from keopscore.formulas.Operation import Broadcast from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.variables.Zero import Zero from keopscore.formulas.maths.Mult import Mult_Impl from keopscore.formulas.variables.IntCst import IntCst, IntCst_Impl ########################## #...
keops-main
keopscore/keopscore/formulas/maths/Subtract.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.variables.Zero import Zero ########################## ###### Minus ##### ########################## class Minus_Impl(VectorizedScalarOp): """the "minus" vectorized operation""" string_id = "Minus" print...
keops-main
keopscore/keopscore/formulas/maths/Minus.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.utils.math_functions import keops_rcp ########################## ###### INVERSE : Inv<F> ##### ########################## class Inv(VectorizedScalarOp): """the "Inv" vectorized operation""" string_id = "Inv" p...
keops-main
keopscore/keopscore/formulas/maths/Inv.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.maths.IntInv import IntInv from keopscore.formulas.maths.Rsqrt import Rsqrt from keopscore.utils.math_functions import keops_sqrt ########################## ###### Sqrt ##### ########################## class Sqrt(V...
keops-main
keopscore/keopscore/formulas/maths/Sqrt.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.maths.IntInv import IntInv ########################## ###### Rsqrt ##### ########################## class Rsqrt(VectorizedScalarOp): """the inverse square root vectorized operation""" string_id = "Rsqrt" ...
keops-main
keopscore/keopscore/formulas/maths/Rsqrt.py
from keopscore.formulas.Operation import Operation from keopscore.formulas.maths.Extract import Extract from keopscore.utils.code_gen_utils import VectCopy ############################ ###### Concat ##### ############################ class Concat(Operation): string_id = "Concat" def __init__(self,...
keops-main
keopscore/keopscore/formulas/maths/Concat.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.utils.math_functions import keops_log class Log(VectorizedScalarOp): """the logarithm vectorized operation""" string_id = "Log" ScalarOpFun = keops_log @staticmethod def Derivative(f): return 1 / f ...
keops-main
keopscore/keopscore/formulas/maths/Log.py
from keopscore.formulas.maths.SqNorm2 import SqNorm2 class SqDist: def __new__(cls, arg0, arg1): return SqNorm2(arg0 - arg1) enable_test = False
keops-main
keopscore/keopscore/formulas/maths/SqDist.py
from keopscore.formulas.maths.Square import Square from keopscore.formulas.maths.Sum import Sum class SqNormDiag: """ Anisotropic (but diagonal) norm, if S.dim == A.dim: SqNormDiag(S,A) = sum_i s_i*a_i*a_i """ def __new__(cls, S, A): return Sum(S * Square(A)) enable_test = False
keops-main
keopscore/keopscore/formulas/maths/SqNormDiag.py
from keopscore.formulas.maths.SqNorm2 import SqNorm2 class WeightedSqDist: """ WEIGHTED SQUARED DISTANCE : WeightedSqDist(S,A) """ def __new__(cls, S, A): return S * SqNorm2(A) enable_test = False
keops-main
keopscore/keopscore/formulas/maths/WeightedSqDist.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.maths.Rsqrt import Rsqrt from keopscore.utils.math_functions import keops_asin class Asin(VectorizedScalarOp): """the arc-sine vectorized operation""" string_id = "Asin" ScalarOpFun = keops_asin @staticmeth...
keops-main
keopscore/keopscore/formulas/maths/Asin.py
from keopscore.formulas.maths.Sum import Sum from keopscore.formulas.maths.TensorProd import TensorProd class SymSqNorm: """ Fully anisotropic norm, if S.dim == A.dim * A.dim SymSqNorm(A,X) = sum_{ij} a_ij * x_i*x_j """ def __new__(cls, A, X): return Sum(A * TensorProd(X, X)) enable_...
keops-main
keopscore/keopscore/formulas/maths/SymSqNorm.py
from keopscore.formulas.maths.Rsqrt import Rsqrt from keopscore.formulas.maths.SqNorm2 import SqNorm2 class Normalize: def __new__(cls, arg): return Rsqrt(SqNorm2(arg)) * arg enable_test = False
keops-main
keopscore/keopscore/formulas/maths/Normalize.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.utils.math_functions import keops_cos class Cos(VectorizedScalarOp): """the cosine vectorized operation""" string_id = "Cos" ScalarOpFun = keops_cos @staticmethod def Derivative(f): from .Sin import Sin ...
keops-main
keopscore/keopscore/formulas/maths/Cos.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.utils.math_functions import keops_atan2 # ////////////////////////////////////////////////////////////// # //// ATAN2 : Atan2< F, G > //// # //////////////////////////////////////////////////////////////...
keops-main
keopscore/keopscore/formulas/maths/Atan2.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_zero_float from keopscore.utils.misc_utils import KeOps_Error # ////////////////////////////////////////////////////////////// # //// ONE-HOT REPRESENTATION : OneHot<F,DIM> //// # /////////////////////////////...
keops-main
keopscore/keopscore/formulas/maths/OneHot.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import value, c_zero_float, c_for_loop from keopscore.utils.misc_utils import KeOps_Error ############################ ###### ELEMENT "INJECTION" : ElemT(f,m,n) ############################ class ElemT(Operation): string_id...
keops-main
keopscore/keopscore/formulas/maths/ElemT.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.maths.Sign import Sign from keopscore.utils.math_functions import keops_abs class Abs(VectorizedScalarOp): """the absolute value vectorized operation""" string_id = "Abs" ScalarOpFun = keops_abs @staticmeth...
keops-main
keopscore/keopscore/formulas/maths/Abs.py
from .Abs import Abs from .Acos import Acos from .Add import Add from .ArgMax import ArgMax from .ArgMin import ArgMin from .Asin import Asin from .Atan import Atan from .Atan2 import Atan2 from .Clamp import Clamp from .ClampInt import ClampInt from .Concat import Concat from .Cos import Cos from .DiffClampInt import ...
keops-main
keopscore/keopscore/formulas/maths/__init__.py
from keopscore.formulas.Operation import Broadcast from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.maths.Scalprod import Scalprod from keopscore.formulas.maths.Square import Square from keopscore.formulas.variables.Zero import Zero from keopscore.utils.misc_utils import KeOp...
keops-main
keopscore/keopscore/formulas/maths/Divide.py
from keopscore.formulas.Operation import Operation from keopscore.formulas.variables.Zero import Zero from keopscore.utils.code_gen_utils import value from keopscore.utils.misc_utils import KeOps_Error ########################## ###### SumT ##### ########################## class SumT_Impl(Operation): # ...
keops-main
keopscore/keopscore/formulas/maths/SumT.py
from keopscore.formulas.Operation import Operation from keopscore.formulas.variables.Zero import Zero from keopscore.utils.code_gen_utils import ( c_zero_float, c_for_loop, c_if, value, c_variable, ) from keopscore.utils.misc_utils import KeOps_Error ############################ ###### ArgMax ...
keops-main
keopscore/keopscore/formulas/maths/ArgMax.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.variables.Zero import Zero from keopscore.utils.math_functions import keops_floor class Floor(VectorizedScalarOp): """the floor vectorized operation""" string_id = "Floor" ScalarOpFun = keops_floor def Diff...
keops-main
keopscore/keopscore/formulas/maths/Floor.py
from keopscore.formulas.maths.Scalprod import Scalprod class SqNorm2: def __new__(cls, arg0): return Scalprod(arg0, arg0) enable_test = False
keops-main
keopscore/keopscore/formulas/maths/SqNorm2.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.utils.math_functions import keops_diffclampint """ ////////////////////////////////////////////////////////////// //// DIFFCLAMPINT : DiffClampInt< F, A, B > //// //////////////////////////////////////////////////////////...
keops-main
keopscore/keopscore/formulas/maths/DiffClampInt.py
from keopscore.formulas.maths.SqNorm2 import SqNorm2 class SqNormIso: """ ISOTROPIC NORM : SqNormIso(S,A) """ def __new__(cls, S, A): return S * SqNorm2(A) enable_test = False
keops-main
keopscore/keopscore/formulas/maths/SqNormIso.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.utils.math_functions import keops_ifelse class IfElse(VectorizedScalarOp): """the if/else vectorized operation IfElse(f,a,b) = a if f>=0, b otherwise """ string_id = "IfElse" ScalarOpFun = keops_ifelse def D...
keops-main
keopscore/keopscore/formulas/maths/IfElse.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.utils.math_functions import keops_powf class Powf(VectorizedScalarOp): """the Power vectorized operation""" string_id = "Powf" ScalarOpFun = keops_powf @staticmethod def Derivative(a, b): from keopscore....
keops-main
keopscore/keopscore/formulas/maths/Powf.py
from keopscore.formulas.Operation import Operation from keopscore.formulas.maths.ArgMin import ArgMin from keopscore.formulas.maths.OneHot import OneHot from keopscore.utils.code_gen_utils import c_for_loop, c_if, value from keopscore.utils.misc_utils import KeOps_Error ############################ ###### Min ...
keops-main
keopscore/keopscore/formulas/maths/Min.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import c_zero_float, VectCopy from keopscore.utils.misc_utils import KeOps_Error # ////////////////////////////////////////////////////////////// # //// VECTOR "INJECTION" : ExtractT<F,START,DIM> //// # ///////////////////...
keops-main
keopscore/keopscore/formulas/maths/ExtractT.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.maths.ClampInt import ClampInt from keopscore.utils.math_functions import keops_clamp class Clamp(VectorizedScalarOp): """Clamp(x,a,b) = a if x<a, x if a<=x<=b, b if b<x""" string_id = "Clamp" ScalarOpFun = keop...
keops-main
keopscore/keopscore/formulas/maths/Clamp.py
from keopscore.formulas.Operation import Operation from keopscore.utils.code_gen_utils import use_pragma_unroll #################################### ###### Tensor Dot Product ##### #################################### def prod(x): # product of all elements in list of integers res = 1 for item in x: ...
keops-main
keopscore/keopscore/formulas/maths/TensorDot.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.variables.Zero import Zero from keopscore.utils.math_functions import keops_step class Step(VectorizedScalarOp): """the Step vectorized operation""" string_id = "Step" ScalarOpFun = keops_step def DiffT(sel...
keops-main
keopscore/keopscore/formulas/maths/Step.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.variables.Zero import Zero from keopscore.utils.math_functions import keops_round class Round(VectorizedScalarOp): """the Round vectorized operation Round(f,d) where d is integer, rounds f to d decimals """ d...
keops-main
keopscore/keopscore/formulas/maths/Round.py
from keopscore.formulas.VectorizedScalarOp import VectorizedScalarOp from keopscore.formulas.maths.Step import Step from keopscore.utils.math_functions import keops_relu class ReLU(VectorizedScalarOp): """the ReLU vectorized operation""" string_id = "ReLU" ScalarOpFun = keops_relu @staticmethod ...
keops-main
keopscore/keopscore/formulas/maths/ReLU.py