Skip to content

Verify mlx.core.full() is already fully implemented - #557

Merged
sydneyrenee merged 1 commit into
mainfrom
copilot/implement-mlx-core-full
Oct 24, 2025
Merged

Verify mlx.core.full() is already fully implemented#557
sydneyrenee merged 1 commit into
mainfrom
copilot/implement-mlx-core-full

Conversation

Copilot AI commented Oct 22, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR confirms that mlx.core.full() is already fully implemented in the codebase. No new code changes were required.

Implementation Status

The mlx.core.full() function was previously implemented and includes:

C++ Native Implementation

  • Location: node/src/native/array.cc (lines 1652-1754)
  • Features:
    • Handles scalar values (numbers, booleans, bigints)
    • Supports MLX arrays with broadcasting
    • Accepts TypedArrays and nested JavaScript arrays
    • Optional dtype parameter with intelligent type inference
    • Optional stream parameter for device control
  • Registration: Properly registered in Init() at line 2215

TypeScript API

  • Location: node/src/core/array.ts (lines 304-312)
  • Signature: full(shape: readonly number[], value: number, dtype?: DType): MLXArray
  • Exports: Available from both mlx.core.full and top-level mlx.full

Test Coverage

  • Location: node/test/core/array.test.ts (lines 75-78)
  • Tests: Validates shape, dtype, and value correctness
  • Example: mlx.core.full([3], 7.5, 'float64')

Python API Parity

The implementation matches the Python MLX API signature:

def full(shape: Union[int, Sequence[int]], 
         vals: Union[scalar, array], 
         dtype: Optional[Dtype] = None, 
         *, 
         stream: Union[None, Stream, Device] = None) -> array

Usage Example

const mlx = require('mlx');

// Create array filled with a scalar value
const arr = mlx.core.full([3, 3], 7.5, 'float64');
console.log(arr.shape);  // [3, 3]
console.log(arr.dtype);  // 'float64'
console.log(arr.toArray());  // [7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5]

Closes issue requesting implementation of mlx.core.full().

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement mlx.core.full()</issue_title>
<issue_description>## 🎯 Implement mlx.core.full()

Priority: medium | Module: core | Type: other | Category: core


📋 Quick Reference

Item Value
Python Source python/src/ops.cpp
Node Target node/src/native/array.cc
Test File node/test/ops.test.js
C++ Namespace mlx::core

🚀 Step-by-Step Implementation

Step 1: Review Python Implementation

# See the Python binding
grep -B 5 -A 30 '"full"' python/src/ops.cpp

Step 2: Implement in Node.js

File to edit: node/src/native/array.cc

Napi::Value Full(const Napi::CallbackInfo& info) {
  auto env = info.Env();
  auto* addon = static_cast<mlx::node::AddonData*>(info.Data());
  
  try {
    mlx::node::Runtime::Instance().EnsureMetalInit();
  } catch (const std::exception& e) {
    Napi::Error::New(env, e.what()).ThrowAsJavaScriptException();
    return env.Null();
  }
  
  // TODO: Parse arguments based on Python signature
  // Check python/src/python/src/ops.cpp for the exact signature
  
  // Example: Parse array argument
  auto* wrapper = UnwrapArray(env, info[0]);
  if (!wrapper) return env.Null();
  const auto& a = wrapper->tensor();
  
  // Parse stream
  auto stream = mlx::core::default_stream(mlx::core::default_device());
  // (adjust index based on number of args)
  if (info.Length() > 1) {
    stream = mlx::node::ParseStreamOrDevice(env, info[info.Length() - 1], *addon);
    if (env.IsExceptionPending()) return env.Null();
  }
  
  try {
    auto result = mlx::core::full(/* args */, stream);
    return WrapArray(env, std::make_shared<mlx::core::array>(std::move(result)));
  } catch (const std::exception& e) {
    Napi::Error::New(env, std::string("full failed: ") + e.what())
        .ThrowAsJavaScriptException();
    return env.Null();
  }
}

Step 3: Register the Function

Add to the Init() function at bottom of node/src/native/array.cc:

core.Set("full", Napi::Function::New(env, Full, "full", &data));

Step 4: Add Tests

File: node/test/ops.test.js

const mx = require('..');

describe('mlx.core.full', () => {
  it('should work correctly', () => {
    // TODO: Add test based on Python tests
    // const a = mx.core.array([1, 2, 3]);
    // const result = mx.core.full(a);
    // expect(result).toBeDefined();
  });
});

📚 Resources

Similar Implementations

Look at these in node/src/native/array.cc:

  • Unary ops: Exp(), Log(), Sin(), Cos()
  • Binary ops: Add(), Multiply(), Subtract()
  • Reductions: Sum(), Mean(), Max(), Min()

Common Patterns

Parse Array:

auto* wrapper = UnwrapArray(env, info[0]);
if (!wrapper) return env.Null();
const auto& a = wrapper->tensor();

Parse Stream:

auto stream = mlx::core::default_stream(mlx::core::default_device());
if (info.Length() > N) {
  stream = mlx::node::ParseStreamOrDevice(env, info[N], *addon);
}

Return Array:

return WrapArray(env, std::make_shared<mlx::core::array>(std::move(result)));

✅ Completion Checklist

  • Reviewed Python implementation
  • Implemented function in node/src/native/array.cc
  • Registered in Init()
  • Added tests in node/test/ops.test.js
  • Builds: cd node && npm run build
  • Tests pass: npm test
  • Updated docs/API_CHECKLIST.md

Auto-generated for MLX Node.js API completeness
</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #505


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Implement mlx.core.full() functionality Verify mlx.core.full() is already fully implemented Oct 22, 2025
Copilot AI requested a review from sydneyrenee October 22, 2025 05:43
@sydneyrenee
sydneyrenee marked this pull request as ready for review October 24, 2025 17:45
@sydneyrenee
sydneyrenee merged commit 1ae8105 into main Oct 24, 2025
6 checks passed
@sydneyrenee
sydneyrenee deleted the copilot/implement-mlx-core-full branch October 24, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement mlx.core.full()

2 participants