Skip to content

Commit

Permalink
make nx optional (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinschweikert authored Oct 8, 2024
1 parent 2fd5f46 commit 024b737
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions lib/frame.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,19 @@ defmodule Xav.Frame do
}
end

@doc """
Converts a frame to an Nx tensor.
"""
@spec to_nx(t()) :: Nx.Tensor.t()
def to_nx(%__MODULE__{type: :video} = frame) do
frame.data
|> Nx.from_binary(:u8)
|> Nx.reshape({frame.height, frame.width, 3})
end
if Code.ensure_loaded?(Nx) do
@doc """
Converts a frame to an Nx tensor.
"""
@spec to_nx(t()) :: Nx.Tensor.t()
def to_nx(%__MODULE__{type: :video} = frame) do
frame.data
|> Nx.from_binary(:u8)
|> Nx.reshape({frame.height, frame.width, 3})
end

def to_nx(%__MODULE__{type: :audio} = frame) do
Nx.from_binary(frame.data, frame.format)
def to_nx(%__MODULE__{type: :audio} = frame) do
Nx.from_binary(frame.data, frame.format)
end
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defmodule Xav.MixProject do

defp deps do
[
{:nx, "~> 0.7.0"},
{:nx, "~> 0.7.0", optional: true},
{:elixir_make, "~> 0.7", runtime: false},

# dev/test
Expand Down

0 comments on commit 024b737

Please sign in to comment.