Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "where T" in julia do without any specification after T?

Tags:

julia

I'm new to julia and I have not been able to find an explanation of where that fully makes sense to me. So I understand that for example function f(x::T, y::T) where {T<:Number} = true is requiring that both the x and y parameters be numeric types of some sort.

But then there are other functions that will look like function f(X::AbstractMatrix{T}) where T without any specification of what T is supposed to be. Can someone explain what that is doing and when I would want to use this syntax?

like image 587
DFL Avatar asked Apr 20 '21 15:04

DFL


People also ask

What is :: In Julia?

A return type can be specified in the function declaration using the :: operator. This converts the return value to the specified type. This function will always return an Int8 regardless of the types of x and y .

What is multiple dispatch in Julia?

Using all of a function's arguments to choose which method should be invoked, rather than just the first, is known as multiple dispatch.

What is Julia exclamation mark?

an exclamation mark is a prefix operator for logical negation ("not") a! function names that end with an exclamation mark modify one or more of their arguments by convention. # the number sign (or hash or pound) character begins single line comments.

What is mutable struct in Julia?

type and immutable are valid up to julia 0.6, mutable struct and struct are the names of the same objects in julia 0.6 and forward. mutable in mutable struct means that the fields can change - which is actually fairly rarely used so being immutable is the default. mutable struct 's are slower than struct s.


Video Answer


1 Answers

where T without anything else is just where {T<:Any} in other words, it's true for all T, but Julia needs you to write something so that `T is defined.

like image 68
Oscar Smith Avatar answered Sep 21 '22 22:09

Oscar Smith