Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][SetParameters] Generalize to work for any type, rename to TypeParameterAccessors #1331

Closed
wants to merge 149 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
1724369
Start working on changing the name of `SetParameters`
kmp5VT Feb 5, 2024
0513d41
Merge commit '172436901f883cd939caf78b81ad433bcc466140' into kmp5/ref…
kmp5VT Feb 5, 2024
4ac2a8f
Merge branch 'main' into kmp5/refactor/rename_setparameters
kmp5VT Feb 5, 2024
f78c142
Move unused files to deprecated to better
kmp5VT Feb 5, 2024
80fecae
Start moving get_parameter/parameter
kmp5VT Feb 5, 2024
7bda99a
Remove `set_parameter` functions from other directories
kmp5VT Feb 5, 2024
9cbbcbf
Make parameter function
kmp5VT Feb 5, 2024
93ec2f4
move set_parameter functions to `set_parameters.jl`
kmp5VT Feb 5, 2024
070166d
format
kmp5VT Feb 5, 2024
37c8eec
Merge branch 'main' into kmp5/refactor/rename_setparameters
kmp5VT Feb 5, 2024
27f147a
add comment to work on `default_parameter` [no ci]
kmp5VT Feb 5, 2024
96446b7
Merge branch 'kmp5/refactor/rename_setparameters' of github.com:kmp5V…
kmp5VT Feb 5, 2024
01bf0f0
Rename `SetParameters` to
kmp5VT Feb 5, 2024
8f9bb82
format
kmp5VT Feb 5, 2024
e55611f
`TypeParameterAccessor` -> `TypeParameterAccessors`
kmp5VT Feb 5, 2024
611e350
Update parameters file remove get_parameters
kmp5VT Feb 6, 2024
fe78a5a
Update tests for get parameters
kmp5VT Feb 6, 2024
023770f
Update documentation
kmp5VT Feb 7, 2024
e1c7e04
Fix typo
kmp5VT Feb 7, 2024
403dd72
Move Position based function to Position.jl
kmp5VT Feb 7, 2024
5e6c405
Create Int conversion function
kmp5VT Feb 7, 2024
b15169d
Use new to _datatype function for type stability
kmp5VT Feb 8, 2024
c7a4cad
Update get_parameters tests
kmp5VT Feb 8, 2024
a8b66ff
Move `parameters.jl` before `position.jl`
kmp5VT Feb 8, 2024
354a07b
Move functions that depend on `Position` to `position.jl`
kmp5VT Feb 8, 2024
26e0bc6
Update set_parameters test
kmp5VT Feb 8, 2024
ec69ce4
Move wrapped array definitions to
kmp5VT Feb 8, 2024
4936d3f
Ammending to previous push
kmp5VT Feb 8, 2024
8141575
Remove parenttype_position def is unecessary here
kmp5VT Feb 8, 2024
65b273a
remove uncessary set_ndims call
kmp5VT Feb 8, 2024
415a39d
Export is_wrapped_array and parenttype
kmp5VT Feb 8, 2024
3800125
Fix some issues and dont use `Position`
kmp5VT Feb 8, 2024
0987f8f
Another issue with type stability
kmp5VT Feb 8, 2024
e7dc057
Start defining parenttype position places
kmp5VT Feb 8, 2024
09dda15
Remove exports from `Unwrap`
kmp5VT Feb 8, 2024
bb12557
Remove the `parenttype.jl` file because of compiling requirements
kmp5VT Feb 8, 2024
49fd429
Some updates to specify_parameters (still working here)
kmp5VT Feb 8, 2024
2c3e62f
Updates to base functions to make more type stable
kmp5VT Feb 8, 2024
3842143
grab the name `TypeParameterAccessors` to be able to set `parenttype_…
kmp5VT Feb 8, 2024
6408feb
Update wrapper type to not have stackoverflow
kmp5VT Feb 8, 2024
0edd59e
Update `set_ndim` and `set_eltype`
kmp5VT Feb 8, 2024
4c6e29d
format
kmp5VT Feb 8, 2024
abfb994
Merge branch 'main' into kmp5/refactor/rename_setparameters
kmp5VT Feb 9, 2024
6bfb87d
Some convention updates in the `TypeParameterAccessor` module
kmp5VT Feb 9, 2024
512ad24
Try and remove positoin when possible
kmp5VT Feb 9, 2024
7348682
Remove unecessary code
kmp5VT Feb 9, 2024
e43f3ae
formatting
kmp5VT Feb 9, 2024
3da8963
formatting of `wrappedarray`
kmp5VT Feb 9, 2024
1e112cd
Remove unecessary tests
kmp5VT Feb 9, 2024
1d1b141
formatting/cleanup
kmp5VT Feb 9, 2024
8994541
Start updating the `Specify_parameters`
kmp5VT Feb 9, 2024
cf58b1a
Update `set_parameters` to be more type stable
kmp5VT Feb 12, 2024
eae0a4b
Tests no longer broken
kmp5VT Feb 12, 2024
ad96b1b
Update specify_parameters
kmp5VT Feb 12, 2024
5037009
format
kmp5VT Feb 12, 2024
4d50a3c
format
kmp5VT Feb 12, 2024
97f28fd
Remove unecessary code and old `specify_parameters`
kmp5VT Feb 12, 2024
ed83acf
Update to the position based on function system
kmp5VT Feb 12, 2024
9ce2045
Add interface
kmp5VT Feb 12, 2024
e69657f
Add interface.jl
kmp5VT Feb 12, 2024
02cc6ed
Define setstoragemode for GPU. And update default parameter
kmp5VT Feb 13, 2024
ffa4876
Add a `UndefinedPosition` set_parameter which does nothing
kmp5VT Feb 13, 2024
015f7b5
Rename undefposition -> undefinedposition
kmp5VT Feb 13, 2024
d1b3cce
Make axestype and alloctype parameters
kmp5VT Feb 13, 2024
5f52eec
Spelling
kmp5VT Feb 13, 2024
dc45b4e
Move undefinedPosition set_parameter out of set_parameter.jl. And spe…
kmp5VT Feb 13, 2024
061aeba
format
kmp5VT Feb 13, 2024
f6569cc
Move these generated functions to the correct place
kmp5VT Feb 13, 2024
bfbee6b
No more parenttype_position function
kmp5VT Feb 13, 2024
6b6b850
Update to position(type, function) but there are some tricky circular…
kmp5VT Feb 13, 2024
0bd183e
missing changes from last push in parenttype
kmp5VT Feb 13, 2024
3fee6a9
format
kmp5VT Feb 13, 2024
b5105b1
Merge branch 'kmp5/temp_branch' into kmp5/refactor/rename_setparameters
kmp5VT Feb 13, 2024
11751e0
Update from parenttype position to position
kmp5VT Feb 13, 2024
6603615
More parenttype_position to position
kmp5VT Feb 13, 2024
5e58e0c
Remove typeparameteraccessor file (to_unionall and unspecifyparameters)
kmp5VT Feb 13, 2024
83dadb4
Add some tests to `set_eltype`
kmp5VT Feb 13, 2024
2a8cd90
Fix default parameters for Dense
kmp5VT Feb 13, 2024
a8b4b38
Add back unspecify_parameters to get wrapper name
kmp5VT Feb 13, 2024
726d9d1
Use new system to set alloctype
kmp5VT Feb 13, 2024
e415155
Update UnallocatedArrays tests
kmp5VT Feb 13, 2024
541f349
Update default_alloctype for UnallocatedArrays
kmp5VT Feb 13, 2024
6d8be2c
Comment out default parameter test for now
kmp5VT Feb 13, 2024
23cb8e0
format
kmp5VT Feb 13, 2024
967953a
Some missing updates to the removed file
kmp5VT Feb 13, 2024
d032707
Remove NDTensors. and just say using TypeParameterAccessors
kmp5VT Feb 14, 2024
7db2ca5
Update SimpleTraits using calls
kmp5VT Feb 14, 2024
cab209f
Move before functions
kmp5VT Feb 14, 2024
4f19e7a
Fix broken test
kmp5VT Feb 14, 2024
c06d717
Remove unecessary @generated
kmp5VT Feb 14, 2024
2bff003
Update specify_parameters to be more type stable and no longer need `…
kmp5VT Feb 14, 2024
66cf178
format
kmp5VT Feb 14, 2024
a5064f4
`unwrap_type` -> `unwrap_array_type`
kmp5VT Feb 14, 2024
b29e169
correct the spelling of set_parameter
kmp5VT Feb 14, 2024
69a7561
Add specify_parameter with function
kmp5VT Feb 14, 2024
91d0b1f
Add some comments and remove `specify_parameters`
kmp5VT Feb 14, 2024
7d2e314
format
kmp5VT Feb 14, 2024
07461a8
Fix typo
kmp5VT Feb 14, 2024
1b0a0bd
Working on type stable `DefaultParameter` system
kmp5VT Feb 14, 2024
e4c56c4
Add test to specify_parameter with function in call
kmp5VT Feb 14, 2024
2a5c444
Add specify_defaults test
kmp5VT Feb 14, 2024
5062135
format
kmp5VT Feb 14, 2024
8276521
Move the list of default parameters to `interface` Still workshopping…
kmp5VT Feb 14, 2024
ea4afda
Add set_parameters, where you can put arbitrary parameters and functions
kmp5VT Feb 14, 2024
16e5c17
Add some context and fix the broken case where `Int` isn't wrapped in…
kmp5VT Feb 14, 2024
25d09d5
Fix typo
kmp5VT Feb 14, 2024
09a9dff
Remove default_parameter test and add back unspecifying parameters test
kmp5VT Feb 14, 2024
adbf686
Update specify_parameter system to work better
kmp5VT Feb 14, 2024
efb2269
format
kmp5VT Feb 14, 2024
5ba9b0c
Make a `Function` based parameter function
kmp5VT Feb 16, 2024
bb5d3d0
Fix specify_defaults
kmp5VT Feb 16, 2024
7f8ee72
use function in parameter getting function
kmp5VT Feb 16, 2024
9c21426
Use alloctype over 4
kmp5VT Feb 16, 2024
07e95b9
Rename file and add defaults
kmp5VT Feb 16, 2024
23c81f7
Move undefined position above parameters for compiling
kmp5VT Feb 16, 2024
8b6dbeb
append to previous push
kmp5VT Feb 16, 2024
d8a791f
Responses to Matts comments
kmp5VT Feb 16, 2024
5f1c948
int -> position
kmp5VT Feb 16, 2024
6864abd
Typos
kmp5VT Feb 16, 2024
719a881
Add mytype for testing
kmp5VT Feb 16, 2024
0ba372e
update tests
kmp5VT Feb 16, 2024
9398a90
Revert to default_parameters for now
kmp5VT Feb 16, 2024
92330e7
format
kmp5VT Feb 16, 2024
dc3a9dd
Merge branch 'main' into kmp5/refactor/rename_setparameters
kmp5VT Feb 16, 2024
87bd412
Start making `parameter_function`
kmp5VT Feb 18, 2024
f345715
Add parameter_function for GPUArrays
kmp5VT Feb 18, 2024
94bd0d2
Start fixing things
kmp5VT Feb 18, 2024
d1fb870
Working on other sections of the code
kmp5VT Feb 18, 2024
6b83902
parameter_function -> parameter_name
kmp5VT Feb 19, 2024
3e68db2
Update mytype for testing
kmp5VT Feb 19, 2024
00e954b
Another update to mytype
kmp5VT Feb 19, 2024
9084b24
format
kmp5VT Feb 19, 2024
73f9527
Use `compat: assume_effects`
kmp5VT Feb 19, 2024
f1ae64f
update CUDA cu function to use all three buffers
kmp5VT Feb 19, 2024
ebde22d
Remove extra set_datatype function
kmp5VT Feb 19, 2024
d0a39e0
Migrate `datatype` to `parenttype` funciton so `TensorStorage` is `Wr…
kmp5VT Feb 19, 2024
887b8bc
format
kmp5VT Feb 19, 2024
fc5f639
Updates for metal
kmp5VT Feb 19, 2024
7465f07
Update similartype for wrapped types properly
kmp5VT Feb 19, 2024
36c4e75
format
kmp5VT Feb 19, 2024
4757858
Update to use buffer
kmp5VT Feb 20, 2024
c171f7f
Fix typo
kmp5VT Feb 20, 2024
b2eef5c
Some updates
kmp5VT Feb 20, 2024
c81e9a0
Remove parenttype definition
kmp5VT Feb 20, 2024
104a157
Update ndims
kmp5VT Feb 20, 2024
528142b
format
kmp5VT Feb 20, 2024
75e0969
Get `TypeParameterAccessors` working for NDTensors. There arestill ma…
kmp5VT Feb 21, 2024
7b315fc
Small fixes
kmp5VT Feb 21, 2024
1ce0406
Changes to the typeparameter system and get working for 1.6
kmp5VT Feb 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ position(::Type{<:AbstractArray}, ::typeof(eltype)) = Position(1)
position(::Type{<:AbstractArray}, ::typeof(ndims)) = Position(2)

## TODO I don't think this is the right place for this but define it here for now
default_parameter(::Type{<:AbstractArray}, ::typeof(eltype)) = Float64
default_parameter(::Type{<:AbstractArray}, ::typeof(ndims)) = 1
default_parameter(::Type{<:AbstractArray}, ::Position{1}) = Float64
default_parameter(::Type{<:AbstractArray}, ::Position{2}) = 1
Comment on lines +8 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning behind this change?


parameter_name(::Type{<:AbstractArray}, ::Position{1}) = eltype
parameter_name(::Type{<:AbstractArray}, ::Position{2}) = ndims
Expand Down
14 changes: 14 additions & 0 deletions NDTensors/src/lib/TypeParameterAccessors/src/Base/internals.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Relies on Julia internals
@generated to_datatype(::Type{type}) where {type} = Base.unwrap_unionall(type)
#to_datatype(type::DataType) = type

"""
parameters(type::DataType)

Gets all the type parameters of the DataType `type`.
"""
parameters(type::DataType) = Tuple(type.parameters)

@generated to_unionall(type::Type, ::Type{ref_type}) where {ref_type} =
Base.rewrap_unionall(parameter(type), ref_type)
@generated unspecify_parameters(::Type{type}) where {type} = Base.typename(type).wrapper
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module TypeParameterAccessors
include("undefinedposition.jl")
include("Base/internals.jl")
include("parameters.jl")
include("unspecify_parameters.jl")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Get the default parameter of an object which is associated with a specific funct
"""
default_parameter(object, fun::Function) = default_parameter(typeof(object), fun)

default_parameter(type::Type, fun::Function) = default_parameter(type, position(type, fun))

Compat.@assume_effects :foldable function default_parameters(type::Type)
return map(name -> default_parameter(type, name), parameter_names(type))
end
4 changes: 2 additions & 2 deletions NDTensors/src/lib/TypeParameterAccessors/src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# Required overloads, generic fallback
position(::Type, ::Function) = UndefinedPosition()

function default_parameter(type::Type, fun::Function)
return error("The default parameter of function $(fun) is not defined for type $(type)")
function default_parameter(type::Type, name)
return error("The default parameter of $(name) is not defined for type $(type)")
end

UnspecifiedFunction() = nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this should be removed.

Expand Down
31 changes: 20 additions & 11 deletions NDTensors/src/lib/TypeParameterAccessors/src/parameters.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# Relies on Julia internals
@generated to_datatype(::Type{type}) where {type} = Base.unwrap_unionall(type)
to_datatype(type::DataType) = type

"""
parameters(type::DataType)

Gets all the type parameters of the DataType `type`.
"""
parameters(type::DataType) = Tuple(type.parameters)

"""
parameters(type::UnionAll, position::Int)

Expand All @@ -23,6 +12,13 @@ Gets all the type parameters of the object `object`.
"""
parameters(object) = parameters(typeof(object))

struct SpecifiedParameter{N} end
SpecifiedParameter(val) = SpecifiedParameter{is_specified_parameter(val)}()

is_specified_parameter(param)::Bool = true
is_specified_parameter(param::TypeVar)::Bool = false
is_parameter_specified(type::Type, pos) = is_specified_parameter(parameter(type, pos))

"""
parameter(type::Type, position::Int)

Expand Down Expand Up @@ -63,3 +59,16 @@ parameter(x) = parameter(typeof(x))
Gets the number of parameters for the Type `type`.
"""
nparameters(type::Type) = length(parameters(type))

function get_parameter(type::Type, pos)
param = parameter(type, pos)
return _get_parameter(SpecifiedParameter(param), param)
end

function _get_parameter(::SpecifiedParameter{true}, parameter)
return parameter
end

function _get_parameter(::SpecifiedParameter{false}, parameter)
return error("The requested type parameter isn't specified.")
end
4 changes: 2 additions & 2 deletions NDTensors/src/lib/TypeParameterAccessors/src/position.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Position(x) = Position{x}()

Get a type parameter of the type `type` at the position `position`.
"""
parameter(type::Type, position::Position) = parameter(type, int(position))
parameter(type::Type, position::Position) = parameter(type, Int(position))

struct TypeParameter{P} end
TypeParameter(x) = TypeParameter{x}()

int(p::Position) = parameter(p)
Base.Int(p::Position) = parameter(p)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Base.Int(p::Position) = parameter(p)
Base.Int(p::Position) = Int(parameter(p))

to make sure it really outputs Int.


eachposition(type::Type) = ntuple(Position, nparameters(type))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Compat: Compat

Set the parameters of DataType `type` to the tuple `paramters`.
"""
function set_parameters(type::DataType, parameters::Tuple)
Compat.@assume_effects :foldable function set_parameters(type::DataType, parameters::Tuple)
return unspecify_parameters(type){parameters...}
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
using Compat: Compat

Compat.@assume_effects :foldable function specify_parameter(type::Type, pos::Int, param)
return _specify_parameter(parameter(type, pos), type, Position(pos), param)
return _specify_parameter(
SpecifiedParameter(parameter(type, pos)), type, Position(pos), param
)
end

Compat.@assume_effects :foldable function specify_parameter(
type::Type, pos::Position, param
)
return _specify_parameter(parameter(type, pos), type, pos, param)
return _specify_parameter(SpecifiedParameter(parameter(type, pos)), type, pos, param)
end

function _specify_parameter(::TypeVar, type::Type, pos::Position, param)
return set_parameter(type, pos, TypeParameter(param))
end

function _specify_parameter(::TypeVar, type::Type, pos::Position, param::Type)
function _specify_parameter(::SpecifiedParameter{false}, type::Type, pos::Position, param)
return set_parameter(type, pos, param)
end

@generated function _specify_parameter(
::Union{<:Int,<:DataType}, ::Type{Typ}, pos, param
::SpecifiedParameter{true}, ::Type{Typ}, pos, param
) where {Typ}
return Typ
end
Expand All @@ -28,7 +26,7 @@ Compat.@assume_effects :foldable function specify_parameter(
type::Type, fun::Function, param
)
pos = position(type, fun)
return _specify_parameter(parameter(type, pos), type, pos, param)
return _specify_parameter(SpecifiedParameter(parameter(type, pos)), type, pos, param)
end

## TODO document this. You are able to put any type of position,
Expand Down
Loading
Loading