Skip to content

Commit dcb8a12

Browse files
author
Joe Petviashvili
committed
add iota
1 parent 5668adc commit dcb8a12

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/util.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Base: cumsum, cumprod, cummin, cummax, chol, abs2
33

44
export constant, get_last_error, err_to_string, sort_index, fir, iir
55
export mean_weighted, var_weighted, set_array_indexer, set_seq_param_indexer
6-
export afeval
6+
export afeval, iota
77

88
const af_threshold = Ref(4*1024*1024*1024)
99
const af_gc_count = Ref(0)
@@ -471,3 +471,11 @@ function iir{T,N}(b::AFArray{T},a::AFArray{T},x::AFArray{T,N})
471471
_error(ccall((:af_iir,af_lib),af_err,(Ptr{af_array},af_array,af_array,af_array),y,b.arr,a.arr,x.arr))
472472
AFArray{T,N}(y[])
473473
end
474+
475+
function iota{T,N}(dims::NTuple{N,Int}, typ::Type{T} = Int32)
476+
out = RefValue{af_array}(0)
477+
_error(ccall((:af_iota,af_lib), af_err,
478+
(Ptr{af_array},UInt32,Ptr{dim_t},UInt32,Ptr{dim_t},af_dtype),
479+
out,UInt32(N),[dims...],UInt32(1),[1],af_type(T)))
480+
AFArray{T,N}(out[])+T(1)
481+
end

test/array.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
x = range(AFArray{Float32}, 2, 3, 10)
1010
@test Array(x) == collect(range(2,3,10))
1111
@test typeof(x) == AFArray{Float32, 1}
12+
13+
@test sum(@inferred iota((2,3))) == 21
1214
end
1315

1416
@testset "linspace" begin

0 commit comments

Comments
 (0)