Questions tagged [multiple-dispatch]

A technique for polymorphic invocation of methods based on the types of many (or all) arguments. Compare to single-dispatch, used in common OO languages, where methods can only be polymorphic in the first argument -- the runtime resolution of a.doSomething(x, y, z) depends only on the type of a.

106 questions
2
votes
1 answer

Multiple dispatch for return values

I have a routine that can return an array of any FloatingPoint type (or really any numeric type but it's intended for floating points). It computes the convergents of a continued fraction. My problem is that I want the compiler to optimize it for…
Sig TM
  • 123
  • 3
2
votes
2 answers

Multiple Dispatch with Generics

I'm trying to abstract away my interface implementations by providing a factory/builder using generics. However, I'm running into an issue with multiple dispatch and C# generics at run time that's doing something that seems odd. The basic scenario…
SignalRichard
  • 1,572
  • 2
  • 17
  • 32
1
vote
1 answer

What is the Julia equivalent to classes and instance variables in Java?

I am trying to avoid repeatedly passing a struct in my functions in order to access its fields. In Java this can be avoided by using a class and defining instance variables. What's the equivalent in Julia? Here is some sample code where I am…
1
vote
1 answer

Use this function if nonlinear expression in vector

I have a vector a that can contain several different types of elements of the expressions QuadExpr, NonlinearExpression, AffExpr, VariableRef. However, I want that if one of the elements (expressions) in a is a NonlinearExpression or a…
Annaquest
  • 131
  • 6
1
vote
1 answer

Union type in Julia

I am wondering about types in Julia, more specific Union. For instance, I have made a function where I add the length of my input a into a vector len_a. If a is of type VariableRefI want the length to be 1. I write it like this; function…
Annaquest
  • 131
  • 6
1
vote
1 answer

How to overload Base.view() for a custom struct of arrays type in Julia or extend StructArrays type with overloaded base.Push!() method

I should preface this by stating I am very new to the Julia language and I think I am missing something fundamental. I am trying to setup a numerical simulation code and ultimately want it to work on both CPU and GPU. The method i am attempting is…
Dizzixx
  • 318
  • 4
  • 13
1
vote
0 answers

Is there a 1:1 mapping between static typing and static dispatch vs dynamic typing and dynamic dispatch?

Context: I'm learning Julia and trying to figure out multiple dispatch. I understand the conceptual leap from single dynamic dispatch to multiple dynamic dispatch, but I'm trying to pin down single dynamic dispatch. Question: Is the following 1:1…
1
vote
1 answer

Java vs. Julia: Differences in JIT Compiling and Resulting Performance

I've recently started reading about JIT compilation. On another note, I've read that well-written Julia code often performs on-par with statically compiled languages (see, e.g., paragraph 2 of the introduction section of the Julia docs) while I've…
ruthra
  • 11
  • 2
1
vote
2 answers

How to use as a default only one property from a struct?

I want to create a struct with many properties, but when applying the functions, I want it to behave like its type is one of the selected properties, for example: mutable struct Field{T} field_type::T field_description::String end I want…
sgaseretto
  • 421
  • 5
  • 13
1
vote
1 answer

Julia identify method by number of keyword arguments

I have two methods with the same name and same amount of "normal" arguments. However, they differ in the number of keyword arguments (which are all non-optional). I think the following minimal example illustrates my point well: julia> f(a; b) =…
MetaColon
  • 2,895
  • 3
  • 16
  • 38
1
vote
1 answer

Julia: Unpack Arguments from Dictionary or Array for Functions with Multiple Dispatch

My question originated where I had a dictionary of DataFrame values (with compatible columns), and I want to vcat them all together. Consider how the string function can take any number of string arguments: string("Fish ", "and ", "chips ") == "Fish…
Owen
  • 448
  • 3
  • 11
1
vote
1 answer

python method overloading - multipledispatch with kwargs

I'm using python3.8 and multipledispatch library in order to overload a method signature. multipledispatch documentation examples suggests overloading like this: from multipledispatch import dispatch @dispatch(int, int) def add(x, y): print(x…
1
vote
1 answer

multipledispatch ModuleNotFoundError running from command-line

Running a locust (locust.io) script from the command line. locust calls main.py which has the following imports: from locust import HttpUser, between, task from StreamLoader.stream_generator import * # thought this brings in everything Packer.py…
Guy
  • 666
  • 1
  • 10
  • 34
1
vote
2 answers

Multiple Dispatch Swift attempt: Conflicting arguments to generic parameter 'T' ('Cat' vs. 'Dog')

I was watching a video on Julia about Multiple Dispatch and was curious if I could write something similar in Swift. I see that Swift relies on the compiler where Julia seems to determine a type at run time, but I also discovered something I don't…
Turnipdabeets
  • 5,815
  • 8
  • 40
  • 63
1
vote
0 answers

Confused about single-dispatch in Java vs multiple dispatch

I’ve read a good post Just still a little confused about the concept of multiple dispatch (not in Java) vs single dispatch (in Java). Let’s use this example: class A { m(A a) { System.out.println(“In A: “ + a.getClass()); } } class B…
ppp
  • 111
  • 7